From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796190909; b=rnnnha7onwoBI+nToFyoYYLBmV1zFEWcnnIdf/VmLoRuVnNc4rGieL0W74R/CQeRkLNo ZeD8nQSUt/HxoBJj8pDYDcpKTg6NE4dlFbyDZub2Ms/Am5KhgYOOug3mK805hAkSj7c9H mjgCLMPM+NcjtfHOpE81PvfS7lVBzd+eHGFaKzwSrAiTnlQvsG/vuAsad9bcVmeUjxMDN svN3BaETrCKkoAdSXzJhzfXnGugTSDiTEnqePKVJajWZJJXiw+Sujwhx6nlHbFeaNBXnO cjjahwk4h+WW4AS0sw1zlj/VJkgzWJcxdzooMav8PhYerA7+irwjmyKd11DJa+m0P6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796190909; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: MIME-Version:Content-Type:Content-Transfer-Encoding:Subject:From:To: Cc:In-Reply-To:References:Date:Message-Id:X-Mailer; bh=h4VLsHrjHvKiOH4gJn8QoYhhEdUPahF7NNhS7tTRSvk=; b=jtbRB9Au+n7SbimyXDSKWdKAU8w9iZILAbxG+VQkVQZZEXrpmUeL1nYdjcWiieQZCR9i Gw27LgN32223PoVQawh/WyPYrmj1bWPVlgtcubvvFA6uYF5VINCMceXJMXZuDsyiTMhmL QQerVaJxDznLasbanGWIMsT4BfBBZZxRRsh9bO40yxK/cPdNltpANwJIiiTRWc1ghbkgx 5GuZ4bwFQwOaNsSQiG9B567FieTiwjI1266XKJ3kaqvXqu40PauCQX0eQjJauByW+I0Rs T7sYlvRzHtHAtXutxSWSTWG7IFt36C5ewPVSQJtHZwmb+/yENO/vbO2xxfCu/vpwYZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=uYewq2iR; arc=none smtp.remote-ip=209.85.222.175 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49230606A323 for ; Wed, 2 Dec 2026 05:55:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49230606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=uYewq2iR Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-949589c1495so1134570485a.3 for ; Tue, 01 Dec 2026 21:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1796190907; x=1796795707; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=h4VLsHrjHvKiOH4gJn8QoYhhEdUPahF7NNhS7tTRSvk=; b=uYewq2iRc4AIL6+a5cMFfAzjWNraBEyU1+k9JIgkQLaFDVXAR+LtNau48mnsLQmTTi mnaX0k04YnAPR4OdOdAvC0vy8fij70ar9dZTSoAwmrACWUAehAvm1yQNHhndg6A6k85P Iyml3CD2dDyc4Xr1lE2zK26KExAIqcuA+A0OOMH10eqmdNx59HQU8F5LTOuWSZBZg06k OtuyxmV9S3/QanwGJpG2lRL26it1x8V1AzjgadfwSAA5gBaoSpFy+eM2jGb54v7lDX5V VbqfwVUpo2qL3WYz1/TnNx74GKKe5zc4Kt1bcXmrSSe3sY/IiZ7151lmQT3jhF6/e1r8 Y9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796190907; x=1796795707; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=h4VLsHrjHvKiOH4gJn8QoYhhEdUPahF7NNhS7tTRSvk=; b=C+Gi7LmWPo93ehtfbzP+WIbFXlLLaxm0EnSVRNhLa6K3NBw2cToFJ84bCPFVLITOxR IOP95FP3PWWreUj2qJ2KGobZpD7oq6gSR8XEI9wOoBtQhPNVirJHfehUsSIDpad76gdr VMnbsrumUmITWpNCepGJv1/JqlinEjPX/8SFq3xZKs3/RvhnPV68UO8qvmSvqWIUfFzh G6I6xGfi/QSppvucGOPhXycJbauNfR8rqsjome1KE0mvRsLZ+njHuu4x9fxk6hgG3G17 M2mBVkqoom+WJX3JgvqEYm9TRlb8bT6P9YtTYQu7qwzYfrXDYQ2rjaHi/YVHHqNAcmOr ffzw== X-Forwarded-Encrypted: i=1; AL+hErFi77SHVdwYGwPN9Jg+4VitnP/DocQAiGX4UDJFJzIgC4gGgxwHVQYFnzMN5xDifCdUIa5zT4PoeKs0MBk=@vger.kernel.org X-Gm-Message-State: APuU4Z9/q9xVOhtcPs/34ExYKNEPKtds1CikXxGyu864dcptAfSeVUcR E0wBOeZp7xdkDLtA7JH+J3175xHFGOzt1ROINQSIQGKuIC+zGlDtnSG7urmcerGyk08= X-Gm-Gg: AZFdTZdqqHPfKdVL6eeR44GjXi8HpNWSmn4yKFw6m9ylSQA+t6tnDz0vBiF25ZnYFfT 7ErK5e18t/tDIJLQhTomWZruuJpcx9FTDtjrerI9H5nbfIlyQf9UxC4/o+P7Vek+DFR8d3vB8Yw ayZ6dF+vZC6/Xh/+evtnNzWKU4Dj18S9ivrwIidW065J1/7ILKHlVoc3OWr7qFYEipdfwjHqKJY bc+35dZp3hZymLhZuKN7cBkvMJGsc5drF0qcpt7DePklKQNtm/Q+AZsnFLuDLoYttXjTWMNivwq 15/TCXD5hdmsJif0Hc2ZbxncF5N2DfNQbil2QnjT1pkgTeHr1RH2gPMK4qQwiejUxiv5hPG6Umz cEHfXgz4W59kJOurAd2qfXSOnMgtRG8Si3UOuWxl4EfG0Q/HcjUOyuMSYEJVQ/p+WLtS/IuckBU BkWD3ohB+WBNG9fqQXsouy1RVbdvxVVnPTAWe2VSMJuDUIXbvYbkwvt+h5QLVrBsQwLuqwKp8AD 6UDPFy+y5ls1M3KIe6FDRtCxF35MGrsfBg7pdguu40QgHI9sPo4TQw6so4aYHVDBNNHOCULNaLh XhLCn1pYLBWotv1EOOusjKntfgaa4EkFKPz11cm5XQnuM+cRRbr7iccRWKb1ALkqBnUjbRnOsDG btRg1dSE= X-Received: by 2002:a05:620a:1a0e:b0:93f:5754:4eb6 with SMTP id af79cd13be357-949bab0dc04mr7318426585a.49.1796190907214; Tue, 01 Dec 2026 21:55:07 -0800 (PST) Received: from [192.168.50.231] (pool-71-191-145-202.washdc.fios.verizon.net. [71.191.145.202]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb34ad6dsm3012489485a.12.2026.12.01.21.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 21:55:06 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH 24/32] mm/mempolicy: reject an empty set of allowed nodes From: "Gregory Price (Meta)" To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , Chris Mason , stable@vger.kernel.org In-Reply-To: <20261129-fixes_core_3-v1-24-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-24-f66094116801@kernel.org> Date: Wed, 02 Dec 2026 00:55:04 -0500 Message-Id: <179619090494.1767256.4287449844580326358.b4-reply@b4> X-Mailer: b4 0.17-dev On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote: > From: Chris Mason > > Installing a mempolicy with MPOL_F_RELATIVE_NODES can trigger a division > by zero when racing with memory offlining. I managed to reproduce this > in a small VM with excessive set_mempolicy() calls while offlining > memory: > > Oops: divide error: 0000 [#1] SMP > RIP: 0010:bitmap_fold+0x43/0x60 > Call Trace: > ? mpol_relative_nodemask+0x26/0x40 > ? mpol_set_nodemask+0x43/0x90 > ? do_set_mempolicy+0x5e/0xe0 > ? __x64_sys_set_mempolicy+0x6c/0x80 > > mpol_set_nodemask() intersects current->mems_allowed with N_MEMORY, and > mpol_relative_nodemask() folds the user's nodemask modulo the weight of > the result. > > If memory offlining just cleared the task's only allowed node in N_MEMORY, > but cpuset did not update mems_allowed yet, the intersection is empty and > nodes_fold() divides by zero. > > do_mbind() and mpol_shared_policy_init() call mpol_set_nodemask() as > well. > > Let's fix it by failing with -EINVAL early if there is no allowed node > with memory, just like ->create() would later fail for an empty nodemask. > > The same division by zero was originally reported by syzkaller for > mpol_rebind_mm() [1]. The discussion of Yury's fix attempt [2] also > identified this path in mpol_set_nodemask() [3], but only the rebind > path got fixed, by commit b983c5642638 ("cgroup/cpuset: rebind mm mempolicy > to effective_mems, not mems_allowed"). > > This has low urgency, as it is extremely unlikely to hit in practice. > > Fixes: 8fe23e057172 ("mm: clear node in N_HIGH_MEMORY and stop kswapd when all memory is offlined") > Cc: stable@vger.kernel.org > Reported-by: David Hildenbrand (Arm) > Closes: https://lore.kernel.org/all/fe33c767-ea11-43e2-8732-f752c9c1205c@kernel.org/ [3] > Link: https://lore.kernel.org/all/CA+0ovCgxbZkXa+OU8w3s84R3KNPNxxRfmsNR-udh+afQBbGNmw@mail.gmail.com/ [1] > Link: https://lore.kernel.org/all/20260528190337.878027-1-ynorov@nvidia.com/ [2] > Signed-off-by: Chris Mason > [ david: update description and comment; add reproduction details ] > Signed-off-by: David Hildenbrand (Arm) fwiw also reproduced finally Tested-by: Gregory Price (Meta) while looking at the test, I wondered whether we could fix alot of these issues by figuring out how do all this work *BEFORE* dropping the node bit (N_MEMORY) and having people check something like node_has_memory() instead - but this seems like it'd be a pretty big lift. I've been learning that node_state[] walks race bigly with hotplug in non-obvious ways, and I don't like it. -- ~Gregory