Skip to content

RFC bpf: Introduce BPF_F_CPU flag for percpu_array map

Leon Hwang bpf 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest3 patches 6 repliesIn review
  2. v1 RFC3 patches 9 repliesSuperseded

Changes in v2 from the cover letter

* Address comments from Andrii:
* Embed cpu to flags on kernel side.
* Change BPF_ALL_CPU macro to BPF_ALL_CPUS enum.
* Copy/update element within RCU protection.
* Update bpf_map_value_size() including BPF_F_CPU case.
* Use zero as default value to get cpu option.
* Update documents of APIs to be generic.
* Add size_t:0 to opts definitions.
* Update validate_map_op() including BPF_F_CPU case.
* Use LIBBPF_OPTS instead of DECLARE_LIBBPF_OPTS.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: Introduce BPF_F_CPU flag for percpu_array mapinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/arraymap.c +2 more+92 -332 replies
2/3bpf, libbpf: Support BPF_F_CPU for percpu_array maptools/lib/bpf/bpf.c tools/lib/bpf/bpf.h tools/lib/bpf/libbpf.c +3 more+172 -142 replies
3/3selftests/bpf: Add case to test BPF_F_CPUtools/testing/selftests/bpf/prog_tests/percpu_alloc.c tools/testing/selftests/bpf/progs/percpu_array_flag.c+194 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH bpf-next v2 0/3] bpf: Introduce BPF_F_CPU flag for percpu_array map

This patch set introduces the BPF_F_CPU flag for percpu_array maps, as discussed in the thread of
"[PATCH bpf-next v3 0/4] bpf: Introduce global percpu data"[1].

The goal is to reduce data caching overhead in light skeletons by allowing a single value to be reused across all CPUs. This avoids the M:N problem where M cached values are used to update a map on N CPUs kernel.

The BPF_F_CPU flag is accompanied by a cpu field, which specifies the target CPUs for the operation:

* For lookup operations: the flag and cpu field enable querying a value on the specified CPU.
* For update operations:
* If cpu == (u32)~0, the provided value is copied to all CPUs.
* Otherwise, the value is copied to the specified CPU only.

Currently, this functionality is only supported for percpu_array maps.

Links:
[1] https://lore.kernel.org/bpf/[email protected]/

Changes:
RFC v1 -> RFC v2:
* Address comments from Andrii:
* Embed cpu to flags on kernel side.
* Change BPF_ALL_CPU macro to BPF_ALL_CPUS enum.
* Copy/update element within RCU protection.
* Update bpf_map_value_size() including BPF_F_CPU case.
* Use zero as default value to get cpu option.
* Update documents of APIs to be generic.
* Add size_t:0 to opts definitions.
* Update validate_map_op() including BPF_F_CPU case.
* Use LIBBPF_OPTS instead of DECLARE_LIBBPF_OPTS.

Leon Hwang (3):
bpf: Introduce BPF_F_CPU flag for percpu_array map bpf, libbpf: Support BPF_F_CPU for percpu_array map selftests/bpf: Add case to test BPF_F_CPU

 include/linux/bpf.h                           |   3 +-
 include/uapi/linux/bpf.h                      |   7 +
 kernel/bpf/arraymap.c                         |  56 ++++--
 kernel/bpf/syscall.c                          |  52 ++++--
 tools/include/uapi/linux/bpf.h                |   7 +
 tools/lib/bpf/bpf.c                           |  23 +++
 tools/lib/bpf/bpf.h                           |  36 +++-
 tools/lib/bpf/libbpf.c                        |  58 +++++-
 tools/lib/bpf/libbpf.h                        |  53 +++++-
 tools/lib/bpf/libbpf.map                      |   4 +
 tools/lib/bpf/libbpf_common.h                 |  14 ++
 .../selftests/bpf/prog_tests/percpu_alloc.c   | 170 ++++++++++++++++++
 .../selftests/bpf/progs/percpu_array_flag.c   |  24 +++
 13 files changed, 460 insertions(+), 47 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/percpu_array_flag.c

--
2.50.0