提交 0d4b70d8 编写于 作者: O Oleg Nesterov 提交者: Zheng Zengkai

kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data()

stable inclusion
from stable-5.10.26
commit 4523e648b7b7fb41f2d6df51890f197ed807d1c9
bugzilla: 51363

--------------------------------

commit 5abbe51a 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: 609c19a3 ("x86/ptrace: Stop setting TS_COMPAT in ptrace code")
Signed-off-by: NOleg Nesterov <oleg@redhat.com>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210201174641.GA17871@redhat.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>

 Conflicts:
	include/linux/thread_info.h
Acked-by: N  Weilong Chen <chenweilong@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 25a4b2b2
...@@ -1055,10 +1055,9 @@ static long do_restart_poll(struct restart_block *restart_block) ...@@ -1055,10 +1055,9 @@ static long do_restart_poll(struct restart_block *restart_block)
ret = do_sys_poll(ufds, nfds, to); ret = do_sys_poll(ufds, nfds, to);
if (ret == -ERESTARTNOHAND) { if (ret == -ERESTARTNOHAND)
restart_block->fn = do_restart_poll; ret = set_restart_fn(restart_block, do_restart_poll);
ret = -ERESTART_RESTARTBLOCK;
}
return ret; return ret;
} }
...@@ -1080,7 +1079,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds, ...@@ -1080,7 +1079,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
struct restart_block *restart_block; struct restart_block *restart_block;
restart_block = &current->restart_block; restart_block = &current->restart_block;
restart_block->fn = do_restart_poll;
restart_block->poll.ufds = ufds; restart_block->poll.ufds = ufds;
restart_block->poll.nfds = nfds; restart_block->poll.nfds = nfds;
...@@ -1091,7 +1089,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds, ...@@ -1091,7 +1089,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
} else } else
restart_block->poll.has_timeout = 0; restart_block->poll.has_timeout = 0;
ret = -ERESTART_RESTARTBLOCK; ret = set_restart_fn(restart_block, do_restart_poll);
} }
return ret; return ret;
} }
......
...@@ -12,12 +12,24 @@ ...@@ -12,12 +12,24 @@
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/restart_block.h> #include <linux/restart_block.h>
#include <linux/thread_bits.h> #include <linux/thread_bits.h>
#include <linux/errno.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <asm/thread_info.h> #include <asm/thread_info.h>
#ifdef __KERNEL__ #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 #ifndef THREAD_ALIGN
#define THREAD_ALIGN THREAD_SIZE #define THREAD_ALIGN THREAD_SIZE
#endif #endif
......
...@@ -2730,14 +2730,13 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ...@@ -2730,14 +2730,13 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
goto out; goto out;
restart = &current->restart_block; restart = &current->restart_block;
restart->fn = futex_wait_restart;
restart->futex.uaddr = uaddr; restart->futex.uaddr = uaddr;
restart->futex.val = val; restart->futex.val = val;
restart->futex.time = *abs_time; restart->futex.time = *abs_time;
restart->futex.bitset = bitset; restart->futex.bitset = bitset;
restart->futex.flags = flags | FLAGS_HAS_TIMEOUT; restart->futex.flags = flags | FLAGS_HAS_TIMEOUT;
ret = -ERESTART_RESTARTBLOCK; ret = set_restart_fn(restart, futex_wait_restart);
out: out:
if (to) { if (to) {
......
...@@ -848,9 +848,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, ...@@ -848,9 +848,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
if (flags == TIMER_ABSTIME) if (flags == TIMER_ABSTIME)
return -ERESTARTNOHAND; return -ERESTARTNOHAND;
restart->fn = alarm_timer_nsleep_restart;
restart->nanosleep.clockid = type; restart->nanosleep.clockid = type;
restart->nanosleep.expires = exp; restart->nanosleep.expires = exp;
set_restart_fn(restart, alarm_timer_nsleep_restart);
return ret; return ret;
} }
......
...@@ -1957,9 +1957,9 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode, ...@@ -1957,9 +1957,9 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,
} }
restart = &current->restart_block; restart = &current->restart_block;
restart->fn = hrtimer_nanosleep_restart;
restart->nanosleep.clockid = t.timer.base->clockid; restart->nanosleep.clockid = t.timer.base->clockid;
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer); restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
set_restart_fn(restart, hrtimer_nanosleep_restart);
out: out:
destroy_hrtimer_on_stack(&t.timer); destroy_hrtimer_on_stack(&t.timer);
return ret; return ret;
......
...@@ -1480,8 +1480,8 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags, ...@@ -1480,8 +1480,8 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
if (flags & TIMER_ABSTIME) if (flags & TIMER_ABSTIME)
return -ERESTARTNOHAND; return -ERESTARTNOHAND;
restart_block->fn = posix_cpu_nsleep_restart;
restart_block->nanosleep.clockid = which_clock; restart_block->nanosleep.clockid = which_clock;
set_restart_fn(restart_block, posix_cpu_nsleep_restart);
} }
return error; return error;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册