Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2073856rwb; Thu, 27 Jul 2023 01:21:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGXoGVYeygpd/x8shLpaftg2M0cuAZP3PN40y5prJkS9FSvMHKVg8neLLMTD12fPGCbd5DB X-Received: by 2002:a17:903:22d0:b0:1b9:c207:1802 with SMTP id y16-20020a17090322d000b001b9c2071802mr4387863plg.0.1690446066000; Thu, 27 Jul 2023 01:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446065; cv=none; d=google.com; s=arc-20160816; b=UJhSGoDPDyZ6VsvLlM9jH95kEzCTym6ClpW9OBUiQKeUhBb+Dq8eNLZ7DwQN0h9s3b VC7iaFRzOMcRmiGOmkIXPMDw7nfbEN03WVaDbxx525ScjRk1sbp0WsOnvugNYciYe9sf sYHLh/TD0On4xTW0bu4b13fpWZn42jeTTcEmDH/tzEgPwzysEHqCecxnEyVBmRqX2ZJX vDixQAPtRMhHDC3jDet3eIMoxKdo0EXKEH/fdoaQeDvsH5UPlPlvVzGG4zQI6aT9pGGy CD0J2qL9L7nEAIfbrhp0snH9Dlb4BcwjWleq5VtPiJ/PQcTifmUj5/vdb/9MZUk5Erj+ p8Zw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; fh=bsub5iJs9v+E5CEQoxVywF7lI7VQh5Icx03Gf/nMSEc=; b=bEzQe1I47SBnp9BSrtFMakco6obVIrzNyX1rnyosCKObgPzxOK9z0FlKhNxHMNgAgj HeqWfxvxETsSXfbhZV5Y/+QqqUZ71xfNdxTEMrfBM8Br1FahQuiciRMhTOrHeTlu+qGx kxlSntU02e/lhkBhEIXZpXqFrl64swUg2r67mxNWmICiy3MOvz+/BVG0MJF9ZgTuKduA LZsw/ryThN3Jrp/JPbdsLtnAiopYfAngtmexYWQGs3jdJUf61ua5Zh0Osc7BmrMk93sS PhZtUwc+HuOCKG+iu5v4s2QbnLLjs7osQ0ObwKXLLanMgnVXep87RUeJLXsVndeTUu5k XYIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=bWsdCjXI; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020a170903301300b001b8af570da3si931391pla.258.2023.07.27.01.20.47; Thu, 27 Jul 2023 01:21:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@bytedance.com header.s=google header.b=bWsdCjXI; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233737AbjG0IKS (ORCPT + 99 others); Thu, 27 Jul 2023 04:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233683AbjG0IKE (ORCPT ); Thu, 27 Jul 2023 04:10:04 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0291BCB for ; Thu, 27 Jul 2023 01:07:02 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-682eef7d752so203231b3a.0 for ; Thu, 27 Jul 2023 01:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445160; x=1691049960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; b=bWsdCjXI/QTCbfrXnl1D1RHs1UzV532bO1xy0F2QKWdmxdeZNg1bc8fwYppoEa2Sii fv3Dw05OLiEoJFGdDqA0cK2BR0yissZW0QGh0p8G2jYOCo1VM3qmhhRKOuDu3Ld44+HC IlU/6E6PL7OGmulpkRgvQIFGvR7K7vSKmFATJlzNsM5VU0kfb+Q9ux9XLDln9HSGLjNa erFo50JbYYva+gdlhuASAFmcGCxJk1UklUElA3OcQq/NsulVXFSALP8x8A3jEL8k5O2s pAuqLDXkBW250K5e8xHlcez81V5k+DmAOms7sfdEUrryxL8JhS9LUOK5EJtF0pDaEYI9 8JWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445160; x=1691049960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; b=SMPnSTGzar/iJQ6vamjNnQcqi49QoGRHZ/aWOFp37efe1+v8yTcB8XYCrvO39MK/1w FOMtpSoJDtYcxpnqGyfZOF2mduAAoi6oh8yOATDO/Hxs7BLzz36EHFmOc/DQFrvtTHji up0ucnObMaBAcjuQ8PH4GAubKF9o5MDauNOQK4U8MECUvjv5Rpv3gNg+oM5kd5hquy5k nlJdhB+VXJpv/E6s0VI5NXJ6KfrilyGYzSVg2xCSTimB6fcKZb1whBR/iSoVYpbb7iGt Hq6yuNUtrtV6zT6837ZV3Ukk3dWJwiFOEenxgEhjrBYSHlTdEomUpPszDPGj/wufQNhr tyIA== X-Gm-Message-State: ABy/qLYmVEDvXAcODYUO6JatQbRTbqftmXY4FvGvBzzb8V/VR9Osc6bi 6usZdLzLuyeiTVDrf+fyX0WymQ== X-Received: by 2002:a05:6a21:78a8:b0:137:3eba:b81f with SMTP id bf40-20020a056a2178a800b001373ebab81fmr6002609pzc.3.1690445159927; Thu, 27 Jul 2023 01:05:59 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:05:59 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng , Carlos Llamas Subject: [PATCH v3 01/49] binder: fix memory leak in binder_init() Date: Thu, 27 Jul 2023 16:04:14 +0800 Message-Id: <20230727080502.77895-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-nfs@vger.kernel.org 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. Fixes: f2517eb76f1f ("android: binder: Add global lru shrinker to binder") Signed-off-by: Qi Zheng Acked-by: Carlos Llamas --- 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