]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched: Use u64 for bandwidth ratio calculations
authorJoseph Salisbury <joseph.salisbury@oracle.com>
Fri, 3 Apr 2026 21:00:14 +0000 (17:00 -0400)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 7 Apr 2026 07:23:52 +0000 (09:23 +0200)
to_ratio() computes BW_SHIFT-scaled bandwidth ratios from u64 period and
runtime values, but it returns unsigned long.  tg_rt_schedulable() also
stores the current group limit and the accumulated child sum in unsigned
long.

On 32-bit builds, large bandwidth ratios can be truncated and the RT
group sum can wrap when enough siblings are present.  That can let an
overcommitted RT hierarchy pass the schedulability check, and it also
narrows the helper result for other callers.

Return u64 from to_ratio() and use u64 for the RT group totals so
bandwidth ratios are preserved and compared at full width on both 32-bit
and 64-bit builds.

Fixes: b40b2e8eb521 ("sched: rt: multi level group constraints")
Assisted-by: Codex:GPT-5
Signed-off-by: Joseph Salisbury <joseph.salisbury@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260403210014.2713404-1-joseph.salisbury@oracle.com
kernel/sched/core.c
kernel/sched/rt.c
kernel/sched/sched.h

index c15c9865299e748bb79132c772ceeecdd8c6836c..49cd5d21716130c51f835d2524aed0ae3cfa59a9 100644 (file)
@@ -4735,7 +4735,7 @@ void sched_post_fork(struct task_struct *p)
        scx_post_fork(p);
 }
 
-unsigned long to_ratio(u64 period, u64 runtime)
+u64 to_ratio(u64 period, u64 runtime)
 {
        if (runtime == RUNTIME_INF)
                return BW_UNIT;
index 4e5f1957b91b13b2174692b58ae58fed4a9f960d..a48e86794913695a97cf4cd1fc69d0e52ae759bb 100644 (file)
@@ -2666,7 +2666,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);
index 9594355a36811cc742c7c83de7941dac306771e4..c95584191d58f488159fa5b5337f0f58ea2a659c 100644 (file)
@@ -2907,7 +2907,7 @@ extern void init_cfs_throttle_work(struct task_struct *p);
 #define MAX_BW_BITS            (64 - BW_SHIFT)
 #define MAX_BW                 ((1ULL << MAX_BW_BITS) - 1)
 
-extern unsigned long to_ratio(u64 period, u64 runtime);
+extern u64 to_ratio(u64 period, u64 runtime);
 
 extern void init_entity_runnable_average(struct sched_entity *se);
 extern void post_init_entity_util_avg(struct task_struct *p);