bpf: Allow selected kfuncs under bpf_spin_lock
Status from this message: This series was applied to bpf/bpf-next.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest3 patches 1 replyApplied 3/3
- v11 patch 8 repliesSuperseded
Changes in v2 from the cover letter
- 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)
Patches in v2 All 3 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: Add KF_SPINLOCK_SAFE flag for kfuncs under bpf_spin_lockinclude/ kernel/ | +16 | 0 replies | Applied |
| 2/3 | bpf: Mark existing lock-safe kfuncs with KF_SPINLOCK_SAFEkernel/ kernel/ kernel/ +1 more | +36 | 0 replies | Applied |
| 3/3 | selftests/bpf: Test module kfunc calls under spin locktools/ tools/ tools/ +1 more | +27 | 0 replies | Applied |
Reviews trailers per patch
None of the 3 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Leon Hwang |
|---|---|
| Series | A-b |
| 1/3 | |
| 2/3 | |
| 3/3 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v2 0/3] bpf: Allow selected kfuncs under bpf_spin_lock
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/[email protected]/
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(-)
Signature · 1 line
2.50.1 (Apple Git-155)