From: "tip-bot2 for Juri Lelli" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Weiheng Qiu <weihengqiuu@gmail.com>,
Juri Lelli <juri.lelli@redhat.com>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/urgent] sched/deadline: Fix stale root domain in cpuset bandwidth transfer
Date: Tue, 03 Nov 2026 13:26:03 -0000 [thread overview]
Message-ID: <179371236348.1009794.4797641388786379495.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20261103-b4-sched-dl-bw-fixes-v1-1-dd761fe005b4@redhat.com>
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: b4a61fdc19c5c40f295b28ad318a3c4827d7d289
Gitweb: https://git.kernel.org/tip/b4a61fdc19c5c40f295b28ad318a3c4827d7d289
Author: Juri Lelli <juri.lelli@redhat.com>
AuthorDate: Tue, 03 Nov 2026 12:26:29 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Nov 2026 14:18:04 +01:00
sched/deadline: Fix stale root domain in cpuset bandwidth transfer
dl_task_needs_bw_move() and set_cpus_allowed_dl() use task_rq(p)->rd
to determine a task's current root domain. For a sleeping task, this
is stale: it points to the rq of the CPU the task last ran on, which
may belong to a different root domain after a cpuset move.
This causes incorrect bandwidth accounting when a sleeping DL task is
moved between exclusive cpuset partitions and back:
1. Move root->partition: task_rq(p)->rd = root, destination in
partition -> different -> bandwidth transferred correctly.
2. Move partition->root: task_rq(p)->rd is still root (task never
ran) -> looks like same domain -> no transfer. Partition keeps
stale bandwidth, root domain is short.
The root domain then over-admits, and when the task exits total_bw
underflows.
Introduce dl_task_root_domain_cpu() helper that uses the task's
cpus_mask (which still reflects the old/source cpuset at call time)
to find the root domain where the bandwidth is actually accounted,
instead of relying on the potentially stale task_rq(p)->rd.
Use cpus_mask rather than cpus_ptr, as the latter may be temporarily
narrowed to a single CPU by migrate_disable().
Reported-by: Weiheng Qiu <weihengqiuu@gmail.com>
Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://patch.msgid.link/20261103-b4-sched-dl-bw-fixes-v1-1-dd761fe005b4@redhat.com
Closes: https://lore.kernel.org/all/14508cb2-805f-41ac-9f6b-bfd7c3d7cb1c@gmail.com/
---
kernel/sched/deadline.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index c0ebdcd..68019da 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3324,14 +3324,28 @@ static void task_woken_dl(struct rq *rq, struct task_struct *p)
}
}
+/*
+ * Find the root domain where a DL task's bandwidth is currently
+ * accounted. For a sleeping task that was moved between cpusets
+ * without running, task_rq(p)->rd may be stale. Use the task's
+ * current cpus_mask (not yet updated to the new mask) to find the
+ * actual root domain. Use cpus_mask rather than cpus_ptr, which
+ * may be temporarily narrowed by migrate_disable().
+ */
+static unsigned int dl_task_root_domain_cpu(struct task_struct *p)
+{
+ unsigned int cpu;
+
+ cpu = cpumask_first_and(&p->cpus_mask, cpu_active_mask);
+ BUG_ON(cpu >= nr_cpu_ids);
+ return cpu;
+}
+
static void set_cpus_allowed_dl(struct task_struct *p,
struct affinity_context *ctx)
{
- struct rq *rq;
-
WARN_ON_ONCE(!dl_task(p));
- rq = task_rq(p);
/*
* Migrating a SCHED_DEADLINE task between exclusive
* cpusets (different root_domains) entails a bandwidth
@@ -3339,16 +3353,16 @@ static void set_cpus_allowed_dl(struct task_struct *p,
* domain (see cpuset_can_attach()).
*/
if (dl_task_needs_bw_move(p, ctx->new_mask)) {
- struct dl_bw *src_dl_b;
+ unsigned int src_cpu = dl_task_root_domain_cpu(p);
+ struct dl_bw *src_dl_b = &cpu_rq(src_cpu)->rd->dl_bw;
- src_dl_b = dl_bw_of(cpu_of(rq));
/*
* We now free resources of the root_domain we are migrating
* off. In the worst case, sched_setattr() may temporary fail
* until we complete the update.
*/
raw_spin_lock(&src_dl_b->lock);
- __dl_sub(src_dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p)));
+ __dl_sub(src_dl_b, p->dl.dl_bw, dl_bw_cpus(src_cpu));
raw_spin_unlock(&src_dl_b->lock);
}
@@ -3358,10 +3372,13 @@ static void set_cpus_allowed_dl(struct task_struct *p,
bool dl_task_needs_bw_move(struct task_struct *p,
const struct cpumask *new_mask)
{
+ unsigned int cpu;
+
if (!dl_task(p))
return false;
- return !cpumask_intersects(task_rq(p)->rd->span, new_mask);
+ cpu = dl_task_root_domain_cpu(p);
+ return !cpumask_intersects(cpu_rq(cpu)->rd->span, new_mask);
}
/* Assumes rq->lock is held */
next prev parent reply other threads:[~2026-11-03 13:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 11:26 [PATCH 0/4] sched/deadline: Fix assorted dl_bw accounting bugs Juri Lelli
2026-11-03 11:26 ` [PATCH 1/4] sched/deadline: Fix stale root domain in cpuset bandwidth transfer Juri Lelli
2026-11-03 13:26 ` tip-bot2 for Juri Lelli [this message]
[not found] ` <CGME20261105102052eucas1p2fa2d23d1c49cdadef3b1099e18ffb958@eucas1p2.samsung.com>
2026-11-05 10:20 ` Marek Szyprowski
2026-11-05 10:38 ` Juri Lelli
2026-11-05 11:16 ` Marek Szyprowski
2026-11-05 11:22 ` Ingo Molnar
2026-11-05 11:32 ` Juri Lelli
2026-11-03 11:26 ` [PATCH 2/4] sched/deadline: Fix total_bw leak when switching away from SCHED_DEADLINE while !queued Juri Lelli
2026-11-03 13:26 ` [tip: sched/urgent] " tip-bot2 for Juri Lelli
2026-11-03 11:26 ` [PATCH 3/4] sched: Reject SCHED_FLAG_KEEP_PARAMS when it would change scheduling class Juri Lelli
2026-11-03 13:26 ` [tip: sched/urgent] " tip-bot2 for Juri Lelli
2026-11-03 11:26 ` [PATCH 4/4] sched/deadline: Reject SCHED_DEADLINE on exited tasks Juri Lelli
2026-11-03 13:25 ` [tip: sched/urgent] " tip-bot2 for Juri Lelli
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=179371236348.1009794.4797641388786379495.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=weihengqiuu@gmail.com \
--cc=x86@kernel.org \
/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®