* [PATCH v2 0/2] sched/deadline: Fix zero-CPU DL bandwidth handling
@ 2026-09-19 15:31 Hui Su
2026-09-19 15:31 ` [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting Hui Su
2026-09-19 15:31 ` [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs Hui Su
0 siblings, 2 replies; 5+ messages in thread
From: Hui Su @ 2026-09-19 15:31 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Mikhail Zaslonko
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Luca Abeni,
Daniel Bristot de Oliveira, linux-kernel
During CPU hot-unplug, a CPU is removed from cpu_active_mask before it
becomes offline. If it is the last active CPU in a root domain,
dl_bw_cpus() can therefore return zero while paths associated with the CPU
are still reachable.
v1 addressed this in the DL server parameter-update path. Mikhail Zaslonko
reported the same divide-by-zero on s390x through sched_setscheduler(),
showing that the problem is more general, and pointed out several other
callers of __dl_sub() and __dl_add().
This version moves the zero-CPU handling into those common helpers. The
debugfs cpu_active() check is kept as a separate follow-up because it
completes the offline-CPU check added by 4043f5498416, while the generic
helper issue dates back much further. Keeping them separate also gives the
two fixes the appropriate stable backport scopes.
Patch 1 fixes the generic divide-by-zero while retaining the existing
total_bw update when no active CPU remains.
Patch 2 rejects per-CPU DL server debugfs writes once the CPU becomes
inactive instead of waiting until it is fully offline.
Validation on x86_64 included:
- cpus=0/1/2/4 DL bandwidth accounting
- targeted task_non_contending() and inactive_task_timer() zero-CPU paths
- 100 root-domain rebuild/offline-online cycles with accounting checks
- 200 cross-root-domain SCHED_DEADLINE cpuset moves
- SCHED_FLAG_RECLAIM policy transitions
- concurrent SCHED_DEADLINE/SCHED_OTHER transitions and CPU hotplug
- 100 CPU hotplug/debugfs update cycles
- A/B validation of the inactive-but-online debugfs window: the write was
accepted and changed runtime with patch 1 only, but was rejected and left
runtime unchanged with both patches
The final series was also built and boot-smoke-tested from its exact HEAD.
Changes since v1:
- Handle cpus == 0 in __dl_sub() and __dl_add(), as suggested by Mikhail.
- Split the generic bandwidth fix from the DL server debugfs check.
- Add the s390x sched_setscheduler() report.
- Extend validation to the other DL bandwidth paths and accounting cases.
Hui Su (2):
sched/deadline: Fix divide-by-zero in DL bandwidth accounting
sched/deadline: Reject debugfs dl_server writes for inactive CPUs
kernel/sched/deadline.c | 6 ++++--
kernel/sched/debug.c | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
base-commit: f259f446f5198d98e13756d2cd531812a0ad3064
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting
2026-09-19 15:31 [PATCH v2 0/2] sched/deadline: Fix zero-CPU DL bandwidth handling Hui Su
@ 2026-09-19 15:31 ` Hui Su
2026-09-22 12:29 ` Juri Lelli
2026-09-19 15:31 ` [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs Hui Su
1 sibling, 1 reply; 5+ messages in thread
From: Hui Su @ 2026-09-19 15:31 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Mikhail Zaslonko
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Luca Abeni,
Daniel Bristot de Oliveira, linux-kernel
During CPU hot-unplug, a CPU can be cleared from cpu_active_mask before it
is marked offline. This can leave a window where dl_bw_cpus() returns zero
for a root domain with no remaining active CPU.
DL bandwidth paths can pass this zero CPU count to __dl_sub() and
__dl_add(), which then divide by zero while distributing the bandwidth
update to active runqueues.
This is not specific to the DL server debugfs path. Mikhail Zaslonko
reported the same failure on s390x through sched_setscheduler(), where
task_non_contending() reached __dl_sub() with no active CPU in the root
domain. Other DL bandwidth paths use the same helpers.
Keep updating dl_bw::total_bw when the CPU count is zero, but skip
__dl_update(), since there are no active runqueues to receive an extra_bw
adjustment. This avoids the division by zero in all callers while retaining
the existing total_bw update.
Fixes: daec57983670 ("sched/deadline: Reclaim bandwidth not used by dl tasks")
Reported-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Link: https://lore.kernel.org/r/c52c9e8c-260e-49a4-a88e-229e0795d07b@linux.ibm.com
Suggested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Hui Su <sh_def@163.com>
---
kernel/sched/deadline.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 0663c00c41c0..840240cff7b9 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -193,14 +193,16 @@ static inline
void __dl_sub(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
{
dl_b->total_bw -= tsk_bw;
- __dl_update(dl_b, (s32)tsk_bw / cpus);
+ if (cpus)
+ __dl_update(dl_b, (s32)tsk_bw / cpus);
}
static inline
void __dl_add(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
{
dl_b->total_bw += tsk_bw;
- __dl_update(dl_b, -((s32)tsk_bw / cpus));
+ if (cpus)
+ __dl_update(dl_b, -((s32)tsk_bw / cpus));
}
static inline bool
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting
2026-09-19 15:31 ` [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting Hui Su
@ 2026-09-22 12:29 ` Juri Lelli
0 siblings, 0 replies; 5+ messages in thread
From: Juri Lelli @ 2026-09-22 12:29 UTC (permalink / raw)
To: Hui Su
Cc: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Mikhail Zaslonko,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Luca Abeni,
Daniel Bristot de Oliveira, linux-kernel
Hello,
On 20/09/26 00:31, Hui Su wrote:
> During CPU hot-unplug, a CPU can be cleared from cpu_active_mask before it
> is marked offline. This can leave a window where dl_bw_cpus() returns zero
> for a root domain with no remaining active CPU.
>
> DL bandwidth paths can pass this zero CPU count to __dl_sub() and
> __dl_add(), which then divide by zero while distributing the bandwidth
> update to active runqueues.
>
> This is not specific to the DL server debugfs path. Mikhail Zaslonko
> reported the same failure on s390x through sched_setscheduler(), where
> task_non_contending() reached __dl_sub() with no active CPU in the root
> domain. Other DL bandwidth paths use the same helpers.
>
> Keep updating dl_bw::total_bw when the CPU count is zero, but skip
> __dl_update(), since there are no active runqueues to receive an extra_bw
> adjustment. This avoids the division by zero in all callers while retaining
> the existing total_bw update.
>
> Fixes: daec57983670 ("sched/deadline: Reclaim bandwidth not used by dl tasks")
> Reported-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
> Link: https://lore.kernel.org/r/c52c9e8c-260e-49a4-a88e-229e0795d07b@linux.ibm.com
> Suggested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Hui Su <sh_def@163.com>
> ---
Looks good to me.
Acked-by: Juri Lelli <juri.lelli@redhat.com>
Thanks,
Juri
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs
2026-09-19 15:31 [PATCH v2 0/2] sched/deadline: Fix zero-CPU DL bandwidth handling Hui Su
2026-09-19 15:31 ` [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting Hui Su
@ 2026-09-19 15:31 ` Hui Su
2026-09-22 12:30 ` Juri Lelli
1 sibling, 1 reply; 5+ messages in thread
From: Hui Su @ 2026-09-19 15:31 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Mikhail Zaslonko
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Luca Abeni,
Daniel Bristot de Oliveira, linux-kernel
Commit 4043f5498416 ("sched/deadline: Reject debugfs dl_server writes
for offline CPUs") rejects per-CPU DL server parameter updates once the
target CPU is offline.
During CPU hot-unplug, however, the CPU is cleared from cpu_active_mask
before it is marked offline. This leaves a window where the CPU is no
longer active but cpu_online() still returns true, so
sched_server_write_common() continues to accept DL server updates.
There is no meaningful reason to reconfigure a per-CPU DL server once the
CPU is being deactivated. Reject the write when the target CPU is inactive
rather than only after it becomes offline.
Fixes: d741f297bcea ("sched/fair: Fair server interface")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/r/anw7IML1xzHys6re@jlelli-thinkpadt14gen4.remote.csb
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Hui Su <sh_def@163.com>
---
kernel/sched/debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 72236db67983..0e1642adb58c 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -416,7 +416,7 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
return -EINVAL;
}
- if (!cpu_online(cpu_of(rq)))
+ if (!cpu_active(cpu_of(rq)))
return -EBUSY;
update_rq_clock(rq);
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs
2026-09-19 15:31 ` [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs Hui Su
@ 2026-09-22 12:30 ` Juri Lelli
0 siblings, 0 replies; 5+ messages in thread
From: Juri Lelli @ 2026-09-22 12:30 UTC (permalink / raw)
To: Hui Su
Cc: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Mikhail Zaslonko,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Luca Abeni,
Daniel Bristot de Oliveira, linux-kernel
Hello,
On 20/09/26 00:31, Hui Su wrote:
> Commit 4043f5498416 ("sched/deadline: Reject debugfs dl_server writes
> for offline CPUs") rejects per-CPU DL server parameter updates once the
> target CPU is offline.
>
> During CPU hot-unplug, however, the CPU is cleared from cpu_active_mask
> before it is marked offline. This leaves a window where the CPU is no
> longer active but cpu_online() still returns true, so
> sched_server_write_common() continues to accept DL server updates.
>
> There is no meaningful reason to reconfigure a per-CPU DL server once the
> CPU is being deactivated. Reject the write when the target CPU is inactive
> rather than only after it becomes offline.
>
> Fixes: d741f297bcea ("sched/fair: Fair server interface")
Isn't 4043f5498416 ("sched/deadline: Reject debugfs dl_server writes for
offline CPUs") more appropriate?
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/r/anw7IML1xzHys6re@jlelli-thinkpadt14gen4.remote.csb
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Hui Su <sh_def@163.com>
> ---
Apart from that the fix looks good to me.
Acked-by: Juri Lelli <juri.lelli@redhat.com>
Thanks,
Juri
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-22 12:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 15:31 [PATCH v2 0/2] sched/deadline: Fix zero-CPU DL bandwidth handling Hui Su
2026-09-19 15:31 ` [PATCH v2 1/2] sched/deadline: Fix divide-by-zero in DL bandwidth accounting Hui Su
2026-09-22 12:29 ` Juri Lelli
2026-09-19 15:31 ` [PATCH v2 2/2] sched/deadline: Reject debugfs dl_server writes for inactive CPUs Hui Su
2026-09-22 12:30 ` Juri Lelli
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®