All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Jiri Olsa <jolsa@kernel.org>, Song Liu <song@kernel.org>,
	Tejun Heo <tj@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	sched-ext@lists.linux.dev
Subject: [PATCH bpf-next v2 4/6] selftests/bpf: Test kfunc variant selection by prototype
Date: Fri, 20 Nov 2026 17:34:01 -0700	[thread overview]
Message-ID: <20261121003403.2928928-5-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20261121003403.2928928-1-ihor.solodrai@linux.dev>

Register two kfunc variants in bpf_testmod that differ only in a struct
pointee:

  int bpf_kfunc_variant(struct task_struct *p);
  int bpf_kfunc_variant___v2(struct file *p);

Check that a declaration of each resolves to it, and that a __weak
declaration with struct inode * stays unresolved.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 .../selftests/bpf/prog_tests/verifier.c       |  3 ++
 .../selftests/bpf/progs/kfunc_variants.c      | 32 +++++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    | 12 +++++++
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |  3 ++
 4 files changed, 50 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/kfunc_variants.c

diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 57ff2578a991..3684670791a8 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -8,6 +8,7 @@
 #include "cap_helpers.h"
 #include "sysctl_helpers.h"
 #include "cb_refs.skel.h"
+#include "kfunc_variants.skel.h"
 #include "verifier_aggregate_arg.skel.h"
 #include "verifier_aggregate_ret.skel.h"
 #include "verifier_alu_range.skel.h"
@@ -220,6 +221,8 @@ void test_arena_kfunc_jit(void)               { RUN_TESTS(arena_kfunc_jit); }
 
 void test_cb_refs(void)                       { RUN_TESTS(cb_refs); }
 
+void test_kfunc_variants(void)                { RUN_TESTS(kfunc_variants); }
+
 void test_verifier_aggregate_arg(void)        { RUN_TESTS(verifier_aggregate_arg); }
 void test_verifier_aggregate_ret(void)        { RUN_TESTS(verifier_aggregate_ret); }
 void test_verifier_alu_range(void)            { RUN(verifier_alu_range); }
diff --git a/tools/testing/selftests/bpf/progs/kfunc_variants.c b/tools/testing/selftests/bpf/progs/kfunc_variants.c
new file mode 100644
index 000000000000..a9c393ea9d82
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/kfunc_variants.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+#include "../test_kmods/bpf_testmod_kfunc.h"
+
+extern int bpf_kfunc_variant___none(struct inode *p) __weak __ksym;
+
+char _license[] SEC("license") = "GPL";
+
+SEC("syscall")
+__retval(1)
+int unsuffixed_name(void *ctx)
+{
+	return bpf_kfunc_variant(NULL);
+}
+
+SEC("syscall")
+__retval(2)
+int kernel_variant(void *ctx)
+{
+	return bpf_kfunc_variant___v2(NULL);
+}
+
+SEC("syscall")
+__retval(0)
+int no_match(void *ctx)
+{
+	return bpf_ksym_exists(bpf_kfunc_variant___none);
+}
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 1fbc0061cc24..764877cdce6e 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -1928,6 +1928,16 @@ __bpf_kfunc void bpf_kfunc_trigger_ctx_check(void)
 	irq_work_queue(&ctx_check_irq);
 }
 
+__bpf_kfunc int bpf_kfunc_variant(struct task_struct *p__nullable)
+{
+	return 1;
+}
+
+__bpf_kfunc int bpf_kfunc_variant___v2(struct file *p__nullable)
+{
+	return 2;
+}
+
 BTF_KFUNCS_START(bpf_testmod_check_kfunc_ids)
 BTF_ID_FLAGS(func, bpf_testmod_test_mod_kfunc, KF_SPINLOCK_SAFE)
 BTF_ID_FLAGS(func, bpf_kfunc_call_test1)
@@ -2019,6 +2029,8 @@ BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy_impl)
 BTF_ID_FLAGS(func, bpf_kfunc_trigger_ctx_check)
+BTF_ID_FLAGS(func, bpf_kfunc_variant)
+BTF_ID_FLAGS(func, bpf_kfunc_variant___v2)
 BTF_KFUNCS_END(bpf_testmod_check_kfunc_ids)
 
 static int bpf_testmod_ops_init(struct btf *btf)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
index 0a7df1798603..ce579eede88d 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
@@ -381,4 +381,7 @@ void bpf_testmod_test_hardirq_fn(void);
 void bpf_testmod_test_softirq_fn(void);
 void bpf_kfunc_trigger_ctx_check(void) __ksym;
 
+int bpf_kfunc_variant(struct task_struct *p__nullable) __ksym;
+int bpf_kfunc_variant___v2(struct file *p__nullable) __ksym;
+
 #endif /* _BPF_TESTMOD_KFUNC_H */
-- 
2.56.1


  parent reply	other threads:[~2026-11-21  0:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  0:33 [PATCH bpf-next v2 0/6] libbpf: Support kernel-side kfunc variants Ihor Solodrai
2026-11-21  0:33 ` [PATCH bpf-next v2 1/6] libbpf: Separate interfaces shared with in-tree tools Ihor Solodrai
2026-11-21  0:33 ` [PATCH bpf-next v2 2/6] sched_ext: Prefer ___v2 kfunc names in compat.bpf.h Ihor Solodrai
2026-11-21  0:34 ` [PATCH bpf-next v2 3/6] libbpf: Resolve kfunc variants by prototype Ihor Solodrai
2026-11-21  0:34 ` Ihor Solodrai [this message]
2026-11-21  0:34 ` [PATCH bpf-next v2 5/6] resolve_btfids: Reject ambiguous kfunc variants Ihor Solodrai
2026-11-21  0:34 ` [PATCH bpf-next v2 6/6] docs/bpf: Describe how to change a kfunc's prototype Ihor Solodrai

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=20261121003403.2928928-5-ihor.solodrai@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alan.maguire@oracle.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=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=sched-ext@lists.linux.dev \
    --cc=song@kernel.org \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.