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=1796382519; b=i5Eo/l0h+WLFHr5qrdGUsjO5yKGiRrfmClF7++lKNjnxQm5jiEYfucdLRr4GNXutlqru A8QzRQiGjQXi58xUoF8SV94ehDq+SU1N+Cp6KLFwPV5i0jXKh7f4Coc0cgNpKYDlAEMWf MVcw0OY8JJk9D4bLATeN9zNIhJtMU2+0YA8qHywNZY+hVOXJc/uXtMIWAibAdg0fWKBcj Edo/QihGQI2QHkwYIYVO4zl2l2Kn8jqBBlpliPFrGa3u33eVkrJu+x52sjQR4Lj411Ahm cidyT6I+jqMx90Fs1itXtfX+uWE4LBvTTpfL4qSvnQETBY+yRIIS7WaiQ5bBI3EVdnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382519; 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=8Ky/kY2gUePqXn6OVk8WrZC8P9E7xmIe/ZLC10om4jc=; b=3IzFLuqBpGlP2EcssiAis9nAMAOceF6aeblUw49/Ve5XgfvksAnqF5O08MqEci+zSZR6 /C7U+UpzwoCpBoUbmai5+nqVjfxf9Q9l6Pc+ivU8wrQ7YyFes5pDjTy3kb+UFLMtsftyT /v//RambkkmwpjeCslyk/ZIgSIhPGkDHV+qPgdck7TqsH/Rm9L/FOLToPvdihn9fE02Ax 5prRLRA7ZelywHRnevtt9M+9qZ5LByKclYYwwdhJA3KoXZYfj8p+5//tSyp4Zfgm1V2wH 2/ucVWPVCxqcgs6OjixEEKoXNNC/CAHILLba4xgKfhmIghGUgYSi3k2Y1VE8vDINFVg== 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=pXXY2gvg; 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 B4C6F606A32D; Fri, 4 Dec 2026 11:08:39 +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=pXXY2gvg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 349561F0093A; Fri, 4 Dec 2026 11:08:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382519; bh=8Ky/kY2gUePqXn6OVk8WrZC8P9E7xmIe/ZLC10om4jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pXXY2gvgMx8pMJ3IquXHGC/3DvaciQbgMHA4GAPOz+vBGm5XauOS0dsuDIFlh74Hq AZJL1wOWISVjUA/UxuJfdQ4KYbSJxrIOsKfkXOD5rDjcbiqf1XWTwYazQsPBsMD2TA qnEKSnV92FPrVLaELd9t7OlgNZO5mO1L07g5kVAI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrew Morton , "Gregory Price (Meta)" , Joshua Hahn , David Hildenbrand , Zi Yan , Rakie Kim , Ying Huang , Harry Yoo Subject: [PATCH 6.18 488/703] mm/mempolicy: use one node set for interleave weights Date: Fri, 4 Dec 2026 19:06:27 +0900 Message-ID: <20261204100640.784420320@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrew Morton commit d7e3ce464470d0ff90b4a0ac87df9b3b7d8258da upstream. Switching weighted interleave back to automatic mode while memory is being onlined can cause a kernel divide error on x86, and a panic if panic_on_oops is set. reduce_interleave_weights() scans N_MEMORY three times, but hotplug can cause N_MEMORY to change at runtime - and torn reads on that nodemask can cause a total sum of zero bandwidth. A node that was hot-unplugged and then hotplugged back can then cause this loop to generate a div/0. Record the nodes visited while summing their bandwidth, then use that same set when scaling and reducing the weights. This gives us a consistent state even if N_MEMORY changes. Link: https://lore.kernel.org/20261030161046.1497894-1-gourry@gourry.net Fixes: e341f9c3c841 ("mm/mempolicy: Weighted Interleave Auto-tuning") Signed-off-by: Andrew Morton Signed-off-by: Gregory Price (Meta) Reviewed-by: Joshua Hahn Cc: David Hildenbrand Cc: Zi Yan Cc: Rakie Kim Cc: Ying Huang Cc: Harry Yoo Cc: Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -184,15 +184,22 @@ static u8 get_il_weight(int node) */ static void reduce_interleave_weights(unsigned int *bw, u8 *new_iw) { + nodemask_t nodes = NODE_MASK_NONE; u64 sum_bw = 0; unsigned int cast_sum_bw, scaling_factor = 1, iw_gcd = 0; int nid; - for_each_node_state(nid, N_MEMORY) + /* + * N_MEMORY can change while wi_state_lock is held. Remember the + * nodes contributing to sum_bw so all passes use the same set. + */ + for_each_node_state(nid, N_MEMORY) { + node_set(nid, nodes); sum_bw += bw[nid]; + } /* Scale bandwidths to whole numbers in the range [1, weightiness] */ - for_each_node_state(nid, N_MEMORY) { + for_each_node_mask(nid, nodes) { /* * Try not to perform 64-bit division. * If sum_bw < scaling_factor, then sum_bw < U32_MAX. @@ -211,7 +218,7 @@ static void reduce_interleave_weights(un } /* 1:2 is strictly better than 16:32. Reduce by the weights' GCD. */ - for_each_node_state(nid, N_MEMORY) + for_each_node_mask(nid, nodes) new_iw[nid] /= iw_gcd; }