sched_ext: Sync tools headers from the scx repo
Tejun Heo
reviewerPATCH 1/1 sched_ext: Sync tools headers from the scx repo
Hello,
The scx repo carries copies of the tools/sched_ext/include/scx headers which accumulated fixes and improvements that the kernel copies lack. Sync them back:
- __COMPAT_read_enum() can now recover 64-bit scx enum values on kernels whose BTF lacks BTF_KIND_ENUM64 encoding, backed by a new autogenerated enumerator ABI table.
- is_migration_disabled() no longer under-reports for the current task on v6.18+ !PREEMPT_RCU kernels where the BPF prolog stopped disabling migration.
- The scx_bpf_dsq_peek() version gate and scx_bpf_reenqueue_local_from_anywhere() which Gavin and Changwoo posted are picked up with the review feedback folded in.
- __COMPAT_scx_bpf_cpu_curr() is restored for schedulers which still run on pre-v6.18 kernels, and the rq clock helpers document their stale-read behavior on idle CPUs.
This patchset contains the following two patches:
0001-sched_ext-Sync-tools-autogen-enum-headers-from-the-s.patch 0002-sched_ext-Sync-common-and-compat-headers-from-the-sc.patch
and is also available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git scx-tools-header-sync
Based on sched_ext/for-7.3-fixes (5f01293930d1).
tools/sched_ext/include/scx/common.bpf.h | 140 ++++++++++++--- tools/sched_ext/include/scx/compat.bpf.h | 68 ++++++-- tools/sched_ext/include/scx/compat.h | 97 +++++++++++ tools/sched_ext/include/scx/enum_defs.autogen.h | 5 +- tools/sched_ext/include/scx/enums_abi.autogen.h | 223 ++++++++++++++++++++++++ 5 files changed, 501 insertions(+), 32 deletions(-)
Thanks.
Signature · 1 line
tejun
Tejun Heo
reviewerPATCH 1/2 sched_ext: Sync tools autogen enum headers from the scx repo
Regenerate enum_defs.autogen.h against the current tree, picking up the dispatch verdict enums and dropping the marker for the removed SCX_RQ_IN_BALANCE. Add enums_abi.autogen.h, a table of 64-bit scx enumerator values generated from vmlinux.h, used as the substitution source when the running kernel's BTF truncates 64-bit enum values to 32 bits.
--- .../sched_ext/include/scx/enum_defs.autogen.h | 5 +- .../sched_ext/include/scx/enums_abi.autogen.h | 223 ++++++++++++++++++ 2 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 tools/sched_ext/include/scx/enums_abi.autogen.h
tools/sched_ext/include/scx/enum_defs.autogen.h +4 -1
@@ -56,6 +56,10 @@#define HAVE_SCX_DEQ_SLEEP #define HAVE_SCX_DEQ_CORE_SCHED_EXEC #define HAVE_SCX_DEQ_SCHED_CHANGE +#define HAVE_SCX_DSP_NONE +#define HAVE_SCX_DSP_LOCAL +#define HAVE_SCX_DSP_PREV +#define HAVE_SCX_DSP_RETRY #define HAVE_SCX_DSQ_FLAG_BUILTIN #define HAVE_SCX_DSQ_FLAG_LOCAL_ON #define HAVE_SCX_DSQ_INVALID
@@ -188,7 +192,6 @@#define HAVE_SCX_RQ_SUB_IDLE_RENOTIFY #define HAVE_SCX_RQ_ROOT_IDLE_RENOTIFY #define HAVE_SCX_RQ_IN_WAKEUP -#define HAVE_SCX_RQ_IN_BALANCE #define HAVE_SCX_RQ_IN_DISPATCH #define HAVE_SCX_SCHED_PCPU_BYPASSING #define HAVE_SCX_SLICE_OOB_DUR_BITS
tools/sched_ext/include/scx/enums_abi.autogen.h new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.55.0
Tejun Heo
reviewerPATCH 2/2 sched_ext: Sync common and compat headers from the scx repo
In reply to Tejun HeoSync common.bpf.h, compat.bpf.h and compat.h with the scx repo, which accumulated the following:
- __COMPAT_read_enum() can now recover 64-bit scx enum values from kernel BTF generated without BTF_KIND_ENUM64 support (pahole < 1.24 or --skip_encoding_btf_enum64, e.g. COS/GKE kernels), substituting values from the build-time vmlinux.h cross-checked against the low 32 bits the kernel does provide.
- is_migration_disabled() no longer assumes the BPF prolog always disables migration. Since 8e4f0b1ebcf2 ("bpf: use rcu_read_lock_dont_migrate() for trampoline.c") the prolog only does so under CONFIG_PREEMPT_RCU, so the old current-task test under-reported on v6.18+ !PREEMPT_RCU kernels. A runtime probe on bpf_scx_reg() handles older kernels with backported trampoline behavior.
- __COMPAT_scx_bpf_dsq_peek() is gated behind kernel v7.1 where 2f2ea7709266 ("sched_ext: Use dsq->first_task instead of list_empty() in dispatch_enqueue() FIFO-tail") fixed the kfunc spuriously returning NULL on non-empty FIFO DSQs, and the new scx_bpf_reenqueue_local_from_anywhere() provides a callable-from-anywhere reenqueue which prefers the generic scx_bpf_dsq_reenq(). Both were first posted by Gavin Guo and Changwoo Min and are picked up here with the review feedback folded in.
- __COMPAT_scx_bpf_cpu_curr() and the scx_bpf_cpu_rq() declaration are restored. Schedulers built from these headers still run on pre-v6.18 kernels where scx_bpf_cpu_curr() does not resolve and the scx_bpf_cpu_rq() fallback still exists.
- scx_clock_task() and scx_clock_pelt() document their stale-read behavior for remote idle CPUs under NO_HZ_IDLE.
--- tools/sched_ext/include/scx/common.bpf.h | 140 +++++++++++++++++++---- tools/sched_ext/include/scx/compat.bpf.h | 68 +++++++++-- tools/sched_ext/include/scx/compat.h | 97 ++++++++++++++++ 3 files changed, 274 insertions(+), 31 deletions(-)
tools/sched_ext/include/scx/common.bpf.h +120 -20
@@ -48,6 +48,7 @@ extern int LINUX_KERNEL_VERSION __kconfig; extern const char CONFIG_CC_VERSION_TEXT[64] __kconfig __weak; extern const char CONFIG_LOCALVERSION[64] __kconfig __weak; +extern bool CONFIG_PREEMPT_RCU __kconfig __weak;/* * Earlier versions of clang/pahole lost upper 32bits in 64bit enums which can
@@ -97,6 +98,7 @@ s32 scx_bpf_pick_any_cpu_node(const cpumask_t *cpus_allowed, int node, u64 flags s32 scx_bpf_pick_any_cpu(const cpumask_t *cpus_allowed, u64 flags) __ksym; bool scx_bpf_task_running(const struct task_struct *p) __ksym; s32 scx_bpf_task_cpu(const struct task_struct *p) __ksym; +struct rq *scx_bpf_cpu_rq (s32 cpu) __ksym__weak ;struct rq *scx_bpf_locked_rq (void ) __ksym;struct task_struct *scx_bpf_cpu_curr (s32 cpu) __ksym__weak ;struct task_struct *scx_bpf_tid_to_task (u64 tid) __ksym__weak ;
@@ -527,32 +529,103 @@ static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask)return (const struct cpumask *)mask; } +/* +* True if the non-sleepable BPF trampoline prolog (__bpf_prog_enter) calls +* migrate_disable() for the current task. Recorded once by +* scx_lib_init_probe, an fentry program on bpf_scx_reg() that fires during +* the natural scheduler-attach call chain (auto-attached by scx_ops_attach!). +* +* Defaults to true (conservative). Over-reporting in is_migration_disabled() +* causes local-only dispatch, which is safe. Under-reporting can crash the +* scheduler, so we err high if the probe somehow fails to run. +*/ +bool __scx_prolog_disables_migration__weak = true; + +/* +* scx_lib_init_probe - non-sleepable prolog probe. +* +* Attached to bpf_scx_reg(), the .reg callback in bpf_sched_ext_ops +* (kernel/sched/ext.c). The kernel's struct_ops machinery invokes +* bpf_scx_reg when userspace creates the scheduler link, before +* ops.init() fires. Its address is taken in the vtable, so the symbol +* is non-inlinable and has been stable since introduction. +* +* Entering via fentry runs us through __bpf_prog_enter -- the +* non-sleepable prolog that consumers of is_migration_disabled() live +* under. +* +* Loud warning: the prolog adds at most 1 to migration_disabled. +* Reading > 1 means something upstream in the +* bpf_struct_ops_link_create -> bpf_scx_reg path disabled migration +* before the prolog ran, invalidating the probe; audit and adjust. +*/ +SEC("fentry/bpf_scx_reg") __weak +int scx_lib_init_probe (void *ctx) +{ +if (bpf_core_field_exists (((struct task_struct *)0 )->migration_disabled)) { +const struct task_struct *p =bpf_get_current_task_btf (); +unsigned int md = p->migration_disabled; + +if (md >1 ) +bpf_printk ("scx_lib_init_probe: unexpected migration_disabled=%u " +"upstream of BPF prolog; probe result unreliable" , + md); + + __scx_prolog_disables_migration = md >0 ; + } +return 0 ; +} +/* * Return true if task @p cannot migrate to a different CPU, false * otherwise. +* +* IMPORTANT: designed for NON-SLEEPABLE BPF contexts only. Sleepable +* contexts (BPF_STRUCT_OPS_SLEEPABLE, SEC("syscall"), +* SEC("fentry.s/...")) enter via __bpf_prog_enter_sleepable() or +* __bpf_prog_enter_sleepable_recur(), both of which unconditionally +* call migrate_disable(); this helper can yield a false negative for +* p == current there, which can crash the scheduler. */ static inline bool is_migration_disabled (const struct task_struct *p) {/* -* Testing p->migration_disabled in a BPF code is tricky because the -* migration is _always_ disabled while running the BPF code. -* The prolog (__bpf_prog_enter) and epilog (__bpf_prog_exit) for BPF -* code execution disable and re-enable the migration of the current -* task, respectively. So, the _current_ task of the sched_ext ops is -* always migration-disabled. Moreover, p->migration_disabled could be -* two or greater when a sched_ext ops BPF code (e.g., ops.tick) is -* executed in the middle of the other BPF code execution. +* Testing p->migration_disabled in BPF is tricky because the BPF prolog +* (__bpf_prog_enter) may call migrate_disable() for the current task, +* making migration_disabled == 1 even for tasks that are not truly +* migration-disabled. +* +* Since commit 8e4f0b1ebcf2 ("bpf: use rcu_read_lock_dont_migrate() for +* trampoline.c"), the BPF prolog calls migrate_disable() only when +* CONFIG_PREEMPT_RCU is enabled. Two fast paths cover the common cases: +* +* 1) CONFIG_PREEMPT_RCU: prolog always calls migrate_disable(), so +* migration_disabled == 1 for the current task is ambiguous. +* Disambiguate by checking p == current. +* +* 2) v6.18+ without CONFIG_PREEMPT_RCU: prolog never calls +* migrate_disable(), so migration_disabled == 1 is unambiguously +* a real migrate_disable() call. * -* Therefore, we should decide that the _current_ task is -* migration-disabled only when its migration_disabled count is greater -* than one. In other words, when p->migration_disabled == 1, there is -* an ambiguity, so we should check if @p is the current task or not. +* A slow path handles pre-v6.18 kernels without CONFIG_PREEMPT_RCU, +* where the prolog historically called migrate_disable() unconditionally +* but a cherry-picked downstream kernel may not. The runtime-probed flag +* __scx_prolog_disables_migration (set by scx_lib_init_probe) distinguishes +* the two cases without relying on the kernel version alone. */ if (bpf_core_field_exists (p->migration_disabled)) { -if (p->migration_disabled ==1 ) -return bpf_get_current_task_btf () != p; -else -return p->migration_disabled; +if (p->migration_disabled ==1 ) { +/* Fast path: prolog always disables migration */ +if (CONFIG_PREEMPT_RCU ) +return bpf_get_current_task_btf () != p; +/* Fast path: prolog never disables migration */ +if (LINUX_KERNEL_VERSION >=KERNEL_VERSION (6 ,18 ,0 )) +return true; +/* Slow path: pre-v6.18, !PREEMPT_RCU - use runtime flag */ +return __scx_prolog_disables_migration ? +bpf_get_current_task_btf () != p : true; + } +return p->migration_disabled; }return false; }
@@ -1021,7 +1094,20 @@ static inline u64 scx_clock_task(u32 cpu) {struct rq___local *rq =get_current_rq (cpu); -/* Equivalent to the kernel's rq_clock_task(). */ +/* +* Equivalent to the kernel's rq_clock_task(): wall-clock time minus +* cumulative IRQ time (CONFIG_IRQ_TIME_ACCOUNTING) and hypervisor +* steal time (CONFIG_PARAVIRT_TIME_ACCOUNTING). Without those configs, +* it equals rq->clock. +* +* Conceptually this clock advances during idle (the idle task counts +* as a running task), but rq->clock_task is only updated on scheduling +* events. With NO_HZ_IDLE (the default), the periodic tick is stopped +* on idle CPUs, so rq->clock_task is not refreshed while a CPU is +* idle. Reading this clock for a remote idle CPU from a BPF timer +* callback returns the value from when the CPU last went idle, making +* the delta over an idle interval effectively zero. +*/ return rq ? rq->clock_task :0 ; }
@@ -1032,9 +1118,23 @@ static inline u64 scx_clock_pelt(u32 cpu)/* * Equivalent to the kernel's rq_clock_pelt(): subtracts * lost_idle_time from clock_pelt to absorb the jump that occurs -* when clock_pelt resyncs with clock_task at idle exit. The result -* is a continuous, capacity-invariant clock safe for both task -* execution time stamping and cross-idle measurements. +* when clock_pelt resyncs with clock_task at idle exit. The intent +* is a continuous, capacity- and frequency-invariant clock that is +* frozen during idle, IRQ, and hypervisor steal. +* +* However, like scx_clock_task(), this clock has a stale-read issue +* for remote idle CPUs with NO_HZ_IDLE (the default). clock_pelt +* itself advances at wall-clock rate (hardware-clock based), but +* lost_idle_time is only updated via update_rq_clock_pelt(), which +* requires update_rq_clock() to be called. With NO_HZ_IDLE, the +* periodic tick is stopped on idle CPUs, so lost_idle_time is not +* refreshed during idle. Reading this clock for a remote idle CPU +* from a BPF timer callback therefore returns a value that drifts +* at wall-clock rate -- the same stale behaviour as scx_clock_task(). +* +* Without NO_HZ_IDLE, periodic ticks keep lost_idle_time nearly in +* sync (stale by at most one tick period, ~1 ms), so the result is +* accurate. */ return rq ? (rq->clock_pelt - rq->lost_idle_time) :0 ; }
tools/sched_ext/include/scx/compat.bpf.h +57 -11
105 lines not on this page · raw message
tools/sched_ext/include/scx/compat.h +97 -0
118 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 2/2] sched_ext: Sync common and compat headers from the scx repo
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The default value of `__scx_prolog_disables_migration` contradicts its safety documentation and…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The default value of __scx_prolog_disables_migration contradicts its safety documentation and causes dangerous under-reporting.
- [High] Missing ksym guard for scx_bpf_cpu_rq causes BPF program load failure on newer kernels.
--
--- Patch [2]: [PATCH 2/2] sched_ext: Sync common and compat headers from the scx repo --- commit d5556fe1c132d0cef0267d7ea8593fa9b725e9e6
Author: Tejun Heo <[email protected]>
sched_ext: Sync common and compat headers from the scx repo
Sync common.bpf.h, compat.bpf.h and compat.h with the scx repo. This includes updates to 64-bit enum recovery, is_migration_disabled() logic, and backwards compatibility for scx_bpf_cpu_curr and scx_bpf_cpu_rq.
Quoted 4 lines
tools/sched_ext/include/scx/common.bpf.h +0
-0
[ ... ]
Quoted 5 lines
tools/sched_ext/include/scx/common.bpf.h +1
-0@@ -527,32 +529,103 @@ static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask)return (const struct cpumask *)mask; } +/*
tools/sched_ext/include/scx/common.bpf.h static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask) · line 542
Quoted 10 lines
tools/sched_ext/include/scx/common.bpf.h +10
-0+* True if the non-sleepable BPF trampoline prolog (__bpf_prog_enter) calls +* migrate_disable() for the current task. Recorded once by +* scx_lib_init_probe, an fentry program on bpf_scx_reg() that fires during +* the natural scheduler-attach call chain (auto-attached by scx_ops_attach!). +* +* Defaults to true (conservative). Over-reporting in is_migration_disabled() +* causes local-only dispatch, which is safe. Under-reporting can crash the +* scheduler, so we err high if the probe somehow fails to run. +*/ +bool __scx_prolog_disables_migration__weak = true;
[Severity: High]
Does this default value actually under-report if the probe fails to run?
The documentation indicates that the fallback should err high (over-report) to avoid crashing the scheduler. However, looking at the slow path in is_migration_disabled() below, when __scx_prolog_disables_migration is true, the macro evaluates bpf_get_current_task_btf() != p. This causes it to return false for the current task, which means it incorrectly assumes migration is not disabled (under-reporting).
Should the default value of __scx_prolog_disables_migration be false instead, so that it falls back to returning true?
Quoted 3 lines
tools/sched_ext/include/scx/common.bpf.h +3
-0+ +/* +* scx_lib_init_probe - non-sleepable prolog probe.
[ ... ]
Quoted 2 lines
static inline bool
is_migration_disabled(const struct task_struct *p){
[ ... ]
Quoted 20 lines
tools/sched_ext/include/scx/common.bpf.h +13
-4+if (bpf_core_field_exists (p->migration_disabled)) { -if (p->migration_disabled ==1 ) -return bpf_get_current_task_btf () != p; -else -return p->migration_disabled; +if (p->migration_disabled ==1 ) { +/* Fast path: prolog always disables migration */ +if (CONFIG_PREEMPT_RCU ) +return bpf_get_current_task_btf () != p; +/* Fast path: prolog never disables migration */ +if (LINUX_KERNEL_VERSION >=KERNEL_VERSION (6 ,18 ,0 )) +return true; +/* Slow path: pre-v6.18, !PREEMPT_RCU - use runtime flag */ +return __scx_prolog_disables_migration ? +bpf_get_current_task_btf () != p : true; + } +return p->migration_disabled; }return false; }
[ ... ]
Quoted 4 lines
tools/sched_ext/include/scx/compat.bpf.h +0
-0
[ ... ]
Quoted 10 lines
tools/sched_ext/include/scx/compat.bpf.h +6
-0@@ -238,6 +243,26 @@ static inline bool __COMPAT_is_enq_cpu_selected(u64 enq_flags) scx_bpf_pick_any_cpu_node(cpus_allowed, node, flags) : \ scx_bpf_pick_any_cpu(cpus_allowed, flags)) +/* +* v6.18: Add a helper to retrieve the current task running on a CPU. +* +* The kernel tree dropped this helper and scx_bpf_cpu_rq(), but schedulers in +* this tree still support pre-v6.18 kernels where scx_bpf_cpu_curr() doesn't +* resolve and the scx_bpf_cpu_rq() fallback still exists. Keep it until
tools/sched_ext/include/scx/compat.bpf.h static inline bool __COMPAT_is_enq_cpu_selected(u64 enq_flags) · line 261
Quoted 10 lines
tools/sched_ext/include/scx/compat.bpf.h +10
-0+* pre-v6.18 kernels fall out of the support window. +*/ +static inline struct task_struct *__COMPAT_scx_bpf_cpu_curr (int cpu) +{ +struct rq *rq; + +if (bpf_ksym_exists (scx_bpf_cpu_curr)) +return scx_bpf_cpu_curr (cpu); + + rq =scx_bpf_cpu_rq (cpu);
[Severity: High]
Will this unconditionally call scx_bpf_cpu_rq() on newer kernels?
If both scx_bpf_cpu_curr and scx_bpf_cpu_rq have been dropped from the kernel tree, on modern kernels bpf_ksym_exists(scx_bpf_cpu_curr) evaluates to false and the fallback path is taken.
Because the call to scx_bpf_cpu_rq() is not guarded by its own bpf_ksym_exists() check, won't libbpf poison the missing call and cause the BPF verifier to reject the program on newer kernels? Should we guard the fallback call as well?
Quoted 3 lines
tools/sched_ext/include/scx/compat.bpf.h +3
-0+ +return rq ? rq->curr :NULL ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Tejun Heo
reviewerRe: [PATCH 2/2] sched_ext: Sync common and compat headers from the scx repo
Hello,
Quoted 22 lines · On Tue, Aug 18, 2026 at 09:07:32PM +0000, [email protected] wrote:
tools/sched_ext/include/scx/common.bpf.h static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask) · line 542
Quoted 11 lines
tools/sched_ext/include/scx/common.bpf.h +11
-0+/* +* True if the non-sleepable BPF trampoline prolog (__bpf_prog_enter) calls +* migrate_disable() for the current task. Recorded once by +* scx_lib_init_probe, an fentry program on bpf_scx_reg() that fires during +* the natural scheduler-attach call chain (auto-attached by scx_ops_attach!). +* +* Defaults to true (conservative). Over-reporting in is_migration_disabled() +* causes local-only dispatch, which is safe. Under-reporting can crash the +* scheduler, so we err high if the probe somehow fails to run. +*/ +bool __scx_prolog_disables_migration__weak = true;[Severity: High]
Does this default value actually under-report if the probe fails to run?The documentation indicates that the fallback should err high (over-report) to avoid crashing the scheduler. However, looking at the slow path in
is_migration_disabled()below, when__scx_prolog_disables_migrationis true, the macro evaluatesbpf_get_current_task_btf()!= p. This causes it to return false for the current task, which means it incorrectly assumes migration is not disabled (under-reporting).
Quoted 2 lines
Should the default value of
__scx_prolog_disables_migrationbe false instead, so that it falls back to returning true?
The comment and the default do disagree. true matches the stock pre-v6.18 prolog behavior, so a failed probe still yields correct results on stock kernels. However, if the probe fails on a kernel that cherry-picked 8e4f0b1ebcf2 ("bpf: use rcu_read_lock_dont_migrate() for trampoline.c"), is_migration_disabled(current) under-reports, which is the direction the comment claims to avoid. Erring high would be defaulting to false.
Changwoo, this code is synced from the scx repo. Can you update the scx side, either flipping the default or fixing the comment? I'll re-sync afterwards.
Quoted 12 lines
tools/sched_ext/include/scx/compat.bpf.h static inline bool __COMPAT_is_enq_cpu_selected(u64 enq_flags) · line 261
Quoted 8 lines
tools/sched_ext/include/scx/compat.bpf.h +8
-0+static inline struct task_struct *__COMPAT_scx_bpf_cpu_curr (int cpu) +{ +struct rq *rq; + +if (bpf_ksym_exists (scx_bpf_cpu_curr)) +return scx_bpf_cpu_curr (cpu); + + rq =scx_bpf_cpu_rq (cpu);[Severity: High]
Will this unconditionally callscx_bpf_cpu_rq()on newer kernels?
Quoted 8 lines
If both
scx_bpf_cpu_currandscx_bpf_cpu_rqhave been dropped from the kernel tree, on modern kernelsbpf_ksym_exists(scx_bpf_cpu_curr)evaluates to false and the fallback path is taken.Because the call to
scx_bpf_cpu_rq()is not guarded by its ownbpf_ksym_exists()check, won't libbpf poison the missing call and cause the BPF verifier to reject the program on newer kernels? Should we guard the fallback call as well?
scx_bpf_cpu_curr() wasn't dropped. It was added in v6.18 and only scx_bpf_cpu_rq() is being removed, so there is no kernel where both are missing. On kernels without scx_bpf_cpu_rq(), bpf_ksym_exists(scx_bpf_cpu_curr) is constant true, the fallback is dead code, and the poisoned call to the missing __weak ksym never reaches the verifier.
Thanks.
--
tejun
Applied to sched_ext/for-7.3-fixes.
Thanks.
Signature · 1 line
tejun
Changwoo Min
reviewerRe: [PATCH 2/2] sched_ext: Sync common and compat headers from the scx repo
In reply to Tejun HeoHello,
Quoted 30 lines · Tejun Heo
Quoted 21 lines
tools/sched_ext/include/scx/common.bpf.h static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask) · line 542
Quoted 11 lines
tools/sched_ext/include/scx/common.bpf.h +11
-0+/* +* True if the non-sleepable BPF trampoline prolog (__bpf_prog_enter) calls +* migrate_disable() for the current task. Recorded once by +* scx_lib_init_probe, an fentry program on bpf_scx_reg() that fires during +* the natural scheduler-attach call chain (auto-attached by scx_ops_attach!). +* +* Defaults to true (conservative). Over-reporting in is_migration_disabled() +* causes local-only dispatch, which is safe. Under-reporting can crash the +* scheduler, so we err high if the probe somehow fails to run. +*/ +bool __scx_prolog_disables_migration__weak = true;[Severity: High]
Does this default value actually under-report if the probe fails to run?The documentation indicates that the fallback should err high (over-report) to avoid crashing the scheduler. However, looking at the slow path in
is_migration_disabled()below, when__scx_prolog_disables_migrationis true, the macro evaluatesbpf_get_current_task_btf()!= p. This causes it to return false for the current task, which means it incorrectly assumes migration is not disabled (under-reporting).Quoted 2 lines
Should the default value of
__scx_prolog_disables_migrationbe false instead, so that it falls back to returning true?The comment and the default do disagree. true matches the stock pre-v6.18 prolog behavior, so a failed probe still yields correct results on stock kernels. However, if the probe fails on a kernel that cherry-picked
8e4f0b1ebcf2("bpf: usercu_read_lock_dont_migrate()fortrampoline.c"),is_migration_disabled(current)under-reports, which is the direction the comment claims to avoid. Erring high would be defaulting to false.
Quoted 3 lines
Changwoo, this code is synced from the scx repo. Can you update the scx side, either flipping the default or fixing the comment? I'll re-sync afterwards.
I submitted a PR to fix this: https://github.com/sched-ext/scx/pull/3766
Regards,
Changwoo Min