public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] Allow storing referenced struct file kptrs in BPF maps
@ 2026-04-20 20:33 Justin Suess
  2026-04-20 20:33 ` [PATCH bpf-next 1/2] bpf: Implement dtor for struct file BTF ID Justin Suess
  2026-04-20 20:33 ` [PATCH bpf-next 2/2] selftests/bpf: Add test for map-stored struct file kptrs Justin Suess
  0 siblings, 2 replies; 11+ messages in thread
From: Justin Suess @ 2026-04-20 20:33 UTC (permalink / raw)
  To: ast, daniel, andrii, eddyz87, memxor
  Cc: martin.lau, song, yonghong.song, jolsa, bpf, mic, Justin Suess

Hello,

This series adds a destructor for struct file, enabling it to be used as a
referenced kptr in BPF maps.

The destructor mirrors bpf_put_file() semantics and releases the reference
via fput(). This allows pointers returned from kfuncs such as
bpf_get_task_exe_file() to be safely stored and later reused with helpers
and kfuncs that operate on struct file.

This fills a gap compared to bpf_dynptr_from_file(), where the resulting
dynptr can be stored in a map, but cannot be passed to kfuncs expecting
a struct file *.

Use cases include caching file references across events and deferring
processing while keeping the underlying file alive.

Patch 1 adds the struct file kptr destructor and wires it into the BTF
kfunc sets.

Patch 2 adds selftests covering successful use and verifier rejection of
unreferenced pointers.

Justin Suess (2):
  bpf: Implement dtor for struct file BTF ID
  selftests/bpf: Add test for map-stored struct file kptrs

 kernel/bpf/helpers.c                          |  16 +-
 .../bpf/prog_tests/refcounted_kptr_file.c     | 246 ++++++++++++++++++
 .../bpf/progs/refcounted_kptr_file.c          | 152 +++++++++++
 .../bpf/progs/refcounted_kptr_file_fail.c     |  35 +++
 4 files changed, 448 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/refcounted_kptr_file.c
 create mode 100644 tools/testing/selftests/bpf/progs/refcounted_kptr_file.c
 create mode 100644 tools/testing/selftests/bpf/progs/refcounted_kptr_file_fail.c

-- 
2.53.0


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

end of thread, other threads:[~2026-04-21 20:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 20:33 [PATCH bpf-next 0/2] Allow storing referenced struct file kptrs in BPF maps Justin Suess
2026-04-20 20:33 ` [PATCH bpf-next 1/2] bpf: Implement dtor for struct file BTF ID Justin Suess
2026-04-20 22:17   ` Song Liu
2026-04-21  1:05   ` sashiko-bot
2026-04-21  2:18     ` Justin Suess
2026-04-21 19:38       ` Justin Suess
2026-04-21 20:29         ` Kumar Kartikeya Dwivedi
2026-04-20 20:33 ` [PATCH bpf-next 2/2] selftests/bpf: Add test for map-stored struct file kptrs Justin Suess
2026-04-20 21:07   ` bot+bpf-ci
2026-04-20 22:28   ` Song Liu
2026-04-21  1:31   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox