Message ID | 20230528142027.5585-6-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | BPF |
Headers | show |
Series | bpf: Support ->show_fdinfo and ->fill_link_info for kprobe prog | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-PR | fail | PR summary |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }} |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for ShellCheck |
bpf/vmtest-bpf-next-VM_Test-3 | fail | Logs for build for aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-4 | fail | Logs for build for s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-5 | fail | Logs for build for x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-6 | fail | Logs for build for x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-7 | success | Logs for set-matrix |
bpf/vmtest-bpf-next-VM_Test-8 | success | Logs for veristat |
netdev/series_format | success | Posting correctly formatted |
netdev/tree_selection | success | Clearly marked for bpf-next, async |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 10 this patch: 10 |
netdev/cc_maintainers | success | CCed 12 of 12 maintainers |
netdev/build_clang | success | Errors and warnings before: 8 this patch: 8 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/deprecated_api | success | None detected |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 10 this patch: 10 |
netdev/checkpatch | warning | WARNING: line length of 89 exceeds 80 columns |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 92a57ef..e6b5127 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3297,9 +3297,36 @@ static void bpf_perf_link_dealloc(struct bpf_link *link) kfree(perf_link); } +static void bpf_perf_link_show_fdinfo(const struct bpf_link *link, + struct seq_file *seq) +{ + struct bpf_perf_link *perf_link = container_of(link, struct bpf_perf_link, link); + const struct perf_event *event; + u64 probe_offset, probe_addr; + u32 prog_id, fd_type; + const char *buf; + int err; + + event = perf_get_event(perf_link->perf_file); + if (IS_ERR(event)) + return; + + err = bpf_get_perf_event_info(event, &prog_id, &fd_type, + &buf, &probe_offset, + &probe_addr); + if (err) + return; + + if (buf) + seq_printf(seq, "func:\t%s\n", buf); + seq_printf(seq, "addr:\t%llx\n", probe_addr); + seq_printf(seq, "offset:\t%llu\n", probe_offset); +} + static const struct bpf_link_ops bpf_perf_link_lops = { .release = bpf_perf_link_release, .dealloc = bpf_perf_link_dealloc, + .show_fdinfo = bpf_perf_link_show_fdinfo, }; static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
By adding support for ->show_fdinfo to the perf_event link, users will be able to examine it through the task's fdinfo. The expected result is as follows: $ cat /proc/9637/fdinfo/11 pos: 0 flags: 02000000 mnt_id: 15 ino: 2094 link_type: perf link_id: 1 prog_tag: a04f5eef06a7f555 prog_id: 5 func: kernel_clone addr: ffffffff8d0bc310 offset: 0 Signed-off-by: Yafang Shao <laoar.shao@gmail.com> --- kernel/bpf/syscall.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)