[RFC PATCH v1 6/8] sched/deadline: Use the root domain a proxy-migrated task runs in

From: Mathieu Desnoyers

Date: Mon Nov 16 2026 - 14:27:03 EST


With proxy execution, find_proxy_task() can queue a task blocked on a
mutex on the runqueue of the mutex owner. It ignores the affinity of
the task, which does not run there. The task returns to p->wake_cpu when
it is woken.

__sched_setscheduler() checks that the affinity of a task covers its
root domain before it lets the task use SCHED_DEADLINE. It takes the
root domain from the runqueue the task is on. sched_dl_overflow() admits
the bandwidth of a task that enters the class in the root domain of
task_cpu(). Both predate proxy execution, when a task was always queued
on a CPU it can run on.

When the mutex owner is in another root domain, both use the wrong one.
sched_setattr() fails with EPERM for a deadline task that waits for the
mutex, and for a task that asks for SCHED_DEADLINE while it waits. In a
test with two cpuset partitions, both calls failed. Without proxy
execution they work.

Fix this by adding task_home_cpu(), which returns p->wake_cpu for such a
task, and by using its root domain in both places. An affinity change
or a CPU hotplug can leave p->wake_cpu stale while the task is queued
elsewhere. task_home_cpu() then returns an active CPU of the task's
mask.

Fixes: b049b81bdff6 ("sched: Handle blocked-waiter migration (and return migration)")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
---
kernel/sched/deadline.c | 2 +-
kernel/sched/sched.h | 23 +++++++++++++++++++++++
kernel/sched/syscalls.c | 9 +++++++--
3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index d14ce3615ba6..c55967135df0 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -4625,7 +4625,7 @@ int sched_dl_overflow(struct task_struct *p, int policy,
if (new_bw == p->dl.dl_bw && counted)
return 0;

- cpu = counted && p->dl.dl_bw ? p->dl.dl_bw_cpu : task_cpu(p);
+ cpu = counted && p->dl.dl_bw ? p->dl.dl_bw_cpu : task_home_cpu(p);
dl_b = dl_bw_of(cpu);

/*
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index f80ea5541b3f..7f5e45a86285 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2585,6 +2585,29 @@ static inline int task_on_rq_queued(struct task_struct *p)
return READ_ONCE(p->on_rq) == TASK_ON_RQ_QUEUED;
}

+/*
+ * Return the CPU where @p runs, or will run. Proxy execution can queue a
+ * task blocked on a mutex on the CPU of the mutex owner. The task does
+ * not run there. It returns to p->wake_cpu when it is woken. The caller
+ * holds the rq lock of @p.
+ */
+static inline int task_home_cpu(struct task_struct *p)
+{
+ int cpu = p->wake_cpu;
+
+ if (!sched_proxy_exec() || !p->is_blocked || !task_on_rq_queued(p))
+ return task_cpu(p);
+
+ /*
+ * An affinity change or a CPU hotplug can leave wake_cpu stale
+ * while the task is queued elsewhere.
+ */
+ if (cpumask_test_cpu(cpu, p->cpus_ptr) && cpu_active(cpu))
+ return cpu;
+ cpu = cpumask_any_and(p->cpus_ptr, cpu_active_mask);
+ return cpu < nr_cpu_ids ? cpu : task_cpu(p);
+}
+
static inline int task_on_rq_migrating(struct task_struct *p)
{
return READ_ONCE(p->on_rq) == TASK_ON_RQ_MIGRATING;
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index 59d78ae6b9fd..a88a6ddc500e 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -647,7 +647,12 @@ int __sched_setscheduler(struct task_struct *p,
#endif /* CONFIG_RT_GROUP_SCHED */
if (dl_bandwidth_enabled() && dl_policy(policy) &&
!(attr->sched_flags & SCHED_FLAG_SUGOV)) {
- cpumask_t *span = rq->rd->span;
+ /*
+ * Use the root domain @p runs in. Proxy execution can
+ * have queued it in the root domain of a mutex owner.
+ */
+ struct root_domain *rd = cpu_rq(task_home_cpu(p))->rd;
+ cpumask_t *span = rd->span;

/*
* Don't allow tasks with an affinity mask smaller than
@@ -655,7 +660,7 @@ int __sched_setscheduler(struct task_struct *p,
* will also fail if there's no bandwidth available.
*/
if (!cpumask_subset(span, &p->cpus_mask) ||
- rq->rd->dl_bw.bw == 0) {
+ rd->dl_bw.bw == 0) {
retval = -EPERM;
goto unlock;
}
--
2.47.3