Re: [PATCH bpf v2 3/4] bpf: Don't spin on rhtab bucket locks with IRQs disabled
From: bot+bpf-ci
Date: Sun Nov 22 2026 - 20:14:04 EST
> bpf: Don't spin on rhtab bucket locks with IRQs disabled
TL;DR: On CONFIG_SMP=n kernels without DEBUG_SPINLOCK, setting trylock_irqsoff
on rhtab may make every new-key insert and delete fail with -EBUSY when IRQs
are disabled, even if the bucket is unlocked, contrary to the commit message.
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -2983,6 +2983,7 @@ struct bpf_rhtab {
> static const struct rhashtable_params rhtab_params = {
> .head_offset = offsetof(struct rhtab_elem, node),
> .key_offset = offsetof(struct rhtab_elem, data),
> + .trylock_irqsoff = true,
> };
On CONFIG_SMP=n kernels without CONFIG_DEBUG_SPINLOCK, can this make every
insert of a new key and every delete fail with -EBUSY whenever the caller
has IRQs disabled, even when no CPU holds the bucket lock?
rht_lock_or_busy() does this:
if (!params.trylock_irqsoff || !irqs_disabled()) {
*flags = rht_lock(tbl, bkt);
return true;
}
/* bit_spin_trylock() always succeeds on UP without DEBUG_SPINLOCK */
if (!IS_ENABLED(CONFIG_SMP) && !IS_ENABLED(CONFIG_DEBUG_SPINLOCK))
return false;
The check happens before any test of the bucket, so
__rhashtable_insert_fast() returns ERR_PTR(-EBUSY) and
__rhashtable_remove_fast_one() returns -EBUSY every time.
rhtab_map_update_elem() then frees the new element and returns -EBUSY, and
rhtab_delete_elem() returns -EBUSY. Updates of existing keys still work,
because rhtab_map_update_existing() takes no lock.
Programs running with IRQs disabled (int3-based kprobes, perf_event
programs, tracepoint, fentry and struct_ops programs in IRQs-off regions,
hardirq context) could insert and delete on UP before this patch, since
bit_spin_lock() only disables preemption there and never spins. Most
programs ignore the helper's return value, so the failure may go
unnoticed.
The commit message says these operations "now fail with -EBUSY when the
bucket is locked, by this CPU or another one, and work as before
otherwise". Is that accurate on such kernels?
Only the earlier rhashtable patch mentions the UP behaviour ("On UP
without DEBUG_SPINLOCK the lock bit isn't kept, so these callers always
get -EBUSY there"). Could this patch state that limitation too, or could
the lock bit be kept on UP for trylock_irqsoff tables so that rhtab fails
only when the bucket is actually held?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45090312341