RFC BPF Standard Streams
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest13 patches 30 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/13 | bpf: Tie dynptrs to referenced source objectskernel/ | +54 | 7 replies | |
| 2/13 | bpf: Compare dynptr_id in regsafekernel/ | +2 | 3 replies | |
| 3/13 | selftests/bpf: Convert dynptr_fail to use vmlinux.htools/ | +6 | 1 reply | |
| 4/13 | selftests/bpf: Add tests for dynptr source object interactiontools/ tools/ tools/ | +41 | 4 replies | |
| 5/13 | locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t typeinclude/ include/ mm/ | +114 | 0 replies | |
| 6/13 | bpf: Introduce bpf_dynptr_from_mem_sliceinclude/ kernel/ kernel/ | +42 | 4 replies | |
| 7/13 | bpf: Introduce per-prog stdout/stderr streamsinclude/ kernel/ kernel/ +4 more | +582 | 6 replies | |
| 8/13 | bpf: Add dump_stack() analogue to print to BPF stderrinclude/ kernel/ | +101 | 1 reply | |
| 9/13 | bpf: Report may_goto timeout to BPF stderrinclude/ kernel/ | +19 | 0 replies | |
| 10/13 | bpf: Report rqspinlock deadlocks/timeout to BPF stderrkernel/ | +22 | 0 replies | |
| 11/13 | bpf: Report arena faults to BPF stderrarch/ include/ kernel/ | +33 | 0 replies | |
| 12/13 | bpftool: Add support for dumping streamstools/ tools/ tools/ | +166 | 3 replies | |
| 13/13 | selftests/bpf: Add tests for prog streamstools/ tools/ tools/ +2 more | +415 | 1 reply |
Reviews trailers per patch
5 of 13 patches have a Reviewed-by or Acked-by.
| Patch | Vlastimil Babka | Sebastian Andrzej Siewior | Shakeel Butt | Eduard Zingerman |
|---|---|---|---|---|
| 1/13 | ||||
| 2/13 | A-b | |||
| 3/13 | A-b | |||
| 4/13 | ||||
| 5/13 | A-b | A-b | R-b | |
| 6/13 | A-b | |||
| 7/13 | ||||
| 8/13 | R-b | |||
| 9/13 | ||||
| 10/13 | ||||
| 11/13 | ||||
| 12/13 | ||||
| 13/13 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [RFC PATCH bpf-next/net v1 00/13] BPF Standard Streams
NOTE: Temporarily based off of bpf-next/net due to Qdisc related fixes.
This set introduces a standard output interface with two streams, namely stdout and stderr, for BPF programs. The idea is that these streams will be written to by BPF programs and the kernel, and serve as standard interfaces for informing user space of any BPF runtime violations. Users can also utilize them for printing normal messages for debugging usage, as is the case with bpf_printk() and trace pipe interface.
BPF programs and the kernel can use these streams to output messages. User space can dump these messages using bpftool.
The stream interface itself is implemented using a lockless list, so that we can queue messages from any context. Every printk statement into the stream leads to memory allocation. Allocation itself relies on the bpf_mem_alloc() API, but in case it fails, we use try_alloc_pages() to construct a bespoke bump allocator to carve out elements. If this fails, we finally give up and drop the message.
Three scenarios (rqspinlock deadlocks, arena page faults, and cond_break timeouts) are covered for reporting errors to user space, the format looks as follows (with file:line info for BPF programs to pin point source of error). The output is as follows:
ERROR: AA or ABBA deadlock detected for bpf_res_spin_lock
Attempted lock = 0xff11000104a875e0
Total held locks = 1
Held lock[ 0] = 0xff11000104a875e0
CPU: 5 UID: 0 PID: 764 Comm: test_progs Call trace: bpf_prog_stderr_dump_stack+0x83/0xc0 bpf_res_spin_lock+0x8c/0xa0 bpf_prog_0f369a1fb6eb23d7_foo+0xe5/0x140: [stream_bpftool.c:62] bpf_prog_986cfd896eb75e8c_stream_bpftool_dump_prog_stream+0x7e/0x2e1: [stream_bpftool.c:93] bpf_prog_test_run_syscall+0x102/0x240 __sys_bpf+0xd68/0x2bf0 __x64_sys_bpf+0x1e/0x30 do_syscall_64+0x68/0x140 entry_SYSCALL_64_after_hwframe+0x76/0x7e
ERROR: Arena READ access at unmapped address 0xdeadbeef
CPU: 5 UID: 0 PID: 764 Comm: test_progs Call trace: bpf_prog_stderr_dump_stack+0x83/0xc0 ex_handler_bpf+0x4a/0xa0 fixup_exception+0xde/0x310 kernelmode_fixup_or_oops.constprop.0+0x2f/0x70 exc_page_fault+0xdd/0x1d0 asm_exc_page_fault+0x26/0x30 bpf_prog_0f369a1fb6eb23d7_foo+0x10c/0x140: [stream_bpftool.c:67] bpf_prog_986cfd896eb75e8c_stream_bpftool_dump_prog_stream+0x7e/0x2e1: [stream_bpftool.c:93] bpf_prog_test_run_syscall+0x102/0x240 __sys_bpf+0xd68/0x2bf0 __x64_sys_bpf+0x1e/0x30 do_syscall_64+0x68/0x140 entry_SYSCALL_64_after_hwframe+0x76/0x7e
ERROR: Arena WRITE access at unmapped address 0xfaceb00c
CPU: 5 UID: 0 PID: 764 Comm: test_progs Call trace: bpf_prog_stderr_dump_stack+0x83/0xc0 ex_handler_bpf+0x4a/0xa0 fixup_exception+0xde/0x310 kernelmode_fixup_or_oops.constprop.0+0x2f/0x70 exc_page_fault+0xdd/0x1d0 asm_exc_page_fault+0x26/0x30 bpf_prog_0f369a1fb6eb23d7_foo+0x111/0x140: [stream_bpftool.c:67] bpf_prog_986cfd896eb75e8c_stream_bpftool_dump_prog_stream+0x7e/0x2e1: [stream_bpftool.c:93] bpf_prog_test_run_syscall+0x102/0x240 __sys_bpf+0xd68/0x2bf0 __x64_sys_bpf+0x1e/0x30 do_syscall_64+0x68/0x140 entry_SYSCALL_64_after_hwframe+0x76/0x7e
ERROR: Timeout detected for may_goto instruction
CPU: 5 UID: 0 PID: 764 Comm: test_progs Call trace: bpf_prog_stderr_dump_stack+0x83/0xc0 bpf_check_timed_may_goto+0x4d/0xa0 arch_bpf_timed_may_goto+0x21/0x40 bpf_prog_0f369a1fb6eb23d7_foo+0x12f/0x140: [stream_bpftool.c:70] bpf_prog_986cfd896eb75e8c_stream_bpftool_dump_prog_stream+0x7e/0x2e1: [stream_bpftool.c:93] bpf_prog_test_run_syscall+0x102/0x240 __sys_bpf+0xd68/0x2bf0 __x64_sys_bpf+0x1e/0x30 do_syscall_64+0x68/0x140 entry_SYSCALL_64_after_hwframe+0x76/0x7e
There is a lot of minor things to address before this is mergeable, but the main logic and approach should be set in stone.
TODO (in order of importance)
-----------------------------
* Add an API for kernel writers to stderr streams to allow them to stage messages to a llist_head and then atomically splice in a bunch of messages into the stream to avoid interleaving from multiple threads. Each "message" consisisting of multiple printk statements then appears as a contiguous sequence to the user space. This will simply be a stage + commit API on top of an object pinning the llist_head that will be del_all'd and then add_batch'd to the stream->log.
* Add bpf_printk() macros for streams.
* Add kdoc comments for kfuncs.
* Add more corner case tests, and negative cases.
* Enforcing memory consumption limits on the log usage, so that in-flight log memory is bounded at runtime.
* Support bpftool filepath printing and JSON output.
Alexei Starovoitov (1):
locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t
type
Kumar Kartikeya Dwivedi (12):
bpf: Tie dynptrs to referenced source objects
bpf: Compare dynptr_id in regsafe
selftests/bpf: Convert dynptr_fail to use vmlinux.h selftests/bpf: Add tests for dynptr source object interaction
bpf: Introduce bpf_dynptr_from_mem_slice
bpf: Introduce per-prog stdout/stderr streams
bpf: Add dump_stack() analogue to print to BPF stderr
bpf: Report may_goto timeout to BPF stderr
bpf: Report rqspinlock deadlocks/timeout to BPF stderr
bpf: Report arena faults to BPF stderr
bpftool: Add support for dumping streams selftests/bpf: Add tests for prog streams
arch/x86/net/bpf_jit_comp.c | 21 +- include/linux/bpf.h | 63 +- include/linux/local_lock.h | 58 +- include/linux/local_lock_internal.h | 207 +++--- kernel/bpf/Makefile | 2 +- kernel/bpf/arena.c | 14 + kernel/bpf/core.c | 29 +- kernel/bpf/helpers.c | 58 +- kernel/bpf/rqspinlock.c | 22 + kernel/bpf/stream.c | 595 ++++++++++++++++++ kernel/bpf/syscall.c | 2 +- kernel/bpf/verifier.c | 104 ++- mm/memcontrol.c | 39 +- tools/bpf/bpftool/Makefile | 2 +- tools/bpf/bpftool/prog.c | 71 ++- tools/bpf/bpftool/skeleton/stream.bpf.c | 96 +++ .../testing/selftests/bpf/prog_tests/dynptr.c | 2 + .../testing/selftests/bpf/prog_tests/stream.c | 57 ++ .../testing/selftests/bpf/progs/dynptr_fail.c | 43 +- .../selftests/bpf/progs/dynptr_fail_qdisc.c | 38 ++ tools/testing/selftests/bpf/progs/stream.c | 150 +++++ .../selftests/bpf/progs/stream_bpftool.c | 142 +++++ .../testing/selftests/bpf/progs/stream_fail.c | 38 ++ 23 files changed, 1597 insertions(+), 256 deletions(-) create mode 100644 kernel/bpf/stream.c create mode 100644 tools/bpf/bpftool/skeleton/stream.bpf.c create mode 100644 tools/testing/selftests/bpf/prog_tests/stream.c create mode 100644 tools/testing/selftests/bpf/progs/dynptr_fail_qdisc.c create mode 100644 tools/testing/selftests/bpf/progs/stream.c create mode 100644 tools/testing/selftests/bpf/progs/stream_bpftool.c create mode 100644 tools/testing/selftests/bpf/progs/stream_fail.c
base-commit: 93cb5375fb16693273144e7627e4fe27b811003a
Signature · 1 line
2.47.1