From patchwork Sat Nov 12 11:20:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13041160 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 79585C43219 for ; Sat, 12 Nov 2022 10:33:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEF206B0074; Sat, 12 Nov 2022 05:33:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D27B6B007B; Sat, 12 Nov 2022 05:33:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8261A6B007E; Sat, 12 Nov 2022 05:33:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 59A206B0071 for ; Sat, 12 Nov 2022 05:33:07 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 23DAFA0B1C for ; Sat, 12 Nov 2022 10:33:07 +0000 (UTC) X-FDA: 80124427614.17.765CF4A Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 0BC6940008 for ; Sat, 12 Nov 2022 10:33:04 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N8X2h3snRz15MWp; Sat, 12 Nov 2022 18:32:44 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 18:33:00 +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; Sat, 12 Nov 2022 18:33:00 +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 v3 0/3] Refactor __kmem_cache_create() and fix memory leak Date: Sat, 12 Nov 2022 19:20:52 +0800 Message-ID: <20221112112055.1111078-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668249186; 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=A+R6Sfkz+HHsksf4ohcdBjT+68ofgbHKJq/9PCDUoy0=; b=aTOzDFwTeC1V5MN/9JhkIVOpkK8q7S4aJMx0gnMDmZlEABc7+TtJMjOG3UeW7Zupk/zdac MdEhxQN54wWFwUuxRe2FVb+70GsBRzPct88/C/3KkeEy8LUix//K1asqvtB/xEpXrAlftb ZPqr0V+MsW6MvSg9BP+jjQnoy7Zpf0s= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 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=1668249186; a=rsa-sha256; cv=none; b=lPYS4QfGF1TF1vO12RlphkITkHbQnBahoD2BtMUXHsgK6TzGIcCQikxp5CFAgaF3q25tgX Ca0I0b8SiyR6Jztlqraco3i6D4MWqdjQkY895lofizVpxapnMlH++KxlkSmn1AQg0b+Y40 lGNf9/m4t14S2521SSigUuuTfzCiGQs= X-Stat-Signature: fbopdat6rxh4sg14ufzpt85g99puus15 X-Rspamd-Queue-Id: 0BC6940008 Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1668249184-662628 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. v1->v2: Fix build error reported by kernel test robot . v2->v3: Don't free kmem_cache that create early. Liu Shixin (3): mm/slab_common: Move cache_name to create_cache() mm/slub: Refactor __kmem_cache_create() mm/slub: Fix memory leak of kobj->name in sysfs_slab_add() include/linux/slub_def.h | 11 +++++++ mm/slab_common.c | 44 +++++++++++++++------------- mm/slub.c | 63 +++++++++++++++------------------------- 3 files changed, 58 insertions(+), 60 deletions(-)