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=1796125493; b=lyXOxKkTAUWBQecMuhKTaENCJlmXntu6d9adrxLPlicCrkpAg8mC1ey53KK36D9cpPWo ZZHl8R0oli3D7mIPcxy/HpEn0psNAxa9xgr6opZ6uHmm1tEQAnOyZ4lu5LR+0bSgLdhsn 5sZXa5+ClBCg3cmdoUeTjXUOk02nVMOZ1tXpAGBcjhHQixcO+vtbD/OAIGJXOFeKihPP4 ZBAdKWNJudMU2v5+8on0RfeHPuBHWP98PORdajrE514hk1R7HPR/CkSsQv/sQWsHA7vhf oVDUyb6FnL+Pgn/7BwQOt0HfWd8/PHM/5PsA8x6PLKoxslDC+GDwOwYmK/ssp/pASfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796125493; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=V/rmGIwFV9kBO/oGjyplk4w/+RvsuQc1pX2Sj2BVAjQ=; b=jr7RhP8SisWDjxol+/hWxIqzw6rYS5/iKmM4qO4tkY4OLwoyWtw9aUVRGeBkvgz3TGhV DJ1d7BrSuIrGil6EX4ld5LDQhd/GM2nvNFW2FiepDbzSBSg1+pa+qnTBJOzp9ZPSapmtT glo4OFyPJtQC/jw7fRt8VBu4vyb7tR/RRAqL2rSXbOqari/bioe4416+HXNLAEq9TesSW VfV+N7Hm+knTfkF2sTTbL4m0rWHsTtg10/HrUwp8LWV+S2DR+ITacBXMXoBUoPXE4o3WA 9nWxmca8CBl4UIPOXMytDUbvPbVMySkR0vtmrLEYa3hgLnyBO313BIP8yH5uCVt21SQ== 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=MegYCNN7; 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 E22BC606A31A; Tue, 1 Dec 2026 11:44:52 +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=MegYCNN7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 259D21F00897; Tue, 1 Dec 2026 11:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796125492; bh=V/rmGIwFV9kBO/oGjyplk4w/+RvsuQc1pX2Sj2BVAjQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=MegYCNN79O6002EwwN2LLtlcLY4swQZAWNpkFZivxmoBWgOUA3sIzKyb04Kw4gCVS WFvMYka0bsa1DaPps1F+5ewBSOrK8u3/OQuibP89Vgibf5plt8nR503c2eIgWBPZm+ c6ZNOTTkDKQT/NYKyiatpuMfChualYMNQKMrP/q48i15QH1U3m+aPaAbFP6aBqsc6I Ogyd7pnn0V7PGssapUTtJAhMxaFnjhSnwJdutomm4Y0USg04vw/tfNloRKDjGuWqFZ sMxQuMngEyOS6hUY7tHOAMK7cW0dvdYsgVVSbjf9q5lK4+QA/xWhd/gTjqaNMuYLkr EcbH/B2RjCILg== Message-ID: <31bb0227-4545-40c0-a6b7-a5a8445eac2b@kernel.org> Date: Tue, 1 Dec 2026 12:44:35 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock() To: "David Hildenbrand (Arm)" , "Gregory Price (Meta)" 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 , 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 , 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 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> From: "Vlastimil Babka (SUSE)" Content-Language: en-US In-Reply-To: <658d4809-6d38-4c0e-b432-bb9ae8dd0c08@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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. Preferring local makes more sense for them anyway? And if they get remote allocations, the bpf programs will just be a bit slower?