All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next  1/5] bpf: Add cookie to tracing bpf_link_info
@ 2025-06-06 16:58 Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 2/5] selftests/bpf: Add cookies check for tracing fill_link_info test Tao Chen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tao Chen @ 2025-06-06 16:58 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

bpf_tramp_link includes cookie info, we can add it in bpf_link_info.

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(+)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index f1160ebbf52..fd4869d8cd1 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -6658,6 +6658,8 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
 			__u32 target_btf_id; /* BTF type id inside the object */
+			__u32 :32;
+			__u64 cookie;
 		} tracing;
 		struct {
 			__u64 cgroup_id;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 89d027cd7ca..4c0ac083518 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3416,6 +3416,7 @@ static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,
 		container_of(link, struct bpf_tracing_link, link.link);
 
 	info->tracing.attach_type = tr_link->attach_type;
+	info->tracing.cookie = tr_link->link.cookie;
 	bpf_trampoline_unpack_key(tr_link->trampoline->key,
 				  &info->tracing.target_obj_id,
 				  &info->tracing.target_btf_id);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index f1160ebbf52..fd4869d8cd1 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -6658,6 +6658,8 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
 			__u32 target_btf_id; /* BTF type id inside the object */
+			__u32 :32;
+			__u64 cookie;
 		} tracing;
 		struct {
 			__u64 cgroup_id;
-- 
2.43.0


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

* [PATCH bpf-next  2/5] selftests/bpf: Add cookies check for tracing fill_link_info test
  2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
@ 2025-06-06 16:58 ` Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 3/5] bpftool: Display cookie for tracing link probe Tao Chen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Chen @ 2025-06-06 16:58 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 tracing.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 .../selftests/bpf/prog_tests/bpf_cookie.c     | 24 ++++++++++++++++++-
 1 file changed, 23 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 0774ae6c1be..4a0670c056b 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -489,10 +489,28 @@ static void pe_subtest(struct test_bpf_cookie *skel)
 	bpf_link__destroy(link);
 }
 
+static int verify_tracing_link_info(int fd, u64 cookie)
+{
+	struct bpf_link_info info;
+	int err;
+	u32 len = 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_TRACING, "link_type"))
+		return -1;
+
+	ASSERT_EQ(info.tracing.cookie, cookie, "tracing_cookie");
+
+	return 0;
+}
+
 static void tracing_subtest(struct test_bpf_cookie *skel)
 {
 	__u64 cookie;
-	int prog_fd;
+	int prog_fd, err;
 	int fentry_fd = -1, fexit_fd = -1, fmod_ret_fd = -1;
 	LIBBPF_OPTS(bpf_test_run_opts, opts);
 	LIBBPF_OPTS(bpf_link_create_opts, link_opts);
@@ -507,6 +525,10 @@ static void tracing_subtest(struct test_bpf_cookie *skel)
 	if (!ASSERT_GE(fentry_fd, 0, "fentry.link_create"))
 		goto cleanup;
 
+	err = verify_tracing_link_info(fentry_fd, cookie);
+	if (!ASSERT_OK(err, "verify_tracing_link_info"))
+		goto cleanup;
+
 	cookie = 0x20000000000000L;
 	prog_fd = bpf_program__fd(skel->progs.fexit_test1);
 	link_opts.tracing.cookie = cookie;
-- 
2.43.0


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

* [PATCH bpf-next  3/5] bpftool: Display cookie for tracing link probe
  2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 2/5] selftests/bpf: Add cookies check for tracing fill_link_info test Tao Chen
@ 2025-06-06 16:58 ` Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 4/5] bpf: Add cookie in fdinfo for tracing Tao Chen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Chen @ 2025-06-06 16:58 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 tracing link probe, in plain mode:

 #bpftool link
5: tracing  prog 34
	prog_type tracing  attach_type trace_fentry
	target_obj_id 1  target_btf_id 60355
	cookie 4503599627370496
	pids test_progs(176)

And in json mode:

 #bpftool link -j | jq
{
    "id": 5,
    "type": "tracing",
    "prog_id": 34,
    "prog_type": "tracing",
    "attach_type": "trace_fentry",
    "target_obj_id": 1,
    "target_btf_id": 60355,
    "cookie": 4503599627370496,
    "pids": [
      {
        "pid": 176,
        "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 cb67ce4eba2..03513ffffb7 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -503,6 +503,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
 					   json_wtr);
 		jsonw_uint_field(json_wtr, "target_obj_id", info->tracing.target_obj_id);
 		jsonw_uint_field(json_wtr, "target_btf_id", info->tracing.target_btf_id);
+		jsonw_uint_field(json_wtr, "cookie", info->tracing.cookie);
 		break;
 	case BPF_LINK_TYPE_CGROUP:
 		jsonw_lluint_field(json_wtr, "cgroup_id",
@@ -900,6 +901,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
 			printf("\n\ttarget_obj_id %u  target_btf_id %u  ",
 			       info->tracing.target_obj_id,
 			       info->tracing.target_btf_id);
+		if (info->tracing.cookie)
+			printf("\n\tcookie %llu  ", info->tracing.cookie);
 		break;
 	case BPF_LINK_TYPE_CGROUP:
 		printf("\n\tcgroup_id %zu  ", (size_t)info->cgroup.cgroup_id);
-- 
2.43.0


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

* [PATCH bpf-next  4/5] bpf: Add cookie in fdinfo for tracing
  2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 2/5] selftests/bpf: Add cookies check for tracing fill_link_info test Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 3/5] bpftool: Display cookie for tracing link probe Tao Chen
@ 2025-06-06 16:58 ` Tao Chen
  2025-06-06 16:58 ` [PATCH bpf-next 5/5] bpf: Add cookie in fdinfo for raw_tp Tao Chen
  2025-06-09 23:50 ` [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Chen @ 2025-06-06 16:58 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

Add cookie in fdinfo for tracing, the info as follows:

link_type:	tracing
link_id:	6
prog_tag:	9dfdf8ef453843bf
prog_id:	35
attach_type:	25
target_obj_id:	1
target_btf_id:	60355
cookie:	9007199254740992

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/bpf/syscall.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 4c0ac083518..d6eba1339ad 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3403,10 +3403,12 @@ static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link,
 	seq_printf(seq,
 		   "attach_type:\t%d\n"
 		   "target_obj_id:\t%u\n"
-		   "target_btf_id:\t%u\n",
+		   "target_btf_id:\t%u\n"
+		   "cookie:\t%llu\n",
 		   tr_link->attach_type,
 		   target_obj_id,
-		   target_btf_id);
+		   target_btf_id,
+		   tr_link->link.cookie);
 }
 
 static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,
-- 
2.43.0


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

* [PATCH bpf-next  5/5] bpf: Add cookie in fdinfo for raw_tp
  2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
                   ` (2 preceding siblings ...)
  2025-06-06 16:58 ` [PATCH bpf-next 4/5] bpf: Add cookie in fdinfo for tracing Tao Chen
@ 2025-06-06 16:58 ` Tao Chen
  2025-06-09 23:50 ` [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Chen @ 2025-06-06 16:58 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

Add cookie in fdinfo for raw_tp, the info as follows:

link_type:	raw_tracepoint
link_id:	31
prog_tag:	9dfdf8ef453843bf
prog_id:	32
tp_name:	sys_enter
cookie:	23925373020405760

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/bpf/syscall.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index d6eba1339ad..51ba1a7aa43 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3654,8 +3654,10 @@ static void bpf_raw_tp_link_show_fdinfo(const struct bpf_link *link,
 		container_of(link, struct bpf_raw_tp_link, link);
 
 	seq_printf(seq,
-		   "tp_name:\t%s\n",
-		   raw_tp_link->btp->tp->name);
+		   "tp_name:\t%s\n"
+		   "cookie:\t%llu\n",
+		   raw_tp_link->btp->tp->name,
+		   raw_tp_link->cookie);
 }
 
 static int bpf_copy_to_user(char __user *ubuf, const char *buf, u32 ulen,
-- 
2.43.0


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

* Re: [PATCH bpf-next  1/5] bpf: Add cookie to tracing bpf_link_info
  2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
                   ` (3 preceding siblings ...)
  2025-06-06 16:58 ` [PATCH bpf-next 5/5] bpf: Add cookie in fdinfo for raw_tp Tao Chen
@ 2025-06-09 23:50 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-09 23:50 UTC (permalink / raw)
  To: Tao Chen
  Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, qmo, jolsa, bpf, linux-kernel

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sat,  7 Jun 2025 00:58:14 +0800 you wrote:
> bpf_tramp_link includes cookie info, we can add it in bpf_link_info.
> 
> 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(+)

Here is the summary with links:
  - [bpf-next,1/5] bpf: Add cookie to tracing bpf_link_info
    https://git.kernel.org/bpf/bpf-next/c/c7beb48344d2
  - [bpf-next,2/5] selftests/bpf: Add cookies check for tracing fill_link_info test
    https://git.kernel.org/bpf/bpf-next/c/d77efc0ef5b0
  - [bpf-next,3/5] bpftool: Display cookie for tracing link probe
    https://git.kernel.org/bpf/bpf-next/c/ad954cbe0849
  - [bpf-next,4/5] bpf: Add cookie in fdinfo for tracing
    https://git.kernel.org/bpf/bpf-next/c/380cb6dfa2bf
  - [bpf-next,5/5] bpf: Add cookie in fdinfo for raw_tp
    https://git.kernel.org/bpf/bpf-next/c/2bc0575fec36

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-06-09 23:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 16:58 [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info Tao Chen
2025-06-06 16:58 ` [PATCH bpf-next 2/5] selftests/bpf: Add cookies check for tracing fill_link_info test Tao Chen
2025-06-06 16:58 ` [PATCH bpf-next 3/5] bpftool: Display cookie for tracing link probe Tao Chen
2025-06-06 16:58 ` [PATCH bpf-next 4/5] bpf: Add cookie in fdinfo for tracing Tao Chen
2025-06-06 16:58 ` [PATCH bpf-next 5/5] bpf: Add cookie in fdinfo for raw_tp Tao Chen
2025-06-09 23:50 ` [PATCH bpf-next 1/5] bpf: Add cookie to tracing bpf_link_info patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.