From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796237827; b=GqmY4vvvHWuhXRxyuJwNvkTCmRAjfFGOPahxVT9kqdnmQH/YvmQt0h+EVD7/NC+472rP 4fqiJG/XtRZsNvVzkteylczX0QLv7/TEI47BQz6gTIbJ9X7gd65E6r4+3snnYtVFB/S/Q TphoBmYC+Ax6+1U2TLk12LMNZ/4i7OzGS+FJF3Q8g54RPeHzRe5z/BO5Nusg2y6lfhuDE GwY+6A/gEjvKwlfBfNoCz/14fTBgIy/zAq81OA7SnuFhRWJ8G7Z2chgs+mY4hM5rv03fN 67vyWvKC6AJU76mMElTGSzAL3WGl816Fx2DjRc5qA/qcKs7LFZg3XdSq9znrJyIFg3Q== 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=s5uB7aF8nRHiNW9S0+MekuxY1pR78ekyr246FhqnDKtc33PEL3h1S6FPP2IM108t2B1q wfcpiF280LrTGW0VklsWxRn34tVupC4H+ju19Envs+AAo6GXQpYyJraiDsEL0L1hJQTwX cC+970+ps5c49URC+seyM7fvCt7K4EYdGfMVste9PEh0lOUIT8J1YCTiChscUoDn16Lin zvhjFXWsfa8Gexf9tquFFOWnPt4eve5xamBjV9rsVe0PvCWobQPmNcUqkL3361xDko7vB qFpplar87ZlKKe57LUM6BCqy/9dVI/Ay/51XRxjJam0FRA1ZDnhLqa6mMQgiOpJjAUg== 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.51 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 CBD4F606A336 for ; Wed, 2 Dec 2026 18:57:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CBD4F606A336 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-f51.google.com with SMTP id 006d021491bc7-6d68de53053so10302253eaf.0 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=Lb+U7b5lxf56i3MWi/P6hmA95IYv1RsqBVe9x5lrSf9C8jeL6oymLmjqmJCpcvgQxL yBQ78/bZKRduUQw9ZZuoTnZRJOmGqC6Kj0iteRHooKS6m6g4qs68skPSK2x0x2so9eqY 2AV0nY/qwkzqdN7+6JtqJgIXH4dnNCie2L2lDoH1cq6C33WZB7TFhQySBS5xpWZs/wQH D5J2HTRdcZ9exBB23YqhlAvhfugpVxxG7k3ms+Q3LyhDTjPQSm76Jh7SoZEmfuSAPbv4 firfplGrI75PeUBaG63ZQfs9j4Yz6Sz7c2X6ik37X4Kd8b+23+cYcvVbI37HB9kkFXO+ R5uw== X-Forwarded-Encrypted: i=1; AL+hErHN63vq6f873hdBfuhOd9FCNB3VFMTkQKvQWPtusWLB/uwK43ByvoLfVcLPpwXgbTvtHsNlfOtmoT3Jdtc=@vger.kernel.org X-Gm-Message-State: APuU4Z8ueHW5AXlRRRWjSPTZBmY/DNY723MPyA2V0UoorJX5LOO8QbU1 usinow7WIpxpQ+WcF5WXH7oRDjjsZluYd331DzmhtDOW1JoqV3W/YUlf X-Gm-Gg: AZFdTZeCHikzpCuyndtA69LtiW+x6/MUptt3teDCBcIkRA4Rka1dOllRodRHPPrU22X C3isI/FafyxhtC9lTyVZDqZ2Rr0QEjlmAavpYKE+OuVHB1/rCd2297hsU7whmG8IeRXHBv3TMd3 Aem1r7XjAReCTpHv2M1RKHo1JbPPce05E+ctOIW6JgZBoFC+YywwPUrtVJf7ytM2CHvLfrAtXQn d+doAnXo/bwXqZshyvWHA3TkKmYOjDUUHTkogDPHqm77rPzKjnzEo17S7bXHi8ZAnG/SYjQ/goN gdTYbX5jRtVrEtbj3ZT47diaNc9zgdzd2pHhrOFobPcVQ0bnqw4G2CR8X5td16fTMUh8oL0DOFY kjFyw39Nmit/YgPyYhDlSDz7ck/OEOmVu5KiaWygsp1VVI9hYyBmnrxxUGi06bkvQOw2bWTmLEp lWC4ubXemqRSncRKl0QwZR3V4cieO53iSibLoj1WNBx7Yg26KyqES7VdLU3Xhjc3CyR9kCMjGDq vNrWK6fsz6cgQLSkZSDean1P68B9LpMNK9r5MbwVzX/4jqX97bvDqARL5jo1YzklNQc/ILMGItv alKOeC/N03djxPM22lglqFR26i1FKf/OBb7B3Mt/DCLCmBF1fznoUVy04386rQYrkQqq2hLNVOp Fggs6 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-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=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