Skip to content

Commit 8d4edc8

Browse files
josephtsalisburygregkh
authored andcommitted
sched: Use u64 for bandwidth ratio calculations
[ Upstream commit c6e8020 ] 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: b40b2e8 ("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 [ dropped `extern` keyword from `to_ratio()` declaration ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ede9eca commit 8d4edc8

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/sched/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4823,7 +4823,7 @@ void sched_post_fork(struct task_struct *p)
48234823
uclamp_post_fork(p);
48244824
}
48254825

4826-
unsigned long to_ratio(u64 period, u64 runtime)
4826+
u64 to_ratio(u64 period, u64 runtime)
48274827
{
48284828
if (runtime == RUNTIME_INF)
48294829
return BW_UNIT;

kernel/sched/rt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ static int tg_rt_schedulable(struct task_group *tg, void *data)
27762776
{
27772777
struct rt_schedulable_data *d = data;
27782778
struct task_group *child;
2779-
unsigned long total, sum = 0;
2779+
u64 total, sum = 0;
27802780
u64 period, runtime;
27812781

27822782
period = ktime_to_ns(tg->rt_bandwidth.rt_period);

kernel/sched/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,7 @@ extern void init_dl_entity(struct sched_dl_entity *dl_se);
24632463
#define RATIO_SHIFT 8
24642464
#define MAX_BW_BITS (64 - BW_SHIFT)
24652465
#define MAX_BW ((1ULL << MAX_BW_BITS) - 1)
2466-
unsigned long to_ratio(u64 period, u64 runtime);
2466+
u64 to_ratio(u64 period, u64 runtime);
24672467

24682468
extern void init_entity_runnable_average(struct sched_entity *se);
24692469
extern void post_init_entity_util_avg(struct task_struct *p);

0 commit comments

Comments
 (0)