Skip to content

Commit 0c4a59d

Browse files
multics69htejun
authored andcommitted
sched_ext: Fix is_bpf_migration_disabled() false negative on non-PREEMPT_RCU
Since commit 8e4f0b1 ("bpf: use rcu_read_lock_dont_migrate() for trampoline.c"), the BPF prolog (__bpf_prog_enter) calls migrate_disable() only when CONFIG_PREEMPT_RCU is enabled, via rcu_read_lock_dont_migrate(). Without CONFIG_PREEMPT_RCU, the prolog never touches migration_disabled, so migration_disabled == 1 always means the task is truly migration-disabled regardless of whether it is the current task. The old unconditional p == current check was a false negative in this case, potentially allowing a migration-disabled task to be dispatched to a remote CPU and triggering scx_error in task_can_run_on_remote_rq(). Only apply the p == current disambiguation when CONFIG_PREEMPT_RCU is enabled, where the ambiguity with the BPF prolog still exists. Fixes: 8e4f0b1 ("bpf: use rcu_read_lock_dont_migrate() for trampoline.c") Cc: stable@vger.kernel.org # v6.18+ Link: https://lore.kernel.org/lkml/20250821090609.42508-8-dongml2@chinatelecom.cn/ Signed-off-by: Changwoo Min <changwoo@igalia.com> Reviewed-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 090d34f commit 0c4a59d

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

kernel/sched/ext_idle.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -860,25 +860,32 @@ static bool check_builtin_idle_enabled(struct scx_sched *sch)
860860
* code.
861861
*
862862
* We can't simply check whether @p->migration_disabled is set in a
863-
* sched_ext callback, because migration is always disabled for the current
864-
* task while running BPF code.
863+
* sched_ext callback, because the BPF prolog (__bpf_prog_enter) may disable
864+
* migration for the current task while running BPF code.
865865
*
866-
* The prolog (__bpf_prog_enter) and epilog (__bpf_prog_exit) respectively
867-
* disable and re-enable migration. For this reason, the current task
868-
* inside a sched_ext callback is always a migration-disabled task.
866+
* Since the BPF prolog calls migrate_disable() only when CONFIG_PREEMPT_RCU
867+
* is enabled (via rcu_read_lock_dont_migrate()), migration_disabled == 1 for
868+
* the current task is ambiguous only in that case: it could be from the BPF
869+
* prolog rather than a real migrate_disable() call.
869870
*
870-
* Therefore, when @p->migration_disabled == 1, check whether @p is the
871-
* current task or not: if it is, then migration was not disabled before
872-
* entering the callback, otherwise migration was disabled.
871+
* Without CONFIG_PREEMPT_RCU, the BPF prolog never calls migrate_disable(),
872+
* so migration_disabled == 1 always means the task is truly
873+
* migration-disabled.
874+
*
875+
* Therefore, when migration_disabled == 1 and CONFIG_PREEMPT_RCU is enabled,
876+
* check whether @p is the current task or not: if it is, then migration was
877+
* not disabled before entering the callback, otherwise migration was disabled.
873878
*
874879
* Returns true if @p is migration-disabled, false otherwise.
875880
*/
876881
static bool is_bpf_migration_disabled(const struct task_struct *p)
877882
{
878-
if (p->migration_disabled == 1)
879-
return p != current;
880-
else
881-
return p->migration_disabled;
883+
if (p->migration_disabled == 1) {
884+
if (IS_ENABLED(CONFIG_PREEMPT_RCU))
885+
return p != current;
886+
return true;
887+
}
888+
return p->migration_disabled;
882889
}
883890

884891
static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,

0 commit comments

Comments
 (0)