Re: [PATCH bpf-next v1 1/4] bpf: Add call for selecting kmalloc or kmalloc_nolock at call time
From: Alexei Starovoitov
Date: Wed Nov 25 2026 - 20:04:32 EST
On Wed, Nov 25, 2026 at 06:09 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> This is absolute atrocious shite. You cannot attempt a spin_trylock from
> NMI context. That thing might be a mutex.
cannot spin_trylock from NMI _on PREEMPT_RT_ ... correct.
And the patch guard against that.
On RT the nolock path doesn't reach zone->lock in NMI or hardirq:
__alloc_frozen_pages_noprof() alloc_flags has ALLOC_NOLOCK
alloc_nolock_allowed()
can_spin_trylock()
if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_nmi() || in_hardirq()))
return false;
fwiw kmalloc_nolock() has the same check.
> This should not work; if it does, that is an accident we need to fix.
It's not an accident.
In NMI only !RT SMP kernels reach the trylock.