From patchwork Mon Oct 24 07:42:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13016743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17B90C3A59D for ; Mon, 24 Oct 2022 06:54:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 272D28E0005; Mon, 24 Oct 2022 02:54:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2220F8E0003; Mon, 24 Oct 2022 02:54:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 074408E0005; Mon, 24 Oct 2022 02:54:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA6C48E0001 for ; Mon, 24 Oct 2022 02:54:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B110BA0A60 for ; Mon, 24 Oct 2022 06:54:06 +0000 (UTC) X-FDA: 80054928492.20.59F5896 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf24.hostedemail.com (Postfix) with ESMTP id B0E8418000C for ; Mon, 24 Oct 2022 06:54:04 +0000 (UTC) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mwm4s0W3rzHv6T; Mon, 24 Oct 2022 14:53:49 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 24 Oct 2022 14:53:59 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 24 Oct 2022 14:53:59 +0800 From: Liu Shixin To: Christoph Lameter , Pekka Enberg , "David Rientjes" , Joonsoo Kim , "Andrew Morton" , Vlastimil Babka , "Roman Gushchin" , Hyeonggon Yoo <42.hyeyoo@gmail.com> CC: , , Liu Shixin Subject: [PATCH 0/4] Refactor __kmem_cache_create() and fix memory leak Date: Mon, 24 Oct 2022 15:42:28 +0800 Message-ID: <20221024074232.151383-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666594445; a=rsa-sha256; cv=none; b=1J7E3e/gkN9r37DnB2/SYXDygLx7oDiyfy69ygXXPSt7HhRzGsRpHPrzJi+t/IaUlE6jyo G+wxmvV5h4pazPGiNDqox22MMsof09x3p142SCP5i4XbcR4mdEBaP4EKLgSaesTPgE2NNG LxwUTD8VYTGlHsEyJkUAQs5HDFAu+Uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666594445; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=0IjFUltHyK07G1GPt2XiUKPBSQRyQImxlTM+8jUad+4=; b=glbGH0d/KTJplEMCZjVFAOncPR4JGHybyRcGOcDoZXv0Zf+2TaaK8jk0aPdiLLbAj0cHtG KyxLGnR6qJcCMye7nGWoAGlHhvCWSn8EmkdMH7dmQzfipdQrYe9dZoal5kvHcs5zrIPCzO 8lCuy6kZvQBzNpkEPP6nEg5kivbIT4w= Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: jb1gwnqph17ugg97xf8ypqcxwyeft6mj X-Rspamd-Queue-Id: B0E8418000C X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666594444-300965 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: I found a memory leak of kobj->name in sysfs_slab_add() which is introduced by 80da026a8e5d ("mm/slub: fix slab double-free in case of duplicate sysfs filename"). Following the rules stated in the comment for kobject_init_and_add(): If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. We should use kobject_put() to free kobject. But we can't simply add kobject_put() since it will free kmem_cache too. If we use kobject_put(), we need to skip other release functions. In this series, We refactor the code to separate sysfs_slab_add() and debugfs_slab_add() from __kmem_cache_create(), and then use kobject_put() to free kobject in sysfs_slab_add(). This can fix the memory leak of kobject->name. Liu Shixin (4): mm/slab_common: Move cache_name to create_cache() mm/slub: rename kmem_cache_release to slab_release in slub.c mm/slab_common: Separate sysfs_slab_add() and debugfs_slab_add() from __kmem_cache_create() mm/slab_common: Fix memory leak of kobj->name in sysfs_slab_add() include/linux/slub_def.h | 11 ++++++++ mm/slab_common.c | 42 ++++++++++++++++-------------- mm/slub.c | 56 +++++++++++----------------------------- 3 files changed, 48 insertions(+), 61 deletions(-)