mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: jstultz@google.com, peterz@infradead.org, mingo@redhat.com,
	juri.lelli@redhat.com, vincent.guittot@linaro.org
Cc: linux-kernel@vger.kernel.org,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	kprateek.nayak@amd.com, connoro@google.com, arighi@nvidia.com,
	akpm@linux-foundation.org, shuah@kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [RFC PATCH v1 6/8] sched/deadline: Use the root domain a proxy-migrated task runs in
Date: Mon, 16 Nov 2026 14:26:36 -0500	[thread overview]
Message-ID: <20261116192638.233125-7-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <20261116192638.233125-1-mathieu.desnoyers@efficios.com>

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@efficios.com>
---
 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


  parent reply	other threads:[~2026-11-16 19:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 19:26 [RFC PATCH v1 0/8] sched/proxy: fixes for proxy execution, with selftests Mathieu Desnoyers
2026-11-16 19:26 ` [RFC PATCH v1 1/8] sched/proxy: Reschedule when a blocked task is woken under a proxy Mathieu Desnoyers
2026-11-16 21:12   ` John Stultz
2026-11-16 19:26 ` [RFC PATCH v1 2/8] sched/proxy: Wake blocked RT and deadline tasks through the full path Mathieu Desnoyers
2026-11-16 21:35   ` John Stultz
2026-11-16 19:26 ` [RFC PATCH v1 3/8] sched/proxy: Stop the chain walk when the blocked_on chain is a cycle Mathieu Desnoyers
2026-11-16 20:36   ` John Stultz
2026-11-16 19:26 ` [RFC PATCH v1 4/8] sched/proxy: Tell the class about a proxy migration Mathieu Desnoyers
2026-11-16 20:42   ` John Stultz
2026-11-16 19:26 ` [RFC PATCH v1 5/8] sched/proxy: Clear blocked_donor when the donor stops donating Mathieu Desnoyers
2026-11-16 19:26 ` Mathieu Desnoyers [this message]
2026-11-16 19:26 ` [RFC PATCH v1 7/8] lib: Add test_proxy_exec, kernel mutexes that user space can hold Mathieu Desnoyers
2026-11-16 19:26 ` [RFC PATCH v1 8/8] selftests/sched: Add tests of proxy execution Mathieu Desnoyers
2026-11-16 20:27 ` [RFC PATCH v1 0/8] sched/proxy: fixes for proxy execution, with selftests John Stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116192638.233125-7-mathieu.desnoyers@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=akpm@linux-foundation.org \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=connoro@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®