On 2026/8/5 23:33, Kaitao Cheng wrote:
> 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(-)
> 


Nice to drop those 'is_*_kfunc()' helpers in verifier.

BTW, some of those kfuncs can be dropped from the special_kfunc_list.
That would be better.

Any way, this series looks good to me.

Acked-by: Leon Hwang <[email protected]>


Reply via email to