Re: [PATCH bpf-next v1 1/4] bpf: Add call for selecting kmalloc or kmalloc_nolock at call time
From: Alexei Starovoitov
Date: Thu Nov 26 2026 - 15:39:46 EST
On Thu, Nov 26, 2026 at 01:44 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> Allowing this on !RT makes people think this is 'OK' and then the RT
> people get to fix endless crap again :-(
...
> You're actively creating something that doesn't and cannot work on RT.
There is nothing for RT people to follow up or to fix.
The diff doesn't introduce any new failure mode or a path.
alloc_pages_nolock() works this way since v6.15.
On RT it returns NULL in NMI and in hard IRQ.
It allocates in all other contexts.
The API that people call is kmalloc_nolock() or alloc_pages_nolock()
and the contract is the same in every config:
any context, and NULL is a normal result.
The caller's code is the same on RT and on !RT.
> Locking constructs should behave identical across the configurations to
> avoid divergence and create problems.
Conceptually I agree, but my bot points out plenty of practical
RT vs !RT differences which are way bigger than
this internals of kmalloc_nolock():
where !RT RT
------------------------- ------------------------- ------------------
debug_objects_fill_pool() allocates in any context preemptible() only
printk(), legacy console spinlock_t under raw lock printer thread
vmbus_isr() spinlock_t in hard IRQ irq thread
kvfree_call_rcu() uses kfree_rcu_sheaf() skips it
local_trylock() works in NMI and hard IRQ fails there