From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214898; b=flIGXD63E8VrlsMl+cf9CHe4Yjn+cULz/VcMcl5r5C8uXZnOaiH4vsG1zx3G4Fynu1hc osPT9yjApxAbrBpwGsIw2JznD6/UVI0Lfntnzwnk2ivBlvqiIcxk38+D1+UzVN4oR0Xel mICO040nk//+h/c1uKM4mMjhr4E9h4vL/tQLsiBLN9m2v6RQRd1t2aWMqSrdLapDVolGZ CQNM13uoND0bt5Chjc4yp/mE5MDHq06Cbt/OxvHfuo8vvkuF26PD41x5rqgUN118yjGes QKli7Z+bGvEms5Vqb5kJRswtertxj49z0ovLMJBcq6BSclVa04/A7JB8sWK+ZPNZWEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214898; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=8SA1+COIanHMlNpUnK4BtGMOcAdk+9gQUNjzIg3w8u8=; b=sIWhPqMU/7urBtRYLTtx58f0mWD0lCu+VXN+q5rCKsW3OUoipN+DzZkW5WrQM22C+CMI wMidhsbhY4WMAV1PEqshAObQSXgBa6ruZ+z/6TUxDWknoCbxCifPSuD4QfDhmJIM+xUOC ETjtTpzFRbM6MeDVOyISuUMYgG5l/GeNtTPtiVzN0zFnNf7ZidOBv2A852IEUreW1noHe otc6Vnq+vThIAcs2kq0eVcSdhUMaG9TZe/Q6dMVa7Eb/pxrY3NTN/h3agwVZyKlU7whY9 b2o2dORrm0L4rVbmwU+FOrckjW1EWU1E3eikSom/EZV0s+BmIfw1Y4c2tynRMtEPy4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Y22uOY1w; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 553B1606A322; Wed, 2 Dec 2026 12:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Y22uOY1w Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AF681F00896; Wed, 2 Dec 2026 12:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214897; bh=8SA1+COIanHMlNpUnK4BtGMOcAdk+9gQUNjzIg3w8u8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y22uOY1whzQrmo0hPjlxQSn6bkKbM8dAV2a9KZ5wPnNEi1OPgTl8CDY2eRPOh4Ane MAyQHmbsKB6Rrzmk61te+lWwZxCdHgXzDvpyZ737HmMQjkr4aXXxdC1Cj1YNeU3QBr sFNWtX6e0oKICbBt4L7dQkhBWFbVJOfhNZ+1rCzirOR7wjWjPt8f0LD9aK4EotfKYa fqxOShvNcWl9//rJroOAhuhxu+ydRmybMT3Ld5Wt5tKfPoxcTdq8cFMvwF7tK26TPF o30IVFSvHUyiZjgEBsAO4Ur04Z36f5Hm3tAW/O+cj92Euiym+V9RNx6DGTz8GMuX1p 2Niv2UzeI7KSA== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , Quentin Monnet , Alan Maguire Subject: [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Date: Wed, 2 Dec 2026 13:30:29 +0100 Message-ID: <20261202123035.10335-26-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add inline_skip test that attaches function with one inlined instance that can be attached and one that can't, and checks the second one is skipped. Also check the attach fails for function that has no entry and its only inlined instance can't be attached. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/kprobe_multi_test.c | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c index 1ff918dd100f..f6556bd9f2d0 100644 --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c @@ -487,6 +487,33 @@ static void test_unique_match(void) kprobe_multi__destroy(skel); } +/* + * Get value of the @name counter from fdinfo of kprobe multi link. + * + * The same counters are available also in link info, but we want to + * have fdinfo tested as well and link info has its own test in + * fill_link_info.c. + */ +static long get_fdinfo_cnt(int link_fd, const char *name) +{ + char path[64], buf[256], fmt[64]; + long cnt = -1; + FILE *f; + + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", link_fd); + f = fopen(path, "r"); + if (!ASSERT_OK_PTR(f, "open_fdinfo")) + return -1; + + snprintf(fmt, sizeof(fmt), "%s:\t%%ld", name); + while (fgets(buf, sizeof(buf), f)) { + if (sscanf(buf, fmt, &cnt) == 1) + break; + } + fclose(f); + return cnt; +} + static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_multi_opts *opts) { long attach_start_ns, attach_end_ns; @@ -949,6 +976,79 @@ static void test_inline_mixed(void) kprobe_multi_inline__destroy(skel); } +/* Inlined instances that can't be attached are skipped. */ +static void test_inline_skip(void) +{ + LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); + const char *syms[1] = { "bpf_kprobe_multi_inline_partial" }; + const char *nosyms[1] = { "bpf_kprobe_multi_inline_nokprobe" }; + struct kprobe_multi_inline *skel = NULL; + unsigned long sites[INLINE_MAX]; + __u64 cookies[1] = { 8 }; + int cnt, i, saved_error, link_fd; + struct ksym *ksym; + bool attached; + + cnt = get_inline_sites(syms[0], sites, INLINE_MAX); + if (cnt == -ENOENT) { + test__skip(); + return; + } + + /* One instance in function that kprobes can attach and one that can't. */ + if (!ASSERT_EQ(cnt, 2, "inline_sites_cnt")) + return; + + skel = kprobe_multi_inline__open_and_load(); + if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load")) + return; + + skel->bss->pid = getpid(); + + opts.syms = syms; + opts.cookies = cookies; + opts.cnt = ARRAY_SIZE(syms); + opts.inlined = true; + + skel->links.test_kprobe_inline = + bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts); + if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "attach_kprobe_multi_opts")) + goto cleanup; + + link_fd = bpf_link__fd(skel->links.test_kprobe_inline); + ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_cnt"), 1, "kprobe_inline_cnt"); + ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_skipped"), 1, "kprobe_inline_skipped"); + + inline_trigger(skel); + + /* Only the instance outside of the nokprobe function is hit. */ + ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt"); + + for (i = 0; i < cnt; i++) { + ksym = ksym_search(sites[i]); + if (!ASSERT_OK_PTR(ksym, "ksym_search")) + continue; + attached = !strcmp(ksym->name, "bpf_kprobe_multi_inline_test3"); + ASSERT_EQ(inline_hits(skel, sites[i], 8), attached ? 1 : 0, "inline_site_hit"); + } + + kprobe_multi_inline__detach(skel); + + /* Function with no entry and all inlined instances skipped fails to attach. */ + opts.syms = nosyms; + opts.cookies = NULL; + + skel->links.test_kprobe_inline = + bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts); + saved_error = -errno; + if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "attach_nokprobe")) + goto cleanup; + ASSERT_EQ(saved_error, -EINVAL, "attach_nokprobe_error"); + +cleanup: + kprobe_multi_inline__destroy(skel); +} + /* Run all the tests for attaching to inlined functions. */ static void test_inline_subtests(void) { @@ -961,6 +1061,8 @@ static void test_inline_subtests(void) test_inline_attach(); if (test__start_subtest("inline_mixed")) test_inline_mixed(); + if (test__start_subtest("inline_skip")) + test_inline_skip(); free_inline_btf(); } -- 2.56.1