select: shift restore_saved_sigmask_unless() into poll_select_copy_remaining()

Now that restore_saved_sigmask_unless() is always called with the same
argument right before poll_select_copy_remaining() we can move it into
poll_select_copy_remaining() and make it the only caller of restore() in
fs/select.c.

The patch also renames poll_select_copy_remaining(),
poll_select_finish() looks better after this change.

kern_select() doesn't use set_user_sigmask(), so in this case
poll_select_finish() does restore_saved_sigmask_unless() "for no
reason".  But this won't hurt, and WARN_ON(!TIF_SIGPENDING) is still
valid.

Link: http://lkml.kernel.org/r/20190606140915.GC13440@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Laight <David.Laight@aculab.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Eric Wong <e@80x24.org>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Oleg Nesterov 2019-07-16 16:29:59 -07:00 committed by Linus Torvalds
parent 8cf8b5539a
commit ac30102062

View File

@ -294,12 +294,14 @@ enum poll_time_type {
PT_OLD_TIMESPEC = 3, PT_OLD_TIMESPEC = 3,
}; };
static int poll_select_copy_remaining(struct timespec64 *end_time, static int poll_select_finish(struct timespec64 *end_time,
void __user *p, void __user *p,
enum poll_time_type pt_type, int ret) enum poll_time_type pt_type, int ret)
{ {
struct timespec64 rts; struct timespec64 rts;
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND);
if (!p) if (!p)
return ret; return ret;
@ -714,9 +716,7 @@ static int kern_select(int n, fd_set __user *inp, fd_set __user *outp,
} }
ret = core_sys_select(n, inp, outp, exp, to); ret = core_sys_select(n, inp, outp, exp, to);
ret = poll_select_copy_remaining(&end_time, tvp, PT_TIMEVAL, ret); return poll_select_finish(&end_time, tvp, PT_TIMEVAL, ret);
return ret;
} }
SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp, SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
@ -757,10 +757,7 @@ static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
return ret; return ret;
ret = core_sys_select(n, inp, outp, exp, to); ret = core_sys_select(n, inp, outp, exp, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, type, ret);
ret = poll_select_copy_remaining(&end_time, tsp, type, ret);
return ret;
} }
/* /*
@ -1102,10 +1099,7 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
return ret; return ret;
ret = do_sys_poll(ufds, nfds, to); ret = do_sys_poll(ufds, nfds, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, PT_TIMESPEC, ret);
ret = poll_select_copy_remaining(&end_time, tsp, PT_TIMESPEC, ret);
return ret;
} }
#if defined(CONFIG_COMPAT_32BIT_TIME) && !defined(CONFIG_64BIT) #if defined(CONFIG_COMPAT_32BIT_TIME) && !defined(CONFIG_64BIT)
@ -1131,10 +1125,7 @@ SYSCALL_DEFINE5(ppoll_time32, struct pollfd __user *, ufds, unsigned int, nfds,
return ret; return ret;
ret = do_sys_poll(ufds, nfds, to); ret = do_sys_poll(ufds, nfds, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, PT_OLD_TIMESPEC, ret);
ret = poll_select_copy_remaining(&end_time, tsp, PT_OLD_TIMESPEC, ret);
return ret;
} }
#endif #endif
@ -1271,9 +1262,7 @@ static int do_compat_select(int n, compat_ulong_t __user *inp,
} }
ret = compat_core_sys_select(n, inp, outp, exp, to); ret = compat_core_sys_select(n, inp, outp, exp, to);
ret = poll_select_copy_remaining(&end_time, tvp, PT_OLD_TIMEVAL, ret); return poll_select_finish(&end_time, tvp, PT_OLD_TIMEVAL, ret);
return ret;
} }
COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp, COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp,
@ -1333,10 +1322,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp,
return ret; return ret;
ret = compat_core_sys_select(n, inp, outp, exp, to); ret = compat_core_sys_select(n, inp, outp, exp, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, type, ret);
ret = poll_select_copy_remaining(&end_time, tsp, type, ret);
return ret;
} }
COMPAT_SYSCALL_DEFINE6(pselect6_time64, int, n, compat_ulong_t __user *, inp, COMPAT_SYSCALL_DEFINE6(pselect6_time64, int, n, compat_ulong_t __user *, inp,
@ -1405,10 +1391,7 @@ COMPAT_SYSCALL_DEFINE5(ppoll_time32, struct pollfd __user *, ufds,
return ret; return ret;
ret = do_sys_poll(ufds, nfds, to); ret = do_sys_poll(ufds, nfds, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, PT_OLD_TIMESPEC, ret);
ret = poll_select_copy_remaining(&end_time, tsp, PT_OLD_TIMESPEC, ret);
return ret;
} }
#endif #endif
@ -1434,10 +1417,7 @@ COMPAT_SYSCALL_DEFINE5(ppoll_time64, struct pollfd __user *, ufds,
return ret; return ret;
ret = do_sys_poll(ufds, nfds, to); ret = do_sys_poll(ufds, nfds, to);
restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); return poll_select_finish(&end_time, tsp, PT_TIMESPEC, ret);
ret = poll_select_copy_remaining(&end_time, tsp, PT_TIMESPEC, ret);
return ret;
} }
#endif #endif