linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/3] add bpf_file_d_path helper and selftests
@ 2024-07-18 11:51 Lin Yikai
  2024-07-18 11:51 ` [PATCH bpf-next v1 1/3] bpf: Add bpf_file_d_path helper Lin Yikai
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lin Yikai @ 2024-07-18 11:51 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Matt Bobrowski, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, Mykola Lysenko, Shuah Khan, Lin Yikai,
	linux-kernel, bpf, linux-trace-kernel, linux-kselftest
  Cc: opensource.kernel

v1:
 - patch 2:
   - [1/2] add bpf_file_d_path helper
   - [2/2] add selftest to it

Hi, we are looking to add the "bpf_file_d_path" helper, 
used to retrieve the path from a struct file object.
	bpf_file_d_path(void *file, char *dst, u32 size);
	
It's worth noting that the "file" parameter is defined as "void*" type.

* Our problems *
Previously, we encountered issues 
on some user-space operating systems(OS):

1.Difficulty using vmlinux.h
(1) The OS lacks support for bpftool.
We can not use:
"bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h".
Bpftool need a separate complex cross-compilation environment to build.

(2) Many duplicate definitions between OS and vmlinux.h.

(3) The vmlinux.h size is large (2.8MB on arm64/Android), 
causing increased ebpf prog size and user space consumption.

2.The "struct file" has many internal variables and definitions,
and maybe change along with Linux version iterations,
making it hard to copy it to OS.


* Benefits of this commit *
1.There is no need to include vmlinux.h or redefine "struct file".

For example, with bpf on kprobe, 
we can directly pass param "(void*)PT_REGS_PARM1(pt_regs)"
to "bpf_file_d_path" helper in order to retrieve the path.


Appreciate your review and assistance. Thank you.
Yikai


Lin Yikai (2):
  bpf: Add bpf_file_d_path helper
  selftests/bpf:Adding test for bpf_file_d_path helper

 include/uapi/linux/bpf.h                      |  20 +++
 kernel/trace/bpf_trace.c                      |  34 ++++++
 tools/include/uapi/linux/bpf.h                |  20 +++
 .../selftests/bpf/prog_tests/file_d_path.c    | 115 ++++++++++++++++++
 .../selftests/bpf/progs/test_file_d_path.c    |  32 +++++
 5 files changed, 221 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/file_d_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_file_d_path.c

-- 
2.34.1


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

end of thread, other threads:[~2024-07-19 18:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-18 11:51 [PATCH bpf-next v1 0/3] add bpf_file_d_path helper and selftests Lin Yikai
2024-07-18 11:51 ` [PATCH bpf-next v1 1/3] bpf: Add bpf_file_d_path helper Lin Yikai
2024-07-19 18:55   ` Andrii Nakryiko
2024-07-18 11:51 ` [PATCH bpf-next v1 2/3] selftests/bpf:Adding test for " Lin Yikai
2024-07-18 17:16 ` [PATCH bpf-next v1 0/3] add bpf_file_d_path helper and selftests Martin KaFai Lau

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).