Skip to content

Commit b4098bf

Browse files
author
Peter Zijlstra
committed
sched/deadline: Impose global limits on sched_attr::sched_period
Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9cc5b86 commit b4098bf

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

include/linux/sched/sysctl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ int sched_proc_update_handler(struct ctl_table *table, int write,
6161
extern unsigned int sysctl_sched_rt_period;
6262
extern int sysctl_sched_rt_runtime;
6363

64+
extern unsigned int sysctl_sched_dl_period_max;
65+
extern unsigned int sysctl_sched_dl_period_min;
66+
6467
#ifdef CONFIG_UCLAMP_TASK
6568
extern unsigned int sysctl_sched_uclamp_util_min;
6669
extern unsigned int sysctl_sched_uclamp_util_max;

kernel/sched/deadline.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,14 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr)
26342634
attr->sched_flags = dl_se->flags;
26352635
}
26362636

2637+
/*
2638+
* Default limits for DL period; on the top end we guard against small util
2639+
* tasks still getting rediculous long effective runtimes, on the bottom end we
2640+
* guard against timer DoS.
2641+
*/
2642+
unsigned int sysctl_sched_dl_period_max = 1 << 22; /* ~4 seconds */
2643+
unsigned int sysctl_sched_dl_period_min = 100; /* 100 us */
2644+
26372645
/*
26382646
* This function validates the new parameters of a -deadline task.
26392647
* We ask for the deadline not being zero, and greater or equal
@@ -2646,6 +2654,8 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr)
26462654
*/
26472655
bool __checkparam_dl(const struct sched_attr *attr)
26482656
{
2657+
u64 period, max, min;
2658+
26492659
/* special dl tasks don't actually use any parameter */
26502660
if (attr->sched_flags & SCHED_FLAG_SUGOV)
26512661
return true;
@@ -2669,12 +2679,21 @@ bool __checkparam_dl(const struct sched_attr *attr)
26692679
attr->sched_period & (1ULL << 63))
26702680
return false;
26712681

2682+
period = attr->sched_period;
2683+
if (!period)
2684+
period = attr->sched_deadline;
2685+
26722686
/* runtime <= deadline <= period (if period != 0) */
2673-
if ((attr->sched_period != 0 &&
2674-
attr->sched_period < attr->sched_deadline) ||
2687+
if (period < attr->sched_deadline ||
26752688
attr->sched_deadline < attr->sched_runtime)
26762689
return false;
26772690

2691+
max = (u64)READ_ONCE(sysctl_sched_dl_period_max) * NSEC_PER_USEC;
2692+
min = (u64)READ_ONCE(sysctl_sched_dl_period_min) * NSEC_PER_USEC;
2693+
2694+
if (period < min || period > max)
2695+
return false;
2696+
26782697
return true;
26792698
}
26802699

kernel/sysctl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,20 @@ static struct ctl_table kern_table[] = {
17791779
.mode = 0644,
17801780
.proc_handler = sched_rt_handler,
17811781
},
1782+
{
1783+
.procname = "sched_deadline_period_max_us",
1784+
.data = &sysctl_sched_dl_period_max,
1785+
.maxlen = sizeof(unsigned int),
1786+
.mode = 0644,
1787+
.proc_handler = proc_dointvec,
1788+
},
1789+
{
1790+
.procname = "sched_deadline_period_min_us",
1791+
.data = &sysctl_sched_dl_period_min,
1792+
.maxlen = sizeof(unsigned int),
1793+
.mode = 0644,
1794+
.proc_handler = proc_dointvec,
1795+
},
17821796
{
17831797
.procname = "sched_rr_timeslice_ms",
17841798
.data = &sysctl_sched_rr_timeslice,

0 commit comments

Comments
 (0)