Skip to content

Commit abca5fc

Browse files
author
Al Viro
committed
sched_rr_get_interval(): move compat to native, get rid of set_fs()
switch to using timespec64 internally, while we are at it Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 7bea578 commit abca5fc

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

‎kernel/compat.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -562,22 +562,6 @@ COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
562562
}
563563
#endif
564564

565-
COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
566-
compat_pid_t, pid,
567-
struct compat_timespec __user *, interval)
568-
{
569-
struct timespec t;
570-
int ret;
571-
mm_segment_t old_fs = get_fs();
572-
573-
set_fs(KERNEL_DS);
574-
ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
575-
set_fs(old_fs);
576-
if (compat_put_timespec(&t, interval))
577-
return -EFAULT;
578-
return ret;
579-
}
580-
581565
/*
582566
* Allocate user-space memory for the duration of a single system call,
583567
* in order to marshall parameters inside a compat thunk.

‎kernel/sched/core.c‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/init_task.h>
1717
#include <linux/context_tracking.h>
1818
#include <linux/rcupdate_wait.h>
19+
#include <linux/compat.h>
1920

2021
#include <linux/blkdev.h>
2122
#include <linux/kprobes.h>
@@ -5098,13 +5099,11 @@ SYSCALL_DEFINE1(sched_get_priority_min, int, policy)
50985099
* Return: On success, 0 and the timeslice is in @interval. Otherwise,
50995100
* an error code.
51005101
*/
5101-
SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
5102-
struct timespec __user *, interval)
5102+
static int sched_rr_get_interval(pid_t pid, struct timespec64 *t)
51035103
{
51045104
struct task_struct *p;
51055105
unsigned int time_slice;
51065106
struct rq_flags rf;
5107-
struct timespec t;
51085107
struct rq *rq;
51095108
int retval;
51105109

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

51305129
rcu_read_unlock();
5131-
jiffies_to_timespec(time_slice, &t);
5132-
retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
5133-
return retval;
5130+
jiffies_to_timespec64(time_slice, t);
5131+
return 0;
51345132

51355133
out_unlock:
51365134
rcu_read_unlock();
51375135
return retval;
51385136
}
51395137

5138+
SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
5139+
struct timespec __user *, interval)
5140+
{
5141+
struct timespec64 t;
5142+
int retval = sched_rr_get_interval(pid, &t);
5143+
5144+
if (retval == 0)
5145+
retval = put_timespec64(&t, interval);
5146+
5147+
return retval;
5148+
}
5149+
5150+
#ifdef CONFIG_COMPAT
5151+
COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
5152+
compat_pid_t, pid,
5153+
struct compat_timespec __user *, interval)
5154+
{
5155+
struct timespec64 t;
5156+
int retval = sched_rr_get_interval(pid, &t);
5157+
5158+
if (retval == 0)
5159+
retval = compat_put_timespec64(&t, interval);
5160+
return retval;
5161+
}
5162+
#endif
5163+
51405164
void sched_show_task(struct task_struct *p)
51415165
{
51425166
unsigned long free = 0;

0 commit comments

Comments
 (0)