From: bot+bpf-ci@kernel.org
To: mt4022@columbia.edu,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,yatsenko@meta.com
Cc: eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,tz2294@columbia.edu,mt4022@columbia.edu,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf] bpf: Fail rhtab inserts and deletes with IRQs disabled
Date: Tue, 3 Nov 2026 19:16:30 +0000 (UTC) [thread overview]
Message-ID: <228df6014515374d68917ecb8bf5d831f40843809ac3d93162aa7fd14b416744@mail.kernel.org> (raw)
In-Reply-To: <20261103-bpf-rhtab-irqs-disabled-v1-1-9874d96a088c@columbia.edu>
[-- Attachment #1: Type: text/plain, Size: 3657 bytes --]
> bpf: Fail rhtab inserts and deletes with IRQs disabled
TL;DR: The irqs_disabled() check in rhtab delete and insert may return -EBUSY
for every IRQs-off caller, such as sched_switch or perf programs, not just
re-entry, breaking previously working users; the commit message's claim about
other hash maps is also questioned.
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
[ ... ]
> @@ -3144,11 +3144,14 @@ static int rhtab_delete_elem(struct bpf_rhtab *rhtab, struct rhtab_elem *elem, v
> int err;
>
> /*
> - * disable_instrumentation() mitigates the deadlock for programs running in NMI context.
> - * rhashtable locks bucket with local_irq_save(). Only NMI programs may reenter
> - * rhashtable code, bpf_disable_instrumentation() disables programs running in NMI, except
> - * raw tracepoints, which we don't have in rhashtable.
> + * rhashtable takes its bucket bit locks with IRQs disabled and can't
> + * detect re-entry. With IRQs already disabled this CPU may already
> + * hold one, e.g., in NMI or in a program attached inside the resize
> + * worker's locked section.
> */
> + if (irqs_disabled())
> + return -EBUSY;
> +
> bpf_disable_instrumentation();
Does this irqs_disabled() check detect re-entry, or does it reject every
delete made from any context that runs with IRQs off?
Most of those contexts do not hold a bucket lock. For example, a tp_btf
program on sched_switch runs after __schedule() has called
local_irq_disable() and taken the rq lock:
__schedule()
trace_sched_switch()
bpf program
bpf_map_delete_elem()
rhtab_map_delete_elem()
rhtab_delete_elem()
irqs_disabled() -> -EBUSY
The same applies to sched_wakeup and irq_handler_entry tracepoints,
perf_event programs (which run from the PMU NMI or hrtimer hardirq),
fentry/kprobe on functions that run with IRQs off, sched_ext callbacks
under the rq lock, and code between bpf_local_irq_save() and
bpf_local_irq_restore().
The verifier has no program type restriction for BPF_MAP_TYPE_RHASH, and
these calls succeeded before this patch. Would a guard that fires only on
actual re-entry, such as a per-CPU or per-map marker set around the
rhashtable locked sections, or a bounded trylock on the bucket lock, avoid
the deadlock without breaking these users?
The commit message says -EBUSY is returned "like the other hash maps do on
re-entry". Is that accurate? htab_lock_bucket() uses
raw_res_spin_lock_irqsave() and fails with -EDEADLK or -ETIMEDOUT only when
rqspinlock detects a deadlock or timeout, not merely because IRQs are
disabled.
Also, 46730ee6e884 ("rhashtable: Use irq work for shrinking") moved the
shrink kick to irq_work so that it may be called in NMI context. With this
check, __rhashtable_remove_fast_one() can no longer reach that
irq_work_queue() call from NMI or with IRQs disabled via this map.
[ ... ]
> @@ -3261,6 +3264,10 @@ static long rhtab_map_update_elem(struct bpf_map *map, void *key, void *value, u
> if (atomic_read(&rhtab->ht.nelems) >= map->max_entries)
> return -E2BIG;
>
> + /* see rhtab_delete_elem() */
> + if (irqs_disabled())
> + return -EBUSY;
> +
The same question applies here: this makes every insert of a new key fail
with -EBUSY from any IRQs-off context, whether or not a bucket lock is held
by the current CPU.
[ ... ]
---
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/41698986159
next prev parent reply other threads:[~2026-11-03 19:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 18:46 Mani Tofigh via B4 Relay
2026-11-03 19:16 ` bot+bpf-ci [this message]
2026-11-04 0:35 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=228df6014515374d68917ecb8bf5d831f40843809ac3d93162aa7fd14b416744@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=mt4022@columbia.edu \
--cc=song@kernel.org \
--cc=tz2294@columbia.edu \
--cc=yatsenko@meta.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®