The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/3] bpf: Allow selected kfuncs under bpf_spin_lock
@ 2026-08-05 15:33 Kaitao Cheng
  2026-08-05 15:33 ` [PATCH bpf-next v2 1/3] bpf: Add KF_SPINLOCK_SAFE flag for " Kaitao Cheng
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Kaitao Cheng @ 2026-08-05 15:33 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend, Shuah Khan, Leon Hwang
  Cc: bpf, linux-kselftest, linux-kernel, Kaitao Cheng

The verifier currently has a hard-coded allowlist of kfuncs that may be
called while a BPF program holds a bpf_spin_lock. This works for the
small set of built-in kfuncs known to the verifier, but it does not give
kfunc providers a registration-time way to declare that a kfunc is safe
in such a region. In particular, module kfuncs cannot be added to that
allowlist without changing verifier code.

This series adds a new KF_SPINLOCK_SAFE kfunc flag and teaches the
verifier to use kfunc registration metadata when deciding whether a
kfunc call is allowed while a bpf_spin_lock is held.

The built-in kfuncs that are currently accepted by the verifier's
lock-held allowlist are annotated with the new flag. This preserves the
existing behavior while removing the verifier-side category checks and
uses the same mechanism for built-in and module kfuncs.

The selftest coverage marks one bpf_testmod kfunc as KF_SPINLOCK_SAFE
and verifies that it can be called under a bpf_spin_lock. It also calls
another registered but unmarked bpf_testmod kfunc under the lock and
checks that the verifier rejects it.

Changes in v2:
- Rename KF_SPIN_LOCK to KF_SPINLOCK_SAFE. (Kumar Kartikeya Dwivedi,
  Leon Hwang)
- Deprecate the verifier's lock-held allowlist mechanism and annotate the
  relevant kfuncs uniformly with KF_SPINLOCK_SAFE (Kumar Kartikeya Dwivedi)
- Add selftests. (Leon Hwang)

Link to v1:
https://lore.kernel.org/bpf/DKG0YUDSTBUY.1X220287HT9V3@gmail.com/

Kaitao Cheng (3):
  bpf: Add KF_SPINLOCK_SAFE flag for kfuncs under bpf_spin_lock
  bpf: Mark existing lock-safe kfuncs with KF_SPINLOCK_SAFE
  selftests/bpf: Test module kfunc calls under spin lock

 include/linux/btf.h                           |  1 +
 kernel/bpf/arena.c                            |  6 +-
 kernel/bpf/helpers.c                          | 56 ++++++++++---------
 kernel/bpf/rqspinlock.c                       |  8 +--
 kernel/bpf/verifier.c                         | 38 +++----------
 .../selftests/bpf/prog_tests/kfunc_call.c     |  2 +
 .../selftests/bpf/progs/kfunc_call_fail.c     | 12 ++++
 .../selftests/bpf/progs/kfunc_call_test.c     | 12 ++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  2 +-
 9 files changed, 72 insertions(+), 65 deletions(-)

-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-06  9:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 15:33 [PATCH bpf-next v2 0/3] bpf: Allow selected kfuncs under bpf_spin_lock Kaitao Cheng
2026-08-05 15:33 ` [PATCH bpf-next v2 1/3] bpf: Add KF_SPINLOCK_SAFE flag for " Kaitao Cheng
2026-08-05 15:33 ` [PATCH bpf-next v2 2/3] bpf: Mark existing lock-safe kfuncs with KF_SPINLOCK_SAFE Kaitao Cheng
2026-08-05 15:33 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test module kfunc calls under spin lock Kaitao Cheng
2026-08-05 16:51 ` [PATCH bpf-next v2 0/3] bpf: Allow selected kfuncs under bpf_spin_lock Leon Hwang
2026-08-06  9:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox