sched/core: Fix context analysis errors in non-preferred CPU push
PATCH 1/1 sched/core: Fix context analysis errors in non-preferred CPU push
Nathan reported build failure with clang23 when CONFIG_PREFERRED_CPU=y.
kernel/sched/core.c:11298:3: error: releasing raw_spinlock 'rq_lockp(rq)' that was not held [-Werror,-Wthread-safety-analysis]
11298 | rq_unlock(rq, &rf);
| ^ kernel/sched/core.c:11303:1: error: raw_spinlock 'rq_lockp(__this_rq())' is not held on every path through here [-Werror,-Wthread-safety-analysis]
context_unsafe_alias(rq) was placed after rq_lock(), by which point it had already associated the lock with the original rq alias.
Move the alias barrier before rq_lock() so that the changing rq alias is accounted for before acquiring the lock.
---
base commit: tip/sched/core1fb28c664a19 ("virt/steal_governor: Enable the driver")
kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -11283,10 +11283,10 @@ static int sched_non_preferred_cpu_push_stop(void *arg)* safely bail out. */ cpu =select_fallback_rq (rq->cpu, p); +context_unsafe_alias (rq);rq_lock (rq, &rf); rq->npc_push_work_pending = false;update_rq_clock (rq); -context_unsafe_alias (rq);if (task_rq (p) == rq &&task_on_rq_queued (p)) {struct rq *dest_rq =__migrate_task (rq, &rf, p, cpu);
Signature · 1 line
2.52.0
Quoted 10 lines · Shrikanth Hegde
Nathan reported build failure with clang23 when
CONFIG_PREFERRED_CPU=y.
kernel/sched/core.c:11298:3: error: releasingraw_spinlock'rq_lockp(rq)' that was not held [-Werror,-Wthread-safety-analysis]11298 | rq_unlock(rq, &rf); | ^
kernel/sched/core.c:11303:1: error:raw_spinlock'rq_lockp(__this_rq())' is not held on every path through here [-Werror,-Wthread-safety-analysis]
context_unsafe_alias(rq)was placed afterrq_lock(), by which point it had already associated the lock with the original rq alias.
Quoted 7 lines
Move the alias barrier before
rq_lock()so that the changing rq alias is accounted for before acquiring the lock.Fixes 74699f56ebcf ("sched/core: Push current task from non preferred CPU")Reported-by Nathan Chancellor <[email protected]>Signed-off-by Shrikanth Hegde <[email protected]>
Thanks for the quick fix!
Quoted 26 lines
---
base commit: tip/sched/core1fb28c664a19("virt/steal_governor: Enable the driver")kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -11283,10 +11283,10 @@ static int sched_non_preferred_cpu_push_stop(void *arg)* safely bail out. */ cpu =select_fallback_rq (rq->cpu, p); +context_unsafe_alias (rq);rq_lock (rq, &rf); rq->npc_push_work_pending = false;update_rq_clock (rq); -context_unsafe_alias (rq);if (task_rq (p) == rq &&task_on_rq_queued (p)) {struct rq *dest_rq =__migrate_task (rq, &rf, p, cpu);Signature · 1 line
2.52.0
Signature · 2 lines
Cheers, Nathan
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 4b1f75be23c4fb0016a102d1cb108ba355c4c00d Gitweb: https://git.kernel.org/tip/4b1f75be23c4fb0016a102d1cb108ba355c4c00d Author: Shrikanth Hegde <[email protected]> AuthorDate: Tue, 29 Sep 2026 22:17:12 +05:30 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 01 Oct 2026 14:00:34 +02:00
sched/core: Fix context analysis errors in non-preferred CPU push
Nathan reported build failure with clang23 when CONFIG_PREFERRED_CPU=y.
kernel/sched/core.c:11298:3: error: releasing raw_spinlock 'rq_lockp(rq)' that was not held [-Werror,-Wthread-safety-analysis]
11298 | rq_unlock(rq, &rf);
| ^ kernel/sched/core.c:11303:1: error: raw_spinlock 'rq_lockp(__this_rq())' is not held on every path through here [-Werror,-Wthread-safety-analysis]
context_unsafe_alias(rq) was placed after rq_lock(), by which point it had already associated the lock with the original rq alias.
Move the alias barrier before rq_lock() so that the changing rq alias is accounted for before acquiring the lock.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -11283,10 +11283,10 @@ static int sched_non_preferred_cpu_push_stop(void *arg)* safely bail out. */ cpu =select_fallback_rq (rq->cpu, p); +context_unsafe_alias (rq);rq_lock (rq, &rf); rq->npc_push_work_pending = false;update_rq_clock (rq); -context_unsafe_alias (rq);if (task_rq (p) == rq &&task_on_rq_queued (p)) {struct rq *dest_rq =__migrate_task (rq, &rf, p, cpu);