Re: [PATCH 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock()

From: Jose A. Perez de Azpillaga

Date: Sun Nov 29 2026 - 16:27:54 EST


On 11/29/26 11:06 AM, 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.
>
> This has low urgency, as it requires a BPF program to allocate with
> kmalloc_nolock() while the task's mems_allowed are being updated.
>
> Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

LGTM:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a