From patchwork Mon Oct 31 13:47:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13025834 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 9123DECAAA1 for ; Mon, 31 Oct 2022 12:59:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5C706B007B; Mon, 31 Oct 2022 08:59:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0C438E0001; Mon, 31 Oct 2022 08:59:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AD726B007E; Mon, 31 Oct 2022 08:59:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 76E056B007B for ; Mon, 31 Oct 2022 08:59:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F3640A0926 for ; Mon, 31 Oct 2022 12:59:44 +0000 (UTC) X-FDA: 80081251488.17.E70207E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf03.hostedemail.com (Postfix) with ESMTP id 8B84920017 for ; Mon, 31 Oct 2022 12:59:42 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N1Cm05fb0zVjHr; Mon, 31 Oct 2022 20:54:40 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 20:59:35 +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, 31 Oct 2022 20:59:35 +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 v2 0/3] Refactor __kmem_cache_create() and fix memory leak Date: Mon, 31 Oct 2022 21:47:44 +0800 Message-ID: <20221031134747.3049593-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: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667221183; a=rsa-sha256; cv=none; b=CLSD7FHV7MwR4sWH/WpJuUPlV8nk9WMTpqtzOL5Q7WHa0dPRGWJ6g6QGECQL2w/kpwWaBc dR2ZfdnJXott2Eyb5SS3/8ehBWL6+pb1iU2LIoDEF2SUdvT+7CvmXhX6mxu1wM0r5S7ZsO /z6Pkg8teeOJ6R8+qb/kWTEb6Ml2Tmw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667221183; 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=dvXocsrLjIJThzVDFY+iFxXxz9p3I3ebM6bC+htXeD0=; b=D6dTbExttwWjWh1y29zBRjedXQ9l2L31WfHYMkbiu7OPzQ5YqmH8REladYB4ypD3oDARmu nlEqCW//Psj65d+fPCyYAzn5JaINH++zypdxSHbzsfJDEav45sPY8kEvOHGs3I73HMHDj1 Jh+AoP7qUXwDB/IOhd7d7b7vB6PM+DI= Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8B84920017 X-Stat-Signature: b1m4yisu3emspsgachot5pkxmwdgp3ws X-Rspam-User: X-HE-Tag: 1667221182-121883 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 . 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 | 52 ++++++++++------------------------------ 3 files changed, 48 insertions(+), 59 deletions(-)