From mboxrd@z Thu Jan 1 00:00:00 1970 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 BAEF4C32793 for ; Tue, 23 Aug 2022 03:02:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE6B38D0007; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6B438D0006; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BB6F8D0007; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3FC828D0001 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 15CB8AB917 for ; Tue, 23 Aug 2022 03:02:41 +0000 (UTC) X-FDA: 79829359722.13.E865CB6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf19.hostedemail.com (Postfix) with ESMTP id 5D6F41A0004 for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MBYq14qbZzlWNY; Tue, 23 Aug 2022 10:59:25 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 23 Aug 2022 11:02:37 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 5/6] mm/hugetlb: fix sysfs group leak in hugetlb_unregister_node() Date: Tue, 23 Aug 2022 11:02:08 +0800 Message-ID: <20220823030209.57434-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220823030209.57434-1-linmiaohe@huawei.com> References: <20220823030209.57434-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223760; a=rsa-sha256; cv=none; b=Y30Bk+SSBalL+AcpBAWHBmYfqiZUvVpj+9oyrQBLcxleEWHyMXNzUibvMvpDTF2/JYmien q03fTa37CnEBjl7RQfldPiANea0wuJTxcH7zi7tdpIwNWv/jcfvYQoq1K7/wYCE24tyEUB ex76yXIhLKSQ9sxyNZe/Z20gg6i8wjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661223760; 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:in-reply-to:references:references; bh=zhci06CO/PLpDAlLPJASM2jNWqIKNvN/37VvjQj5+c0=; b=kZ9bTrmU5XGwL4AnZiqVneFFH/eJ9VmQ+r7gAdxw8omymK3fIVfmN4DRwl5G/9wlD9qZWj cvzJMxFfvpRO/JpzjRZt7dogRWTWN+eKCFhKTZpraK0Qnio+ElFgGMjp2MaUWpjFO3K+6V JujJJnS4UPYgcycOaWEb8iqHCS1Fnn0= Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: o3a67shmsyoq7rt6m1fhkd84pnsto5tn X-Rspamd-Queue-Id: 5D6F41A0004 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1661223760-430856 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: The sysfs group per_node_hstate_attr_group and hstate_demote_attr_group when h->demote_order != 0 are created in hugetlb_register_node(). But these sysfs groups are not removed when unregister the node, thus sysfs group is leaked. Using sysfs_remove_group() to fix this issue. Signed-off-by: Miaohe Lin Reviewed-by: Fengwei Yin --- mm/hugetlb.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8e62da153c64..2dfd10599f98 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3851,12 +3851,18 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, } if (h->demote_order) { - if (sysfs_create_group(hstate_kobjs[hi], - &hstate_demote_attr_group)) + retval = sysfs_create_group(hstate_kobjs[hi], + &hstate_demote_attr_group); + if (retval) { pr_warn("HugeTLB unable to create demote interfaces for %s\n", h->name); + sysfs_remove_group(hstate_kobjs[hi], hstate_attr_group); + kobject_put(hstate_kobjs[hi]); + hstate_kobjs[hi] = NULL; + return retval; + } } - return retval; + return 0; } static void __init hugetlb_sysfs_init(void) @@ -3942,10 +3948,15 @@ static void hugetlb_unregister_node(struct node *node) for_each_hstate(h) { int idx = hstate_index(h); - if (nhs->hstate_kobjs[idx]) { - kobject_put(nhs->hstate_kobjs[idx]); - nhs->hstate_kobjs[idx] = NULL; - } + struct kobject *hstate_kobj = nhs->hstate_kobjs[idx]; + + if (!hstate_kobj) + continue; + if (h->demote_order) + sysfs_remove_group(hstate_kobj, &hstate_demote_attr_group); + sysfs_remove_group(hstate_kobj, &per_node_hstate_attr_group); + kobject_put(hstate_kobj); + nhs->hstate_kobjs[idx] = NULL; } kobject_put(nhs->hugepages_kobj); -- 2.23.0