* [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info
@ 2025-06-03 2:26 Tao Chen
2025-06-03 2:26 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test Tao Chen
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Tao Chen @ 2025-06-03 2:26 UTC (permalink / raw)
To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, qmo, jolsa
Cc: bpf, linux-kernel, Tao Chen
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.
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
include/uapi/linux/bpf.h | 2 ++
kernel/bpf/syscall.c | 1 +
tools/include/uapi/linux/bpf.h | 2 ++
3 files changed, 5 insertions(+)
Change list:
- v1 -> v2:
- fill the hole in bpf_link_info.(Jiri)
- v1:
https://lore.kernel.org/bpf/20250529165759.2536245-1-chen.dylane@linux.dev
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 07ee73cdf9..f3e2aae302 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -6644,6 +6644,8 @@ 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 */
+ __u32 reserved; /* just fill the hole */
+ __u64 cookie;
} raw_tracepoint;
struct {
__u32 attach_type;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 9794446bc8..1c3dbe44ac 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 07ee73cdf9..f3e2aae302 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -6644,6 +6644,8 @@ 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 */
+ __u32 reserved; /* just fill the hole */
+ __u64 cookie;
} raw_tracepoint;
struct {
__u32 attach_type;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test
2025-06-03 2:26 [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Tao Chen
@ 2025-06-03 2:26 ` Tao Chen
2025-06-03 12:19 ` Jiri Olsa
2025-06-03 2:26 ` [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe Tao Chen
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Tao Chen @ 2025-06-03 2:26 UTC (permalink / raw)
To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, qmo, jolsa
Cc: bpf, linux-kernel, Tao Chen
Adding tests for getting cookie with fill_link_info for raw_tp.
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
.../selftests/bpf/prog_tests/bpf_cookie.c | 26 ++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 6befa87043..0774ae6c1b 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe
2025-06-03 2:26 [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Tao Chen
2025-06-03 2:26 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test Tao Chen
@ 2025-06-03 2:26 ` Tao Chen
2025-06-03 9:36 ` Quentin Monnet
2025-06-03 12:19 ` [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Jiri Olsa
2025-06-03 14:52 ` Yonghong Song
3 siblings, 1 reply; 10+ messages in thread
From: Tao Chen @ 2025-06-03 2:26 UTC (permalink / raw)
To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, qmo, jolsa
Cc: bpf, linux-kernel, Tao Chen
Display 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"
}
]
}
]
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
tools/bpf/bpftool/link.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 52fd2c9fac..bd37f364be 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe
2025-06-03 2:26 ` [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe Tao Chen
@ 2025-06-03 9:36 ` Quentin Monnet
2025-06-03 12:05 ` Tao Chen
0 siblings, 1 reply; 10+ messages in thread
From: Quentin Monnet @ 2025-06-03 9:36 UTC (permalink / raw)
To: Tao Chen, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, jolsa
Cc: bpf, linux-kernel
On 03/06/2025 03:26, Tao Chen wrote:
> Display 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"
> }
> ]
> }
> ]
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
> tools/bpf/bpftool/link.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index 52fd2c9fac..bd37f364be 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -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' ",
Nit: See how we use a double space at the end of the string here, to
separate the different fields in the plain output...
> (const char *)u64_to_ptr(info->raw_tracepoint.tp_name));
> + if (info->raw_tracepoint.cookie)
> + printf("cookie %llu ", info->raw_tracepoint.cookie);
... Please use a double space here in a similar way, at the end of your
"cookie %llu " format string.
Looks good otherwise. Thanks,
Quentin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe
2025-06-03 9:36 ` Quentin Monnet
@ 2025-06-03 12:05 ` Tao Chen
0 siblings, 0 replies; 10+ messages in thread
From: Tao Chen @ 2025-06-03 12:05 UTC (permalink / raw)
To: Quentin Monnet, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, jolsa
Cc: bpf, linux-kernel
在 2025/6/3 17:36, Quentin Monnet 写道:
> On 03/06/2025 03:26, Tao Chen wrote:
>> Display 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"
>> }
>> ]
>> }
>> ]
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>> tools/bpf/bpftool/link.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
>> index 52fd2c9fac..bd37f364be 100644
>> --- a/tools/bpf/bpftool/link.c
>> +++ b/tools/bpf/bpftool/link.c
>> @@ -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' ",
>
>
> Nit: See how we use a double space at the end of the string here, to
> separate the different fields in the plain output...
>
>
>> (const char *)u64_to_ptr(info->raw_tracepoint.tp_name));
>> + if (info->raw_tracepoint.cookie)
>> + printf("cookie %llu ", info->raw_tracepoint.cookie);
>
>
> ... Please use a double space here in a similar way, at the end of your
> "cookie %llu " format string.
>
Will fix it in v3, thanks.
> Looks good otherwise. Thanks,
> Quentin
--
Best Regards
Tao Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info
2025-06-03 2:26 [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Tao Chen
2025-06-03 2:26 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test Tao Chen
2025-06-03 2:26 ` [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe Tao Chen
@ 2025-06-03 12:19 ` Jiri Olsa
2025-06-03 14:52 ` Yonghong Song
3 siblings, 0 replies; 10+ messages in thread
From: Jiri Olsa @ 2025-06-03 12:19 UTC (permalink / raw)
To: Tao Chen
Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, qmo, bpf, linux-kernel
On Tue, Jun 03, 2025 at 10:26:08AM +0800, Tao Chen wrote:
> 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.
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> include/uapi/linux/bpf.h | 2 ++
> kernel/bpf/syscall.c | 1 +
> tools/include/uapi/linux/bpf.h | 2 ++
> 3 files changed, 5 insertions(+)
>
> Change list:
> - v1 -> v2:
> - fill the hole in bpf_link_info.(Jiri)
> - v1:
> https://lore.kernel.org/bpf/20250529165759.2536245-1-chen.dylane@linux.dev
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 07ee73cdf9..f3e2aae302 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -6644,6 +6644,8 @@ 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 */
> + __u32 reserved; /* just fill the hole */
> + __u64 cookie;
> } raw_tracepoint;
> struct {
> __u32 attach_type;
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 9794446bc8..1c3dbe44ac 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -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;
> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index 07ee73cdf9..f3e2aae302 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -6644,6 +6644,8 @@ 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 */
> + __u32 reserved; /* just fill the hole */
> + __u64 cookie;
> } raw_tracepoint;
> struct {
> __u32 attach_type;
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test
2025-06-03 2:26 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test Tao Chen
@ 2025-06-03 12:19 ` Jiri Olsa
0 siblings, 0 replies; 10+ messages in thread
From: Jiri Olsa @ 2025-06-03 12:19 UTC (permalink / raw)
To: Tao Chen
Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, qmo, bpf, linux-kernel
On Tue, Jun 03, 2025 at 10:26:09AM +0800, Tao Chen wrote:
> Adding tests for getting cookie with fill_link_info for raw_tp.
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> .../selftests/bpf/prog_tests/bpf_cookie.c | 26 ++++++++++++++++++-
> 1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> index 6befa87043..0774ae6c1b 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> @@ -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;
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info
2025-06-03 2:26 [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Tao Chen
` (2 preceding siblings ...)
2025-06-03 12:19 ` [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Jiri Olsa
@ 2025-06-03 14:52 ` Yonghong Song
2025-06-03 15:07 ` Tao Chen
3 siblings, 1 reply; 10+ messages in thread
From: Yonghong Song @ 2025-06-03 14:52 UTC (permalink / raw)
To: Tao Chen, ast, daniel, andrii, martin.lau, eddyz87, song,
john.fastabend, kpsingh, sdf, qmo, jolsa
Cc: bpf, linux-kernel
On 6/2/25 7:26 PM, Tao Chen wrote:
> 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.
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
> include/uapi/linux/bpf.h | 2 ++
> kernel/bpf/syscall.c | 1 +
> tools/include/uapi/linux/bpf.h | 2 ++
> 3 files changed, 5 insertions(+)
>
> Change list:
> - v1 -> v2:
> - fill the hole in bpf_link_info.(Jiri)
> - v1:
> https://lore.kernel.org/bpf/20250529165759.2536245-1-chen.dylane@linux.dev
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 07ee73cdf9..f3e2aae302 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -6644,6 +6644,8 @@ 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 */
> + __u32 reserved; /* just fill the hole */
See various examples in uapi/linux/bpf.h, '__u32 :32;' is the preferred
apporach to fill the hole.
> + __u64 cookie;
> } raw_tracepoint;
> struct {
> __u32 attach_type;
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 9794446bc8..1c3dbe44ac 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -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;
> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index 07ee73cdf9..f3e2aae302 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -6644,6 +6644,8 @@ 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 */
> + __u32 reserved; /* just fill the hole */
> + __u64 cookie;
> } raw_tracepoint;
> struct {
> __u32 attach_type;
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info
2025-06-03 14:52 ` Yonghong Song
@ 2025-06-03 15:07 ` Tao Chen
2025-06-03 16:12 ` Jiri Olsa
0 siblings, 1 reply; 10+ messages in thread
From: Tao Chen @ 2025-06-03 15:07 UTC (permalink / raw)
To: Yonghong Song, ast, daniel, andrii, martin.lau, eddyz87, song,
john.fastabend, kpsingh, sdf, qmo, jolsa
Cc: bpf, linux-kernel
在 2025/6/3 22:52, Yonghong Song 写道:
>
>
> On 6/2/25 7:26 PM, Tao Chen wrote:
>> 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.
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>> include/uapi/linux/bpf.h | 2 ++
>> kernel/bpf/syscall.c | 1 +
>> tools/include/uapi/linux/bpf.h | 2 ++
>> 3 files changed, 5 insertions(+)
>>
>> Change list:
>> - v1 -> v2:
>> - fill the hole in bpf_link_info.(Jiri)
>> - v1:
>> https://lore.kernel.org/bpf/20250529165759.2536245-1-
>> chen.dylane@linux.dev
>>
>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> index 07ee73cdf9..f3e2aae302 100644
>> --- a/include/uapi/linux/bpf.h
>> +++ b/include/uapi/linux/bpf.h
>> @@ -6644,6 +6644,8 @@ 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 */
>> + __u32 reserved; /* just fill the hole */
>
> See various examples in uapi/linux/bpf.h, '__u32 :32;' is the preferred
> apporach to fill the hole.
Well, it looks better, will change it in v3, thanks.
>
>> + __u64 cookie;
>> } raw_tracepoint;
>> struct {
>> __u32 attach_type;
>> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
>> index 9794446bc8..1c3dbe44ac 100644
>> --- a/kernel/bpf/syscall.c
>> +++ b/kernel/bpf/syscall.c
>> @@ -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;
>> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/
>> linux/bpf.h
>> index 07ee73cdf9..f3e2aae302 100644
>> --- a/tools/include/uapi/linux/bpf.h
>> +++ b/tools/include/uapi/linux/bpf.h
>> @@ -6644,6 +6644,8 @@ 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 */
>> + __u32 reserved; /* just fill the hole */
>> + __u64 cookie;
>> } raw_tracepoint;
>> struct {
>> __u32 attach_type;
>
--
Best Regards
Tao Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info
2025-06-03 15:07 ` Tao Chen
@ 2025-06-03 16:12 ` Jiri Olsa
0 siblings, 0 replies; 10+ messages in thread
From: Jiri Olsa @ 2025-06-03 16:12 UTC (permalink / raw)
To: Tao Chen
Cc: Yonghong Song, ast, daniel, andrii, martin.lau, eddyz87, song,
john.fastabend, kpsingh, sdf, qmo, bpf, linux-kernel
On Tue, Jun 03, 2025 at 11:07:03PM +0800, Tao Chen wrote:
> 在 2025/6/3 22:52, Yonghong Song 写道:
> >
> >
> > On 6/2/25 7:26 PM, Tao Chen wrote:
> > > 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.
> > >
> > > Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> > > ---
> > > include/uapi/linux/bpf.h | 2 ++
> > > kernel/bpf/syscall.c | 1 +
> > > tools/include/uapi/linux/bpf.h | 2 ++
> > > 3 files changed, 5 insertions(+)
> > >
> > > Change list:
> > > - v1 -> v2:
> > > - fill the hole in bpf_link_info.(Jiri)
> > > - v1:
> > > https://lore.kernel.org/bpf/20250529165759.2536245-1-
> > > chen.dylane@linux.dev
> > >
> > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > > index 07ee73cdf9..f3e2aae302 100644
> > > --- a/include/uapi/linux/bpf.h
> > > +++ b/include/uapi/linux/bpf.h
> > > @@ -6644,6 +6644,8 @@ 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 */
> > > + __u32 reserved; /* just fill the hole */
> >
> > See various examples in uapi/linux/bpf.h, '__u32 :32;' is the preferred
> > apporach to fill the hole.
>
> Well, it looks better, will change it in v3, thanks.
ugh, sry.. forgot about this one
jirka
>
> >
> > > + __u64 cookie;
> > > } raw_tracepoint;
> > > struct {
> > > __u32 attach_type;
> > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > > index 9794446bc8..1c3dbe44ac 100644
> > > --- a/kernel/bpf/syscall.c
> > > +++ b/kernel/bpf/syscall.c
> > > @@ -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;
> > > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/
> > > linux/bpf.h
> > > index 07ee73cdf9..f3e2aae302 100644
> > > --- a/tools/include/uapi/linux/bpf.h
> > > +++ b/tools/include/uapi/linux/bpf.h
> > > @@ -6644,6 +6644,8 @@ 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 */
> > > + __u32 reserved; /* just fill the hole */
> > > + __u64 cookie;
> > > } raw_tracepoint;
> > > struct {
> > > __u32 attach_type;
> >
>
>
> --
> Best Regards
> Tao Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-06-03 16:12 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03 2:26 [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Tao Chen
2025-06-03 2:26 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add cookies check for raw_tp fill_link_info test Tao Chen
2025-06-03 12:19 ` Jiri Olsa
2025-06-03 2:26 ` [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe Tao Chen
2025-06-03 9:36 ` Quentin Monnet
2025-06-03 12:05 ` Tao Chen
2025-06-03 12:19 ` [PATCH bpf-next v2 1/3] bpf: Add cookie to raw_tp bpf_link_info Jiri Olsa
2025-06-03 14:52 ` Yonghong Song
2025-06-03 15:07 ` Tao Chen
2025-06-03 16:12 ` Jiri Olsa
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).