From: Sun Jian <sun.jian.kdev@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, shuah@kernel.org,
laoar.shao@gmail.com, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH bpf 2/2] selftests/bpf: Cover link info metadata on ENOSPC
Date: Wed, 24 Jun 2026 19:18:37 +0800 [thread overview]
Message-ID: <20260624111837.889209-2-sun.jian.kdev@gmail.com> (raw)
In-Reply-To: <20260624111837.889209-1-sun.jian.kdev@gmail.com>
Add a perf event tracepoint link info check with a one-byte tp_name
buffer. The query is expected to return -ENOSPC because the nested name
buffer is too small, but it should still report the top-level link type,
perf event type, cookie, and real tp_name length.
Before the fix, bpf_link_get_info_by_fd() returned -ENOSPC but did not
copy the top-level bpf_link_info back to userspace, leaving info.type as
zero.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
.../selftests/bpf/prog_tests/fill_link_info.c | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index f589eefbf9fb..95132c80b3b9 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -126,6 +126,37 @@ static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long add
return err;
}
+static int verify_perf_tp_link_info_enospc(int fd)
+{
+ struct bpf_link_info info;
+ __u32 len = sizeof(info);
+ char buf[1] = {};
+ int err;
+
+ memset(&info, 0, sizeof(info));
+ info.perf_event.tracepoint.tp_name = ptr_to_u64(buf);
+ info.perf_event.tracepoint.name_len = sizeof(buf);
+
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ if (!ASSERT_EQ(err, -ENOSPC, "get_link_info_enospc"))
+ return -1;
+
+ if (!ASSERT_EQ(info.type, BPF_LINK_TYPE_PERF_EVENT, "link_type_enospc"))
+ return -1;
+ if (!ASSERT_EQ(info.perf_event.type, BPF_PERF_EVENT_TRACEPOINT, "perf_type_enospc"))
+ return -1;
+ if (!ASSERT_EQ(info.perf_event.tracepoint.name_len, strlen(TP_NAME) + 1,
+ "tp_name_len_enospc"))
+ return -1;
+ if (!ASSERT_EQ(info.perf_event.tracepoint.cookie, PERF_EVENT_COOKIE,
+ "tp_cookie_enospc"))
+ return -1;
+ if (!ASSERT_EQ(buf[0], '\0', "short_tp_name_nul"))
+ return -1;
+
+ return 0;
+}
+
static void kprobe_fill_invalid_user_buffer(int fd)
{
struct bpf_link_info info;
@@ -200,6 +231,10 @@ static void test_tp_fill_link_info(struct test_fill_link_info *skel)
link_fd = bpf_link__fd(link);
err = verify_perf_link_info(link_fd, BPF_PERF_EVENT_TRACEPOINT, 0, 0, 0);
ASSERT_OK(err, "verify_perf_link_info");
+
+ err = verify_perf_tp_link_info_enospc(link_fd);
+ ASSERT_OK(err, "verify_perf_tp_link_info_enospc");
+
bpf_link__destroy(link);
}
--
2.43.0
next prev parent reply other threads:[~2026-06-24 11:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 11:18 [PATCH bpf 1/2] bpf: Preserve link info metadata on ENOSPC Sun Jian
2026-06-24 11:18 ` Sun Jian [this message]
2026-06-24 12:08 ` [PATCH bpf 2/2] selftests/bpf: Cover " bot+bpf-ci
2026-06-24 20:59 ` [PATCH bpf 1/2] bpf: Preserve " Alexei Starovoitov
2026-06-25 7:14 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260624111837.889209-2-sun.jian.kdev@gmail.com \
--to=sun.jian.kdev@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox