Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796237827; b=1WfGmdBmhpGqH8wWg8SVtbbwLWxASNo2Kxn4B9Tefnt92RQ+ldtUXxdlRjGQS/tCY/Ci LqYHIWVzoOqt3qKsnvFsiu7Qbsk6YMhhqu3Y0IOBrUtutkBVAqdRO6FWfblm0qVZwDra4 /5fkLtxPqRVFfQt5/f9+0y2KMQQGqnQtQjwDfDgX7BNL1HcUjcNbeoOUNsFkjXnUOWqwe cJskWI2K2z/+MgqKM8cFhBdDA0XpS8+VexbyYdUKGGOicU9HpZfR8oms1FfHklvURIHVU GxU/QRvYx5K+1dG2PtalrhV2CbSRMrC8QxnuCtpPyLXqDwzpKQ5yTeoxlrLe1GsKQIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796237827; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=9x/+sF6du1DMqiHjYKQ+7ZH6cyuvbvgXFHHW7ag/jWA=; b=KiORCiWE7C88tKKdt2gDrOhdAwmNJ7shqsUa0fGq1LOn5AOy7gWhEN76g4/fnQNxAWmp +0iVYIi36Ie0W2XAU4mTX+Hgvg+8kssV6twJVnuPhM7bZOa/Ntdjg2SJ0+zgGG4xs/DWe nFMWRWfbdabjPBl18gB5hjxDr49lh7DeObfyjnc6HfY0zoTX6ozd2FGNqTvUtOLk+OmTV wPQ2DP1HLD1/Mx7+qTWypzOZMJ7FtmxgN3IO3od8rfgaCPbyH8TW9VVF4W9TMU2DPzt1Y SnU5YiA7basTyHB2MAI4bBQT9AGDFVsf4CmBolJzilajQjzhuEh35kb68OXeSL4Z3xw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zwXu3OzO; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 B05AB606A32C for ; Wed, 2 Dec 2026 18:57:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B05AB606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zwXu3OzO Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-71ad099391dso6301391eaf.3 for ; Wed, 02 Dec 2026 10:57:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796237826; x=1796842626; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9x/+sF6du1DMqiHjYKQ+7ZH6cyuvbvgXFHHW7ag/jWA=; b=zwXu3OzOZKT8gbr4ZyI89UVObO5jrboz3SS7IGG6FTOLbB4+jaqk7RZ1GYsUwIq3wM QgLFKib6lJF8cwAKWoxz3NIz30i+v7KpKcEZ1JCT6YOmtifb1gC7khneBJ4OCRkdLCMd qRI/ZZ3KyMDPrBe99Zfs9fkEwQ3ehbvszWp8UtpOp47yTId6mbgYjtKw6ZQwSF7U1PUj isPApqMDEbqu46+yJn9qXLhibrw6A+V1gN3ljCur6V89dhNBgxfn/JsWZ8VblSZ/tMpW 6s8fzVBx5WogsvKUe3Tzkmw2mDezmIRkZHmKHvs6gJNlTI/sCgvMhIHMhyazCN4xlBQp b20Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796237826; x=1796842626; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9x/+sF6du1DMqiHjYKQ+7ZH6cyuvbvgXFHHW7ag/jWA=; b=xvEV/6zo+sJUX2PX6NNkrYqucu/brDCjEIvCjMMCO/Cqqv934D2KpW1GYm4VyRbkLL eO6BIvResOQumI5ZfEQbI1s6soGbeIHJCJ/ByWwIKR/rds2gEoUflIgS4iw1UjtkO3+2 mv3ebGh8NIKmr11r+j2nyb1ngKTfBU7q4ZD3uktBGBa02g06aPQn7JpBA//g9CwaKnto 6QfZMFZjmcBgN6NQXI+Stu+jmxuX34UomVUGm1FQK5v3MGgJAT9SnrxA+CP3iw5eP2jQ 6jnZu4y/uw+tK4A20OhUdKKau0qIQOOi8bA3xJoRZWSJeZcFaI28QxJYtk74LCXkJJ8W dl/g== X-Forwarded-Encrypted: i=1; AL+hErEtexZqElsw5VmzLf9JtA6IR62zBYy3gqQUjievjLpPWXT5BRLBH87ULvyEVaU6qjLkpps6oeyrEXk=@vger.kernel.org X-Gm-Message-State: APuU4Z8NMKZhs5jvdEC1EjlgXxQv0P3tQqcncKw5e1+/vCJBzqZhBD6J HiObCvoB4woOOJCqFf9yePSLBIO+fpRex0GXnacceH+hPw3O2x2YNBYg X-Gm-Gg: AZFdTZelcTCpWNvXmvZY4ZorowIcKoYNhJU1oPiXr8IGdwE/cnlXmhqg4tOncc0mwiq aOG07eGYIf6FPps3Wq398tlvaxnrfpxVQ+KUDBlq9fpnVQPT/JE7SBM+D4JmArLtETWLcvT4O0n 4N2jG6A9y2moeeb6OlK6TbAd7yVMKUIZDAx8vjRhSEfq0HFk6e/r5shgSRSHzpt+di+ygWIOvuc gS3IToGJR1fkDjYjnYnFZO/7+qPGDVbNd5wDwcMBKR6pzJrzLpn5c/l7OXofH7K4HeaBEkOX4m7 NDozEweaOdavE44hF3Rqf+2mm7O/GWe/0bYtd8G/c80NGxkEqLscAQz0e5/lBVNYlv0Jv1Srz2d l7liPdpB6TCoxdDVp7uEOCaGxBVsSnjNMWcfFoEuU+np7X8yMp0ItL4a497WO2udXWt7+fA1Xq3 k3rdUw+O8KWv9iTGPczPHCRYtXLN1IJH2s2D0sAefEQv8bY27uoPg0t7TAY09cjEZaYTKy3R4RV bkjty/yd8YXFHqrSUUSsP3SELC0ryfil0AX/R8zRTUIEI6U+qbEFa2QcXIPgMHhwg3KkW0PLWIs FZFzLRHdO79vnSKS1nOf0yCCf1XBiVhWlX+505iywISTEltVQgZUUvD1KjkVMUIzc5aOp23Dw9R jKp9K X-Received: by 2002:a05:6820:c2cf:20b0:6f5:217:b0a2 with SMTP id 006d021491bc7-71b3920a765mr24247746eaf.12.1796237825678; Wed, 02 Dec 2026 10:57:05 -0800 (PST) Received: from localhost ([2a03:2880:10ff:47::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168f784fsm29908544a34.16.2026.12.02.10.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 10:57:05 -0800 (PST) Date: Wed, 2 Dec 2026 10:57:04 -0800 From: Joshua Hahn 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 , 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 , 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: <20261202184825.2250433-2-joshua.hahnjy@gmail.com> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-25-f66094116801@kernel.org> <0b0086cf-456b-4db6-babf-3841c50845bb@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: <0b0086cf-456b-4db6-babf-3841c50845bb@kernel.org> On Tue, Dec 01, 2026 at 10:40:17AM +0100, David Hildenbrand (Arm) wrote: > On 11/30/26 16:55, Joshua Hahn wrote: > > On Sun, Nov 29, 2026 at 11:06:56AM +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. > > > > In general this one looks good to me but I just want to note that below, > > we turn the strict slab_strict_numa into a best-effort case when > > spinning is not allowed. Maybe something that is worth documenting? > > Yes, probably, what would be the best place? Maybe in Documentation/admin-guide/mm/slab.rst, right below the slab_strict_numa section? Maybe just a sentence that the memory policies are best-effort could be good enough: ``slab_strict_numa`` Enables the application of memory policies on each allocation. This results in more accurate placement of objects which may result in the reduction of accesses to remote nodes. The default is to only apply memory policies at the folio level when a new folio is acquired or a folio is retrieved from the lists. Enabling this option reduces the fastpath performance of the slab allocator. + Memory policies are still best-effort, and can be ignored and + allocated from the local node in contexts that cannot spin. > Meanwhile I figure out if we can drop mempolicy support for kmalloc_nolock() > entirely. Yeah, that sounds good to me too! It would also make the contract a bit easier to follow as well. I had an AI agent look through to see when the mempolicy is consulted, and I think without slab_strict_numa it's only in get_from_any_partial() anyways. New slabs come from alloc_frozen_pages_nolock() which just uses numa_node_id() :p Thanks David, have a great day! Joshua