bpf: introduce BPF_MAP_TYPE_RELAY
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 7 repliesIn review
Changes in v1 from the cover letter
- change bpf_relay_output into kfunc instead of helper
- refactor relay_map_update_elem to avoid race
- add attr->map_extra check in map_alloc
- add selftests
- other minor bug fixs
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: implement relay map basisinclude/ include/ kernel/ +2 more | +214 | 1 reply | |
| 2/3 | bpf: add bpf_relay_output kfunckernel/ kernel/ | +25 | 2 replies | |
| 3/3 | selftests/bpf: add bpf relay map selfteststools/ tools/ tools/ +2 more | +275 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH bpf-next v1 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 kfunc 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).
In addition, it's possible to implement relay interface with kfuncs, which can be used with kptrs to "simulate" a new type of map. I'll try it if necessary.
This patch set depends on a bugfix patch for relay [2]. I'm working on it to make sure relay map works well. Currently, the selftests could fail without that patch, but it doesn't affect how we use relay map.
[0]
https://github.com/torvalds/linux/blob/master/Documentation/filesystems/relay.rst
[1]
https://lore.kernel.org/bpf/[email protected]/T/
[2]
https://lore.kernel.org/all/[email protected]/
Change logs:
v1:
- change bpf_relay_output into kfunc instead of helper
- refactor relay_map_update_elem to avoid race
- add attr->map_extra check in map_alloc
- add selftests
- other minor bug fixs
Philo Lu (3):
bpf: implement relay map basis
bpf: add bpf_relay_output kfunc
selftests/bpf: add bpf relay map selftests
include/linux/bpf_types.h | 3 + include/uapi/linux/bpf.h | 7 + kernel/bpf/Makefile | 3 + kernel/bpf/helpers.c | 3 + kernel/bpf/relaymap.c | 221 ++++++++++++++++++ kernel/bpf/syscall.c | 2 + tools/include/uapi/linux/bpf.h | 7 + tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/config | 1 + .../selftests/bpf/prog_tests/relay_map.c | 197 ++++++++++++++++ .../selftests/bpf/progs/test_relay_map.c | 69 ++++++ 11 files changed, 514 insertions(+), 1 deletion(-) create mode 100644 kernel/bpf/relaymap.c create mode 100644 tools/testing/selftests/bpf/prog_tests/relay_map.c create mode 100644 tools/testing/selftests/bpf/progs/test_relay_map.c
--
2.32.0.3.g01195cf9f