Re: [PATCH 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock()
From: David Hildenbrand (Arm)
Date: Tue Dec 01 2026 - 04:40:43 EST
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?
Meanwhile I figure out if we can drop mempolicy support for kmalloc_nolock()
entirely.
--
Cheers,
David