Re: [PATCH bpf-next v3 0/9] bpf: Add log support for tracing link_create

From: Alexei Starovoitov

Date: Mon Nov 23 2026 - 19:12:58 EST


On Mon, Nov 23, 2026 at 07:27 AM Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
> .../selftests/bpf/prog_tests/cgroup_link.c | 324 ++++++++
> .../selftests/bpf/prog_tests/iter_link.c | 156 ++++
> .../selftests/bpf/prog_tests/tracing_link.c | 741 ++++++++++++++++++
> .../selftests/bpf/progs/tracing_link_ctx.c | 17 +
> .../selftests/bpf/progs/tracing_link_multi.c | 36 +
> .../selftests/bpf/test_kmods/bpf_testmod.c | 5 +

1279 lines of selftests for log messages ?
This is way too much.

pw-bot: cr

One row per attach path is enough. It checks that the log gets there.
The base kernel leaves the log empty, so all four rows fail on it.
Something like this:

diff --git a/tools/testing/selftests/bpf/prog_tests/link_log.c b/tools/testing/selftests/bpf/prog_tests/link_log.c
new file mode 100644
index 0000000..4f7e71a
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/link_log.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+
+/* One row per attach path. It checks that the log gets there. */
+static const struct {
+ const char *name;
+ enum bpf_prog_type type;
+ enum bpf_attach_type attach_type;
+ const char *func;
+ struct bpf_link_create_opts opts;
+ int err;
+ const char *msg;
+} tests[] = {
+ { "tracing", BPF_PROG_TYPE_TRACING, BPF_TRACE_FENTRY, "bpf_fentry_test1",
+ { .target_btf_id = 1 }, -EINVAL, "target_btf_id" },
+#ifdef __x86_64__
+ { "tracing_multi", BPF_PROG_TYPE_TRACING, BPF_TRACE_FENTRY_MULTI, NULL,
+ { .tracing_multi = { .ids = (const __u32[]){ ~0U }, .cnt = 1 } },
+ -EINVAL, "4294967295" },
+#endif
+ { "iter", BPF_PROG_TYPE_TRACING, BPF_TRACE_ITER, "bpf_map",
+ { .iter.len = 4 }, -EINVAL, "iter_info_len" },
+ { "cgroup", BPF_PROG_TYPE_CGROUP_SKB, BPF_CGROUP_INET_EGRESS, NULL,
+ { .cgroup.expected_revision = 2 }, -ESTALE, "revision" },
+};
+
+static void run_test(int i, int cg)
+{
+ const struct bpf_insn insns[] = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ };
+ struct bpf_link_create_opts opts = tests[i].opts;
+ char buf[128] = {};
+ LIBBPF_OPTS(bpf_log_opts, log_opts, .buf = buf, .size = sizeof(buf), .level = 1);
+ LIBBPF_OPTS(bpf_prog_load_opts, load_opts,
+ .expected_attach_type = tests[i].attach_type);
+ int prog_fd, fd;
+
+ if (tests[i].func)
+ load_opts.attach_btf_id =
+ libbpf_find_vmlinux_btf_id(tests[i].func, tests[i].attach_type);
+ prog_fd = bpf_prog_load(tests[i].type, NULL, "GPL", insns, ARRAY_SIZE(insns),
+ &load_opts);
+ if (!ASSERT_OK_FD(prog_fd, "bpf_prog_load"))
+ return;
+
+ opts.sz = sizeof(opts);
+ opts.log_opts = &log_opts;
+ fd = bpf_link_create(prog_fd, tests[i].type == BPF_PROG_TYPE_CGROUP_SKB ? cg : 0,
+ tests[i].attach_type, &opts);
+ if (fd >= 0)
+ close(fd);
+ ASSERT_EQ(fd, tests[i].err, "err");
+ ASSERT_HAS_SUBSTR(buf, tests[i].msg, "log");
+ ASSERT_EQ(log_opts.true_size, strlen(buf) + 1, "true_size");
+ close(prog_fd);
+}
+
+void test_link_log(void)
+{
+ int i, cg;
+
+ cg = test__join_cgroup("/link_log");
+ if (!ASSERT_OK_FD(cg, "join_cgroup"))
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(tests); i++)
+ if (test__start_subtest(tests[i].name))
+ run_test(i, cg);
+ close(cg);
+}