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=1796388560; b=5CHS74BUp9rx8BylyiPZliCSiOR2hAB3/MjRfolWsnMw2NQrF8XK2cwFVhLxe1sjdUvu mLHHfQ5PjuXUeWa1AGoztyNXv73MPx9fP8zFlTA4QYrNoi0x0ZiCZcli0hP7DbXzSj6kM 7szYvgCZT7EZmP794x0VbXkgL1ezYPppjx6eddTnWI5JAFhwEcxFqHy+Zyy0y8Hqhpei0 ustL6SC1aQzLTByBZPTZ6pAk5eBBUh7+RdzxLiwSw5QUe2HFH4HDl6i79JFeIaQp4jOl6 04LAFwFkLD3i+fTQ6kVj9fxz9om3Myfe5yK1m3VXiZlKs+dYmF/wBTGWER3fHno+0Pw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388560; 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=Dr+o2V4xpqoHKu6oSf7wgYv2LHc07wjlZOiL86cQR2A=; b=3YFwyx6j6VYvFRFJL0XwXOlVc0NuEpYMXC9JyznPAp/QVbZL94ijg8jIfHGgF+7v4Ir7 dowMOatSz+CFg0IZunUVvSgcp1jdU/gj9CScWrtHODBePkuaII/gjtpSXb0FF9qQnoS+5 jjmJb/MMRN6jAhnxlG57rSHxcWoXyUJUCrYJwtfJemHp/ILeEE5wyQXCODPDlThpvenhJ pf0BMmfrfjfC3stLW3/RBiX/TmXiu7OS64JHHiYrpd6hfL1tcYPHEixiZUUnzvmaHvf3a j7gqrDOIlmr/Za2al21RBL9dz/QDpYNYrRvW10O89eILJjqQ0i7aUg4Vu4/3WMY6JzA== 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="W8UXeYX/"; 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 F2C05606A32C; Fri, 4 Dec 2026 12:49:19 +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=W8UXeYX/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 549151F000CE; Fri, 4 Dec 2026 12:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388559; bh=Dr+o2V4xpqoHKu6oSf7wgYv2LHc07wjlZOiL86cQR2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W8UXeYX/gV8V61eVi/WEsiiery8p9GhWoadf+vr9Zf3johfT7ERN9liIX3b8p25Ek rAQjhW0tQDNJ2Tuu2LPILQUJM0fi2yRWwatZX2NoGuPnoZ819vIT4KfrYDTTLa0DXU 0cg62vJVnQQNSZsbwN1dHqaTHGGB7o7bizJ92kw8= 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 0663/1059] mm/mempolicy: read the zoneref slot once in mempolicy_slab_node() Date: Fri, 4 Dec 2026 19:03:14 +0900 Message-ID: <20261204100701.209911875@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: stable@vger.kernel.org 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 4cc1bcdf2e4ebcd319005ce2ea132489f6155139 ] For a bind or preferred-many policy, mempolicy_slab_node() tests the first matching slot's zone for NULL, then reads the slot again to look up the zone's node. Offlining a zone's last block rebuilds the zonelists in place, so the second read can return the terminator: CPU 0 CPU 1 mempolicy_slab_node() zonelist_zone(slot 4) = node 2 NORMAL offline_pages() build_all_zonelists() slot 4 = NULL zonelist_node_idx(slot 4) zone_to_nid(NULL) Current GCC merges the two reads, but nothing requires it. With mm/mempolicy.o built with -fno-inline -fno-ipa-sra, holding a bound task's slab_strict_numa allocation between the reads while a movable block earlier in the zonelist goes offline oopses every time: BUG: kernel NULL pointer dereference, address: 0000000000000060 RIP: 0010:zone_to_nid+0x0/0x10 Call Trace: kmem_cache_alloc_noprof+0x294/0x610 do_getname+0x34/0x230 mempolicy_slab_node() and zonelist_node_idx() are tail calls here, so neither appears in the trace. Read the slot once and use that zone. Fixes: 11cd8638c37f ("mm, page_alloc: remove stop_machine from build_all_zonelists") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Reviewed-by: Vlastimil Babka (SUSE) Link: https://patch.msgid.link/20261101021340.2251928-12-gourry@gourry.net Reviewed-by: Zi Yan Signed-off-by: Vlastimil Babka (SUSE) Signed-off-by: Sasha Levin --- mm/mempolicy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index bfc94fb823608..527cb7e798471 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1915,6 +1915,7 @@ unsigned int mempolicy_slab_node(void) case MPOL_PREFERRED_MANY: { struct zoneref *z; + struct zone *zone; /* * Follow bind policy behavior and start allocation at the @@ -1925,7 +1926,8 @@ unsigned int mempolicy_slab_node(void) zonelist = &NODE_DATA(node)->node_zonelists[ZONELIST_FALLBACK]; z = first_zones_zonelist(zonelist, highest_zoneidx, &policy->nodes); - return zonelist_zone(z) ? zonelist_node_idx(z) : node; + zone = zonelist_zone(z); + return zone ? zone_to_nid(zone) : node; } case MPOL_LOCAL: return node; -- 2.53.0