sched/rt: use u64 for RT group bandwidth accounting
PATCH 1/1 sched/rt: use u64 for RT group bandwidth accounting
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.
--- kernel/sched/rt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/rt.c +1 -1
@@ -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);
Signature · 1 line
2.47.3
Hi.
Quoted 5 lines · Joseph Salisbury
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)...
Quoted 2 lines
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.
Quoted 3 lines
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
Thanks for the feedback, Michal!
Quoted 8 lines · Michal Koutný
Hi.
Quoted 5 lines · Joseph Salisbury
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.
Quoted 7 lines
As per my calculation this'd require at least 4096 sibling RT groups (see
to_ratio()andBW_SHIFT)...Quoted 2 lines
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.
Quoted 10 lines
Quoted 3 lines
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.