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=1796381065; b=CKK7akCa+8am3Kt0wqEpr5IyFJyk3xrgMRm6I6avTno2w9nE+ktVMTgGBC1hgbgjf9zY D+muLhI0wZpB2SXkv+bMUtWDN4nEFUfMccDrxVZQTY/eYPGNzi8iPjFWhoI0kX1BxHCYT fMFYCFLiwiQCOcfOCtPMUl2j0LAU48+AxZBSPhaImTT4lXJ3Tl60wc8FTIsMpM7eIVXd6 D2+13kJq1DwYQGK3p263QiHGKH/hV6F8dvK8KwnsRtNyHgqfUzf8gwJP9xW8TQPw7LDYt Eiq0WQp2iQq8CoFSKUAAEClc3V1Bt+08brirzqfY4dSVAiOYifzT0tu+NHigli5fO+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381065; 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=StUdpVlu5V9+Ykjnw5tvPS/jrLe/4qsbq1MLnx9e6uc=; b=EM2ihZ18BEt9NWxF1mR2r30kW1R0kpgP814zOsSF0O1uKU8VrQAioNwVuO3RYRl3Mhri mWRIS2uji1v2Lg5ZuIEodGnvoVFlX24cqeI8iVA/hw49FpkqLuk7FQLjTYlkk1Q4WXtid LEVzViwN61pj+m9GnZSiKPjejvU6rX6kTQ5FQ2aajtVqXKj6qRmv1HWHv6bu3Ofnf/d1E RRpu0mm2CtGvk7Yll2gAaiVdqufM6Rxjzs+nH3O168yKUktKtd8dmHyjdip4sfbuC52Ru +HQVYG33bQ9dVapFnf3uoBSgl/SFSOYakbRzXWZ+rujiWirLNEnHXVIK00TWR3tjMnw== 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=pFIrAx1i; 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 211DA606A337; Fri, 4 Dec 2026 10:44:25 +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=pFIrAx1i Received: by smtp.kernel.org (Postfix) with ESMTPSA id 952FF1F000CE; Fri, 4 Dec 2026 10:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381065; bh=StUdpVlu5V9+Ykjnw5tvPS/jrLe/4qsbq1MLnx9e6uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pFIrAx1iIwhn1mnorz4kJTev98qjQX0li2iIfMxBLDyZAUmJQZxUmdrJx/WHoLT2G nWxZvwHcKYQFEBpL8vwZGIHaKpNY/C7COE2FBPiDSyX8NIyGtIYwdbCsw5uKxQs06v OUIS/Yc26CmKidRvCSwGIBigCYxHSLDz2vamsXDI= 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 7.3 544/742] mm/mempolicy: use one node set for interleave weights Date: Fri, 4 Dec 2026 19:06:48 +0900 Message-ID: <20261204100649.614678170@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -187,15 +187,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. @@ -214,7 +221,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; }