All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch()
@ 2026-03-22 14:44 Cheng-Yang Chou
  2026-03-22 20:12 ` Tejun Heo
  2026-03-23  7:51 ` Andrea Righi
  0 siblings, 2 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-03-22 14:44 UTC (permalink / raw)
  To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Ching-Chun Huang, Chia-Ping Tsai, yphbchou0911

Add __COMPAT_scx_bpf_sub_dispatch() to compat.bpf.h so that schedulers
using sub-sched dispatch can build and run on older kernels that lack the
kfunc. Guard the call with CONFIG_EXT_SUB_SCHED and bpf_ksym_exists(),
falling back to false when unavailable.

Update scx_qmap to use the new wrapper instead of calling
scx_bpf_sub_dispatch() directly.

Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
 tools/sched_ext/include/scx/compat.bpf.h | 13 +++++++++++++
 tools/sched_ext/scx_qmap.bpf.c           |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
index 83b3425e63b2..f24b9a1c75ad 100644
--- a/tools/sched_ext/include/scx/compat.bpf.h
+++ b/tools/sched_ext/include/scx/compat.bpf.h
@@ -108,6 +108,19 @@ static inline struct task_struct *__COMPAT_scx_bpf_dsq_peek(u64 dsq_id)
 	return p;
 }
 
+/*
+ * v7.1: scx_bpf_sub_dispatch() for sub-sched dispatch. Preserve until we drop
+ * the compat layer for older kernels that lack the kfunc.
+ */
+static inline bool __COMPAT_scx_bpf_sub_dispatch(u64 cgroup_id)
+{
+#ifdef CONFIG_EXT_SUB_SCHED
+	if (bpf_ksym_exists(scx_bpf_sub_dispatch))
+		return scx_bpf_sub_dispatch(cgroup_id);
+#endif
+	return false;
+}
+
 /**
  * __COMPAT_is_enq_cpu_selected - Test if SCX_ENQ_CPU_SELECTED is on
  * in a compatible way. We will preserve this __COMPAT helper until v6.16.
diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
index f3587fb709c9..dd44d8db0341 100644
--- a/tools/sched_ext/scx_qmap.bpf.c
+++ b/tools/sched_ext/scx_qmap.bpf.c
@@ -490,7 +490,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
 
 	for (i = 0; i < MAX_SUB_SCHEDS; i++) {
 		if (sub_sched_cgroup_ids[i] &&
-		    scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
+		    __COMPAT_scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
 			return;
 	}
 
-- 
2.48.1


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

* Re: [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch()
  2026-03-22 14:44 [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch() Cheng-Yang Chou
@ 2026-03-22 20:12 ` Tejun Heo
  2026-03-23 12:53   ` Cheng-Yang Chou
  2026-03-23  7:51 ` Andrea Righi
  1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2026-03-22 20:12 UTC (permalink / raw)
  To: Cheng-Yang Chou, sched-ext, David Vernet, Andrea Righi,
	Changwoo Min
  Cc: Ching-Chun Huang, Chia-Ping Tsai, Emil Tsalapatis, linux-kernel

Hello,

Let's not use the __COMPAT prefix. I'd like to move toward making compat
wrappers transparent so that schedulers don't need code changes for
compatibility as much as reasonably possible.

Instead, declare the kfunc with a ___compat suffix and provide a static
inline wrapper with the original name, like scx_bpf_dsq_insert() does:

  bool scx_bpf_sub_dispatch___compat(u64 cgroup_id) __ksym __weak;

  static inline bool scx_bpf_sub_dispatch(u64 cgroup_id)
  {
  	if (bpf_ksym_exists(scx_bpf_sub_dispatch___compat))
  		return scx_bpf_sub_dispatch___compat(cgroup_id);
  	return false;
  }

See tools/sched_ext/include/scx/compat.bpf.h around line 326-342 for the
full pattern.

This way schedulers just call scx_bpf_sub_dispatch() directly and the
compat layer handles everything. The no-op fallback (returning false) is
fine here since without sub-sched support the dispatch path can't do
anything useful anyway.

Thanks.

--
tejun

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

* Re: [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch()
  2026-03-22 14:44 [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch() Cheng-Yang Chou
  2026-03-22 20:12 ` Tejun Heo
@ 2026-03-23  7:51 ` Andrea Righi
  2026-03-23 12:46   ` Cheng-Yang Chou
  1 sibling, 1 reply; 5+ messages in thread
From: Andrea Righi @ 2026-03-23  7:51 UTC (permalink / raw)
  To: Cheng-Yang Chou
  Cc: sched-ext, Tejun Heo, David Vernet, Changwoo Min,
	Ching-Chun Huang, Chia-Ping Tsai

Hi Cheng-Yang,

On Sun, Mar 22, 2026 at 10:44:23PM +0800, Cheng-Yang Chou wrote:
> Add __COMPAT_scx_bpf_sub_dispatch() to compat.bpf.h so that schedulers
> using sub-sched dispatch can build and run on older kernels that lack the
> kfunc. Guard the call with CONFIG_EXT_SUB_SCHED and bpf_ksym_exists(),
> falling back to false when unavailable.
> 
> Update scx_qmap to use the new wrapper instead of calling
> scx_bpf_sub_dispatch() directly.
> 
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
>  tools/sched_ext/include/scx/compat.bpf.h | 13 +++++++++++++
>  tools/sched_ext/scx_qmap.bpf.c           |  2 +-
>  2 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
> index 83b3425e63b2..f24b9a1c75ad 100644
> --- a/tools/sched_ext/include/scx/compat.bpf.h
> +++ b/tools/sched_ext/include/scx/compat.bpf.h
> @@ -108,6 +108,19 @@ static inline struct task_struct *__COMPAT_scx_bpf_dsq_peek(u64 dsq_id)
>  	return p;
>  }
>  
> +/*
> + * v7.1: scx_bpf_sub_dispatch() for sub-sched dispatch. Preserve until we drop
> + * the compat layer for older kernels that lack the kfunc.
> + */
> +static inline bool __COMPAT_scx_bpf_sub_dispatch(u64 cgroup_id)
> +{
> +#ifdef CONFIG_EXT_SUB_SCHED
> +	if (bpf_ksym_exists(scx_bpf_sub_dispatch))
> +		return scx_bpf_sub_dispatch(cgroup_id);
> +#endif

Isn't bpf_ksym_exists() enough? The CONFIG_EXT_SUB_SCHED guard takes effect
only when we build an scx scheduler using __COMPAT_scx_bpf_sub_dispatch(),
instead we want to build the scheduler anywhere and then the BPF verifier
should evaluate the availability of scx_bpf_sub_dispatch().

Then the symbol will be resolved by this (from include/scx/common.bpf.h):

 bool scx_bpf_sub_dispatch(u64 cgroup_id) __ksym __weak;

So, IIUC the #ifdef CONFIG_EXT_SUB_SCHED guard is not really needed here.

Thanks,
-Andrea

> +	return false;
> +}
> +
>  /**
>   * __COMPAT_is_enq_cpu_selected - Test if SCX_ENQ_CPU_SELECTED is on
>   * in a compatible way. We will preserve this __COMPAT helper until v6.16.
> diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
> index f3587fb709c9..dd44d8db0341 100644
> --- a/tools/sched_ext/scx_qmap.bpf.c
> +++ b/tools/sched_ext/scx_qmap.bpf.c
> @@ -490,7 +490,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
>  
>  	for (i = 0; i < MAX_SUB_SCHEDS; i++) {
>  		if (sub_sched_cgroup_ids[i] &&
> -		    scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
> +		    __COMPAT_scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
>  			return;
>  	}
>  
> -- 
> 2.48.1
> 

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

* Re: [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch()
  2026-03-23  7:51 ` Andrea Righi
@ 2026-03-23 12:46   ` Cheng-Yang Chou
  0 siblings, 0 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-03-23 12:46 UTC (permalink / raw)
  To: Andrea Righi
  Cc: sched-ext, Tejun Heo, David Vernet, Changwoo Min,
	Ching-Chun Huang, Chia-Ping Tsai

On Mon, Mar 23, 2026 at 08:51:28AM +0100, Andrea Righi wrote:
> Hi Cheng-Yang,
> 
> On Sun, Mar 22, 2026 at 10:44:23PM +0800, Cheng-Yang Chou wrote:
> > Add __COMPAT_scx_bpf_sub_dispatch() to compat.bpf.h so that schedulers
> > using sub-sched dispatch can build and run on older kernels that lack the
> > kfunc. Guard the call with CONFIG_EXT_SUB_SCHED and bpf_ksym_exists(),
> > falling back to false when unavailable.
> > 
> > Update scx_qmap to use the new wrapper instead of calling
> > scx_bpf_sub_dispatch() directly.
> > 
> > Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> > ---
> >  tools/sched_ext/include/scx/compat.bpf.h | 13 +++++++++++++
> >  tools/sched_ext/scx_qmap.bpf.c           |  2 +-
> >  2 files changed, 14 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
> > index 83b3425e63b2..f24b9a1c75ad 100644
> > --- a/tools/sched_ext/include/scx/compat.bpf.h
> > +++ b/tools/sched_ext/include/scx/compat.bpf.h
> > @@ -108,6 +108,19 @@ static inline struct task_struct *__COMPAT_scx_bpf_dsq_peek(u64 dsq_id)
> >  	return p;
> >  }
> >  
> > +/*
> > + * v7.1: scx_bpf_sub_dispatch() for sub-sched dispatch. Preserve until we drop
> > + * the compat layer for older kernels that lack the kfunc.
> > + */
> > +static inline bool __COMPAT_scx_bpf_sub_dispatch(u64 cgroup_id)
> > +{
> > +#ifdef CONFIG_EXT_SUB_SCHED
> > +	if (bpf_ksym_exists(scx_bpf_sub_dispatch))
> > +		return scx_bpf_sub_dispatch(cgroup_id);
> > +#endif
> 
> Isn't bpf_ksym_exists() enough? The CONFIG_EXT_SUB_SCHED guard takes effect
> only when we build an scx scheduler using __COMPAT_scx_bpf_sub_dispatch(),
> instead we want to build the scheduler anywhere and then the BPF verifier
> should evaluate the availability of scx_bpf_sub_dispatch().
> 
> Then the symbol will be resolved by this (from include/scx/common.bpf.h):
> 
>  bool scx_bpf_sub_dispatch(u64 cgroup_id) __ksym __weak;
> 
> So, IIUC the #ifdef CONFIG_EXT_SUB_SCHED guard is not really needed here.

Indeed, this CONFIG_EXT_SUB_SCHED is redundant. 
Thanks for the explanation!

> 
> Thanks,
> -Andrea
> 
> > +	return false;
> > +}
> > +
> >  /**
> >   * __COMPAT_is_enq_cpu_selected - Test if SCX_ENQ_CPU_SELECTED is on
> >   * in a compatible way. We will preserve this __COMPAT helper until v6.16.
> > diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
> > index f3587fb709c9..dd44d8db0341 100644
> > --- a/tools/sched_ext/scx_qmap.bpf.c
> > +++ b/tools/sched_ext/scx_qmap.bpf.c
> > @@ -490,7 +490,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
> >  
> >  	for (i = 0; i < MAX_SUB_SCHEDS; i++) {
> >  		if (sub_sched_cgroup_ids[i] &&
> > -		    scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
> > +		    __COMPAT_scx_bpf_sub_dispatch(sub_sched_cgroup_ids[i]))
> >  			return;
> >  	}
> >  
> > -- 
> > 2.48.1
> > 

-- 
Thanks,
Cheng-Yang

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

* Re: [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch()
  2026-03-22 20:12 ` Tejun Heo
@ 2026-03-23 12:53   ` Cheng-Yang Chou
  0 siblings, 0 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-03-23 12:53 UTC (permalink / raw)
  To: Tejun Heo
  Cc: sched-ext, David Vernet, Andrea Righi, Changwoo Min,
	Ching-Chun Huang, Chia-Ping Tsai, Emil Tsalapatis, linux-kernel

On Sun, Mar 22, 2026 at 10:12:29AM -1000, Tejun Heo wrote:
> Hello,
> 
> Let's not use the __COMPAT prefix. I'd like to move toward making compat
> wrappers transparent so that schedulers don't need code changes for
> compatibility as much as reasonably possible.

I think this might be another good first issue for me to tackle next :-)
I'll keep the v2 patch focused only on the scx_bpf_sub_dispatch() change,
and then I can go on to take a look at refactoring the rest of these 
__COMPAT wrappers.

> 
> Instead, declare the kfunc with a ___compat suffix and provide a static
> inline wrapper with the original name, like scx_bpf_dsq_insert() does:
> 
>   bool scx_bpf_sub_dispatch___compat(u64 cgroup_id) __ksym __weak;
> 
>   static inline bool scx_bpf_sub_dispatch(u64 cgroup_id)
>   {
>   	if (bpf_ksym_exists(scx_bpf_sub_dispatch___compat))
>   		return scx_bpf_sub_dispatch___compat(cgroup_id);
>   	return false;
>   }
> 
> See tools/sched_ext/include/scx/compat.bpf.h around line 326-342 for the
> full pattern.
> 
> This way schedulers just call scx_bpf_sub_dispatch() directly and the
> compat layer handles everything. The no-op fallback (returning false) is
> fine here since without sub-sched support the dispatch path can't do
> anything useful anyway.

Got it.
I'll send a v2 patch implementing this approach.

-- 
Thanks,
Cheng-Yang

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

end of thread, other threads:[~2026-03-23 12:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-22 14:44 [PATCH sched_ext/for-7.1] tools/sched_ext: Add __COMPAT wrapper for scx_bpf_sub_dispatch() Cheng-Yang Chou
2026-03-22 20:12 ` Tejun Heo
2026-03-23 12:53   ` Cheng-Yang Chou
2026-03-23  7:51 ` Andrea Righi
2026-03-23 12:46   ` Cheng-Yang Chou

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.