* [PATCH] sched/rt: use u64 for RT group bandwidth accounting
@ 2026-03-17 19:34 Joseph Salisbury
2026-04-01 9:48 ` Michal Koutný
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Salisbury @ 2026-03-17 19:34 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
tg_rt_schedulable() sums the bandwidth ratios of all child RT groups
and compares the result against the bandwidth available to the parent.
On 32-bit builds, the running sum is stored in unsigned long and can
overflow when enough child groups are present. In that case, an
overcommitted hierarchy may incorrectly pass the schedulability check.
Use u64 for the local bandwidth totals so the accumulated child sum and
the parent limit are compared without 32-bit overflow.
Fixes: b40b2e8eb521 ("sched: rt: multi level group constraints")
Cc: stable@vger.kernel.org
Assisted-by: Codex:GPT-5
Signed-off-by: Joseph Salisbury <joseph.salisbury@oracle.com>
---
kernel/sched/rt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f69e1f16d923..906f6c656c2e 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2652,7 +2652,7 @@ static int tg_rt_schedulable(struct task_group *tg, void *data)
{
struct rt_schedulable_data *d = data;
struct task_group *child;
- unsigned long total, sum = 0;
+ u64 total, sum = 0;
u64 period, runtime;
period = ktime_to_ns(tg->rt_bandwidth.rt_period);
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched/rt: use u64 for RT group bandwidth accounting
2026-03-17 19:34 [PATCH] sched/rt: use u64 for RT group bandwidth accounting Joseph Salisbury
@ 2026-04-01 9:48 ` Michal Koutný
2026-04-03 20:29 ` Joseph Salisbury
0 siblings, 1 reply; 3+ messages in thread
From: Michal Koutný @ 2026-04-01 9:48 UTC (permalink / raw)
To: Joseph Salisbury
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]
Hi.
On Tue, Mar 17, 2026 at 03:34:02PM -0400, Joseph Salisbury <joseph.salisbury@oracle.com> wrote:
> tg_rt_schedulable() sums the bandwidth ratios of all child RT groups
> and compares the result against the bandwidth available to the parent.
>
> On 32-bit builds, the running sum is stored in unsigned long and can
> overflow when enough child groups are present.
As per my calculation this'd require at least 4096 sibling RT groups
(see to_ratio() and BW_SHIFT)...
> In that case, an overcommitted hierarchy may incorrectly pass the
> schedulability check.
...and I expect there'd other issues with so many so little RT groups
than allowing theoretically unschedulabile configuration.
>
> Use u64 for the local bandwidth totals so the accumulated child sum and
> the parent limit are compared without 32-bit overflow.
You may want to fix this also in to_ratio() return type as there are
other consumers besides this check. (Although, some conditions would
still be similarly exotic, e.g. normalize_cfs_quota(), like CFQ quota of
more than 4096 (32b!) CPUs.)
Thanks,
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched/rt: use u64 for RT group bandwidth accounting
2026-04-01 9:48 ` Michal Koutný
@ 2026-04-03 20:29 ` Joseph Salisbury
0 siblings, 0 replies; 3+ messages in thread
From: Joseph Salisbury @ 2026-04-03 20:29 UTC (permalink / raw)
To: Michal Koutný
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
Thanks for the feedback, Michal!
On 4/1/26 5:48 AM, Michal Koutný wrote:
> Hi.
>
> On Tue, Mar 17, 2026 at 03:34:02PM -0400, Joseph Salisbury <joseph.salisbury@oracle.com> wrote:
>> tg_rt_schedulable() sums the bandwidth ratios of all child RT groups
>> and compares the result against the bandwidth available to the parent.
>>
>> On 32-bit builds, the running sum is stored in unsigned long and can
>> overflow when enough child groups are present.
> As per my calculation this'd require at least 4096 sibling RT groups
> (see to_ratio() and BW_SHIFT)...
>
>> In that case, an overcommitted hierarchy may incorrectly pass the
>> schedulability check.
> ...and I expect there'd other issues with so many so little RT groups
> than allowing theoretically unschedulabile configuration.
You are right. This is mostly a correctness fix for a corner case. This
patch primarily addresses the case where the arithmetic can silently
truncate on 32-bit.
>
>> Use u64 for the local bandwidth totals so the accumulated child sum and
>> the parent limit are compared without 32-bit overflow.
> You may want to fix this also in to_ratio() return type as there are
> other consumers besides this check. (Although, some conditions would
> still be similarly exotic, e.g. normalize_cfs_quota(), like CFQ quota of
> more than 4096 (32b!) CPUs.)
>
> Thanks,
> Michal
That's a good point. I can send a v2 that returns u64 from to_ratio()
and keeps the RT totals in u64 as well.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-03 20:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-17 19:34 [PATCH] sched/rt: use u64 for RT group bandwidth accounting Joseph Salisbury
2026-04-01 9:48 ` Michal Koutný
2026-04-03 20:29 ` Joseph Salisbury
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®