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=1796130817; b=aafvRgkMg9McdKCJzLeZBwIig9AXNluTc1D9TXdJ64R5LXWqzh9hK9dp+mkRv+iM50fn OtY6kS5v5In2U9kc36qi7QhPmPdQf2bHFbRDHp4douByG60aZUraI2qBZX5SosQEYGT3S LrIu5PDW9/LXNcMb75faIWdaikbOdzg3RdwtRbp+6lAElmjhAz5btt4Gi4auByVdQUNDP 5liAZRUaGy+aAbmOvM0pK5pEKSLU3TeUV+8+9UQPZrqJq8Kvz3rnEE10Lea8l6BJprBeA nkgjYbga3iyIEmnZjDymGwGi+5i5CWt4wTwYJmulUYxgfa5hCmX42N+MpeIlDMElgig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130817; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=Sp4sMOFqQUFagF+Bi1pp54gQV01aozy4WkCWsCaGo7A=; b=qlQ1p995ekZDPmRt1xwNP1L+tLB0PQjNb+Jq7Z3zU8WOydGu4QypcenXdciJUopP0Iqe nRIiP5JNw8u5LpjcrcQk4xZw6YcF8itn5HDAjA6+Hg68ra6wd3moc0k6HVku0A1MfpOq8 fTFgW8RbDqRGCdvGctW93V8503iDTPPpXxFARxNMEMVUH1RvksEdJ8qzl2jqTgbbVIp0n M9NzADYDnfjLOk+c+Ogoht7ZlWImekAJ6Tz+ss3FSESlXD/QbBf25NpvnLeooxMjMOM7k ndIpfo7kCZzt+ZmEZ+4loEdqrk2okwZ5BFeAEz5XoLyUtO6EkVg6fMvUm+FpTV6rxWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mQbMCtBb; 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 57A2A606A329; Tue, 1 Dec 2026 13:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mQbMCtBb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4B11F0092A; Tue, 1 Dec 2026 13:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796130816; bh=Sp4sMOFqQUFagF+Bi1pp54gQV01aozy4WkCWsCaGo7A=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=mQbMCtBb7D4RvqDBNCwD63Oua5t2QwjCoBpiRdN6qgkIyn4yDN7+vEIOfheksNZpa YKuJM+GT6bDJMMMX3JD2scB2fze4HNf6tQGkEF3OejNHfitdn58MAC6Idpel+gyb0I Jbp4oinGHI4OikNqRG2jfqYVIkNirBgJpYPwcUhrwlBWNnid4eOYQBWfZDY9H7Siuc tSSkpSpGp+e5QfPKM7eJZ4m/grp02MaD3PGsdpqQEipJu2lxl7WLWpNOs9iADz8vFV +Pk7Jt06JOy1xbIvW8YzIibNehWgQqp4cYwpZOOakfzU8A++w1AFOcEygjDBN6lHqL lXasgKuvi15uQ== Date: Tue, 1 Dec 2026 13:13:34 +0000 From: Harry Yoo To: "Vlastimil Babka (SUSE)" Cc: "David Hildenbrand (Arm)" , "Gregory Price (Meta)" , 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 , 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 , 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 , stable@vger.kernel.org, Chris Mason Subject: Re: [PATCH 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock() Message-ID: References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-25-f66094116801@kernel.org> <179606232333.412063.9827468608746549903.b4-reply@b4> <658d4809-6d38-4c0e-b432-bb9ae8dd0c08@kernel.org> <31bb0227-4545-40c0-a6b7-a5a8445eac2b@kernel.org> X-Mailing-List: linux-cxl@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=us-ascii Content-Disposition: inline In-Reply-To: <31bb0227-4545-40c0-a6b7-a5a8445eac2b@kernel.org> On Tue, Dec 01, 2026 at 12:44:35PM +0100, Vlastimil Babka (SUSE) wrote: > On 12/1/26 10:39 AM, David Hildenbrand (Arm) wrote:> On 11/30/26 19:12, > Gregory Price (Meta) wrote: > >> On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote: > >>> kmalloc_nolock() must not wait for locks, including seqlocks. > >>> get_from_any_partial() therefore skips read_mems_allowed_begin() if > >>> spinning is not allowed. > >>> > >>> However, with an MPOL_INTERLEAVE or MPOL_WEIGHTED_INTERLEAVE task policy, > >>> mempolicy_slab_node() calls interleave_nodes() or > >>> weighted_interleave_nodes(), which both spin on tsk->mems_allowed_seq > >>> since commit 274519ed414b ("mm/mempolicy: protect task interleave > >>> functions with tsk->mems_allowed_seq"). The same applies to > >>> apply_strict_numa_policy() with slab_strict_numa. > >>> > >>> Consequently, a BPF program that allocates using kmalloc_nolock() within > >>> the write section of that seqcount, for example in > >>> cpuset_change_task_nodemask(), can deadlock. On PREEMPT_RT, waiting for > >>> the seqcount can then even sleep in atomic context. > >>> > >>> Let's fix it by passing whether spinning is allowed to > >>> mempolicy_slab_node(), simply using the local node for interleave > >>> policies if disallowed. > >>> > >>> While not perfect, it shouldn't matter in practice, is in line with > >>> !in_task() handling, and slab interleaving is best-effort either way, > >>> unless slab_strict_numa is set. > >>> > >> > >> Should we just blanket ignore mempolicy when spinning is not allowed? > >> If another mempolicy gets added later we have moles to whack. > > > > Yes, that's what we get for merging half-baked things like kmalloc_nolock(). > >> > >> I think then this just becomes a slub.c-only change where we ignore > >> mempolicy is spinning isn't allowed and always prefer local. > >> > >> That also makes the behavior consistent - no-spin = no policy. > > > > I'm not sure if that's preferable. @Vlastimil, @Harry what are your thoughts on > > this? > > I think it's fine. kmalloc_nolock() are usually bpf allocations from > tracepoints/probes that do their own thing not related to the main code > and its policies. I don't have a good answer to "should BPF programs follow the task's mempolicy or have their own memplicy". But I think it's fine. We've never properly supported mempolicy in kmalloc_nolock() anyway to avoid deadlock. And at this stage it doesn't make much sense to try too hard to enforce mempolicy when we have a bigger problem of allocating memory reliably :) -- Cheers, Harry / Hyeonggon