Skip to content

bpf: introduce BPF_MAP_TYPE_RELAY

Philo Lu bpf linux-trace-kernel llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: implement relay map basisinclude/linux/bpf_types.h include/uapi/linux/bpf.h kernel/bpf/Makefile +2 more+171 -06 replies
2/3bpf: implement map_update_elem to init relay filekernel/bpf/relaymap.c+31 -14 replies
3/3bpf: introduce bpf_relay_output helperinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/helpers.c +3 more+53 -02 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH bpf-next 0/3] bpf: introduce BPF_MAP_TYPE_RELAY

The patch set introduce a new type of map, BPF_MAP_TYPE_RELAY, based on relay interface [0]. It provides a way for persistent and overwritable data transfer.

As stated in [0], relay is a efficient method for log and data transfer. And the interface is simple enough so that we can implement and use this type of map with current map interfaces. Besides we need a new helper bpf_relay_output to output data to user, similar with bpf_ringbuf_output.

We need this map because currently neither ringbuf nor perfbuf satisfies the requirements of relatively long-term consistent tracing, where the bpf program keeps writing into the buffer without any bundled reader, and the buffer supports overwriting. For users, they just run the bpf program to collect data, and are able to read as need. The detailed discussion can be found at [1].

The buffer is exposed to users as per-cpu files in debugfs, supporting read and mmap, and it is up to users how to formulate and read it, either through a program with mmap or just cat. Specifically, the files are created as "/sys/kerenl/debug/<dirname>/<mapname>#cpu", where the <dirname> is defined with map_update_elem (Note that we do not need to implement actual elem operators for relay_map).

If this map is acceptable, other parts including docs, libbpf support, selftests, and benchmarks (if need) will be added in the following version.

[0]
https://github.com/torvalds/linux/blob/master/Documentation/filesystems/relay.rst
[1]
https://lore.kernel.org/bpf/[email protected]/T/

Philo Lu (3):
bpf: implement relay map basis
bpf: implement map_update_elem to init relay file
bpf: introduce bpf_relay_output helper

 include/linux/bpf.h       |   1 +
 include/linux/bpf_types.h |   3 +
 include/uapi/linux/bpf.h  |  17 +++
 kernel/bpf/Makefile       |   3 +
 kernel/bpf/helpers.c      |   4 +
 kernel/bpf/relaymap.c     | 213 ++++++++++++++++++++++++++++++++++++++
 kernel/bpf/syscall.c      |   1 +
 kernel/bpf/verifier.c     |   8 ++
 kernel/trace/bpf_trace.c  |   4 +
 9 files changed, 254 insertions(+)
 create mode 100644 kernel/bpf/relaymap.c

--
2.32.0.3.g01195cf9f