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=1796388554; b=xNIxCZmkZj1TLVwqAlyufMkh1/lxgAftnu9qqAz+TycsV9iQqofg+zhGi3jOw4GSSPgE 5uZGGfn0yHqxpBLbgxHvD7FCr6QSYcNe9bE3mvWUliJTDxVOnVqTVLO/VC+4igA/UWHK9 vyAJecJemcaE32gzYGty7ySCYQW7DJQOWWCTtOsC8Al0tSVnmX5K4ojYkP1aTAIHI07kc PAGYuRoXKIFQaHh9Vgunw8ne+22RrcoTjhZ/6qBm4uOgyFHzv6a+Fhoe/Bk4z71nfjzJm Lg6wWhiWwNqA4oZ5/s3hepjuKVDkcjyJK1Jq4XW5b43YjhNItMWjyukG5uEifoF66fA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388554; 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=mla681N7aiQumZ3j7eKIqOs3tbyXVIbJRDFpZFskn20=; b=wTjl7kl2TRIF+/19kzb8em0OTbt22L/RytqfCvYayA7XAICdbWS+NUdDWCDeQ6EoXgA9 lZdpi3YdU5Y0PaviH7vyyTWNTJxkljI03kddk+U6jCB/slLc0hbKq+59ndVQhXsG08y2k 0yXK8nMQp7ttCo+YKeFs/v4UUfCxZ3y9wSZMg3hU+zh/fWEycC5WZ4QYAd9gibwhb+puR KV4xACv4VE7j3Nev9cbmhc9fWVW2YUtgxkxIJ4rKYdle0qqRKslPKL/p9V6y/VWgHSNuQ X8I0K6ir94mva4mgYADoSVCjzuzcXupEiPR/krG3Y/0bKmo1q/AEfQytC8lZzPwJS+w== 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=GObtXpli; 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 6219E606A32D; Fri, 4 Dec 2026 12:49:14 +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=GObtXpli Received: by smtp.kernel.org (Postfix) with ESMTPSA id D43301F000C2; Fri, 4 Dec 2026 12:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388554; bh=mla681N7aiQumZ3j7eKIqOs3tbyXVIbJRDFpZFskn20=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GObtXpliBjoGVV76wm/ITWxXhtVJDDG5AaENPq/a5bs3IfRC6OhKnW7wkjGVRUqKB 2y/ldFs0xmA8DhTm+K6TRDMxNr+kHaJLuAsRH7evM5DDoBG6waog5AhquGW+oiI1xz PMgO1U2KBR212EbJZe7sH58OhIGzUDaUuny3rhMU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Gregory Price (Meta)" , "Vlastimil Babka (SUSE)" , Zi Yan , Sasha Levin Subject: [PATCH 6.1 0662/1059] mm/page_alloc: retry alloc_contig_pages() when the zonelist is rebuilt Date: Fri, 4 Dec 2026 19:03:13 +0900 Message-ID: <20261204100701.185797669@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gregory Price (Meta) [ Upstream commit da0d7a895e9021dc2cffa90fb6fafd8b9379e544 ] Onlining the first block of a zone rebuilds every zonelist in place, shifting the slots after the new zone. alloc_contig_frozen_pages_noprof() approves a slot by the caller's gfp and nodemask, then loads the zone from it: CPU 0 CPU 1 alloc_contig_frozen_pages_noprof(GFP_HIGHUSER | __GFP_THISNODE) slot 0 (NORMAL1) approved online_pages() build_all_zonelists() [NORMAL1] -> [MOVABLE1, NORMAL1] zone = zonelist_zone(slot 0) /* MOVABLE1 */ alloc_contig_frozen_range(MOVABLE1 pfns) A gigantic hugetlb page can then land in ZONE_MOVABLE, and a nodemask caller can get a range from another node. Gigantic pages are kept out of ZONE_MOVABLE since commit 79b63f12abcb ("mm, hugetlb: do not allocate non-migrateable gigantic pages from movable zones"). Check zonelist_update_seq before using each zone, and restart the walk if it changed, as the hugetlb pool walk does. Check again before escalating to the pass that may migrate hugetlb pages, so a pass a rebuild cut short is redone rather than escalated. With kprobes holding the walk across the online, the base kernel put the 1G page in ZONE_MOVABLE in 3 of 3 runs, and this change put it in ZONE_NORMAL in 3 of 3. Direct GFP_KERNEL calls with nodemask {1} and {2} got a ZONE_MOVABLE range and a node 1 range on base, 3 of 3 each, and neither with this change. Fixes: 5e27a2df03b8 ("mm/page_alloc: add alloc_contig_pages()") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Reviewed-by: Vlastimil Babka (SUSE) Link: https://patch.msgid.link/20261101021340.2251928-11-gourry@gourry.net Acked-by: Zi Yan Signed-off-by: Vlastimil Babka (SUSE) [ sashal: Backported to the older alloc_contig_pages() function, since the frozen-pages variant doesn't exist here, and the retry label and check were placed at the end of the function with no hugetlb escalation path. ] Signed-off-by: Sasha Levin --- mm/page_alloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2bd1641d8403a..44a22f7f213da 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9509,13 +9509,20 @@ struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, int nid, nodemask_t *nodemask) { unsigned long ret, pfn, flags; + unsigned int zonelist_cookie; struct zonelist *zonelist; struct zone *zone; struct zoneref *z; +retry: zonelist = node_zonelist(nid, gfp_mask); + zonelist_cookie = zonelist_iter_begin(); for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nodemask) { + /* A rebuild may have shifted an ineligible zone into this slot. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry; + spin_lock_irqsave(&zone->lock, flags); pfn = ALIGN(zone->zone_start_pfn, nr_pages); @@ -9539,6 +9546,9 @@ struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, } spin_unlock_irqrestore(&zone->lock, flags); } + /* Redo a pass that a rebuild cut short. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry; return NULL; } #endif /* CONFIG_CONTIG_ALLOC */ -- 2.53.0