Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd505b8a

Browse files
changhuaixinPeter Zijlstra
authored and
Peter Zijlstra
committed
sched: Defend cfs and rt bandwidth quota against overflow
When users write some huge number into cpu.cfs_quota_us orcpu.rt_runtime_us, overflow might happen during to_ratio() shifts ofschedulable checks.to_ratio() could be altered to avoid unnecessary internal overflow, butmin_cfs_quota_period is less than 1 << BW_SHIFT, so a cutoff would stillbe needed. Set a cap MAX_BW for cfs_quota_us and rt_runtime_us toprevent overflow.Signed-off-by: Huaixin Chang <changhuaixin@linux.alibaba.com>Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>Reviewed-by: Ben Segall <bsegall@google.com>Link:https://lkml.kernel.org/r/20200425105248.60093-1-changhuaixin@linux.alibaba.com
1 parentdbe9337 commitd505b8a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

‎kernel/sched/core.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7379,6 +7379,8 @@ static DEFINE_MUTEX(cfs_constraints_mutex);
73797379

73807380
constu64max_cfs_quota_period=1*NSEC_PER_SEC;/* 1s */
73817381
staticconstu64min_cfs_quota_period=1*NSEC_PER_MSEC;/* 1ms */
7382+
/* More than 203 days if BW_SHIFT equals 20. */
7383+
staticconstu64max_cfs_runtime=MAX_BW*NSEC_PER_USEC;
73827384

73837385
staticint__cfs_schedulable(structtask_group*tg,u64period,u64runtime);
73847386

@@ -7406,6 +7408,12 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota)
74067408
if (period>max_cfs_quota_period)
74077409
return-EINVAL;
74087410

7411+
/*
7412+
* Bound quota to defend quota against overflow during bandwidth shift.
7413+
*/
7414+
if (quota!=RUNTIME_INF&&quota>max_cfs_runtime)
7415+
return-EINVAL;
7416+
74097417
/*
74107418
* Prevent race between setting of cfs_rq->runtime_enabled and
74117419
* unthrottle_offline_cfs_rqs().

‎kernel/sched/rt.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
intsched_rr_timeslice=RR_TIMESLICE;
1111
intsysctl_sched_rr_timeslice= (MSEC_PER_SEC /HZ)*RR_TIMESLICE;
12+
/* More than 4 hours if BW_SHIFT equals 20. */
13+
staticconstu64max_rt_runtime=MAX_BW;
1214

1315
staticintdo_sched_rt_period_timer(structrt_bandwidth*rt_b,intoverrun);
1416

@@ -2585,6 +2587,12 @@ static int tg_set_rt_bandwidth(struct task_group *tg,
25852587
if (rt_period==0)
25862588
return-EINVAL;
25872589

2590+
/*
2591+
* Bound quota to defend quota against overflow during bandwidth shift.
2592+
*/
2593+
if (rt_runtime!=RUNTIME_INF&&rt_runtime>max_rt_runtime)
2594+
return-EINVAL;
2595+
25882596
mutex_lock(&rt_constraints_mutex);
25892597
err=__rt_schedulable(tg,rt_period,rt_runtime);
25902598
if (err)
@@ -2702,7 +2710,9 @@ static int sched_rt_global_validate(void)
27022710
return-EINVAL;
27032711

27042712
if ((sysctl_sched_rt_runtime!=RUNTIME_INF)&&
2705-
(sysctl_sched_rt_runtime>sysctl_sched_rt_period))
2713+
((sysctl_sched_rt_runtime>sysctl_sched_rt_period)||
2714+
((u64)sysctl_sched_rt_runtime*
2715+
NSEC_PER_USEC>max_rt_runtime)))
27062716
return-EINVAL;
27072717

27082718
return0;

‎kernel/sched/sched.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ extern void init_dl_inactive_task_timer(struct sched_dl_entity *dl_se);
19151915
#defineBW_SHIFT20
19161916
#defineBW_UNIT(1 << BW_SHIFT)
19171917
#defineRATIO_SHIFT8
1918+
#defineMAX_BW_BITS(64 - BW_SHIFT)
1919+
#defineMAX_BW((1ULL << MAX_BW_BITS) - 1)
19181920
unsigned longto_ratio(u64period,u64runtime);
19191921

19201922
externvoidinit_entity_runnable_average(structsched_entity*se);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp