From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
KP Singh <kpsingh@kernel.org>,
Matt Bobrowski <matt@bobrowski.net>,
Shuah Khan <shuah@kernel.org>, Leon Hwang <leon.hwang@linux.dev>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf-next 8/9] selftests/bpf: Verify iter link_create logs
Date: Mon, 9 Nov 2026 22:08:15 +0800 [thread overview]
Message-ID: <20261109140816.5196-9-leon.hwang@linux.dev> (raw)
In-Reply-To: <20261109140816.5196-1-leon.hwang@linux.dev>
Check the error code, log message, and reported log size for invalid target
FDs, flags, and iterator information. Also cover attaching a sleepable
program to an iterator that does not support it.
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
.../selftests/bpf/prog_tests/iter_link.c | 132 ++++++++++++++++++
1 file changed, 132 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/iter_link.c
diff --git a/tools/testing/selftests/bpf/prog_tests/iter_link.c b/tools/testing/selftests/bpf/prog_tests/iter_link.c
new file mode 100644
index 000000000000..c684a109091a
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/iter_link.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "bpf_iter_bpf_map.skel.h"
+
+static void test_iter_link_create_log(int target_fd, struct bpf_link_create_opts *opts,
+ __u64 flags, int err_exp, const char *msg)
+{
+ struct bpf_iter_bpf_map *skel;
+ char log_buf[128] = {};
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+
+ skel = bpf_iter_bpf_map__open();
+ if (!ASSERT_OK_PTR(skel, "bpf_iter_bpf_map__open"))
+ return;
+
+ err = bpf_program__set_flags(skel->progs.dump_bpf_map, flags);
+ if (!ASSERT_OK(err, "bpf_program__set_flags"))
+ goto out;
+
+ err = bpf_iter_bpf_map__load(skel);
+ if (!ASSERT_OK(err, "bpf_iter_bpf_map__load"))
+ goto out;
+
+ opts->log_opts = &log_opts;
+ prog_fd = bpf_program__fd(skel->progs.dump_bpf_map);
+ fd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_ITER, opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ bpf_iter_bpf_map__destroy(skel);
+}
+
+static void test_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid target_fd.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+
+ test_iter_link_create_log(-1, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_invalid_flags(void)
+{
+ const char *msg = "Invalid flags.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = 1,
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_iter_info_only(void)
+{
+ const char *msg = "iter_info and iter_info_len must be both set or both unset.\n";
+ union bpf_iter_link_info info = {};
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = &info,
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_iter_info_len_only(void)
+{
+ const char *msg = "iter_info and iter_info_len must be both set or both unset.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.len = sizeof(union bpf_iter_link_info),
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_invalid_iter_info(void)
+{
+ unsigned char info[sizeof(union bpf_iter_link_info) + 1] = {};
+ const char *msg = "Invalid iter_info.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = (union bpf_iter_link_info *)info,
+ .iter.len = sizeof(info),
+ );
+
+ info[sizeof(info) - 1] = 1;
+ test_iter_link_create_log(0, &opts, 0, -E2BIG, msg);
+}
+
+static void test_log_invalid_iter_info_len(void)
+{
+ const char *msg = "Invalid iter_info_len.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = (union bpf_iter_link_info *)1,
+ .iter.len = sizeof(union bpf_iter_link_info),
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EFAULT, msg);
+}
+
+static void test_log_invalid_prog(void)
+{
+ const char *msg = "The iter target does not support the bpf prog.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+
+ test_iter_link_create_log(0, &opts, BPF_F_SLEEPABLE, -EINVAL, msg);
+}
+
+void test_iter_link_log(void)
+{
+ if (test__start_subtest("invalid_target_fd"))
+ test_log_invalid_target_fd();
+ if (test__start_subtest("invalid_flags"))
+ test_log_invalid_flags();
+ if (test__start_subtest("iter_info_only"))
+ test_log_iter_info_only();
+ if (test__start_subtest("iter_info_len_only"))
+ test_log_iter_info_len_only();
+ if (test__start_subtest("invalid_iter_info"))
+ test_log_invalid_iter_info();
+ if (test__start_subtest("invalid_iter_info_len"))
+ test_log_invalid_iter_info_len();
+ if (test__start_subtest("invalid_prog"))
+ test_log_invalid_prog();
+}
--
2.55.0
next prev parent reply other threads:[~2026-11-09 14:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 14:08 [PATCH bpf-next 0/9] bpf: Add log support for tracing link_create Leon Hwang
2026-11-09 14:08 ` [PATCH bpf-next 1/9] " Leon Hwang
2026-11-09 14:47 ` bot+bpf-ci
2026-11-09 14:08 ` [PATCH bpf-next 2/9] bpf: Add log support for tracing_multi link_create Leon Hwang
2026-11-09 14:08 ` [PATCH bpf-next 3/9] bpf: Add log support for iter link_create Leon Hwang
2026-11-09 14:08 ` [PATCH bpf-next 4/9] bpf: Add log support for cgroup prog link_create Leon Hwang
2026-11-09 14:47 ` bot+bpf-ci
2026-11-09 14:08 ` [PATCH bpf-next 5/9] libbpf: Add log_opts support for BPF_TRACE_ITER Leon Hwang
2026-11-09 14:47 ` bot+bpf-ci
2026-11-09 14:08 ` [PATCH bpf-next 6/9] selftests/bpf: Verify tracing link_create logs Leon Hwang
2026-11-09 14:47 ` bot+bpf-ci
2026-11-09 14:08 ` [PATCH bpf-next 7/9] selftests/bpf: Verify tracing_multi " Leon Hwang
2026-11-09 14:08 ` Leon Hwang [this message]
2026-11-09 14:08 ` [PATCH bpf-next 9/9] selftests/bpf: Verify cgroup prog " Leon Hwang
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=20261109140816.5196-9-leon.hwang@linux.dev \
--to=leon.hwang@linux.dev \
--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=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--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
all inboxes | Powered by JetHome®