Skip to content

bpf: adding get_fd_path helper

Wenbo Zhang bpf linux-fsdevel netdev 14 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v14 Latest2 patches 12 repliesIn review
  2. v132 patches 5 repliesSuperseded
  3. v122 patches 11 repliesSuperseded
Earlier versions · 11
VersionPostedPatchesRepliesStatus
v112 patches2 repliesSuperseded
v102 patches7 repliesSuperseded
v91 patch1 replySuperseded
v81 patch0 repliesSuperseded
v7 posting 2/21 patch2 repliesSuperseded
v7 posting 1/21 patch0 repliesSuperseded
v61 patch0 repliesSuperseded
v51 patch2 repliesSuperseded
v41 patch4 repliesSuperseded
v31 patch1 replySuperseded
v11 patch1 replySuperseded

Changes in v14 from the cover letter

* Fix this helper's description to be consistent with comments in d_path

* Fix error handling logic fill zeroes not '0's

Patches in v14 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: add new helper get_fd_path for mapping a file descriptor to a pathnameinclude/uapi/linux/bpf.h kernel/trace/bpf_trace.c tools/include/uapi/linux/bpf.h+125 -211 replies
2/2selftests/bpf: test for bpf_get_fd_path() from tracepointtools/testing/selftests/bpf/prog_tests/get_fd_path.c tools/testing/selftests/bpf/progs/test_get_fd_path.c+214 -01 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchYonghong SongJiri Olsa
1/2A-b T-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v14 thread

Cover letter [PATCH bpf-next v14 0/2] bpf: adding get_fd_path helper

This patch series introduce a bpf helper that can be used to map a file descriptor to a pathname.

This requirement is mainly discussed here:

https://github.com/iovisor/bcc/issues/237

This implementation supports both local and mountable pseudo file systems, and ensure we're in user context which is safe for this helper to run.

Changes since v13:

* Fix this helper's description to be consistent with comments in d_path

* Fix error handling logic fill zeroes not '0's

Changes since v12:

* Rename to get_fd_patch

* Fix test issue on big-endian machines

Changes since v11:

* Only allow tracepoints to make sure it won't dead lock

Changes since v10:

* Fix missing fput

Changes since v9:

* Associate help patch with its selftests patch to this series

* Refactor selftests code for further simplification

Changes since v8:

* Format helper description

Changes since v7:

* Use fget_raw instead of fdget_raw, as fdget_raw is only used inside fs/

* Ensure we're in user context which is safe fot the help to run

* Filter unmountable pseudo filesystem, because they don't have real path

* Supplement the description of this helper function

Changes since v6:

* Fix missing signed-off-by line

Changes since v5:

* Refactor helper avoid unnecessary goto end by having two explicit returns

Changes since v4:

* Rename bpf_fd2path to bpf_get_file_path to be consistent with other helper's names

* When fdget_raw fails, set ret to -EBADF instead of -EINVAL

* Remove fdput from fdget_raw's error path

* Use IS_ERR instead of IS_ERR_OR_NULL as d_path ether returns a pointer into the buffer or an error code if the path was too long

* Modify the normal path's return value to return copied string length including NUL

* Update helper description's Return bits.

* Refactor selftests code for further simplification

Changes since v3:

* Remove unnecessary LOCKDOWN_BPF_READ

* Refactor error handling section for enhanced readability

* Provide a test case in tools/testing/selftests/bpf

* Refactor sefltests code to use real global variables instead of maps

Changes since v2:

* Fix backward compatibility

* Add helper description

* Refactor selftests use global data instead of perf_buffer to simplified code

* Fix signed-off name

Wenbo Zhang (2):
bpf: add new helper get_fd_path for mapping a file descriptor to a
pathname
selftests/bpf: test for bpf_get_fd_path() from tracepoint

 include/uapi/linux/bpf.h                      |  29 ++-
 kernel/trace/bpf_trace.c                      |  69 +++++++
 tools/include/uapi/linux/bpf.h                |  29 ++-
 .../selftests/bpf/prog_tests/get_fd_path.c    | 171 ++++++++++++++++++
 .../selftests/bpf/progs/test_get_fd_path.c    |  43 +++++
 5 files changed, 339 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_fd_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_get_fd_path.c
Signature · 1 line
2.17.1