Files
linux/include/uapi/linux
David Vernet 2057156738 bpf: Add bpf_user_ringbuf_drain() helper
In a prior change, we added a new BPF_MAP_TYPE_USER_RINGBUF map type which
will allow user-space applications to publish messages to a ring buffer
that is consumed by a BPF program in kernel-space. In order for this
map-type to be useful, it will require a BPF helper function that BPF
programs can invoke to drain samples from the ring buffer, and invoke
callbacks on those samples. This change adds that capability via a new BPF
helper function:

bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx,
                       u64 flags)

BPF programs may invoke this function to run callback_fn() on a series of
samples in the ring buffer. callback_fn() has the following signature:

long callback_fn(struct bpf_dynptr *dynptr, void *context);

Samples are provided to the callback in the form of struct bpf_dynptr *'s,
which the program can read using BPF helper functions for querying
struct bpf_dynptr's.

In order to support bpf_ringbuf_drain(), a new PTR_TO_DYNPTR register
type is added to the verifier to reflect a dynptr that was allocated by
a helper function and passed to a BPF program. Unlike PTR_TO_STACK
dynptrs which are allocated on the stack by a BPF program, PTR_TO_DYNPTR
dynptrs need not use reference tracking, as the BPF helper is trusted to
properly free the dynptr before returning. The verifier currently only
supports PTR_TO_DYNPTR registers that are also DYNPTR_TYPE_LOCAL.

Note that while the corresponding user-space libbpf logic will be added
in a subsequent patch, this patch does contain an implementation of the
.map_poll() callback for BPF_MAP_TYPE_USER_RINGBUF maps. This
.map_poll() callback guarantees that an epoll-waiting user-space
producer will receive at least one event notification whenever at least
one sample is drained in an invocation of bpf_user_ringbuf_drain(),
provided that the function is not invoked with the BPF_RB_NO_WAKEUP
flag. If the BPF_RB_FORCE_WAKEUP flag is provided, a wakeup
notification is sent even if no sample was drained.

Signed-off-by: David Vernet <void@manifault.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220920000100.477320-3-void@manifault.com
2022-09-21 16:24:58 -07:00
..
2022-02-21 19:33:05 +00:00
2021-01-25 18:44:44 +01:00
2022-04-19 13:13:47 +01:00
2021-11-01 13:36:08 +00:00
2022-08-11 10:31:19 -07:00
2022-06-03 20:09:27 +08:00
2022-09-21 16:24:58 -07:00
2022-06-07 10:20:42 -07:00
2021-11-26 16:48:59 +01:00
2022-04-04 08:55:23 +02:00
2021-10-07 13:51:11 +02:00
2022-08-10 13:49:50 +01:00
2021-02-08 13:01:24 +01:00
2022-03-11 08:28:05 -08:00
2021-11-15 07:53:10 -08:00
2021-06-03 15:31:34 -07:00
2022-06-03 20:09:27 +08:00
2021-03-10 09:34:06 +01:00
2021-10-14 23:06:28 +02:00
2021-07-06 10:37:46 -05:00
2021-01-07 16:17:32 +01:00
2022-08-11 04:31:15 -04:00
2022-07-17 10:58:06 +01:00
2021-06-12 13:16:45 -07:00