Skip to content

Commit

Permalink
sched_rr_get_interval(): move compat to native, get rid of set_fs()
Browse files Browse the repository at this point in the history
switch to using timespec64 internally, while we are at it

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Sep 20, 2017
1 parent 7bea578 commit abca5fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
16 changes: 0 additions & 16 deletions kernel/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,22 +562,6 @@ COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
}
#endif

COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
compat_pid_t, pid,
struct compat_timespec __user *, interval)
{
struct timespec t;
int ret;
mm_segment_t old_fs = get_fs();

set_fs(KERNEL_DS);
ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
set_fs(old_fs);
if (compat_put_timespec(&t, interval))
return -EFAULT;
return ret;
}

/*
* Allocate user-space memory for the duration of a single system call,
* in order to marshall parameters inside a compat thunk.
Expand Down
36 changes: 30 additions & 6 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/init_task.h>
#include <linux/context_tracking.h>
#include <linux/rcupdate_wait.h>
#include <linux/compat.h>

#include <linux/blkdev.h>
#include <linux/kprobes.h>
Expand Down Expand Up @@ -5098,13 +5099,11 @@ SYSCALL_DEFINE1(sched_get_priority_min, int, policy)
* Return: On success, 0 and the timeslice is in @interval. Otherwise,
* an error code.
*/
SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
struct timespec __user *, interval)
static int sched_rr_get_interval(pid_t pid, struct timespec64 *t)
{
struct task_struct *p;
unsigned int time_slice;
struct rq_flags rf;
struct timespec t;
struct rq *rq;
int retval;

Expand All @@ -5128,15 +5127,40 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
task_rq_unlock(rq, p, &rf);

rcu_read_unlock();
jiffies_to_timespec(time_slice, &t);
retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
return retval;
jiffies_to_timespec64(time_slice, t);
return 0;

out_unlock:
rcu_read_unlock();
return retval;
}

SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
struct timespec __user *, interval)
{
struct timespec64 t;
int retval = sched_rr_get_interval(pid, &t);

if (retval == 0)
retval = put_timespec64(&t, interval);

return retval;
}

#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
compat_pid_t, pid,
struct compat_timespec __user *, interval)
{
struct timespec64 t;
int retval = sched_rr_get_interval(pid, &t);

if (retval == 0)
retval = compat_put_timespec64(&t, interval);
return retval;
}
#endif

void sched_show_task(struct task_struct *p)
{
unsigned long free = 0;
Expand Down

0 comments on commit abca5fc

Please sign in to comment.