From patchwork Tue Aug 23 03:02:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951656 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 7AB3CC28D13 for ; Tue, 23 Aug 2022 03:02:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16F438D0008; Mon, 22 Aug 2022 23:02:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 080C48D0001; 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 AE2638D0001; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 630A58D0001 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3BE83161379 for ; Tue, 23 Aug 2022 03:02:41 +0000 (UTC) X-FDA: 79829359722.05.C1845EA Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf16.hostedemail.com (Postfix) with ESMTP id 989D6180009 for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MBYpg5lkbz1N7Yg; Tue, 23 Aug 2022 10:59:07 +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:35 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 1/6] mm/hugetlb: fix incorrect update of max_huge_pages Date: Tue, 23 Aug 2022 11:02:04 +0800 Message-ID: <20220823030209.57434-2-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 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223760; a=rsa-sha256; cv=none; b=ZnqWEHsHoLQAMtG3jWjqxzv+eE4+XJxBlWdlxrsAjcfI53CrgwEkjwvgq623haDWqTjFzl heOy0zUmJCdsdTmZkO4JJ36hwXRNMPARxngv3UWb1uulHZmdW85PBZq6bivNvYsinznGB5 x1vL3jbhaozsjHdoLqBnAjmWMIvfgXU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com 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=keVTywJflwEJgCckn2VIGDICCp5S9FDDsuQUkAZ/RHk=; b=4euD5mtC8rzqzzDcH9hfSUVmdI01B9IXhruwVdZhvXybjLjmg8rakz29ftyzwmnKiO6XAt Vl4m+g6O2BLm42yxCtSNoZReXHV1QR36a8zB9y/iaBoyp6AW740nseDPMwX9QpiT2RnAoX yitjx8My6BUJ3KwWRELlvJY4a9JZcmQ= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 989D6180009 X-Stat-Signature: pe4auop1mn8e8kzuins6jhee9t59ozme X-HE-Tag: 1661223760-494626 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: There should be pages_per_huge_page(h) / pages_per_huge_page(target_hstate) pages incremented for target_hstate->max_huge_pages when page is demoted. Update max_huge_pages accordingly for consistency. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/hugetlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f8f1540108ab..19a7a83af569 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3473,7 +3473,8 @@ static int demote_free_huge_page(struct hstate *h, struct page *page) * based on pool changes for the demoted page. */ h->max_huge_pages--; - target_hstate->max_huge_pages += pages_per_huge_page(h); + target_hstate->max_huge_pages += + pages_per_huge_page(h) / pages_per_huge_page(target_hstate); return rc; } From patchwork Tue Aug 23 03:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951654 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 83834C32774 for ; Tue, 23 Aug 2022 03:02:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E66C8D0003; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F3398D0008; 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 514C48D0003; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) 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 28C698D0003 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E330EC1377 for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) X-FDA: 79829359680.22.AF3E73A Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf24.hostedemail.com (Postfix) with ESMTP id EFC0B18004F for ; Tue, 23 Aug 2022 03:02:39 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MBYnl5CwSzXdyw; Tue, 23 Aug 2022 10:58:19 +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:36 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 2/6] mm/hugetlb: fix WARN_ON(!kobj) in sysfs_create_group() Date: Tue, 23 Aug 2022 11:02:05 +0800 Message-ID: <20220823030209.57434-3-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 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223760; a=rsa-sha256; cv=none; b=qLg3AWeK4liWHoMWY5s3WTXOF8IhEPfYjTzOXV1Eo8HKK+9p0njvDVnahXpoBMZWjaxFox 10x5CQy7I5tco+//zSZPHUkDJWt2udnAEFBthuNyEdJNxm/MIuGsynuLmxAKdR6pQozfRL rSqeMQ8JUtHVq0nRTc1Icoe2lBHQ/Eg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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-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=vDlx3jrWgZWh824jEUgO3qxGyaYWfa5Jsj80MVyFH/Q=; b=QaCSlnQAq/joqym+nMHu0YZDf3yV9Y/xWQVJgJ5OySRIk6O/FJG7Bu84kqcoCUZrkTatxb ySZyrKuT/ByQLEuQwBYEhhe/7NkCgGVfuYIRCVYnNcw+9gnrXeTLeFdGo+mUrFxQXNB2B7 /F4KMGAELChQ+wMa76sCiZRz7KQgg2E= X-Rspamd-Queue-Id: EFC0B18004F X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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-Rspamd-Server: rspam01 X-Stat-Signature: z3nwdzrw3ohnguzmcfd5tg9e7e6gdm46 X-HE-Tag: 1661223759-715287 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: If sysfs_create_group() fails with hstate_attr_group, hstate_kobjs[hi] will be set to NULL. Then it will be passed to sysfs_create_group() if h->demote_order != 0 thus triggering WARN_ON(!kobj) check. Fix this by making sure hstate_kobjs[hi] != NULL when calling sysfs_create_group. Fixes: 79dfc695525f ("hugetlb: add demote hugetlb page sysfs interfaces") Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 19a7a83af569..d46dfe5ba62c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3847,6 +3847,7 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, if (retval) { kobject_put(hstate_kobjs[hi]); hstate_kobjs[hi] = NULL; + return retval; } if (h->demote_order) { From patchwork Tue Aug 23 03:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951653 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 C0568C32789 for ; Tue, 23 Aug 2022 03:02:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 518CF8D0005; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A0CA8D0006; 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 2D8AD8D0005; Mon, 22 Aug 2022 23:02:41 -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 160A98D0001 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E56078135F for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) X-FDA: 79829359680.23.4313702 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf27.hostedemail.com (Postfix) with ESMTP id 4ADCE4000F for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MBYq04wSszlWRv; Tue, 23 Aug 2022 10:59:24 +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:36 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 3/6] mm/hugetlb: fix missing call to restore_reserve_on_error() Date: Tue, 23 Aug 2022 11:02:06 +0800 Message-ID: <20220823030209.57434-4-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 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-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=Kqkn5SxGMf5GwNIiPFaKP+kjkG9eONWj7GoENs/VlYc=; b=Nmen5lG6WuGKVQqow+6rYldyYh1LSFQ8mtumQPn9W8UkcgovoejCYKnNIwWV3kIdE5eXOk ZOoDEmwNOjrQ9RBiSEIqus6goyPEUtiu7HVe6kxDkrYDjTd20rskykwknBGgVOOqKnhW/j ee9xp9qy6v7RuIfKxcpVK1kKrg0sKg8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223760; a=rsa-sha256; cv=none; b=012Ukdp6OheawWZknvO/y/SYRiUP312jUCz8xSr/WZn8jAqF4meZ34+TMS5kdJ/VnPNbED JBoqehyQr1E9D/Bxv1szd26bpKsCyv448//09l3D63QecwFiSGs9L8SiXVyMP/5ArEMWUe H40RmjA7L+bb7sHPpzZBg81GMCAD5/M= X-Rspamd-Queue-Id: 4ADCE4000F X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam03 X-Stat-Signature: 4aeayixcwakd33zxmhr5ufwui855smqq X-HE-Tag: 1661223760-113217 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: When huge_add_to_page_cache() fails, the page is freed directly without calling restore_reserve_on_error() to restore reserve for newly allocated pages not in page cache. Fix this by calling restore_reserve_on_error() when huge_add_to_page_cache fails. Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d46dfe5ba62c..8e62da153c64 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5576,7 +5576,6 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, if (idx >= size) goto out; -retry: new_page = false; page = find_lock_page(mapping, idx); if (!page) { @@ -5616,9 +5615,15 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, if (vma->vm_flags & VM_MAYSHARE) { int err = huge_add_to_page_cache(page, mapping, idx); if (err) { + /* + * err can't be -EEXIST which implies someone + * else consumed the reservation since hugetlb + * fault mutex is held when add a hugetlb page + * to the page cache. So it's safe to call + * restore_reserve_on_error() here. + */ + restore_reserve_on_error(h, vma, haddr, page); put_page(page); - if (err == -EEXIST) - goto retry; goto out; } new_pagecache_page = true; From patchwork Tue Aug 23 03:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951657 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 90F09C32774 for ; Tue, 23 Aug 2022 03:02:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B6478D0001; Mon, 22 Aug 2022 23:02:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31B008D0009; Mon, 22 Aug 2022 23:02:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF71C8D000A; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B03558D0008 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 867D9141392 for ; Tue, 23 Aug 2022 03:02:41 +0000 (UTC) X-FDA: 79829359722.19.8A0EB95 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf24.hostedemail.com (Postfix) with ESMTP id A21E118003C for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MBYr355K3zhYC2; Tue, 23 Aug 2022 11:00:19 +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 4/6] mm: hugetlb_vmemmap: add missing smp_wmb() before set_pte_at() Date: Tue, 23 Aug 2022 11:02:07 +0800 Message-ID: <20220823030209.57434-5-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 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-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=79T6XfuYSWh/t3Z82G3AULdVuMX2a1/3yuX3xG/QCJ0=; b=GSabQeKV6fIbFVyYMLexMx7eq65Xmu0Si9+0N+E/zJ+h49spiUXE+dLDFBia01ci7fRHS6 w8EyR6iWhXO4fIHu2OohYGjqGuAtX+7bkQ8MOgPHGPNw6mj5uywn6hjcnL9Da+oCnh+bvz 1AoxvR890GJ1xvkFrOONDvyet/YKoAQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 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=djUYS2UDMJnEuTTnkDxiPERK3z2SeuxEwfqlXVuzkgWRAeeGhRHluF+xGoaloUxhsgU4CT 7QljNJpCgJmgGSY4B1OWnVT8e/dM0nUp62jRplJ9exm5k1zwwWcbMPefYMgBqvSObAYIbB o583iJ5wDl33W3jjTYehMWB1uTxRZC4= X-Stat-Signature: 7g6kz9ors5cu4duygqkp8tioy6ehjcie Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A21E118003C X-Rspam-User: X-HE-Tag: 1661223760-887160 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 memory barrier smp_wmb() is needed to make sure that preceding stores to the page contents become visible before the below set_pte_at() write. Signed-off-by: Miaohe Lin Reviewed-by: Yin Fengwei Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 196159000897..ba2a2596fb4e 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -286,6 +286,11 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr, copy_page(to, (void *)walk->reuse_addr); reset_struct_pages(to); + /* + * Makes sure that preceding stores to the page contents become visible + * before the set_pte_at() write. + */ + smp_wmb(); set_pte_at(&init_mm, addr, pte, mk_pte(page, pgprot)); } From patchwork Tue Aug 23 03:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951655 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 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); From patchwork Tue Aug 23 03:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951659 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 BF82CC28D13 for ; Tue, 23 Aug 2022 03:02:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64FEF8D000A; Mon, 22 Aug 2022 23:02:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D9138D0009; Mon, 22 Aug 2022 23:02:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452C38D000A; Mon, 22 Aug 2022 23:02:43 -0400 (EDT) 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 3320D8D0009 for ; Mon, 22 Aug 2022 23:02:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 11A44A138C for ; Tue, 23 Aug 2022 03:02:43 +0000 (UTC) X-FDA: 79829359806.05.94EA030 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf08.hostedemail.com (Postfix) with ESMTP id 48BAB160002 for ; Tue, 23 Aug 2022 03:02:42 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MBYq216nyzlWW9; Tue, 23 Aug 2022 10:59:26 +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:38 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 6/6] mm/hugetlb: make detecting shared pte more reliable Date: Tue, 23 Aug 2022 11:02:09 +0800 Message-ID: <20220823030209.57434-7-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 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223762; a=rsa-sha256; cv=none; b=uyCjUbCrGVlERbU/uE5tXU7sLr7bUDqDNPWgN0txiMdFe4lWS+VcYVBB6OlDuMQxV3a1MH bhZ4NNB9VbhCUVygU3JG6YOxvlM3H97D5kySyVmYNmF4KhbEM4Im1WEuEXMWJ80PAFy6H8 wP9DP+cE01lbv31h5N5xTF7yU4P+kBo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661223762; 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=bp5t9ep0ITsTufI9Fiu07ASXocCk1x1Ja359IGIRJkM=; b=f1a1XBmw1Yxsm5BAg031mVAlvJkS/tcoD2uIIZa335t075NFH1NgSz1SUeoR//+MeCt3YC fch8RjYOK+jNz47F0ZJEgmLdUMDEWlDj+Q3RC8MAgUIrt4p/WYG0I4CD6LZMGsQErCQ/mK y+KPGakTPPGTkqjlJFWaHzhErmYc+xo= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 48BAB160002 X-Stat-Signature: 8ozxtr49y4i5cnis75roi51y11cc6d4b X-HE-Tag: 1661223762-309947 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: If the pagetables are shared, we shouldn't copy or take references. Since src could have unshared and dst shares with another vma, huge_pte_none() is thus used to determine whether dst_pte is shared. But this check isn't reliable. A shared pte could have pte none in pagetable in fact. The page count of ptep page should be checked here in order to reliably determine whether pte is shared. [Thanks Lukas for cleanup unused local variable dst_entry.] Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz Cc: Lukas Bulwahn --- mm/hugetlb.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2dfd10599f98..8aa62765a055 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4763,7 +4763,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) { - pte_t *src_pte, *dst_pte, entry, dst_entry; + pte_t *src_pte, *dst_pte, entry; struct page *ptepage; unsigned long addr; bool cow = is_cow_mapping(src_vma->vm_flags); @@ -4808,15 +4808,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, /* * If the pagetables are shared don't copy or take references. - * dst_pte == src_pte is the common case of src/dest sharing. * + * dst_pte == src_pte is the common case of src/dest sharing. * However, src could have 'unshared' and dst shares with - * another vma. If dst_pte !none, this implies sharing. - * Check here before taking page table lock, and once again - * after taking the lock below. + * another vma. So page_count of ptep page is checked instead + * to reliably determine whether pte is shared. */ - dst_entry = huge_ptep_get(dst_pte); - if ((dst_pte == src_pte) || !huge_pte_none(dst_entry)) { + if (page_count(virt_to_page(dst_pte)) > 1) { addr |= last_addr_mask; continue; } @@ -4825,13 +4823,10 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, src_ptl = huge_pte_lockptr(h, src, src_pte); spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); entry = huge_ptep_get(src_pte); - dst_entry = huge_ptep_get(dst_pte); again: - if (huge_pte_none(entry) || !huge_pte_none(dst_entry)) { + if (huge_pte_none(entry)) { /* - * Skip if src entry none. Also, skip in the - * unlikely case dst entry !none as this implies - * sharing with another vma. + * Skip if src entry none. */ ; } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) { @@ -4910,7 +4905,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, restore_reserve_on_error(h, dst_vma, addr, new); put_page(new); - /* dst_entry won't change as in child */ + /* huge_ptep of dst_pte won't change as in child */ goto again; } hugetlb_install_page(dst_vma, dst_pte, addr, new);