From patchwork Tue Aug 16 13:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944896 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 7BA29C28B2B for ; Tue, 16 Aug 2022 13:06:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B37838D0008; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABF338D0009; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78AFF8D0006; Tue, 16 Aug 2022 09:06:24 -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 4DC0C8D0008 for ; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 29B52141056 for ; Tue, 16 Aug 2022 13:06:24 +0000 (UTC) X-FDA: 79805479488.03.13054FC Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf11.hostedemail.com (Postfix) with ESMTP id 83D1C401D1 for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M6WXf2C2LzkWQq; Tue, 16 Aug 2022 21:02:58 +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, 16 Aug 2022 21:06:17 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 1/6] mm/hugetlb: fix incorrect update of max_huge_pages Date: Tue, 16 Aug 2022 21:05:48 +0800 Message-ID: <20220816130553.31406-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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=1660655183; a=rsa-sha256; cv=none; b=dHxwF/2afde6PJN26ufPwGaIrm3yMRPqfrYuCf+6fU8UFyaNspQAMI5NAk2p3QMFyVcoJ6 +FyhFO0jLCTH76QILbngn5qqDw6oqZjuyVIoyhc0PcsxegmQP4Ai4E8LW39Nh/kGUtEZJl pgfbFtfYZG5OTBOfFk3hdKmbbVUtJs0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 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=1660655183; 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=pc7exYF4oEoKE7cskg6bxhhDm8ODRTE+5SV0ak+pQSY=; b=m/yscaKWnYqai+A64xnNdM86PCcrvyZIv11WQlUUe3LPrKudo8DRuh4Uj+ffn/1zwhXjL8 XUT9XsI121ly7y3jiYOEBHbPiIqxIIvRfqgGs6hgjzPxBlyeN0hMVUZwwJjgoD8AfAeTvb /D09MNNP11iUWtm8QcgOO9SD+ctMa9A= Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 83D1C401D1 X-Stat-Signature: m4skny1j979f7ukmsd4xrj7j5cujkfnt X-Rspam-User: X-HE-Tag: 1660655183-77902 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 ea1c7bfa1cc3..e72052964fb5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3472,7 +3472,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 16 13:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944892 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 B08F3C25B0E for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A8F78D0002; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 232338D0001; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D3448D0002; Tue, 16 Aug 2022 09:06:23 -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 F22268D0001 for ; Tue, 16 Aug 2022 09:06:22 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C0EA6140D8F for ; Tue, 16 Aug 2022 13:06:22 +0000 (UTC) X-FDA: 79805479404.26.E5888E9 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf27.hostedemail.com (Postfix) with ESMTP id D5F9840065 for ; Tue, 16 Aug 2022 13:06:21 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M6WXg1Brvz1M8xv; Tue, 16 Aug 2022 21:02:59 +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, 16 Aug 2022 21:06:18 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 2/6] mm/hugetlb: fix WARN_ON(!kobj) in sysfs_create_group() Date: Tue, 16 Aug 2022 21:05:49 +0800 Message-ID: <20220816130553.31406-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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=1660655182; a=rsa-sha256; cv=none; b=T/yBVn422eezNZLfO2PDl+Qv6N0mFNWhbW06oAOGlvkpC8yET1omQw+dJtNRTnr5Quz5ze Ic08Mj01CHATRQa4RhYE8WVqiXbRsFreFI4rQyT0OE5csCdyZCpLbgjCiJKk5/b+q36PvW jBnwNUoVwphuh2slEnu4uOaMdASq4fM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 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=1660655182; 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=W3/clTcnLGJxTGNbpkP0Yyon62dURfYJ2FHwKz+Ejgw=; b=B3/WH2NKY7js39kNlx5LgVHokdK6zpacRLTOvz+HEw/Mu8SDLbMppA2h5T0zRPKPlRSMlH 2jekCJCDM2MSm2nlrNad3c1nfEkHBXGCPpAk1TtAc8FhINDIg1tC/6aWdWh6thnuqG6yVd HNuOBFYa7+ZWggEhTmIndBafsBeuT1g= X-Stat-Signature: 4rcyioagnbkf77izqcwixg64x4sdbqne X-Rspamd-Queue-Id: D5F9840065 Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1660655181-758979 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. 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 e72052964fb5..ff991e5bdf1f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3846,6 +3846,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 16 13:05:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944893 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 8784CC2BB41 for ; Tue, 16 Aug 2022 13:06:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76A9A8D0003; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 762058D0005; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DAB48D0003; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4ECB98D0001 for ; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2637D41015 for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) X-FDA: 79805479446.21.0476E45 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 4AAD1801DA for ; Tue, 16 Aug 2022 13:06:22 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M6WZ02KypzmVX4; Tue, 16 Aug 2022 21:04:08 +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, 16 Aug 2022 21:06:18 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 3/6] mm/hugetlb: fix missing call to restore_reserve_on_error() Date: Tue, 16 Aug 2022 21:05:50 +0800 Message-ID: <20220816130553.31406-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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=1660655182; 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=Oil/VJ5gE0/7sZGswETNnt5928NlpMbTKaEs4rAPiG4=; b=Nc360DR2HaKk4Rerh9ntzjLekQmuYFSRG/iT7C0bz6l/XNT2T5xsqeyI0U7jj74o4TFkxC INET65IkkE3cna8u0QQiBQ/SbgWC+c40tNWpS9c1vTW7LIIoK12XtmOCAMaHt0Q0k6isZW GOShRZSUynVRtSK0hqwXYH8CDT6vNXE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.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=1660655182; a=rsa-sha256; cv=none; b=nTTFUkKR4/qHUYXPB3I0x/wppY/1fV2sQIBUcUb/ogyzHWKtYJIlKpXAIBipoYA9D5rgSG 1LYMT4jIZoaF1k+/BVdFUwhsrhtLaqu7aVHk7Fe1IWsK/Nu9raQuHD3jnKi8fdeOGIRJhs YUxs6Bfy2RnYvAtAMUiysgWCuw7vP3I= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4AAD1801DA X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.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-Stat-Signature: 5cuoihw1zgcmbauuyzido63h8awnns83 X-HE-Tag: 1660655182-221696 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 --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ff991e5bdf1f..b69d7808f457 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5603,6 +5603,7 @@ 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) { + restore_reserve_on_error(h, vma, haddr, page); put_page(page); if (err == -EEXIST) goto retry; From patchwork Tue Aug 16 13:05:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944897 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 92DC1C25B0E for ; Tue, 16 Aug 2022 13:06:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 620338D0005; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 540E68D0009; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BD0B8D0006; Tue, 16 Aug 2022 09:06:24 -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 DDF008D0005 for ; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ABF58A10B5 for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) X-FDA: 79805479446.28.FBD878B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id DDD05201D4 for ; Tue, 16 Aug 2022 13:06:22 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M6WY10B01zlVpm; Tue, 16 Aug 2022 21:03:17 +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, 16 Aug 2022 21:06:19 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 4/6] mm: hugetlb_vmemmap: add missing smp_wmb() before set_pte_at() Date: Tue, 16 Aug 2022 21:05:51 +0800 Message-ID: <20220816130553.31406-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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=1660655183; 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=FuN6T2p2RJ2CpDWMi2zsepaC0Qel6Up9shsoD+jS828=; b=bPjs9DbDpc5FFsFqSYutTEvoQpri6Yg/nlPMSE+jxyqXvY6egkQBkNtd0FcUb0rHyhrPc7 Igqk445lD8uGBDPGskZb67GWTGBwjdUQMv0grrYbrQv0t8XIB99vYDgSNrLuZK0DHn4ezI 4Gx87/M1Mz006OrGA1l8Vw6C1SPXXo0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.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=1660655183; a=rsa-sha256; cv=none; b=ohxCBu/NGZhnMDjrvJyTnWaJ+EF7oFFtPbtB2E+6sz0qvdUd4ooufBEd5iuJ3hXCNT3yra AKXJLw5jei/FXBlRzGrvyO+SxYLvBiw4ciY0bYgoh2mepU6omMa+y80eEYINa/Svf7TgkV 3IfjWEkHSANaigBHhYxznlg6Kqz+SIM= Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Stat-Signature: 4r1ygxu1z9z8itr39uikx34m5711x5pz X-Rspamd-Queue-Id: DDD05201D4 X-Rspamd-Server: rspam11 X-HE-Tag: 1660655182-761774 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 20f414c0379f..76b2d03a0d8d 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -287,6 +287,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 16 13:05:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944894 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 0ED9CC25B0E for ; Tue, 16 Aug 2022 13:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD0C48D0001; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B58D88D0005; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF0A8D0001; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6BA008D0001 for ; Tue, 16 Aug 2022 09:06:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 431C780DAD for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) X-FDA: 79805479446.15.D1E0FFB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id 9AF03801BE for ; Tue, 16 Aug 2022 13:06:22 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M6WZ11d2wzmVXv; Tue, 16 Aug 2022 21:04:09 +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, 16 Aug 2022 21:06:19 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 5/6] mm/hugetlb: fix sysfs group leak in hugetlb_unregister_node() Date: Tue, 16 Aug 2022 21:05:52 +0800 Message-ID: <20220816130553.31406-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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=1660655182; a=rsa-sha256; cv=none; b=E8v2YCguCsm7TdbPY+/mkBJ+i8Ryq/57NQ8qkhhATbBTJfTX0oMwzzrTeqgK07CE6ULQze ZnUBOjIDN3n+41VCBxl5+IauSw2oP2OmaHJCXt+bAmoOwFPL718M+GFy6CRV2fvdSAY5St mnPpLMqpSBcfYGWXcuIYt6mKz5oGftk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 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=1660655182; 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=Kn4w+i96i+xiHSdBkPz5Vfv4mhY8QQC1ileyZmg8rb4=; b=n+Jl37KeFmhJFw9RpvNiWbLY6+Ni/rD4Ipsv0dty2b5LFOWqefZn1gpMrsuUT2KvsS/FkB DLG4Kv2qLh8FjPvss4yqOQyhhOkmFqU2UM0vySi0tHI7yI5jycrkg1oUDOHUKtOAFB9tDc Lw+rFWv1cE1aToJ0/pltG8fy0MZlI58= Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9AF03801BE X-Stat-Signature: jos5pyd5u7if793rxze5rpmw146ddn4a X-Rspam-User: X-HE-Tag: 1660655182-749687 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 b69d7808f457..e1356ad57087 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3850,12 +3850,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) @@ -3941,10 +3947,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 16 13:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12944898 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 80A4CC28B2B for ; Tue, 16 Aug 2022 13:06:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FCD28D0006; Tue, 16 Aug 2022 09:06:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2CDA8D0009; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B32EC8D0006; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8CF528D0008 for ; Tue, 16 Aug 2022 09:06:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 509EE1C68AE for ; Tue, 16 Aug 2022 13:06:24 +0000 (UTC) X-FDA: 79805479488.20.BFBA0A0 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf17.hostedemail.com (Postfix) with ESMTP id 63195401C6 for ; Tue, 16 Aug 2022 13:06:23 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M6WXh6pW3z1M8ym; Tue, 16 Aug 2022 21:03:00 +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, 16 Aug 2022 21:06:20 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 6/6] mm/hugetlb: make detecting shared pte more reliable Date: Tue, 16 Aug 2022 21:05:53 +0800 Message-ID: <20220816130553.31406-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220816130553.31406-1-linmiaohe@huawei.com> References: <20220816130553.31406-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; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660655183; a=rsa-sha256; cv=none; b=zzvVo1juO3ZY+O0jGhcIlnL4tX6LvkAIJ4BHAGUX6N9T8IW3FpYwuIkiC2nhrDfzuE7V4A C0Qqeoxup3W1IY4s5PcWYf4QYThYwvjNEP5m20U7HihtUlGG2QvYxvMGzfVgEYI31tJRt9 u5TBVlzFkAqiIcGWv+8WvIgIbp4fC4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660655183; 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=i52LnC/SKqRKQBLmUqiGxyypLtHKsokj+klQMRxKyRI=; b=WkheyXeIGnjW50514XCE4yzd0uRgozxFRhHfNnkEVVcl1o6vbHEgA63ZRTduRWnKrI1fRX PbH7GwDUSvqLoQG8kUHl8pxkbedkNimAOegmsXdLvnYtQMgCLExXaYICouQDEaP54gaiig tYkh2Xlaj+cbO3LH2Ko0nmVnHIU3N5Y= Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: iizeim7qzjjmwo9ebsn87x5epxabiedw X-Rspamd-Server: rspam09 X-Rspam-User: X-Rspamd-Queue-Id: 63195401C6 X-HE-Tag: 1660655183-544354 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. Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e1356ad57087..25db6d07479e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4795,15 +4795,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; } @@ -4814,11 +4812,9 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, 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))) {