Message ID | 20230625154937.64316-1-qi.zheng@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6984062vqr; Sun, 25 Jun 2023 09:02:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rhX+/mRH2FCgP/qgyIGC0RqP1ogDxPJyp4IFrQ2dSXnDIIUoFylchxMQliOSa0I0uwBfS X-Received: by 2002:a17:907:2ce9:b0:98e:2423:708 with SMTP id hz9-20020a1709072ce900b0098e24230708mr1850029ejc.62.1687708956398; Sun, 25 Jun 2023 09:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687708956; cv=none; d=google.com; s=arc-20160816; b=cNvI10a0SArlnOrQqfTsHMZVSS1OhlkTF8EfeWIjkCsxYANz0hOAipVWJpNUrXDnLk a/PDB8kqj7BF57WNXoZTYwcqh8/qztkyJS5Rn/tAHeU41oAif7wYT5wE86hBsgMZCa46 wrsYcp/bFoWgYNU1pDWHU0sU8DxOCt+VEBI18uhVYq5ph5UnWKeGfbN88z6zrOnqmvKV o8NW9pyjv2QSFriO7FOXDDyKpJJsxDsGG4YnxInGTM6oMEM7pCXeHhHg6TlIi3r0UG4Y JCKCekuEKi1Vrvoc0NwG39krMvoo/0BxzIPVRKiKA0o0XEFSTnOlETv3B8zOTGNtFL1x 8uWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Q/q3dtLrCdlJ7WBbM40cZSb4jbe1BvLJqZ9PUXcu0LQ=; fh=zJySvKWxwXgr+JoHZOajLIPo+LjKx+AMcAiUcWSYRCU=; b=vSJOwB1ZAbhW8tqC/E1Qu4L8JJSNBLGHsSfpVP9orsAurBWR4YSCOA1o9r9J+egI9o OMwvmbuBMxMk8EkYKYqKf1agFnVKCQXgA0DOLhOoypZAqeQ69yhkEzs+34PXXfuEOA6l gMSuqFZ5xMls4CVxFrYCEaC3jOLgBVuPmYiOpid6Bn29418Rv3fZqV9YGv2gPWBiqrxn JUXzk+z9kbaNM4cFmayJ27NO3BL5iKiRZvEygvH2lX0yKQonFGn5kWMEagJXLXNT6/2d 3riP4kceops8e0ZNFqjYegK3CoDXJn5saE3r4R8peeIpykgnA3gI02AnKEve/WW+Vh7w +YPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ta3IybJO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gx4-20020a170906f1c400b0098f564f6369si446880ejb.1006.2023.06.25.09.01.41; Sun, 25 Jun 2023 09:02:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ta3IybJO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjFYPuP (ORCPT <rfc822;duw91626@gmail.com> + 99 others); Sun, 25 Jun 2023 11:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjFYPuO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 25 Jun 2023 11:50:14 -0400 Received: from out-55.mta1.migadu.com (out-55.mta1.migadu.com [IPv6:2001:41d0:203:375::37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFD0A91 for <linux-kernel@vger.kernel.org>; Sun, 25 Jun 2023 08:50:11 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1687708209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Q/q3dtLrCdlJ7WBbM40cZSb4jbe1BvLJqZ9PUXcu0LQ=; b=ta3IybJOsQx57BtZ8tuN+hHqmjFjPxJptHp/LVOmYQvnA7KQQFfVzzxUU1cvlaaZHAAAb+ US1AJ7nxSln2f8RCUzAFbCAYw4Het9pZbPuyTYkIU9YUJWIEXpNn/8Tgqnl8XhpIO/Uo6G 7s41M4HfZqTs3R9Trkqt8FEXDiZ0Mm4= From: Qi Zheng <qi.zheng@linux.dev> To: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, brauner@kernel.org, cmllamas@google.com, surenb@google.com Cc: linux-kernel@vger.kernel.org, Qi Zheng <zhengqi.arch@bytedance.com> Subject: [PATCH] binder: fix memory leak in binder_init() Date: Sun, 25 Jun 2023 15:49:37 +0000 Message-Id: <20230625154937.64316-1-qi.zheng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769691106678250825?= X-GMAIL-MSGID: =?utf-8?q?1769691106678250825?= |
Series |
binder: fix memory leak in binder_init()
|
|
Commit Message
Qi Zheng
June 25, 2023, 3:49 p.m. UTC
From: Qi Zheng <zhengqi.arch@bytedance.com> In binder_init(), the destruction of binder_alloc_shrinker_init() is not performed in the wrong path, which will cause memory leaks. So this commit introduces binder_alloc_shrinker_exit() and calls it in the wrong path to fix that. Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> --- drivers/android/binder.c | 1 + drivers/android/binder_alloc.c | 6 ++++++ drivers/android/binder_alloc.h | 1 + 3 files changed, 8 insertions(+)
Comments
On Sun, Jun 25, 2023 at 03:49:37PM +0000, Qi Zheng wrote: > From: Qi Zheng <zhengqi.arch@bytedance.com> > > In binder_init(), the destruction of binder_alloc_shrinker_init() is not > performed in the wrong path, which will cause memory leaks. So this commit > introduces binder_alloc_shrinker_exit() and calls it in the wrong path to > fix that. > > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> > --- > drivers/android/binder.c | 1 + > drivers/android/binder_alloc.c | 6 ++++++ > drivers/android/binder_alloc.h | 1 + > 3 files changed, 8 insertions(+) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 486c8271cab7..d720f93d8b19 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -6617,6 +6617,7 @@ static int __init binder_init(void) > > err_alloc_device_names_failed: > debugfs_remove_recursive(binder_debugfs_dir_entry_root); > + binder_alloc_shrinker_exit(); > > return ret; > } > diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c > index 662a2a2e2e84..e3db8297095a 100644 > --- a/drivers/android/binder_alloc.c > +++ b/drivers/android/binder_alloc.c > @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) > return ret; > } > > +void binder_alloc_shrinker_exit(void) > +{ > + unregister_shrinker(&binder_shrinker); > + list_lru_destroy(&binder_alloc_lru); > +} > + > /** > * check_buffer() - verify that buffer/offset is safe to access > * @alloc: binder_alloc for this proc > diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h > index 138d1d5af9ce..dc1e2b01dd64 100644 > --- a/drivers/android/binder_alloc.h > +++ b/drivers/android/binder_alloc.h > @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, > int pid); > extern void binder_alloc_init(struct binder_alloc *alloc); > extern int binder_alloc_shrinker_init(void); > +extern void binder_alloc_shrinker_exit(void); > extern void binder_alloc_vma_close(struct binder_alloc *alloc); > extern struct binder_buffer * > binder_alloc_prepare_to_free(struct binder_alloc *alloc, > -- > 2.30.2 > Thanks for the fix Qi Zheng. Acked-by: Carlos Llamas <cmllamas@google.com>
On 2023/6/25 23:49, Qi Zheng wrote: > From: Qi Zheng <zhengqi.arch@bytedance.com> > > In binder_init(), the destruction of binder_alloc_shrinker_init() is not > performed in the wrong path, which will cause memory leaks. So this commit > introduces binder_alloc_shrinker_exit() and calls it in the wrong path to > fix that. > > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> Oh, I forgot to add Fixes tag: Fixes: f2517eb76f1f ("android: binder: Add global lru shrinker to binder") > --- > drivers/android/binder.c | 1 + > drivers/android/binder_alloc.c | 6 ++++++ > drivers/android/binder_alloc.h | 1 + > 3 files changed, 8 insertions(+) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 486c8271cab7..d720f93d8b19 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -6617,6 +6617,7 @@ static int __init binder_init(void) > > err_alloc_device_names_failed: > debugfs_remove_recursive(binder_debugfs_dir_entry_root); > + binder_alloc_shrinker_exit(); > > return ret; > } > diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c > index 662a2a2e2e84..e3db8297095a 100644 > --- a/drivers/android/binder_alloc.c > +++ b/drivers/android/binder_alloc.c > @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) > return ret; > } > > +void binder_alloc_shrinker_exit(void) > +{ > + unregister_shrinker(&binder_shrinker); > + list_lru_destroy(&binder_alloc_lru); > +} > + > /** > * check_buffer() - verify that buffer/offset is safe to access > * @alloc: binder_alloc for this proc > diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h > index 138d1d5af9ce..dc1e2b01dd64 100644 > --- a/drivers/android/binder_alloc.h > +++ b/drivers/android/binder_alloc.h > @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, > int pid); > extern void binder_alloc_init(struct binder_alloc *alloc); > extern int binder_alloc_shrinker_init(void); > +extern void binder_alloc_shrinker_exit(void); > extern void binder_alloc_vma_close(struct binder_alloc *alloc); > extern struct binder_buffer * > binder_alloc_prepare_to_free(struct binder_alloc *alloc,
On 2023/6/26 00:16, Carlos Llamas wrote: > On Sun, Jun 25, 2023 at 03:49:37PM +0000, Qi Zheng wrote: >> From: Qi Zheng <zhengqi.arch@bytedance.com> >> >> In binder_init(), the destruction of binder_alloc_shrinker_init() is not >> performed in the wrong path, which will cause memory leaks. So this commit >> introduces binder_alloc_shrinker_exit() and calls it in the wrong path to >> fix that. >> >> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> >> --- >> drivers/android/binder.c | 1 + >> drivers/android/binder_alloc.c | 6 ++++++ >> drivers/android/binder_alloc.h | 1 + >> 3 files changed, 8 insertions(+) >> >> diff --git a/drivers/android/binder.c b/drivers/android/binder.c >> index 486c8271cab7..d720f93d8b19 100644 >> --- a/drivers/android/binder.c >> +++ b/drivers/android/binder.c >> @@ -6617,6 +6617,7 @@ static int __init binder_init(void) >> >> err_alloc_device_names_failed: >> debugfs_remove_recursive(binder_debugfs_dir_entry_root); >> + binder_alloc_shrinker_exit(); >> >> return ret; >> } >> diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c >> index 662a2a2e2e84..e3db8297095a 100644 >> --- a/drivers/android/binder_alloc.c >> +++ b/drivers/android/binder_alloc.c >> @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) >> return ret; >> } >> >> +void binder_alloc_shrinker_exit(void) >> +{ >> + unregister_shrinker(&binder_shrinker); >> + list_lru_destroy(&binder_alloc_lru); >> +} >> + >> /** >> * check_buffer() - verify that buffer/offset is safe to access >> * @alloc: binder_alloc for this proc >> diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h >> index 138d1d5af9ce..dc1e2b01dd64 100644 >> --- a/drivers/android/binder_alloc.h >> +++ b/drivers/android/binder_alloc.h >> @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, >> int pid); >> extern void binder_alloc_init(struct binder_alloc *alloc); >> extern int binder_alloc_shrinker_init(void); >> +extern void binder_alloc_shrinker_exit(void); >> extern void binder_alloc_vma_close(struct binder_alloc *alloc); >> extern struct binder_buffer * >> binder_alloc_prepare_to_free(struct binder_alloc *alloc, >> -- >> 2.30.2 >> > > Thanks for the fix Qi Zheng. > > Acked-by: Carlos Llamas <cmllamas@google.com> Hi Greg, Can this patch be merged? The Fixes tag is: Fixes: f2517eb76f1f ("android: binder: Add global lru shrinker to binder") Thanks, Qi
diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 486c8271cab7..d720f93d8b19 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -6617,6 +6617,7 @@ static int __init binder_init(void) err_alloc_device_names_failed: debugfs_remove_recursive(binder_debugfs_dir_entry_root); + binder_alloc_shrinker_exit(); return ret; } diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 662a2a2e2e84..e3db8297095a 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) return ret; } +void binder_alloc_shrinker_exit(void) +{ + unregister_shrinker(&binder_shrinker); + list_lru_destroy(&binder_alloc_lru); +} + /** * check_buffer() - verify that buffer/offset is safe to access * @alloc: binder_alloc for this proc diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h index 138d1d5af9ce..dc1e2b01dd64 100644 --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, int pid); extern void binder_alloc_init(struct binder_alloc *alloc); extern int binder_alloc_shrinker_init(void); +extern void binder_alloc_shrinker_exit(void); extern void binder_alloc_vma_close(struct binder_alloc *alloc); extern struct binder_buffer * binder_alloc_prepare_to_free(struct binder_alloc *alloc,