bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/3] bpf: introduce BPF_MAP_TYPE_RELAY
@ 2023-12-27 10:01 Philo Lu
  2023-12-27 10:01 ` [PATCH bpf-next v1 1/3] bpf: implement relay map basis Philo Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Philo Lu @ 2023-12-27 10:01 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
	joannelkoong, laoar.shao, kuifeng, houtao, shung-hsi.yu,
	xuanzhuo, dust.li, alibuda, guwen, hengqi

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@gandalf.local.home/T/
[2]
https://lore.kernel.org/all/20231220074725.23211-1-lulie@linux.alibaba.com/

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-01-03 19:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 10:01 [PATCH bpf-next v1 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Philo Lu
2023-12-27 10:01 ` [PATCH bpf-next v1 1/3] bpf: implement relay map basis Philo Lu
2023-12-27 13:41   ` Yafang Shao
2023-12-27 10:01 ` [PATCH bpf-next v1 2/3] bpf: add bpf_relay_output kfunc Philo Lu
2023-12-27 14:23   ` Hou Tao
2023-12-27 18:07   ` Alexei Starovoitov
2023-12-27 10:01 ` [PATCH bpf-next v1 3/3] selftests/bpf: add bpf relay map selftests Philo Lu
2023-12-27 13:42   ` Yafang Shao
2023-12-27 18:02 ` [PATCH bpf-next v1 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Alexei Starovoitov
2023-12-28 11:19   ` Philo Lu
2024-01-03 19:58     ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).