]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/bpf: Add cases to test BPF_F_CPU and BPF_F_ALL_CPUS flags
authorLeon Hwang <leon.hwang@linux.dev>
Wed, 7 Jan 2026 02:20:22 +0000 (10:20 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Jan 2026 04:48:32 +0000 (20:48 -0800)
commit07bf7aa58e5e7fb27b8addcc33052400a7d9ce32
tree2402dad36a68e520d03b1bb893d2af6330ed9a6e
parent2546863b4a723c96f55af7127827d62632cfbc9c
selftests/bpf: Add cases to test BPF_F_CPU and BPF_F_ALL_CPUS flags

Add test coverage for the new BPF_F_CPU and BPF_F_ALL_CPUS flags support
in percpu maps. The following APIs are exercised:

* bpf_map_update_batch()
* bpf_map_lookup_batch()
* bpf_map_update_elem()
* bpf_map__update_elem()
* bpf_map_lookup_elem_flags()
* bpf_map__lookup_elem()

For lru_percpu_hash map, set max_entries to
'libbpf_num_possible_cpus() + 1' and only use the first
'libbpf_num_possible_cpus()' entries. This ensures a spare entry is always
available in the LRU free list, avoiding eviction.

When updating an existing key in lru_percpu_hash map:

1. l_new = prealloc_lru_pop();  /* Borrow from free list */
2. l_old = lookup_elem_raw();   /* Found, key exists */
3. pcpu_copy_value();           /* In-place update */
4. bpf_lru_push_free();         /* Return l_new to free list */

Also add negative tests to verify that non-percpu array and hash maps
reject the BPF_F_CPU and BPF_F_ALL_CPUS flags.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20260107022022.12843-8-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/percpu_alloc.c
tools/testing/selftests/bpf/progs/percpu_alloc_array.c