Message ID | 20190115101513.2822-2-patrick.bellasi@arm.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | Add utilization clamping support | expand |
Hello Patrick, What do you think about the following minor changes: On Tue, Jan 15, 2019 at 10:14:58AM +0000, Patrick Bellasi wrote: > /* SCHED_ISO: reserved but not implemented yet */ > #define SCHED_IDLE 5 > #define SCHED_DEADLINE 6 > +/* Must be the last entry: used to sanity check attr.policy values */ I would remove this comment: - the meaning of SCHED_POLICY_MAX is evident, and - should we hint on how the value is used? That comment will be removed the next time SCHED_POLICY_MAX is used for something else. This is what should also happen to the comment of SETPARAM_POLICY: now sched_setparam() is no more the only code path accessing SETPARAM_POLICY. > +#define SCHED_POLICY_MAX 7 +#define SCHED_POLICY_MAX SCHED_DEADLINE This would make it compliant with the definition of MAX. > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4560,8 +4560,17 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, > if (retval) > return retval; > > - if ((int)attr.sched_policy < 0) > + /* > + * A valid policy is always required from userspace, unless > + * SCHED_FLAG_KEEP_POLICY is set and the current policy > + * is enforced for this call. > + */ > + if (attr.sched_policy >= SCHED_POLICY_MAX && + if (attr.sched_policy > SCHED_POLICY_MAX && In line with the previous update. > + !(attr.sched_flags & SCHED_FLAG_KEEP_POLICY)) { > return -EINVAL; Thanks, Alessio
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index 22627f80063e..43832a87016a 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -40,6 +40,8 @@ /* SCHED_ISO: reserved but not implemented yet */ #define SCHED_IDLE 5 #define SCHED_DEADLINE 6 +/* Must be the last entry: used to sanity check attr.policy values */ +#define SCHED_POLICY_MAX 7 /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ #define SCHED_RESET_ON_FORK 0x40000000 @@ -50,9 +52,11 @@ #define SCHED_FLAG_RESET_ON_FORK 0x01 #define SCHED_FLAG_RECLAIM 0x02 #define SCHED_FLAG_DL_OVERRUN 0x04 +#define SCHED_FLAG_KEEP_POLICY 0x08 #define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \ SCHED_FLAG_RECLAIM | \ - SCHED_FLAG_DL_OVERRUN) + SCHED_FLAG_DL_OVERRUN | \ + SCHED_FLAG_KEEP_POLICY) #endif /* _UAPI_LINUX_SCHED_H */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a674c7db2f29..a68763a4ccae 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4560,8 +4560,17 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, if (retval) return retval; - if ((int)attr.sched_policy < 0) + /* + * A valid policy is always required from userspace, unless + * SCHED_FLAG_KEEP_POLICY is set and the current policy + * is enforced for this call. + */ + if (attr.sched_policy >= SCHED_POLICY_MAX && + !(attr.sched_flags & SCHED_FLAG_KEEP_POLICY)) { return -EINVAL; + } + if (attr.sched_flags & SCHED_FLAG_KEEP_POLICY) + attr.sched_policy = SETPARAM_POLICY; rcu_read_lock(); retval = -ESRCH;
The sched_setattr() syscall mandates that a policy is always specified. This requires to always know which policy a task will have when attributes are configured and it makes it impossible to add more generic task attributes valid across different scheduling policies. Reading the policy before setting generic tasks attributes is racy since we cannot be sure it is not changed concurrently. Introduce the required support to change generic task attributes without affecting the current task policy. This is done by adding an attribute flag (SCHED_FLAG_KEEP_POLICY) to enforce the usage of the current policy. This is done by extending to the sched_setattr() non-POSIX syscall with the SETPARAM_POLICY policy already used by the sched_setparam() POSIX syscall. Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> --- Changes in v6: Message-ID: <20181107135801.GE9761@hirez.programming.kicks-ass.net> - rename SCHED_FLAG_TUNE_POLICY in SCHED_FLAG_KEEP_POLICY - moved at the beginning of the series --- include/uapi/linux/sched.h | 6 +++++- kernel/sched/core.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-)