From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386000; b=MQdCW4yUymGWKDlb2ePNVrPbD01kXkEGsKszgtXkGXFKlVBdWfPjZsBnIk/C67A2VsC/ CLrON1RCWkN8uSs3T1XY3CKCR1uXZnHeEmwuEmK9qVyuHJp5ddom2ppsuC+I0zUWIDRDZ 7ura9EXKEIo3q8O2s40tH+evFgNJPHQPTI1dOInB4cPpcpzXTelQejTDm9M440AdFmLJm HDRzmGK97s0wiclwjLGNAO/F5JGduqmly94oMKLBOoPqY63n0e556Df4WuOKwOn+NWm8C 8mx7pRa2J4c1I08kuhVgRVXNJiPOuRDAnKpeiI5pgN2JmqCRtDOPjPh3m3mdXpkAIlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386000; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=JWnocgwhb3RbV6pAzWk2EYQ8ybG2yj1Y8tubkQuBfso=; b=OpSVtMxjpb9wSzLU+9+k93w+lFHESRwSRlxluLJf9BNe3MjrmH+KWBZTD98aCKcz/bL0 oE8cHnhMh3MskR7+k9aMnvVvjxmMv2BbHL9xZYbCcCvuNLRjAXT7+q4EWXl6Zar78erbK +vjFGsn42nHzLTWPO5bQSOUz48mWm8PMB7epfPvKqdu7/dIoxH0z89xyGmjrghKFNkj4r E4Jk/JxDolJ/4yz6h+jFLGjAksP51KVET1QHe31MR/6U0CIAEGJoFzlQlBDN0brW/s/s8 VK2V4zMxvIlWup0BAjfHDan8buOEoS6Wq3N71WVPlJJ2vOdB9BS5cUytmQVy2T4L7ug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ThPDe1bw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91966606A322; Fri, 4 Dec 2026 12:06:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ThPDe1bw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 088421F000CE; Fri, 4 Dec 2026 12:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386000; bh=JWnocgwhb3RbV6pAzWk2EYQ8ybG2yj1Y8tubkQuBfso=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ThPDe1bwZP+6kx7eBjcl6znx/I2c1qR2P9oyLPSDJ9wgZo6aKZiwv5ZH6T0P4nGCM pNUC/Mr+e7QTjn46fTyZ5wpSOVL4DUR7BIcnQczB7hqmVQDUxe0IhwBVMv1z9xFeb5 EysG8pQbEDY1Qtwt0sDgNBPR+9+4hvoRsE8sYu4c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Gregory Price (Meta)" , "Vlastimil Babka (SUSE)" , Sasha Levin Subject: [PATCH 6.6 0783/1167] mm/hugetlb: retry the pool walk when the zonelist is rebuilt Date: Fri, 4 Dec 2026 19:03:30 +0900 Message-ID: <20261204100722.511166786@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gregory Price (Meta) [ Upstream commit 9f6674f842bbceda8326cf4e494af5ad3a5a05e6 ] Onlining the first block of a zone rebuilds every zonelist in place, shifting the slots after the new zone. dequeue_hugetlb_folio_nodemask() approves a slot by its node, then loads the zone from it, so a hugetlb fault bound to one node can take a pool page from another: CPU 0 CPU 1 dequeue_hugetlb_folio_nodemask(nodemask {2}) slot 3 (NORMAL2) approved online_pages() build_all_zonelists() [.., NORMAL1, NORMAL2] -> [.., MOVABLE1, NORMAL1, ...] zone = zonelist_zone(slot 3) /* NORMAL1 */ dequeue_hugetlb_folio_node_exact(h, 1) Check zonelist_update_seq before using each zone, and on the way out with nothing found, and restart the walk if it changed. Checking before the dequeue leaves nothing to put back. Reset the last-tried node on restart, so it is not skipped. With kprobes holding the walk across the online, a fault bound to node 2 took a node 1 page in 3 of 3 runs, and a node 2 page in 3 of 3 with this change. Fixes: 11cd8638c37f ("mm, page_alloc: remove stop_machine from build_all_zonelists") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Link: https://patch.msgid.link/20261101021340.2251928-10-gourry@gourry.net Signed-off-by: Vlastimil Babka (SUSE) [ sashal: Moved the zonelist seqlock helpers into mm/internal.h since there is no mm/page_alloc.h, and adjusted context for the NUMA_NO_NODE fixup. ] Signed-off-by: Sasha Levin --- mm/hugetlb.c | 13 ++++++++++--- mm/internal.h | 19 +++++++++++++++++++ mm/page_alloc.c | 18 +----------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cfbc1776f452c..3ae64e32328dd 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1362,19 +1362,25 @@ static struct folio *dequeue_hugetlb_folio_node_exact(struct hstate *h, static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nmask) { - unsigned int cpuset_mems_cookie; + unsigned int cpuset_mems_cookie, zonelist_cookie; struct zonelist *zonelist; struct zone *zone; struct zoneref *z; - int node = NUMA_NO_NODE; + int node; zonelist = node_zonelist(nid, gfp_mask); retry_cpuset: + node = NUMA_NO_NODE; cpuset_mems_cookie = read_mems_allowed_begin(); + zonelist_cookie = zonelist_iter_begin(); for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nmask) { struct folio *folio; + /* A rebuild may have shifted a node outside @nmask into this slot. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry_cpuset; + if (!cpuset_zone_allowed(zone, gfp_mask)) continue; /* @@ -1389,7 +1395,8 @@ static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_ if (folio) return folio; } - if (unlikely(read_mems_allowed_retry(cpuset_mems_cookie))) + if (unlikely(read_mems_allowed_retry(cpuset_mems_cookie) || + check_retry_zonelist(zonelist_cookie))) goto retry_cpuset; return NULL; diff --git a/mm/internal.h b/mm/internal.h index 7e7102969f3a0..851a9f53da50d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct folio_batch; @@ -518,6 +519,24 @@ extern void zone_pcp_disable(struct zone *zone); extern void zone_pcp_enable(struct zone *zone); extern void zone_pcp_init(struct zone *zone); +extern seqlock_t zonelist_update_seq; + +static inline unsigned int zonelist_iter_begin(void) +{ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return read_seqbegin(&zonelist_update_seq); + + return 0; +} + +static inline unsigned int check_retry_zonelist(unsigned int seq) +{ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return read_seqretry(&zonelist_update_seq, seq); + + return 0; +} + extern void *memmap_alloc(phys_addr_t size, phys_addr_t align, phys_addr_t min_addr, int nid, bool exact_nid); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4d9637a558aa3..d587f6a3f4b4d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3659,15 +3659,7 @@ EXPORT_SYMBOL_GPL(fs_reclaim_release); * retries the allocation if zonelist changes. Writer side is protected by the * embedded spin_lock. */ -static DEFINE_SEQLOCK(zonelist_update_seq); - -static unsigned int zonelist_iter_begin(void) -{ - if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) - return read_seqbegin(&zonelist_update_seq); - - return 0; -} +DEFINE_SEQLOCK(zonelist_update_seq); /* * Never wait for the writer, which an ALLOC_NOLOCK caller in NMI may have @@ -3682,14 +3674,6 @@ static unsigned int zonelist_iter_sample(void) return 0; } -static unsigned int check_retry_zonelist(unsigned int seq) -{ - if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) - return read_seqretry(&zonelist_update_seq, seq); - - return 0; -} - /* Perform direct synchronous page reclaim */ static unsigned long __perform_reclaim(gfp_t gfp_mask, unsigned int order, -- 2.53.0