KFunc bpf_res_spin_lock
Takes a Resilient Queued Spin Lock (rqspinlock
).
Definition
Returns
A conditional result, depending on whether the lock was acquired (NULL
is returned when lock acquisition succeeds, non-NULL upon failure). The memory pointed to by the returned pointer upon failure can be dereferenced after the NULL
check to obtain the error code.
Preemption is disabled upon successful lock acquisition, however IRQs are not.
Signature
int bpf_res_spin_lock(struct bpf_res_spin_lock *lock)
Note
The pointer returned by the kfunc may be NULL. Hence, it forces the user to do a NULL check on the pointer returned from the kfunc before making use of it (dereferencing or passing to another helper).
Usage
This is a qspinlock
variant which recovers the kernel from a stalled state when the lock acquisition path cannot make forward progress. This can occur when a lock acquisition attempt enters a deadlock situation (e.g. AA, or ABBA), or more generally, when the owner of the lock (which we’re trying to acquire) isn’t making forward progress.
With regular spinlocks the eBPF verifier ensured deadlock safety by only permitting one lock acquisition at a time, and by preventing any functions to be called from within the critical section. Additionally, only a few restricted program types are allowed to call spin locks.
The rqspinlock
implementation allows us to permit more flexible locking patterns in BPF programs, without limiting them to the subset that can be proven safe statically. But this means that acquiring the lock may fail.
Program types
The following program types can make use of this kfunc:
BPF_PROG_TYPE_CGROUP_DEVICE
v6.12 -BPF_PROG_TYPE_CGROUP_SKB
BPF_PROG_TYPE_CGROUP_SOCK
v6.12 -BPF_PROG_TYPE_CGROUP_SOCKOPT
v6.12 -BPF_PROG_TYPE_CGROUP_SOCK_ADDR
v6.7 -BPF_PROG_TYPE_CGROUP_SYSCTL
v6.12 -BPF_PROG_TYPE_LSM
BPF_PROG_TYPE_LWT_IN
BPF_PROG_TYPE_LWT_OUT
BPF_PROG_TYPE_LWT_SEG6LOCAL
BPF_PROG_TYPE_LWT_XMIT
BPF_PROG_TYPE_NETFILTER
BPF_PROG_TYPE_PERF_EVENT
v6.12 -BPF_PROG_TYPE_SCHED_ACT
BPF_PROG_TYPE_SCHED_CLS
BPF_PROG_TYPE_SK_SKB
BPF_PROG_TYPE_SOCKET_FILTER
BPF_PROG_TYPE_SOCK_OPS
v6.15 -BPF_PROG_TYPE_STRUCT_OPS
BPF_PROG_TYPE_SYSCALL
BPF_PROG_TYPE_TRACEPOINT
v6.12 -BPF_PROG_TYPE_TRACING
BPF_PROG_TYPE_XDP
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome