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=1796214917; b=Ft0zd0Va6pw5XuhLuWtchWZKgF02uLkwBOZ5XoAKeNGUMY3sALZQcGu45JipOZkBF7Ip cMDqqh9rJNv/nkhaXLtE8eXPfgI13zli+JxwtjXMeACUZqIqKlYeGT7FJ6+Y2u19gZ/iC 5j+MyKTfuC7VmoqXRq8GhZXwKU80YyFZpN0JADICtFlwX7e6XXj47fpbQCB7s+knjWWLk Xoob+NCE5zeSyYkTpFqFN92uNMzQSmucKb1RMEf2z6aAIASQdGXi6/L2bXbq6ex47N1eo BR6B46TKABUYbXjcAKd+j7YFPAmfiYdQatccqlrqTip16biH9CCEWj8CwE4/GvkhPqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214917; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=5XWMf4P5A8EXSedAw4zjTsV5kr/2c+xy3MvtrEBjiGI=; b=H6XeMQQPx5lMRE99rZE+Nfy6K6gyru58RtVdZyhGeKBBzrJ7BbGX1LsYDqZz1A93f3qJ 6mqlJO92mlEAHFN/7XUYr0+RqmeawVahQHkqN94zevGljiYI6aKdzdC/1cbP7B4Naquzc L4RGJvBf6RO6OFp5sqh4bcnb0P0QeIFNwUwFOkTBEh+NP1OZpxfSvqcl5fwkhz0/58FVx yuBf8o+5CpHBSYEd1DV8RKbaAZMBdyrv7NR2RJ9fEjgmN8N5VeOB66IIvbrn0qtzr3XJE mCWsKrtFuRPKP4gWgbrnh0pcEGTPoG3MEd62HM7Tr3c0zl1oAE+/+f8qW5XX6XhuAPA== 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="FIpD/OOK"; 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 5C157606A322; Wed, 2 Dec 2026 12:35:17 +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=FIpD/OOK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 454271F000C1; Wed, 2 Dec 2026 12:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214917; bh=5XWMf4P5A8EXSedAw4zjTsV5kr/2c+xy3MvtrEBjiGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FIpD/OOKJZcZS1TwmagMlWMLYPyihQQL0fgFOw6LYiaNDq8Q9of16wMMHJd2wCIMO RV4eHSycxlWE6HGvA8wnMxZnN5WHs47I+14Idkmw9NKdI/jdP9+miMR9eaB16aj0hF en2u4NLNaTlEohyoBtBQ0mln0jbcoMOoIdFPjO5av3QfjLiKkHdHz5zAA7FRUQqaxV Lz6nJe9K4Yc4FDW2jTi7h7JZcCKN7Nut6Jzxauk+sxCcKkDAwiftEsW/up5c3AbSTu k3DFUjgDK/h25NMEBzcH0mGhqZ2WAgd4pTNloshm/kH7bI5ndYUrFEh2KGcZw8pcJg wwLiuR3iZ1ydw== 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 27/31] selftests/bpf: Add kprobe multi inline module test Date: Wed, 2 Dec 2026 13:30:31 +0100 Message-ID: <20261202123035.10335-28-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-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_module test that attaches function inlined in bpf_testmod module with BPF_F_KPROBE_MULTI_INLINE flag and checks its inlined instance is hit once with the function cookie and that the probe is gone after detach. The expected address of the inlined instance is read from bpf_testmod inline BTF, the test is skipped if it's not available. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/kprobe_multi_test.c | 115 +++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) 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 3f5d5b5198e6..761cd7fe63ac 100644 --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c @@ -775,6 +775,8 @@ static int find_inline_sites(struct btf *inline_btf, unsigned long base, const c /* BTF used to find inlined instances, loaded once on first use. */ static struct btf *vmlinux_btf; static struct btf *vmlinux_inline_btf; +static struct btf *testmod_btf; +static struct btf *testmod_inline_btf; static struct btf *get_vmlinux_btf(void) { @@ -805,9 +807,11 @@ static int get_split_btf(struct btf **cache, const char *path, struct btf *base) static void free_inline_btf(void) { + btf__free(testmod_inline_btf); + btf__free(testmod_btf); btf__free(vmlinux_inline_btf); btf__free(vmlinux_btf); - vmlinux_inline_btf = vmlinux_btf = NULL; + testmod_inline_btf = testmod_btf = vmlinux_inline_btf = vmlinux_btf = NULL; } /* @@ -839,6 +843,56 @@ static int get_inline_sites(const char *func, unsigned long *addrs, int max) return find_inline_sites(vmlinux_inline_btf, base, func, addrs, max); } +/* Get address of bpf_testmod .text section, zero if it's not available. */ +static unsigned long get_testmod_text_addr(void) +{ + static unsigned long addr; + FILE *f; + + if (addr) + return addr; + + f = fopen("/sys/module/bpf_testmod/sections/.text", "r"); + if (!f) + return 0; + if (fscanf(f, "%lx", &addr) != 1) + addr = 0; + fclose(f); + return addr; +} + +/* + * Get addresses of inlined instances of @func from bpf_testmod inline BTF. + * Returns number of instances or -ENOENT if there's no inline BTF. + */ +static int get_testmod_inline_sites(const char *func, unsigned long *addrs, int max) +{ + unsigned long base; + int err; + + /* LOCSEC offsets are relative to the module .text section base. */ + base = get_testmod_text_addr(); + if (!ASSERT_NEQ(base, 0, "testmod_text_addr")) + return -EINVAL; + + if (!ASSERT_OK_PTR(get_vmlinux_btf(), "vmlinux_btf")) + return -EINVAL; + + err = get_split_btf(&testmod_btf, "/sys/kernel/btf/bpf_testmod", vmlinux_btf); + if (!ASSERT_OK(err, "testmod_btf")) + return -EINVAL; + + err = get_split_btf(&testmod_inline_btf, "/sys/kernel/btf/bpf_testmod.inline", testmod_btf); + if (err) { + /* pahole may not have inline BTF feature support. */ + if (err != -ENOENT) + ASSERT_OK(err, "parse_testmod_inline_btf"); + return err; + } + + return find_inline_sites(testmod_inline_btf, base, func, addrs, max); +} + static int inline_hits(struct kprobe_multi_inline *skel, unsigned long ip, __u64 cookie) { int i, cnt = 0; @@ -1049,6 +1103,63 @@ static void test_inline_skip(void) kprobe_multi_inline__destroy(skel); } +/* Attach inlined function in kernel module. */ +static void test_inline_module(void) +{ + LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); + const char *syms[1] = { "bpf_testmod_kprobe_multi_inline" }; + struct kprobe_multi_inline *skel = NULL; + unsigned long sites[INLINE_MAX]; + __u64 cookies[1] = { 7 }; + struct ksym *ksym; + int cnt; + + cnt = get_testmod_inline_sites(syms[0], sites, INLINE_MAX); + if (cnt == -ENOENT) { + test__skip(); + return; + } + if (!ASSERT_EQ(cnt, 1, "sites_cnt")) + return; + + ksym = ksym_search(sites[0]); + if (!ASSERT_OK_PTR(ksym, "ksym_search")) + return; + ASSERT_STREQ(ksym->name, "bpf_testmod_kprobe_multi_inline_test", "inline_site_caller"); + + 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; + + skel->bss->hits_cnt = 0; + ASSERT_OK(trigger_module_test_read(1), "trigger_read"); + + ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt"); + ASSERT_EQ(inline_hits(skel, sites[0], 7), 1, "inline_site_hit"); + + /* Make sure the probe is gone after detach. */ + kprobe_multi_inline__detach(skel); + + skel->bss->hits_cnt = 0; + ASSERT_OK(trigger_module_test_read(1), "trigger_read"); + ASSERT_EQ(skel->bss->hits_cnt, 0, "hits_cnt_detached"); + +cleanup: + kprobe_multi_inline__destroy(skel); +} + /* * Make sure the link create fails with @error and kernel explains * the failure with @msg in the log. @@ -1231,6 +1342,8 @@ static void test_inline_subtests(void) test_inline_skip(); if (test__start_subtest("inline_fails")) test_inline_fails(); + if (test__start_subtest("inline_module")) + test_inline_module(); free_inline_btf(); } -- 2.56.1