]> git.ipfire.org Git - thirdparty/linux.git/commit
libbpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu maps
authorLeon Hwang <leon.hwang@linux.dev>
Wed, 7 Jan 2026 02:20:21 +0000 (10:20 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Jan 2026 04:48:32 +0000 (20:48 -0800)
commit2546863b4a723c96f55af7127827d62632cfbc9c
treeda5a01a96cec643ca03e0546b7dbd26b4518b132
parent47c79f05aa0d289f760caf5ad6521fd8dbae37a1
libbpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu maps

Add libbpf support for the BPF_F_CPU flag for percpu maps by embedding the
cpu info into the high 32 bits of:

1. **flags**: bpf_map_lookup_elem_flags(), bpf_map__lookup_elem(),
   bpf_map_update_elem() and bpf_map__update_elem()
2. **opts->elem_flags**: bpf_map_lookup_batch() and
   bpf_map_update_batch()

And the flag can be BPF_F_ALL_CPUS, but cannot be
'BPF_F_CPU | BPF_F_ALL_CPUS'.

Behavior:

* If the flag is BPF_F_ALL_CPUS, the update is applied across all CPUs.
* If the flag is BPF_F_CPU, it updates value only to the specified CPU.
* If the flag is BPF_F_CPU, lookup value only from the specified CPU.
* lookup does not support BPF_F_ALL_CPUS.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20260107022022.12843-7-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/bpf.h
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h