Linux Trace Kernel
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	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>,
	John Fastabend <john.fastabend@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	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-perf-users@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next 4/4] selftests/bpf: Test perf event and multi-probe link creation logs
Date: Wed,  2 Dec 2026 23:37:39 +0800	[thread overview]
Message-ID: <20261202153739.57959-5-leon.hwang@linux.dev> (raw)
In-Reply-To: <20261202153739.57959-1-leon.hwang@linux.dev>

Check the link creation log for a perf event program with an invalid
target fd and a tracepoint program targeting a software perf event.

Exercise kprobe multi attachment without symbols or addresses and
uprobe multi attachment without a path. Check the errno, diagnostic
text and reported log size for each failure.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 .../selftests/bpf/prog_tests/link_log.c       | 46 ++++++++++++++++---
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/link_log.c b/tools/testing/selftests/bpf/prog_tests/link_log.c
index 8a05d6c48d9b..73a5e876ea2b 100644
--- a/tools/testing/selftests/bpf/prog_tests/link_log.c
+++ b/tools/testing/selftests/bpf/prog_tests/link_log.c
@@ -21,6 +21,15 @@ static const struct link_log_case {
 	  { .iter.len = sizeof(union bpf_iter_link_info) }, -EINVAL, "iter_info_len" },
 	{ "cgroup", BPF_PROG_TYPE_CGROUP_SKB, BPF_CGROUP_INET_EGRESS, NULL,
 	  { .cgroup.expected_revision = 2 }, -ESTALE, "revision" },
+	{ "perf_event", BPF_PROG_TYPE_PERF_EVENT, BPF_PERF_EVENT, NULL,
+	  {}, -EBADF, "Invalid target_fd" },
+	{ "tracepoint", BPF_PROG_TYPE_TRACEPOINT, BPF_PERF_EVENT, NULL,
+	  {}, -EINVAL, "Prog type must be BPF_PROG_TYPE_PERF_EVENT" },
+	{ "kprobe_multi", BPF_PROG_TYPE_KPROBE, BPF_TRACE_KPROBE_MULTI, NULL,
+	  { .kprobe_multi.cnt = 1 }, -EINVAL, "Exactly one of kprobe_multi.addrs" },
+	{ "uprobe_multi", BPF_PROG_TYPE_KPROBE, BPF_TRACE_UPROBE_MULTI, NULL,
+	  { .uprobe_multi = { .cnt = 1, .offsets = (const unsigned long[]){ 0 } } },
+	  -EINVAL, "uprobe_multi.path must be set" },
 };
 
 static void run_test(const struct link_log_case *test)
@@ -30,7 +39,8 @@ static void run_test(const struct link_log_case *test)
 		BPF_EXIT_INSN(),
 	};
 	struct bpf_link_create_opts opts = test->opts;
-	int prog_fd, fd, btf_id, cg = -1;
+	int prog_fd, fd, btf_id, target_fd;
+	bool close_target_fd = false;
 	LIBBPF_OPTS(bpf_prog_load_opts, load_opts,
 		    .expected_attach_type = test->attach_type,
 	);
@@ -53,15 +63,37 @@ static void run_test(const struct link_log_case *test)
 	if (!ASSERT_OK_FD(prog_fd, "bpf_prog_load"))
 		return;
 
-	if (test->type == BPF_PROG_TYPE_CGROUP_SKB) {
-		cg = test__join_cgroup("/link_log");
-		if (!ASSERT_OK_FD(cg, "join_cgroup"))
+	switch (test->type) {
+	case BPF_PROG_TYPE_CGROUP_SKB:
+		target_fd = test__join_cgroup("/link_log");
+		if (!ASSERT_OK_FD(target_fd, "join_cgroup"))
 			goto out;
+		close_target_fd = true;
+		break;
+	case BPF_PROG_TYPE_TRACEPOINT: {
+		struct perf_event_attr attr = {
+			.type = PERF_TYPE_SOFTWARE,
+			.config = PERF_COUNT_SW_DUMMY,
+			.size = sizeof(attr),
+		};
+
+		target_fd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);
+		if (!ASSERT_OK_FD(target_fd, "perf_event_open"))
+			goto out;
+		close_target_fd = true;
+		break;
+	}
+	case BPF_PROG_TYPE_PERF_EVENT:
+		target_fd = -1;
+		break;
+	default:
+		target_fd = 0;
+		break;
 	}
 
 	opts.sz = sizeof(opts);
 	opts.log_opts = &log_opts;
-	fd = bpf_link_create(prog_fd, cg < 0 ? 0 : cg, test->attach_type, &opts);
+	fd = bpf_link_create(prog_fd, target_fd, test->attach_type, &opts);
 	if (fd >= 0)
 		close(fd);
 
@@ -69,8 +101,8 @@ static void run_test(const struct link_log_case *test)
 	ASSERT_HAS_SUBSTR(buf, test->msg, "log");
 	ASSERT_EQ(log_opts.true_size, strlen(buf) + 1, "true_size");
 
-	if (cg >= 0)
-		close(cg);
+	if (close_target_fd)
+		close(target_fd);
 out:
 	close(prog_fd);
 }
-- 
2.55.0


      parent reply	other threads:[~2026-12-02 15:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:37 [PATCH bpf-next 0/4] bpf: Add log support for perf link_create Leon Hwang
2026-12-02 15:37 ` [PATCH bpf-next 1/4] " Leon Hwang
2026-12-02 15:37 ` [PATCH bpf-next 2/4] bpf: Add log support for kprobe_multi link_create Leon Hwang
2026-12-02 15:37 ` [PATCH bpf-next 3/4] bpf: Add log support for uprobe_multi link_create Leon Hwang
2026-12-02 15:37 ` Leon Hwang [this message]

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=20261202153739.57959-5-leon.hwang@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.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=ihor.solodrai@linux.dev \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --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-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=matt@bobrowski.net \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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