[RFC 12/12][PATCH] SCHED_DEADLINE: modified sched_*_ex API
From: Raistlin
Date: Fri Oct 16 2009 - 11:49:48 EST
This commit amends the new API introduced to deal with the new sched_param_ex
scheduling parameter data structure.
What we add is one more parameter to all the functions, containing the size of
sched_param_ex. It might turn out useful in possible future extensions of
sched_param_ex itself, to avoid issue with ABI of legacy applications.
Signed-off-by: Raistlin <raistlin@xxxxxxxx>
---
include/linux/syscalls.h | 6 +++---
kernel/sched.c | 25 ++++++++++++++++---------
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index e01f59c..60a99a7 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -391,16 +391,16 @@ asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
asmlinkage long sys_nice(int increment);
asmlinkage long sys_sched_setscheduler(pid_t pid, int policy,
struct sched_param __user *param);
-asmlinkage long sys_sched_setscheduler_ex(pid_t pid, int policy,
+asmlinkage long sys_sched_setscheduler_ex(pid_t pid, int policy, unsigned len,
struct sched_param_ex __user *param);
asmlinkage long sys_sched_setparam(pid_t pid,
struct sched_param __user *param);
-asmlinkage long sys_sched_setparam_ex(pid_t pid,
+asmlinkage long sys_sched_setparam_ex(pid_t pid, unsigned len,
struct sched_param_ex __user *param);
asmlinkage long sys_sched_getscheduler(pid_t pid);
asmlinkage long sys_sched_getparam(pid_t pid,
struct sched_param __user *param);
-asmlinkage long sys_sched_getparam_ex(pid_t pid,
+asmlinkage long sys_sched_getparam_ex(pid_t pid, unsigned len,
struct sched_param_ex __user *param);
asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
unsigned long __user *user_mask_ptr);
diff --git a/kernel/sched.c b/kernel/sched.c
index a8ebfa2..d3a61f5 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6662,7 +6662,7 @@ do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
}
static int
-do_sched_setscheduler_ex(pid_t pid, int policy,
+do_sched_setscheduler_ex(pid_t pid, int policy, unsigned int len,
struct sched_param_ex __user *param_ex)
{
struct sched_param lparam;
@@ -6672,8 +6672,9 @@ do_sched_setscheduler_ex(pid_t pid, int policy,
if (!param_ex || pid < 0)
return -EINVAL;
- if (copy_from_user(&lparam_ex, param_ex,
- sizeof(struct sched_param_ex)))
+ if (len > sizeof(struct sched_param_ex))
+ return -EINVAL;
+ if (copy_from_user(&lparam_ex, param_ex,len))
return -EFAULT;
rcu_read_lock();
@@ -6708,15 +6709,17 @@ SYSCALL_DEFINE3(sched_setscheduler, pid_t, pid, int, policy,
* sys_sched_setscheduler_ex - set/change the scheduler policy to SCHED_DEADLINE
* @pid: the pid in question.
* @policy: new policy (should be SCHED_DEADLINE).
+ * @len: size of data pointed by param_ex.
* @param: structure containg the extended deadline parameters.
*/
-SYSCALL_DEFINE3(sched_setscheduler_ex, pid_t, pid, int, policy,
+SYSCALL_DEFINE4(sched_setscheduler_ex, pid_t, pid,
+ int, policy, unsigned, len,
struct sched_param_ex __user *, param_ex)
{
if (policy < 0)
return -EINVAL;
- return do_sched_setscheduler_ex(pid, policy, param_ex);
+ return do_sched_setscheduler_ex(pid, policy, len, param_ex);
}
/**
@@ -6732,12 +6735,13 @@ SYSCALL_DEFINE2(sched_setparam, pid_t, pid, struct sched_param __user *, param)
/**
* sys_sched_setparam - set/change the DEADLINE parameters of a thread
* @pid: the pid in question.
+ * @len: size of data pointed by param_ex.
* @param_ex: structure containing the new parameters (deadline, runtime, etc.).
*/
-SYSCALL_DEFINE2(sched_setparam_ex, pid_t, pid,
+SYSCALL_DEFINE3(sched_setparam_ex, pid_t, pid, unsigned, len,
struct sched_param_ex __user *, param_ex)
{
- return do_sched_setscheduler_ex(pid, -1, param_ex);
+ return do_sched_setscheduler_ex(pid, -1, len, param_ex);
}
/**
@@ -6807,9 +6811,10 @@ out_unlock:
/**
* sys_sched_getparam - get the DEADLINE task parameters of a thread
* @pid: the pid in question.
+ * @len: size of data pointed by param_ex.
* @param_ex: structure containing the new parameters (deadline, runtime, etc.).
*/
-SYSCALL_DEFINE2(sched_getparam_ex, pid_t, pid,
+SYSCALL_DEFINE3(sched_getparam_ex, pid_t, pid, unsigned, len,
struct sched_param_ex __user *, param_ex)
{
struct sched_param_ex lp;
@@ -6818,6 +6823,8 @@ SYSCALL_DEFINE2(sched_getparam_ex, pid_t, pid,
if (!param_ex || pid < 0)
return -EINVAL;
+ if (len < sizeof(struct sched_param_ex))
+ return -EINVAL;
read_lock(&tasklist_lock);
p = find_process_by_pid(pid);
@@ -6837,7 +6844,7 @@ SYSCALL_DEFINE2(sched_getparam_ex, pid_t, pid,
/*
* This one might sleep, we cannot do it with a spinlock held ...
*/
- retval = copy_to_user(param_ex, &lp, sizeof(*param_ex)) ? -EFAULT : 0;
+ retval = copy_to_user(param_ex, &lp, len) ? -EFAULT : 0;
return retval;
--
1.6.0.4
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa (Italy)
http://blog.linux.it/raistlin / raistlin@xxxxxxxxx /
dario.faggioli@xxxxxxxxxx
Attachment:
signature.asc
Description: This is a digitally signed message part