mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 sched_ext/for-6.19] sched_ext/tools: Add compat layer for kfuncs using struct *_args
@ 2025-10-23  8:01 Andrea Righi
  2025-10-23 14:03 ` Emil Tsalapatis
  2025-10-24  1:12 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Andrea Righi @ 2025-10-23  8:01 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min
  Cc: Emil Tsalapatis, sched-ext, linux-kernel

Commit c0d630ba347c7 ("sched_ext: Wrap kfunc args in struct to prepare
for aux__prog") introduced new kfuncs that take their scalar arguments
packed into dedicated *_args structs.

However, these new kfuncs need to coexist with the previous scalar
variants, which causes build failures in sched_ext schedulers when
building against older kernels.

To address this, mirror the struct definitions adding a __COMPAT prefix,
ensuring schedulers can still build also on old kernels that don't have
the BTF definitions for these structs.

Moreover, add a __COMPAT_bpf_ksym_exists() helper, which extends
bpf_ksym_exists() to handle static inline kfunc wrappers and fall back
to the *___compat() variants, where available.

Fixes: c0d630ba347c7 ("sched_ext: Wrap kfunc args in struct to prepare for aux__prog")
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
Changes v2 -> v3:
 - Drop the ___v2() suffix from the new kfuncs (Tejun)
 - Add __COMPAT_bpf_ksym_exists() to handle kfunc detection with static
   inline wrappers
 - Link to v2: https://lore.kernel.org/all/20251022153610.20111-1-arighi@nvidia.com/

ChangeLog v1 -> v2:
 - Introduce __COMPAT_* struct to fix build error with v6.19 (thanks Emil)

 tools/sched_ext/include/scx/common.bpf.h |  3 --
 tools/sched_ext/include/scx/compat.bpf.h | 36 +++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
index e65b1eb668ea5..64e5411d04c04 100644
--- a/tools/sched_ext/include/scx/common.bpf.h
+++ b/tools/sched_ext/include/scx/common.bpf.h
@@ -60,9 +60,6 @@ static inline void ___vmlinux_h_sanity_check___(void)
 
 s32 scx_bpf_create_dsq(u64 dsq_id, s32 node) __ksym;
 s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, bool *is_idle) __ksym;
-s32 __scx_bpf_select_cpu_and(struct task_struct *p, const struct cpumask *cpus_allowed,
-			     struct scx_bpf_select_cpu_and_args *args) __ksym __weak;
-bool __scx_bpf_dsq_insert_vtime(struct task_struct *p, struct scx_bpf_dsq_insert_vtime_args *args) __ksym __weak;
 u32 scx_bpf_dispatch_nr_slots(void) __ksym;
 void scx_bpf_dispatch_cancel(void) __ksym;
 bool scx_bpf_dsq_move_to_local(u64 dsq_id) __ksym __weak;
diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
index a023b71991a6a..d534cacb94066 100644
--- a/tools/sched_ext/include/scx/compat.bpf.h
+++ b/tools/sched_ext/include/scx/compat.bpf.h
@@ -15,6 +15,13 @@
 	__ret;									\
 })
 
+/*
+ * Extended version of bpf_ksym_exists() that handles static inline kfunc
+ * wrappers, falling back to the *___compat versions.
+ */
+#define __COMPAT_bpf_ksym_exists(sym) \
+	(__builtin_constant_p(!!sym) ? bpf_ksym_exists(sym##___compat) : !!sym)
+
 /*
  * v6.15: 950ad93df2fc ("bpf: add kfunc for populating cpumask bits")
  *
@@ -161,6 +168,27 @@ static inline struct task_struct *__COMPAT_scx_bpf_cpu_curr(int cpu)
 	return rq ? rq->curr : NULL;
 }
 
+/*
+ * v6.19: Mirror the following _args structs, to prevent build errors in
+ * kernels that don't have these structs defined yet.
+ *
+ * The kernel will carry these __COMPAT_* structs until v6.23 (see below).
+ */
+#define scx_bpf_select_cpu_and_args __COMPAT_scx_bpf_select_cpu_and_args
+struct __COMPAT_scx_bpf_select_cpu_and_args {
+	s32 prev_cpu;
+	u64 wake_flags;
+	u64 flags;
+};
+
+#define scx_bpf_dsq_insert_vtime_args __COMPAT_scx_bpf_dsq_insert_vtime_args
+struct __COMPAT_scx_bpf_dsq_insert_vtime_args {
+	u64 dsq_id;
+	u64 slice;
+	u64 vtime;
+	u64 enq_flags;
+};
+
 /*
  * v6.19: To work around BPF maximum parameter limit, the following kfuncs are
  * replaced with variants that pack scalar arguments in a struct. Wrappers are
@@ -170,9 +198,15 @@ static inline struct task_struct *__COMPAT_scx_bpf_cpu_curr(int cpu)
  * compatibility. After v6.23 release, remove the compat handling and move the
  * wrappers to common.bpf.h.
  */
+s32 __scx_bpf_select_cpu_and(struct task_struct *p, const struct cpumask *cpus_allowed,
+			     struct scx_bpf_select_cpu_and_args *args) __ksym __weak;
 s32 scx_bpf_select_cpu_and___compat(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
 				    const struct cpumask *cpus_allowed, u64 flags) __ksym __weak;
-void scx_bpf_dsq_insert_vtime___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak;
+
+bool __scx_bpf_dsq_insert_vtime(struct task_struct *p,
+				struct scx_bpf_dsq_insert_vtime_args *args) __ksym __weak;
+void scx_bpf_dsq_insert_vtime___compat(struct task_struct *p,
+				u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak;
 
 /**
  * scx_bpf_select_cpu_and - Pick an idle CPU usable by task @p
-- 
2.51.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-24  1:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-23  8:01 [PATCH v3 sched_ext/for-6.19] sched_ext/tools: Add compat layer for kfuncs using struct *_args Andrea Righi
2025-10-23 14:03 ` Emil Tsalapatis
2025-10-24  1:12 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®