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 2/6] sched_ext: Prefer ___v2 kfunc names in compat.bpf.h
Date: Fri, 20 Nov 2026 17:33:59 -0700 [thread overview]
Message-ID: <20261121003403.2928928-3-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20261121003403.2928928-1-ihor.solodrai@linux.dev>
compat.bpf.h declares scx_bpf_dsq_insert___v2___compat and similar
names. libbpf drops the last ___ suffix of a declaration and looks up
the rest exactly, so these resolve the kernel's ___v2 kfuncs.
The next patch makes libbpf drop the last suffix of kernel function
names too and select a variant by prototype. The ___v2___compat
names then resolve nothing, and the wrappers silently fall back to
the ___v1 kfuncs. For example, scx_bpf_dsq_move_to_local() drops
enq_flags.
Try the ___v2 names first. libbpf with that patch resolves them by
prototype. Older libbpf leaves them unresolved, because the
unsuffixed kfunc has a different prototype, and still resolves the
___v2___compat names that follow.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
tools/sched_ext/include/scx/compat.bpf.h | 39 ++++++++++++++++--------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
index 254882bd8ce6..16cf255e4221 100644
--- a/tools/sched_ext/include/scx/compat.bpf.h
+++ b/tools/sched_ext/include/scx/compat.bpf.h
@@ -29,8 +29,10 @@ struct cgroup *scx_bpf_task_cgroup___new(struct task_struct *p) __ksym __weak;
* scx_bpf_dispatch_from_dsq() and friends were added during v6.12 by
* 4c30f5ce4f7a ("sched_ext: Implement scx_bpf_dispatch[_vtime]_from_dsq()").
*
- * v7.1: scx_bpf_dsq_move_to_local___v2() to add @enq_flags.
+ * v7.1: scx_bpf_dsq_move_to_local___v2() to add @enq_flags. Older libbpf can
+ * resolve it only through the extra ___compat suffix.
*/
+bool scx_bpf_dsq_move_to_local___v2(u64 dsq_id, u64 enq_flags) __ksym __weak;
bool scx_bpf_dsq_move_to_local___v2___compat(u64 dsq_id, u64 enq_flags) __ksym __weak;
bool scx_bpf_dsq_move_to_local___v1(u64 dsq_id) __ksym __weak;
void scx_bpf_dsq_move_set_slice___new(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym __weak;
@@ -45,11 +47,13 @@ bool scx_bpf_dispatch_from_dsq___old(struct bpf_iter_scx_dsq *it__iter, struct t
bool scx_bpf_dispatch_vtime_from_dsq___old(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;
#define scx_bpf_dsq_move_to_local(dsq_id, enq_flags) \
- (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v2___compat) ? \
- scx_bpf_dsq_move_to_local___v2___compat((dsq_id), (enq_flags)) : \
- (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v1) ? \
- scx_bpf_dsq_move_to_local___v1((dsq_id)) : \
- scx_bpf_consume___old((dsq_id))))
+ (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v2) ? \
+ scx_bpf_dsq_move_to_local___v2((dsq_id), (enq_flags)) : \
+ (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v2___compat) ? \
+ scx_bpf_dsq_move_to_local___v2___compat((dsq_id), (enq_flags)) : \
+ (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v1) ? \
+ scx_bpf_dsq_move_to_local___v1((dsq_id)) : \
+ scx_bpf_consume___old((dsq_id)))))
#define scx_bpf_dsq_move_set_slice(it__iter, slice) \
(bpf_ksym_exists(scx_bpf_dsq_move_set_slice___new) ? \
@@ -430,12 +434,13 @@ scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime
/*
* v6.19: scx_bpf_dsq_insert() now returns bool instead of void. Move
* scx_bpf_dsq_insert() decl to common.bpf.h and drop compat helper after v6.22.
- * The extra ___compat suffix is to work around libbpf not ignoring __SUFFIX on
- * kernel side. The entire suffix can be dropped later.
+ * Older libbpf can resolve scx_bpf_dsq_insert___v2() only through the extra
+ * ___compat suffix.
*
* v6.13: scx_bpf_dsq_insert() renaming is also handled here. See the block on
* dispatch renaming above for more details.
*/
+bool scx_bpf_dsq_insert___v2(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak;
bool scx_bpf_dsq_insert___v2___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak;
void scx_bpf_dsq_insert___v1(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak;
void scx_bpf_dispatch___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak;
@@ -443,7 +448,9 @@ void scx_bpf_dispatch___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64
static inline bool
scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags)
{
- if (bpf_ksym_exists(scx_bpf_dsq_insert___v2___compat)) {
+ if (bpf_ksym_exists(scx_bpf_dsq_insert___v2)) {
+ return scx_bpf_dsq_insert___v2(p, dsq_id, slice, enq_flags);
+ } else if (bpf_ksym_exists(scx_bpf_dsq_insert___v2___compat)) {
return scx_bpf_dsq_insert___v2___compat(p, dsq_id, slice, enq_flags);
} else if (bpf_ksym_exists(scx_bpf_dsq_insert___v1)) {
scx_bpf_dsq_insert___v1(p, dsq_id, slice, enq_flags);
@@ -506,12 +513,12 @@ static inline bool __COMPAT_has_dsq_reenq_task(void)
/*
* v6.19: The new void variant can be called from anywhere while the older v1
- * variant can only be called from ops.cpu_release(). The double ___ prefixes on
- * the v2 variant need to be removed once libbpf is updated to ignore ___ prefix
- * on kernel side. Drop the wrapper and move the decl to common.bpf.h after
- * v6.22.
+ * variant can only be called from ops.cpu_release(). Older libbpf can resolve
+ * the v2 variant only through the extra ___compat suffix. Drop the wrapper and
+ * move the decl to common.bpf.h after v6.22.
*/
u32 scx_bpf_reenqueue_local___v1(void) __ksym __weak;
+void scx_bpf_reenqueue_local___v2(void) __ksym __weak;
void scx_bpf_reenqueue_local___v2___compat(void) __ksym __weak;
static inline bool __COMPAT_scx_bpf_reenqueue_local_from_anywhere(void)
@@ -523,6 +530,8 @@ static inline void scx_bpf_reenqueue_local(void)
{
if (__COMPAT_has_generic_reenq())
scx_bpf_dsq_reenq___compat(SCX_DSQ_LOCAL, 0);
+ else if (bpf_ksym_exists(scx_bpf_reenqueue_local___v2))
+ scx_bpf_reenqueue_local___v2();
else if (__COMPAT_scx_bpf_reenqueue_local_from_anywhere())
scx_bpf_reenqueue_local___v2___compat();
else
@@ -541,6 +550,10 @@ static inline int scx_bpf_reenqueue_local_from_anywhere(void)
scx_bpf_dsq_reenq___compat(SCX_DSQ_LOCAL, 0);
return 0;
}
+ if (bpf_ksym_exists(scx_bpf_reenqueue_local___v2)) {
+ scx_bpf_reenqueue_local___v2();
+ return 0;
+ }
if (__COMPAT_scx_bpf_reenqueue_local_from_anywhere()) {
scx_bpf_reenqueue_local___v2___compat();
return 0;
--
2.56.1
next prev 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 ` Ihor Solodrai [this message]
2026-11-21 0:34 ` [PATCH bpf-next v2 3/6] libbpf: Resolve kfunc variants by prototype Ihor Solodrai
2026-11-21 0:34 ` [PATCH bpf-next v2 4/6] selftests/bpf: Test kfunc variant selection " Ihor Solodrai
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-3-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.