bpf: Add cookie to raw_tp bpf_link_info
Subsystems (5)
PATCH 1/3 bpf: Add cookie to raw_tp bpf_link_info
After commit 68ca5d4eebb8 ("bpf: support BPF cookie in raw tracepoint (raw_tp, tp_btf) programs"), we can show the cookie in bpf_link_info like kprobe etc.
--- include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 1 + tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 3 insertions(+)
include/uapi/linux/bpf.h +1 -0
@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */ +__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;
kernel/bpf/syscall.c +1 -0
@@ -3687,6 +3687,7 @@ static int bpf_raw_tp_link_fill_link_info(const struct bpf_link *link,return -EINVAL ; info->raw_tracepoint.tp_name_len = tp_len +1 ; + info->raw_tracepoint.cookie = raw_tp_link->cookie;if (!ubuf)return 0 ;
tools/include/uapi/linux/bpf.h +1 -0
@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */ +__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;
Signature · 1 line
2.43.0
PATCH 2/3 selftests/bpf: Add cookies check for raw_tp fill_link_info test
Add tests for getting cookie with fill_link_info for raw_tp.
--- .../selftests/bpf/prog_tests/bpf_cookie.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c +25 -1
@@ -635,10 +635,29 @@ static void tp_btf_subtest(struct test_bpf_cookie *skel)bpf_link__destroy (link); } +static int verify_raw_tp_link_info (int fd,u64 cookie) +{ +struct bpf_link_info info; +int err; +u32 len =sizeof (info); + +memset (&info,0 ,sizeof (info)); + err =bpf_link_get_info_by_fd (fd, &info, &len); +if (!ASSERT_OK (err,"get_link_info" )) +return -1 ; + +if (!ASSERT_EQ (info.type,BPF_LINK_TYPE_RAW_TRACEPOINT ,"link_type" )) +return -1 ; + +ASSERT_EQ (info.raw_tracepoint.cookie, cookie,"raw_tp_cookie" ); + +return 0 ; +} +static void raw_tp_subtest (struct test_bpf_cookie *skel) {__u64 cookie; -int prog_fd, link_fd =-1 ; +int err, prog_fd, link_fd =-1 ;struct bpf_link *link =NULL ;LIBBPF_OPTS (bpf_raw_tp_opts, raw_tp_opts);LIBBPF_OPTS (bpf_raw_tracepoint_opts, opts);
@@ -656,6 +675,11 @@ static void raw_tp_subtest(struct test_bpf_cookie *skel) goto cleanup;usleep (1 );/* trigger */ + + err =verify_raw_tp_link_info (link_fd, cookie); +if (!ASSERT_OK (err,"verify_raw_tp_link_info" )) + goto cleanup; +close (link_fd);/* detach */ link_fd =-1 ;
Signature · 1 line
2.43.0
PATCH 3/3 bpftool: Display cookie for raw_tp link probe
In reply to Tao ChenDisplay cookie for raw_tp link probe, in plain mode:
#bpftool link
22: raw_tracepoint prog 14
tp 'sys_enter' cookie 23925373020405760
pids test_progs(176)And in json mode:
#bpftool link -j | jq
[
{
"id": 47,
"type": "raw_tracepoint",
"prog_id": 79,
"tp_name": "sys_enter",
"cookie": 23925373020405760,
"pids": [
{
"pid": 274,
"comm": "test_progs"
}
] }
]
--- tools/bpf/bpftool/link.c | 3 +++ 1 file changed, 3 insertions(+)
tools/bpf/bpftool/link.c +3 -0
@@ -484,6 +484,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)case BPF_LINK_TYPE_RAW_TRACEPOINT :jsonw_string_field (json_wtr,"tp_name" ,u64_to_ptr (info->raw_tracepoint.tp_name)); +jsonw_lluint_field (json_wtr,"cookie" , info->raw_tracepoint.cookie);break ;case BPF_LINK_TYPE_TRACING : err =get_prog_info (info->prog_id, &prog_info);
@@ -876,6 +877,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)case BPF_LINK_TYPE_RAW_TRACEPOINT :printf ("\n\ttp '%s' " , (const char *)u64_to_ptr (info->raw_tracepoint.tp_name)); +if (info->raw_tracepoint.cookie) +printf ("cookie %llu " , info->raw_tracepoint.cookie);break ;case BPF_LINK_TYPE_TRACING : err =get_prog_info (info->prog_id, &prog_info);
Signature · 1 line
2.43.0
Re: [PATCH bpf-next 3/3] bpftool: Display cookie for raw_tp link probe
Quoted 8 lines · Tao Chen
Display cookie for
raw_tplink probe, in plain mode:#bpftool link
22:
raw_tracepointprog 14tp 'sys_enter' cookie 23925373020405760 pids test_progs(176)
Curious number.
What 0x55000000000000 was used for ?
Re: [PATCH bpf-next 3/3] bpftool: Display cookie for raw_tp link probe
Quoted 4 lines · Alexei Starovoitov
Quoted 3 lines · Tao Chen
Display cookie for
raw_tplink probe, in plain mode:
Quoted 8 lines
Quoted 5 lines
#bpftool link
22:
raw_tracepointprog 14tp 'sys_enter' cookie 23925373020405760 pids test_progs(176)Curious number.
What0x55000000000000was used for ?
Yes, no practical in fact, i just ran the selftest case in bpf_cookie.c. raw_tp_opts.cookie = cookie = 0x55000000000000L;
Signature · 2 lines
Best Regards Tao Chen
Quoted 16 lines · Tao Chen
After commit
68ca5d4eebb8("bpf: support BPF cookie in raw tracepoint (raw_tp,tp_btf) programs"), we can show the cookie inbpf_link_infolike kprobe etc.Signed-off-by Tao Chen <[email protected]>--- include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 1 + tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 3 insertions(+)include/uapi/linux/bpf.h +0
-0
include/uapi/linux/bpf.h struct bpf_link_info { · line 6646
Quoted 3 lines
include/uapi/linux/bpf.h +0
-0@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */
there's hole now in here, let's add something like
__u32 reserved;
jirka
Quoted 31 lines
include/uapi/linux/bpf.h +1
-0+__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;kernel/bpf/syscall.c +1
-0@@ -3687,6 +3687,7 @@ static int bpf_raw_tp_link_fill_link_info(const struct bpf_link *link,return -EINVAL ; info->raw_tracepoint.tp_name_len = tp_len +1 ; + info->raw_tracepoint.cookie = raw_tp_link->cookie;if (!ubuf)return 0 ;tools/include/uapi/linux/bpf.h +1
-0@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */ +__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;Signature · 1 line
2.43.0
Quoted 23 lines · Jiri Olsa
Quoted 16 lines · Tao Chen
After commit
68ca5d4eebb8("bpf: support BPF cookie in raw tracepoint (raw_tp,tp_btf) programs"), we can show the cookie inbpf_link_infolike kprobe etc.Signed-off-by Tao Chen <[email protected]>--- include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 1 + tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 3 insertions(+)include/uapi/linux/bpf.h +0
-0include/uapi/linux/bpf.h struct bpf_link_info { · line 6646
Quoted 3 lines
include/uapi/linux/bpf.h +0
-0@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */ there's hole now in here, let's add something like
Quoted 2 lines
__u32 reserved;
Sounds good, i will add it in v2, thanks.
Quoted 34 lines
jirka
Quoted 31 lines
include/uapi/linux/bpf.h +1
-0+__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;kernel/bpf/syscall.c +1
-0@@ -3687,6 +3687,7 @@ static int bpf_raw_tp_link_fill_link_info(const struct bpf_link *link,return -EINVAL ; info->raw_tracepoint.tp_name_len = tp_len +1 ; + info->raw_tracepoint.cookie = raw_tp_link->cookie;if (!ubuf)return 0 ;tools/include/uapi/linux/bpf.h +1
-0@@ -6644,6 +6644,7 @@ struct bpf_link_info {struct {__aligned_u64 tp_name;/* in/out: tp_name buffer ptr */ __u32 tp_name_len;/* in/out: tp_name buffer len */ +__u64 cookie; } raw_tracepoint;struct {__u32 attach_type;Signature · 1 line
2.43.0
Signature · 2 lines
Best Regards Tao Chen