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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/20231219122850.433be151@xxxxxxxxxxxxxxxxxx/T/
[2]
https://lore.kernel.org/all/20231220074725.23211-1-lulie@xxxxxxxxxxxxxxxxx/

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





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux