Skip to content

Commit

Permalink
kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_d…
Browse files Browse the repository at this point in the history
…ata()

commit 5abbe51 upstream.

Preparation for fixing get_nr_restart_syscall() on X86 for COMPAT.

Add a new helper which sets restart_block->fn and calls a dummy
arch_set_restart_data() helper.

Fixes: 609c19a ("x86/ptrace: Stop setting TS_COMPAT in ptrace code")
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210201174641.GA17871@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Oleg Nesterov authored and Greg Kroah-Hartman committed Mar 24, 2021
1 parent d20c7a7 commit 591d6c2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
10 changes: 4 additions & 6 deletions fs/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,9 @@ static long do_restart_poll(struct restart_block *restart_block)

ret = do_sys_poll(ufds, nfds, to);

if (ret == -EINTR) {
restart_block->fn = do_restart_poll;
ret = -ERESTART_RESTARTBLOCK;
}
if (ret == -EINTR)
ret = set_restart_fn(restart_block, do_restart_poll);

return ret;
}

Expand All @@ -1031,7 +1030,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
struct restart_block *restart_block;

restart_block = &current->restart_block;
restart_block->fn = do_restart_poll;
restart_block->poll.ufds = ufds;
restart_block->poll.nfds = nfds;

Expand All @@ -1042,7 +1040,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
} else
restart_block->poll.has_timeout = 0;

ret = -ERESTART_RESTARTBLOCK;
ret = set_restart_fn(restart_block, do_restart_poll);
}
return ret;
}
Expand Down
13 changes: 13 additions & 0 deletions include/linux/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/types.h>
#include <linux/bug.h>
#include <linux/restart_block.h>
#include <linux/errno.h>

#ifdef CONFIG_THREAD_INFO_IN_TASK
/*
Expand Down Expand Up @@ -39,6 +40,18 @@ enum {

#ifdef __KERNEL__

#ifndef arch_set_restart_data
#define arch_set_restart_data(restart) do { } while (0)
#endif

static inline long set_restart_fn(struct restart_block *restart,
long (*fn)(struct restart_block *))
{
restart->fn = fn;
arch_set_restart_data(restart);
return -ERESTART_RESTARTBLOCK;
}

#ifndef THREAD_ALIGN
#define THREAD_ALIGN THREAD_SIZE
#endif
Expand Down
3 changes: 1 addition & 2 deletions kernel/futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2875,14 +2875,13 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
goto out;

restart = &current->restart_block;
restart->fn = futex_wait_restart;
restart->futex.uaddr = uaddr;
restart->futex.val = val;
restart->futex.time = *abs_time;
restart->futex.bitset = bitset;
restart->futex.flags = flags | FLAGS_HAS_TIMEOUT;

ret = -ERESTART_RESTARTBLOCK;
ret = set_restart_fn(restart, futex_wait_restart);

out:
if (to) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/time/alarmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
if (flags == TIMER_ABSTIME)
return -ERESTARTNOHAND;

restart->fn = alarm_timer_nsleep_restart;
restart->nanosleep.clockid = type;
restart->nanosleep.expires = exp;
set_restart_fn(restart, alarm_timer_nsleep_restart);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/time/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,9 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp,
}

restart = &current->restart_block;
restart->fn = hrtimer_nanosleep_restart;
restart->nanosleep.clockid = t.timer.base->clockid;
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
set_restart_fn(restart, hrtimer_nanosleep_restart);
out:
destroy_hrtimer_on_stack(&t.timer);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion kernel/time/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,8 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
if (flags & TIMER_ABSTIME)
return -ERESTARTNOHAND;

restart_block->fn = posix_cpu_nsleep_restart;
restart_block->nanosleep.clockid = which_clock;
set_restart_fn(restart_block, posix_cpu_nsleep_restart);
}
return error;
}
Expand Down

0 comments on commit 591d6c2

Please sign in to comment.