Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796318083; b=b1aMJhutxJn/frxItcVXRBn9ZvGC2Bq/zfF+Hyq/ngY8zApFNyGlKIupTaysQNqslAJO Z3B343v//rPF85hSYBrfpobslBvresT4kBRx6tEcrSz827uzHvz6e1PyFI80npQ9gIPG5 u+OsKgQ/ZMaCwTN6kXOFDv1S0hqHsShjBalu4o/Wz8xtcxkYG4tUZsZNqeAM+/g7AyH0V ljudD/3HLfXcV9+5cUyM/OI8z1/mSn/F9b3aJMdLZfmH4a7N+GdJ8Yplt2HvgEKZmm0+F xES2oRJLZKOfoXDs6L6kd83IZOYkmgBiYX0bggnJKQAwYVxoy4rfBODCtzeFxnC/J/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796318083; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=WDei4hwiHpXOoybGtafWNOOiYZhSuNryGyOzyc2UiJc=; b=4NOmm3AT1B2sOvJCDIltczqXgrdd+eM2PXXckHWVwXYPIvO4jJw+VT48TDhh08s4Xbsz m5SNIcBsNufSSEooTrX6jnPQ1AeIC/vCdiIZ01cK1gmIWYI1TMPsxtV6wCfet/e1hkBtA /oUkHDP4vyLLx6OYjI5d2X/UgjFCKdJqQhh+HY6T00w99Wm78wNOhZI0C48kbhSLsQe9y 1zPj9wo7SD2V6hBsHfvPVGytnzQ7hmAlB0XqLaO0LTwSW/v/UswMITOs9av4zcSdp2KYe jSSSdCYgAka6bPTOVTr5t0lKqSDCYpmxHo6Zm2ASI62AG7pLOk6QyJ+Rj0geH0wPeyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EvHMnC5H; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D606C606A330 for ; Thu, 3 Dec 2026 17:14:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D606C606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EvHMnC5H Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so134638065e9.2 for ; Thu, 03 Dec 2026 09:14:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796318081; x=1796922881; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WDei4hwiHpXOoybGtafWNOOiYZhSuNryGyOzyc2UiJc=; b=EvHMnC5Hm/XdNyce1UyCm96x6ffbNpvT/AdqFiCshm9sWtN/g+XI1bkf76TOZsDpl/ z0zDffxCAz5jX0d4jt2PoVvBpwRyKXv8ACo6gk2S7ysF1Lv9eWBQDqZjqjQGrFDulSPU rnSx+FwH6x98Bdf+ijNRBZGWfwjHqkKTqB4/NPdLIAoV8lI/+z76jJoY9yFC4630dLNx jJAaqJMH1AkjkSc1XomafkHzTjWH1/4muBhe8eo3+rtIBmap3qgkqgq7s9+aHVZaNywh D81EERWEN836XyRzCIVvBO7lHMIePYYzhESRnGM5FvbJmEyXJqzfnVp2cDGZfYtqY85V KvsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796318081; x=1796922881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WDei4hwiHpXOoybGtafWNOOiYZhSuNryGyOzyc2UiJc=; b=CFBShNgW8qW+JvR1+85bi5nOU+il9zEA6Ija8RX8pN7QAI6jNqdc4uk307wxu2KSAE /iuSA3SE5aJYg5j7V2y91zkPKtZLZy84WMu+XAbmp87dPYifQfWqnQ53YeGnkaGEmH+6 GmlmklMl/9jAh3Ro4SN19juVZPDrwzxg1A1FPM3ENCkKcVqYwFX+DHswgLrGKjoSgxAt wY2eb3eIZnolMxQK3WVGlEHWlBQ5IVm1LOc2ygtCGQI6kXejQRIy3ZQu0FyKevHsHZDz KRf42j3WJB2PhJx3ECMnWtyxO4hL3YJcXQezIbxGFJZ8dIchXMqXcYzPMEYEDPTzW+Bd 75QA== X-Gm-Message-State: APuU4Z+sTyuByoLPhnEy6zJiHo3y3kUjYcmviN7Ue6dBr4J4HkS0emfy jR0ly4wOw7Idk49NHrK4msGoWMEcghzJgzqCiVjBQcYEsLv7jJP8FUVmBdHT1u3D X-Gm-Gg: AZFdTZeOcUsNm9JUQe4qv/ogEbsw+8epIbOZRs6ps6eQtNXXUPVt2pbOGdZdwtTW0Us tTGUyTGBjRQ8sAcddvMFBCKsbQdEPdhz3i1aepQB46DoyIHg2D7HWu6z4X5jy9iGiZsoFFTodHI LqwX8uDhuq5j4OC+ZbbSMOxjiHiFlKnV06++qD+pa5KHQKbZDVy5u3F3uMGcWdLLas6hmcWHDwA zbDy9QjVtgsP+v2zzmzLaQ6A65rxAjB8sBAcOMsO1BdE5Mag7tmZdP6AsQE5T1f8F5CZwWWsSSK LztfcmytWJ6y2w42+j/BY+CYZIWfY/6mk5HNBub2m011DHrRuyKAHb8cp5uVn4w1Zb2Xr22f2AN J6SaPXlXKbuINpnYNIgB3+hvFIo4oJAdS5LU8Z6rG+zQvf+0M/FHmib58jcU9575RdRqniDx9as 7AJ+z/YdOnB7/OUtAX22g5E7qPqWDQqeqfcgiR+FD5/UB6p/IxD22W5ygSUIgL3YFIFz7SUkKlG DlivDOEQcnWOFrg0aeD/LPWTFH1G++IMaZq2ySIfzIo0msrU3NpSRpzaL+VRTCJW+qI8DyLy0sO VfhSpvRoE8FqXgJFG1FP4ob7hDehOLPpog3QKZLRXtWjo6o= X-Received: by 2002:a05:600c:638f:b0:4bb:7581:2bb9 with SMTP id 5b1f17b1804b1-4bb8892692dmr804156135e9.22.1796318081230; Thu, 03 Dec 2026 09:14:41 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb9067846esm906409615e9.4.2026.12.03.09.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:14:40 -0800 (PST) From: Anton Protopopov To: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , John Fastabend , Viktor Malik Cc: Anton Protopopov Subject: [PATCH v1 bpf-next 4/4] selftests/bpf: Test a vmlinux function ID with the BTF of a module Date: Thu, 3 Dec 2026 17:26:15 +0000 Message-ID: <20261203172617.1137735-5-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203172617.1137735-1-a.s.protopopov@gmail.com> References: <20261203172617.1137735-1-a.s.protopopov@gmail.com> X-Mailing-List: bpf@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 a bpf_fexit_test_ret_ppfile() to bpf_testmod which takes an argument. The vmlinux function of the same name takes none, so the module has a FUNC of its own for it. Check in module_fentry_shadow that the ID of the vmlinux function is refused with the BTF of the module, both at load and at the creation of a tracing multi link. Check in module_attach that libbpf takes the function of the module for "bpf_testmod:bpf_fexit_test_ret_ppfile", for both fentry and fentry.multi. Only x86_64 has tracing multi, so the multi parts are skipped elsewhere. Split module_fentry_shadow into the subtests shadow and multi for that. Signed-off-by: Anton Protopopov --- .../selftests/bpf/prog_tests/module_attach.c | 11 +++ .../bpf/prog_tests/module_fentry_shadow.c | 96 +++++++++++++++++-- .../selftests/bpf/progs/test_module_attach.c | 16 ++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 10 ++ 4 files changed, 126 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c index 92c336333fcb..c63d7f282fd8 100644 --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c @@ -179,6 +179,17 @@ void test_module_attach(void) READ_SZ, "bpf_testmod:bpf_testmod_test_read", 0); } + /* libbpf must pick the function of the module, not the one of vmlinux */ + if (test__start_subtest("handle_fentry_own_func")) + test_module_attach_prog("handle_fentry_own_func", 0, NULL, 0); + if (test__start_subtest("handle_fentry_multi_own_func")) { +#ifdef __x86_64__ + test_module_attach_prog("handle_fentry_multi_own_func", 0, NULL, 0); +#else + printf("%s:SKIP:tracing multi is supported only on x86_64\n", __func__); + test__skip(); +#endif + } if (test__start_subtest("handle_fexit")) test_module_attach_prog("handle_fexit", READ_SZ, NULL, -EIO); if (test__start_subtest("handle_fexit_ret")) diff --git a/tools/testing/selftests/bpf/prog_tests/module_fentry_shadow.c b/tools/testing/selftests/bpf/prog_tests/module_fentry_shadow.c index bea05f78de5f..0d44a6a0ace6 100644 --- a/tools/testing/selftests/bpf/prog_tests/module_fentry_shadow.c +++ b/tools/testing/selftests/bpf/prog_tests/module_fentry_shadow.c @@ -8,6 +8,7 @@ static const char *module_name = "bpf_testmod"; static const char *symbol_name = "bpf_fentry_shadow_test"; +static const char *other_name = "bpf_fexit_test_ret_ppfile"; static int get_bpf_testmod_btf_fd(void) { @@ -53,20 +54,16 @@ static int get_bpf_testmod_btf_fd(void) return -ENOENT; } -void test_module_fentry_shadow(void) +static void test_shadow(void) { struct btf *vmlinux_btf = NULL, *mod_btf = NULL; - int err, i; + int err, i, fd; + __s32 id; int btf_fd[2] = {}; int prog_fd[2] = {}; int link_fd[2] = {}; __s32 btf_id[2] = {}; - if (!env.has_testmod) { - test__skip(); - return; - } - LIBBPF_OPTS(bpf_prog_load_opts, load_opts, .expected_attach_type = BPF_TRACE_FENTRY, ); @@ -120,6 +117,25 @@ void test_module_fentry_shadow(void) err = bpf_prog_test_run_opts(prog_fd[0], NULL); ASSERT_OK(err, "running test"); + /* + * The bpf_fexit_test_ret_ppfile() of bpf_testmod has a prototype other + * than the one of vmlinux, so the vmlinux one is refused with the BTF + * of the module + */ + id = btf__find_by_name_kind_own(mod_btf, other_name, BTF_KIND_FUNC); + if (!ASSERT_GT(id, 0, "module func")) + goto out; + id = btf__find_by_name_kind(vmlinux_btf, other_name, BTF_KIND_FUNC); + if (!ASSERT_GT(id, 0, "vmlinux func")) + goto out; + load_opts.attach_btf_id = id; + load_opts.attach_btf_obj_fd = btf_fd[1]; + fd = bpf_prog_load(BPF_PROG_TYPE_TRACING, NULL, "GPL", trace_program, + ARRAY_SIZE(trace_program), &load_opts); + ASSERT_EQ(fd, -EINVAL, "vmlinux func with module btf"); + if (fd >= 0) + close(fd); + out: btf__free(vmlinux_btf); btf__free(mod_btf); @@ -132,3 +148,69 @@ void test_module_fentry_shadow(void) close(link_fd[i]); } } + +/* A multi program gets the ID with its link */ +static void test_multi(void) +{ + LIBBPF_OPTS(bpf_prog_load_opts, load_opts, + .expected_attach_type = BPF_TRACE_FENTRY_MULTI, + ); + LIBBPF_OPTS(bpf_link_create_opts, link_opts, + .tracing_multi.cnt = 1, + ); + const struct bpf_insn trace_program[] = { + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_EXIT_INSN(), + }; + struct btf *vmlinux_btf; + int btf_fd, fd, link_fd; + __u32 ids[1]; + __s32 id; + +#ifndef __x86_64__ + printf("%s:SKIP:tracing multi is supported only on x86_64\n", __func__); + test__skip(); + return; +#endif + + vmlinux_btf = btf__load_vmlinux_btf(); + if (!ASSERT_OK_PTR(vmlinux_btf, "load_vmlinux_btf")) + return; + id = btf__find_by_name_kind(vmlinux_btf, other_name, BTF_KIND_FUNC); + btf__free(vmlinux_btf); + if (!ASSERT_GT(id, 0, "vmlinux func")) + return; + + btf_fd = get_bpf_testmod_btf_fd(); + if (!ASSERT_GE(btf_fd, 0, "get_bpf_testmod_btf_fd")) + return; + + load_opts.attach_btf_obj_fd = btf_fd; + fd = bpf_prog_load(BPF_PROG_TYPE_TRACING, NULL, "GPL", trace_program, + ARRAY_SIZE(trace_program), &load_opts); + if (!ASSERT_GE(fd, 0, "load multi")) + goto out; + + ids[0] = id; + link_opts.tracing_multi.ids = ids; + link_fd = bpf_link_create(fd, 0, BPF_TRACE_FENTRY_MULTI, &link_opts); + ASSERT_EQ(link_fd, -EINVAL, "vmlinux func with module btf, multi"); + if (link_fd >= 0) + close(link_fd); + close(fd); +out: + close(btf_fd); +} + +void test_module_fentry_shadow(void) +{ + if (!env.has_testmod) { + test__skip(); + return; + } + + if (test__start_subtest("shadow")) + test_shadow(); + if (test__start_subtest("multi")) + test_multi(); +} diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c index 5609e388fb58..3f98562443ac 100644 --- a/tools/testing/selftests/bpf/progs/test_module_attach.c +++ b/tools/testing/selftests/bpf/progs/test_module_attach.c @@ -56,6 +56,22 @@ int BPF_PROG(handle_fentry, return 0; } +/* + * bpf_testmod has a function of its own with the name of a vmlinux function + * of another prototype + */ +SEC("?fentry/bpf_testmod:bpf_fexit_test_ret_ppfile") +int BPF_PROG(handle_fentry_own_func, int a) +{ + return 0; +} + +SEC("?fentry.multi/bpf_testmod:bpf_fexit_test_ret_ppfile") +int BPF_PROG(handle_fentry_multi_own_func) +{ + return 0; +} + SEC("?fentry") int BPF_PROG(handle_fentry_manual, struct file *file, struct kobject *kobj, diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c index 86d25638a727..2e72b54d2445 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c @@ -922,6 +922,16 @@ noinline int bpf_fentry_shadow_test(int a) } EXPORT_SYMBOL_GPL(bpf_fentry_shadow_test); +/* + * Has the name of a vmlinux function, but not its prototype, so it has a + * FUNC of its own + */ +noinline int bpf_fexit_test_ret_ppfile(int a) +{ + return a; +} +EXPORT_SYMBOL_GPL(bpf_fexit_test_ret_ppfile); + __bpf_hook_end(); static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = { -- 2.43.0