]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Introduce lock-free bpf_async_update_prog_callback()
authorMykyta Yatsenko <yatsenko@meta.com>
Tue, 20 Jan 2026 15:59:12 +0000 (15:59 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 21 Jan 2026 02:12:19 +0000 (18:12 -0800)
commit8bb1e32b3fac1becb4c1c8079d720784b8e33e34
tree91413a98d93b3905cd376ac7cf62f50b7930bb3d
parent57d31e72dbdd1f71455aa62a2505a8cf088f46c6
bpf: Introduce lock-free bpf_async_update_prog_callback()

Introduce bpf_async_update_prog_callback(): lock-free update of cb->prog
and cb->callback_fn. This function allows updating prog and callback_fn
fields of the struct bpf_async_cb without holding lock.
For now use it under the lock from __bpf_async_set_callback(), in the
next patches that lock will be removed.

Lock-free algorithm:
 * Acquire a guard reference on prog to prevent it from being freed
   during the retry loop.
 * Retry loop:
    1. Each iteration acquires a new prog reference and stores it
       in cb->prog via xchg. The previous prog is released.
    2. The loop condition checks if both cb->prog and cb->callback_fn
       match what we just wrote. If either differs, a concurrent writer
       overwrote our value, and we must retry.
    3. When we retry, our previously-stored prog was already released by
       the concurrent writer or will be released by us after
       overwriting.
 * Release guard reference.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Link: https://lore.kernel.org/r/20260120-timer_nolock-v6-3-670ffdd787b4@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c