From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796133555; b=MzDvhUDftrFuqS/VYbhZ5voi82B30Yv5Em9DZl4aH4IKnIGkoWSaxHI1mTBbqIDt3uTS f+QSL78tgIDYqZpjrFYskxjDXeR57vmZSLIMOkUHZDiZPUuVNTvZg9TWvH22f1cLUmfvE Pp+re4TQQ6qJ9v6XW7mG+FnMrY/Kz7R8IVYIORx1ybyDYhwMTsBvKV4gb1mLBy3mcfL0I yrgVE5NPLNG3sTQxht28ty/J1mAZHxyqEx5NdlscwF15FTnKRVhq3LyxeX95zxf8VVl9E NKcUil9SOShMgmOMapERQNlhE/QfFh8nPyEThLdClVvbb9VHW/3vBpeBugubkfJYPDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796133555; 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=DgEYreYxtvlLxVB52sliEZ9SQLmDHsQxrEOjeI96fuk=; b=3uTvMaT5U9rLfmFwExj9nJ8AnBANzcIycfw2Lw2Pu6DbxoUr9BzwlsqR8CnOYdsGIUUj 4LQ1lXV8xamJjQrdJgBJSBhFlf7+wofq4j9ytbyyts5AHrPui07OdLEHNctvf8qR1900Z hfsonkv23x8FsWexb4chvOejIpqgmtj6yOCHOQXp2PpUjTsEeGm7hMfxF092flo1nkw2w Txo3wKavdfwmC+hza6Cn/oQrq/aWjDxzdcHzY2N6stbcP8NmG/oIG0XqKUG7NOANL3jtW Gyg/IOTdWNHcE7gqX3nWR3PVj/IhwlmN2mELYZOzb11SLt4vcAV6KzJ2+5/3kYkCdjw== 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=VCi+R+2s; arc=none smtp.remote-ip=209.85.219.41 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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 03005606A320 for ; Tue, 1 Dec 2026 13:59:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 03005606A320 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=VCi+R+2s Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-91e8a05ec5aso154264826d6.1 for ; Tue, 01 Dec 2026 05:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1796133554; x=1796738354; 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=DgEYreYxtvlLxVB52sliEZ9SQLmDHsQxrEOjeI96fuk=; b=VCi+R+2si52O3+Pr0ZUMMfjWyovl/G2KG5+0TguZwz1gGaVQzpCsLmShXYB2Cbe22d I7sxYhAe8gBKNWwrNrO/o7o2cjTtnbujIViFXf7VcaAKqW2QyaYnx50Gb1V5SobluWY4 FWP1YGJvX22H6pj77fWKCTmOkzZSSZBKKsJi/9G0HjEjMcvUduzGh6CeOI4XVmu+qAEU sVzv2DoCwrsw+nFsFVYwOHZXR+Si2HRvYL2Jozz9QwL4ocBDAwywvD12LMSlAXH8z319 2WzbZPctxoM0KMKPKmi6Y+s/p3sS4uHAWu//GHbi8fq62gMBDb42dWvyoNXvZ5pVhIrQ 3xNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796133554; x=1796738354; 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=DgEYreYxtvlLxVB52sliEZ9SQLmDHsQxrEOjeI96fuk=; b=ludseAL/JvZX4TIvNY8IzttFDvWII5mGEB1uSqeNGPoFkVBrEEZQTDdunCOs8DPhy5 pnPxpCuK9PcxzNVLjEpUTBiGTq94XuF744Y/BZJCyoeF2O8yS7iPb/pnvoQq9Fe2E1ls ZcWhf0L2b/VxdrTqvaHl2OQac6UzVkRGkgy/Q2nab/MzbiwizPIK3+hUZdUrS/XkOQ76 nC+D89DQ00K2MdHRUm1liEFO8tQP9WY1UeNnIWYqO4gnxSIqZnlHFfvD+N/AxQUwCv4s KG6GfE2dxqe2gPlXvmLHrylRGuxPHRavIePEwjm/rN/X+uM9g01Mnxq4WjxJ4M17jFQp b+wQ== X-Forwarded-Encrypted: i=1; AL+hErHHribGDx3bjeaCTdwVutlKS3YoBd1R+wVeUh7Afijai+WgN08Exjk1pAT2aK9YmJsoGPqJesp53TXg6YI=@vger.kernel.org X-Gm-Message-State: APuU4Z+gcSwkY/yCC4o68CKjhz5x2eLejWkKWkx6b3r5VeSinImYPk2b LT9OATbACi4UfxBKIetj8HSsdVOZKDOO5xTa6/KEotChK5M6Faabp+vghV1LRMUyHhY= X-Gm-Gg: AZFdTZdiIiM3pvrD+NKma8w1XEf8aqjJYmlpJx4ZbGjtnoX97O21mvZWb9C/zcPuA3N Dim32V8awjwWVj6DQ5Roi4TKMg3Yv/abBdUxsN9eO+b7myGr7Fn0i2O7yuSkigUL6kfkHqHv721 XNg5rIom/V6kVFebp0y8XOrqrTKk+GBJchXt9CxZ51V4+LRi/nHAZnAxwMuoc0dsZdeQXmqYwG1 ZUOPlxD85dV5P228uPdv7grkFcuFYPewfAxNg15qkb0MXTC56lIFWFL8uWZLJfInwEfuP4tklRy p4RsdH63X66xwj846eKBdVNLLWwZcmUUo8vcpkk3rACrgRa8w4nChCdujr0ViBF0k6U51FijXRT uT/4sDOUEB/KcQ4krrBJhFgrIzKpoEHJ33+pUQnUNHzOJcFzjPCcHgrqqzjIB0U+yYsasHea0sZ GyZtzn5hF9iMoFuXCxOqzwZDO8Wb3lZMdJWQ08CXSPa/rnZOjYb1RMrrmmisoQDiIAGBS2zTMoK wy7vvXzmil77YAG2Kacvnpkgm9ASP/VjIijw7Mlza9fokvlvf9GOWe/egLyFbm5t70G8gPBpVc6 Sqy4fQa+gz15z8lTIN42l8qVa2hQsxByypS5x2uk+Wv6atZGIMNRV0PQ72/mkdYCyen4mTq9GC7 /Rh8+ajcRZepmtJUERbsy76dtAg55 X-Received: by 2002:ad4:5d48:0:b0:921:6668:9f4b with SMTP id 6a1803df08f44-9216668ad70mr485119286d6.43.1796133553841; Tue, 01 Dec 2026 05:59:13 -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 6a1803df08f44-92134a2806dsm319533876d6.45.2026.12.01.05.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 05:59:13 -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 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock() From: "Gregory Price (Meta)" To: Harry Yoo Cc: "Vlastimil Babka (SUSE)" , "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 In-Reply-To: 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> Date: Tue, 01 Dec 2026 08:59:11 -0500 Message-Id: <179613355111.412063.15718514507935111070.b4-reply@b4> X-Mailer: b4 0.17-dev On 2026-12-01 13:13 +0000, Harry Yoo wrote: > 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". > If you want my real opinion - I think we should kill task mempolicies and instead convert set_mempolicy() to change a task's VMA policies. I don't think allowing a task-wide mempolicy to drive kernel allocations is any definition of sane for a variety of reasons. -- ~Gregory