LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] sched/deadline: Fix sched_getattr() for DL tasks
@ 2021-07-29 17:52 Quentin Perret
2021-07-30 9:22 ` Juri Lelli
0 siblings, 1 reply; 2+ messages in thread
From: Quentin Perret @ 2021-07-29 17:52 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel
Cc: kernel-team, Quentin Perret
In its current state, sched_getattr() can report incorrect sched_flags
if called on a deadline task.
Firstly, if the reset_on_fork flag is set on a deadline task using
sched_setattr() with SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_PARAMS,
p->sched_reset_on_fork will be set but __setscheduler() will bail out
early without updating the dl_se->flags. Consequently, if sched_getattr
is then called on the same task, __getparam_dl() will override
kattr.sched_flags with the now out-of-date copy in dl_se->flags and
report a stale reset_on_fork value to userspace.
And secondly, sched_getattr() currently reports SCHED_FLAG_SUGOV as set
if called on a schedutil worker, despite this flag being a kernel-only
value that is not exposed in UAPI headers.
To fix both of these problems, make sure to only copy the flags that are
relevant to sched_deadline to dl_se->flags, and filter them out when
reporting them back to userspace.
Signed-off-by: Quentin Perret <qperret@google.com>
---
v1 can be found here:
https://lore.kernel.org/r/20210727101103.2729607-1-qperret@google.com/
Changes since v1:
- squashed the two patches together
- moved the SCHED_FLAG_SUGOV filtering to __getparam_dl()
---
kernel/sched/deadline.c | 7 ++++---
kernel/sched/sched.h | 2 ++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index aaacd6cfd42f..358a8a2acfc2 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2741,7 +2741,7 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
dl_se->dl_runtime = attr->sched_runtime;
dl_se->dl_deadline = attr->sched_deadline;
dl_se->dl_period = attr->sched_period ?: dl_se->dl_deadline;
- dl_se->flags = attr->sched_flags;
+ dl_se->flags = attr->sched_flags & SCHED_DL_FLAGS;
dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime);
dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime);
}
@@ -2754,7 +2754,8 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr)
attr->sched_runtime = dl_se->dl_runtime;
attr->sched_deadline = dl_se->dl_deadline;
attr->sched_period = dl_se->dl_period;
- attr->sched_flags = dl_se->flags;
+ attr->sched_flags &= ~SCHED_DL_FLAGS;
+ attr->sched_flags |= dl_se->flags & ~SCHED_FLAG_SUGOV;
}
/*
@@ -2851,7 +2852,7 @@ bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr)
if (dl_se->dl_runtime != attr->sched_runtime ||
dl_se->dl_deadline != attr->sched_deadline ||
dl_se->dl_period != attr->sched_period ||
- dl_se->flags != attr->sched_flags)
+ dl_se->flags != (attr->sched_flags & SCHED_DL_FLAGS))
return true;
return false;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 14a41a243f7b..ad3aee63db26 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -227,6 +227,8 @@ static inline void update_avg(u64 *avg, u64 sample)
*/
#define SCHED_FLAG_SUGOV 0x10000000
+#define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED_FLAG_SUGOV)
+
static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se)
{
#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
--
2.32.0.554.ge1b32706d8-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] sched/deadline: Fix sched_getattr() for DL tasks
2021-07-29 17:52 [PATCH v2] sched/deadline: Fix sched_getattr() for DL tasks Quentin Perret
@ 2021-07-30 9:22 ` Juri Lelli
0 siblings, 0 replies; 2+ messages in thread
From: Juri Lelli @ 2021-07-30 9:22 UTC (permalink / raw)
To: Quentin Perret
Cc: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, kernel-team
Hi,
On 29/07/21 18:52, Quentin Perret wrote:
> In its current state, sched_getattr() can report incorrect sched_flags
> if called on a deadline task.
>
> Firstly, if the reset_on_fork flag is set on a deadline task using
> sched_setattr() with SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_PARAMS,
> p->sched_reset_on_fork will be set but __setscheduler() will bail out
> early without updating the dl_se->flags. Consequently, if sched_getattr
> is then called on the same task, __getparam_dl() will override
> kattr.sched_flags with the now out-of-date copy in dl_se->flags and
> report a stale reset_on_fork value to userspace.
>
> And secondly, sched_getattr() currently reports SCHED_FLAG_SUGOV as set
> if called on a schedutil worker, despite this flag being a kernel-only
> value that is not exposed in UAPI headers.
>
> To fix both of these problems, make sure to only copy the flags that are
> relevant to sched_deadline to dl_se->flags, and filter them out when
> reporting them back to userspace.
>
> Signed-off-by: Quentin Perret <qperret@google.com>
Looks good to me.
Acked-by: Juri Lelli <juri.lelli@redhat.com>
Thanks!
Juri
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-30 9:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 17:52 [PATCH v2] sched/deadline: Fix sched_getattr() for DL tasks Quentin Perret
2021-07-30 9:22 ` Juri Lelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).