All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 00/10] bpf: Introduce file dynptr
@ 2025-10-03 16:04 Mykyta Yatsenko
  2025-10-03 16:04 ` [RFC PATCH v1 01/10] selftests/bpf: remove unnecessary kfunc prototypes Mykyta Yatsenko
                   ` (9 more replies)
  0 siblings, 10 replies; 41+ messages in thread
From: Mykyta Yatsenko @ 2025-10-03 16:04 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87, memxor
  Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

This series adds a new dynptr kind, file dynptr, which enables BPF
programs to perform safe reads from files in a structured way.
Initial motivations include:
 * Parsing the executable’s ELF to locate thread-local variable symbols
 * Capturing stack traces when frame pointers are disabled

By leveraging the existing dynptr abstraction, we reuse the verifier’s
lifetime/size checks and keep the API consistent with existing dynptr
read helpers.

Technical details:
1. Reuses the existing freader library to read files a folio at a time.
2. bpf_dynptr_slice() and bpf_dynptr_read() always copy data from folios
into a program-provided buffer; zero-copy access is intentionally not
supported to keep it simple.
3. Reads may sleep if the requested folios are not in the page cache.
4. Few verifier changes required:
  * Support dynptr destruction in kfuncs
  * Add kfunc address substitution based on whether the program runs in
  a sleepable or non-sleepable context.

Open challenges:
Patch 6 introduces mechanism for handling dynptrs destruction in
kfuncs, it feels hacky as we need to check for concrete kfunc id to tell
verifier to destroy dynptr, also the way we pass release_regno could be
better. I'm open to suggestions on how to implement this.

Testing:
The final patch adds a selftest that parses the executable’s ELF to
locate thread-local symbol information, demonstrating the file dynptr
workflow end-to-end.

Mykyta Yatsenko (10):
  selftests/bpf: remove unnecessary kfunc prototypes
  bpf: widen dynptr size/offset to 64 bit
  lib: extract freader into a separate files
  lib/freader: support reading more than 2 folios
  bpf: verifier: centralize const dynptr check in
    unmark_stack_slots_dynptr()
  bpf: add plumbing for file-backed dynptr
  bpf: add kfuncs and helpers support for file dynptrs
  bpf: verifier: refactor kfunc specialization
  bpf: dispatch to sleepable file dynptr
  selftests/bpf: add file dynptr tests

 include/linux/bpf.h                           |  30 ++-
 include/linux/bpf_verifier.h                  |   2 +
 include/linux/freader.h                       |  32 +++
 kernel/bpf/helpers.c                          | 170 +++++++++---
 kernel/bpf/log.c                              |   2 +
 kernel/bpf/verifier.c                         | 137 ++++++----
 kernel/trace/bpf_trace.c                      |  46 ++--
 lib/Makefile                                  |   2 +-
 lib/buildid.c                                 | 145 +----------
 lib/freader.c                                 | 138 ++++++++++
 tools/testing/selftests/bpf/bpf_kfuncs.h      |  12 +-
 .../selftests/bpf/prog_tests/file_reader.c    |  81 ++++++
 .../selftests/bpf/progs/dynptr_success.c      |  12 +-
 .../testing/selftests/bpf/progs/file_reader.c | 241 ++++++++++++++++++
 .../selftests/bpf/progs/file_reader_fail.c    |  57 +++++
 .../selftests/bpf/progs/ip_check_defrag.c     |   5 -
 .../bpf/progs/verifier_netfilter_ctx.c        |   5 -
 17 files changed, 840 insertions(+), 277 deletions(-)
 create mode 100644 include/linux/freader.h
 create mode 100644 lib/freader.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/file_reader.c
 create mode 100644 tools/testing/selftests/bpf/progs/file_reader.c
 create mode 100644 tools/testing/selftests/bpf/progs/file_reader_fail.c

-- 
2.51.0


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

end of thread, other threads:[~2025-10-08 19:15 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-03 16:04 [RFC PATCH v1 00/10] bpf: Introduce file dynptr Mykyta Yatsenko
2025-10-03 16:04 ` [RFC PATCH v1 01/10] selftests/bpf: remove unnecessary kfunc prototypes Mykyta Yatsenko
2025-10-03 17:46   ` Eduard Zingerman
2025-10-03 16:04 ` [RFC PATCH v1 02/10] bpf: widen dynptr size/offset to 64 bit Mykyta Yatsenko
2025-10-03 18:16   ` Andrii Nakryiko
2025-10-03 18:40   ` Eduard Zingerman
2025-10-03 18:53     ` Mykyta Yatsenko
2025-10-03 16:04 ` [RFC PATCH v1 03/10] lib: extract freader into a separate files Mykyta Yatsenko
2025-10-03 18:16   ` Andrii Nakryiko
2025-10-03 20:04   ` Alexei Starovoitov
2025-10-03 16:04 ` [RFC PATCH v1 04/10] lib/freader: support reading more than 2 folios Mykyta Yatsenko
2025-10-03 18:16   ` Andrii Nakryiko
2025-10-03 18:29     ` Mykyta Yatsenko
2025-10-03 18:46       ` Andrii Nakryiko
2025-10-03 16:04 ` [RFC PATCH v1 05/10] bpf: verifier: centralize const dynptr check in unmark_stack_slots_dynptr() Mykyta Yatsenko
2025-10-03 18:18   ` Andrii Nakryiko
2025-10-03 19:02   ` Eduard Zingerman
2025-10-03 16:04 ` [RFC PATCH v1 06/10] bpf: add plumbing for file-backed dynptr Mykyta Yatsenko
2025-10-03 18:38   ` Andrii Nakryiko
2025-10-03 20:55   ` Eduard Zingerman
2025-10-03 16:04 ` [RFC PATCH v1 07/10] bpf: add kfuncs and helpers support for file dynptrs Mykyta Yatsenko
2025-10-03 18:38   ` Andrii Nakryiko
2025-10-03 18:59     ` Mykyta Yatsenko
2025-10-03 21:35   ` Eduard Zingerman
2025-10-08  0:25     ` Mykyta Yatsenko
2025-10-03 16:04 ` [RFC PATCH v1 08/10] bpf: verifier: refactor kfunc specialization Mykyta Yatsenko
2025-10-03 22:08   ` Eduard Zingerman
2025-10-08  0:35     ` Mykyta Yatsenko
2025-10-08 18:27     ` Mykyta Yatsenko
2025-10-08 19:15       ` Eduard Zingerman
2025-10-03 16:04 ` [RFC PATCH v1 09/10] bpf: dispatch to sleepable file dynptr Mykyta Yatsenko
2025-10-03 18:45   ` Andrii Nakryiko
2025-10-03 20:10   ` Alexei Starovoitov
2025-10-03 22:17   ` Eduard Zingerman
2025-10-03 16:04 ` [RFC PATCH v1 10/10] selftests/bpf: add file dynptr tests Mykyta Yatsenko
2025-10-03 20:02   ` Andrii Nakryiko
2025-10-06 11:50     ` Mykyta Yatsenko
2025-10-06 16:15       ` Andrii Nakryiko
2025-10-03 22:24   ` Eduard Zingerman
2025-10-06 11:54     ` Mykyta Yatsenko
2025-10-08  0:39     ` Mykyta Yatsenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.