]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched: Fix modifying donor->blocked on without proper locking
authorJohn Stultz <jstultz@google.com>
Tue, 24 Mar 2026 19:13:20 +0000 (19:13 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 3 Apr 2026 12:23:39 +0000 (14:23 +0200)
Introduce an action enum in find_proxy_task() which allows
us to handle work needed to be done outside the mutex.wait_lock
and task.blocked_lock guard scopes.

This ensures proper locking when we clear the donor's blocked_on
pointer in proxy_deactivate(), and the switch statement will be
useful as we add more cases to handle later in this series.

Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://patch.msgid.link/20260324191337.1841376-6-jstultz@google.com
kernel/sched/core.c

index 1913dbc68eb98360f8095c15188a678a79603d55..bf4338f71667febfd5cd2605b634aa5b5d9c6f58 100644 (file)
@@ -6568,7 +6568,7 @@ static struct task_struct *proxy_deactivate(struct rq *rq, struct task_struct *d
                 * as unblocked, as we aren't doing proxy-migrations
                 * yet (more logic will be needed then).
                 */
-               donor->blocked_on = NULL;
+               clear_task_blocked_on(donor, NULL);
        }
        return NULL;
 }
@@ -6592,6 +6592,7 @@ static struct task_struct *proxy_deactivate(struct rq *rq, struct task_struct *d
 static struct task_struct *
 find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
 {
+       enum { FOUND, DEACTIVATE_DONOR } action = FOUND;
        struct task_struct *owner = NULL;
        int this_cpu = cpu_of(rq);
        struct task_struct *p;
@@ -6625,12 +6626,14 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
 
                if (!READ_ONCE(owner->on_rq) || owner->se.sched_delayed) {
                        /* XXX Don't handle blocked owners/delayed dequeue yet */
-                       return proxy_deactivate(rq, donor);
+                       action = DEACTIVATE_DONOR;
+                       break;
                }
 
                if (task_cpu(owner) != this_cpu) {
                        /* XXX Don't handle migrations yet */
-                       return proxy_deactivate(rq, donor);
+                       action = DEACTIVATE_DONOR;
+                       break;
                }
 
                if (task_on_rq_migrating(owner)) {
@@ -6688,6 +6691,13 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
                 */
        }
 
+       /* Handle actions we need to do outside of the guard() scope */
+       switch (action) {
+       case DEACTIVATE_DONOR:
+               return proxy_deactivate(rq, donor);
+       case FOUND:
+               /* fallthrough */;
+       }
        WARN_ON_ONCE(owner && !owner->on_rq);
        return owner;
 }