Skip to content

Commit f950915

Browse files
Quentin PerretPeter Zijlstra
authored andcommitted
sched/deadline: Fix reset_on_fork reporting of DL tasks
It is possible for sched_getattr() to incorrectly report the state of the reset_on_fork flag when called on a deadline task. Indeed, if the flag was set on a deadline task using sched_setattr() with flags (SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_PARAMS), then p->sched_reset_on_fork will be set, but __setscheduler() will bail out early, which means that the dl_se->flags will not get updated by __setscheduler_params()->__setparam_dl(). Consequently, if sched_getattr() is then called on the task, __getparam_dl() will override kattr.sched_flags with the now out-of-date copy in dl_se->flags and report the stale value to userspace. To fix this, make sure to only copy the flags that are relevant to sched_deadline to and from the dl_se->flags field. Signed-off-by: Quentin Perret <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f912d05 commit f950915

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

kernel/sched/deadline.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
27412741
dl_se->dl_runtime = attr->sched_runtime;
27422742
dl_se->dl_deadline = attr->sched_deadline;
27432743
dl_se->dl_period = attr->sched_period ?: dl_se->dl_deadline;
2744-
dl_se->flags = attr->sched_flags;
2744+
dl_se->flags = attr->sched_flags & SCHED_DL_FLAGS;
27452745
dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime);
27462746
dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime);
27472747
}
@@ -2754,7 +2754,8 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr)
27542754
attr->sched_runtime = dl_se->dl_runtime;
27552755
attr->sched_deadline = dl_se->dl_deadline;
27562756
attr->sched_period = dl_se->dl_period;
2757-
attr->sched_flags = dl_se->flags;
2757+
attr->sched_flags &= ~SCHED_DL_FLAGS;
2758+
attr->sched_flags |= dl_se->flags;
27582759
}
27592760

27602761
/*
@@ -2851,7 +2852,7 @@ bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr)
28512852
if (dl_se->dl_runtime != attr->sched_runtime ||
28522853
dl_se->dl_deadline != attr->sched_deadline ||
28532854
dl_se->dl_period != attr->sched_period ||
2854-
dl_se->flags != attr->sched_flags)
2855+
dl_se->flags != (attr->sched_flags & SCHED_DL_FLAGS))
28552856
return true;
28562857

28572858
return false;

kernel/sched/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ static inline void update_avg(u64 *avg, u64 sample)
227227
*/
228228
#define SCHED_FLAG_SUGOV 0x10000000
229229

230+
#define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED_FLAG_SUGOV)
231+
230232
static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se)
231233
{
232234
#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL

0 commit comments

Comments
 (0)