UPSTREAM: epoll: add syscall epoll_pwait2
Add syscall epoll_pwait2, an epoll_wait variant with nsec resolution that
replaces int timeout with struct timespec. It is equivalent otherwise.
int epoll_pwait2(int fd, struct epoll_event *events,
int maxevents,
const struct timespec *timeout,
const sigset_t *sigset);
The underlying hrtimer is already programmed with nsec resolution.
pselect and ppoll also set nsec resolution timeout with timespec.
The sigset_t in epoll_pwait has a compat variant. epoll_pwait2 needs
the same.
For timespec, only support this new interface on 2038 aware platforms
that define __kernel_timespec_t. So no CONFIG_COMPAT_32BIT_TIME.
Link: https://lkml.kernel.org/r/20201121144401.3727659-3-willemdebruijn.kernel@gmail.com
Change-Id: I8cb4e756aacb4bee7cbe1c2cb5320a59e07626f8
Signed-off-by: Willem de Bruijn <willemb@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
theshaenix
parent
0927c223ca
commit
d9d0b12dc3
@@ -2250,11 +2250,10 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
|
||||
* Implement the event wait interface for the eventpoll file. It is the kernel
|
||||
* part of the user space epoll_pwait(2).
|
||||
*/
|
||||
SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
|
||||
int, maxevents, int, timeout, const sigset_t __user *, sigmask,
|
||||
size_t, sigsetsize)
|
||||
static int do_epoll_pwait(int epfd, struct epoll_event __user *events,
|
||||
int maxevents, struct timespec64 *to,
|
||||
const sigset_t __user *sigmask, size_t sigsetsize)
|
||||
{
|
||||
struct timespec64 to;
|
||||
int error;
|
||||
sigset_t ksigmask, sigsaved;
|
||||
|
||||
@@ -2271,8 +2270,7 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
|
||||
set_current_blocked(&ksigmask);
|
||||
}
|
||||
|
||||
error = do_epoll_wait(epfd, events, maxevents,
|
||||
ep_timeout_to_timespec(&to, timeout));
|
||||
error = do_epoll_wait(epfd, events, maxevents, to);
|
||||
|
||||
/*
|
||||
* If we changed the signal mask, we need to restore the original one.
|
||||
@@ -2292,14 +2290,41 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
|
||||
return error;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
|
||||
struct epoll_event __user *, events,
|
||||
int, maxevents, int, timeout,
|
||||
const compat_sigset_t __user *, sigmask,
|
||||
compat_size_t, sigsetsize)
|
||||
SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
|
||||
int, maxevents, int, timeout, const sigset_t __user *, sigmask,
|
||||
size_t, sigsetsize)
|
||||
{
|
||||
struct timespec64 to;
|
||||
|
||||
return do_epoll_pwait(epfd, events, maxevents,
|
||||
ep_timeout_to_timespec(&to, timeout),
|
||||
sigmask, sigsetsize);
|
||||
}
|
||||
|
||||
SYSCALL_DEFINE6(epoll_pwait2, int, epfd, struct epoll_event __user *, events,
|
||||
int, maxevents, const struct __kernel_timespec __user *, timeout,
|
||||
const sigset_t __user *, sigmask, size_t, sigsetsize)
|
||||
{
|
||||
struct timespec64 ts, *to = NULL;
|
||||
|
||||
if (timeout) {
|
||||
if (get_timespec64(&ts, timeout))
|
||||
return -EFAULT;
|
||||
to = &ts;
|
||||
if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return do_epoll_pwait(epfd, events, maxevents, to,
|
||||
sigmask, sigsetsize);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
static int do_compat_epoll_pwait(int epfd, struct epoll_event __user *events,
|
||||
int maxevents, struct timespec64 *timeout,
|
||||
const compat_sigset_t __user *sigmask,
|
||||
compat_size_t sigsetsize)
|
||||
{
|
||||
long err;
|
||||
compat_sigset_t csigmask;
|
||||
sigset_t ksigmask, sigsaved;
|
||||
@@ -2318,8 +2343,7 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
|
||||
set_current_blocked(&ksigmask);
|
||||
}
|
||||
|
||||
err = do_epoll_wait(epfd, events, maxevents,
|
||||
ep_timeout_to_timespec(&to, timeout));
|
||||
err = do_epoll_wait(epfd, events, maxevents, timeout);
|
||||
|
||||
/*
|
||||
* If we changed the signal mask, we need to restore the original one.
|
||||
@@ -2338,6 +2362,41 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
|
||||
struct epoll_event __user *, events,
|
||||
int, maxevents, int, timeout,
|
||||
const compat_sigset_t __user *, sigmask,
|
||||
compat_size_t, sigsetsize)
|
||||
{
|
||||
struct timespec64 to;
|
||||
|
||||
return do_compat_epoll_pwait(epfd, events, maxevents,
|
||||
ep_timeout_to_timespec(&to, timeout),
|
||||
sigmask, sigsetsize);
|
||||
}
|
||||
|
||||
COMPAT_SYSCALL_DEFINE6(epoll_pwait2, int, epfd,
|
||||
struct epoll_event __user *, events,
|
||||
int, maxevents,
|
||||
const struct __kernel_timespec __user *, timeout,
|
||||
const compat_sigset_t __user *, sigmask,
|
||||
compat_size_t, sigsetsize)
|
||||
{
|
||||
struct timespec64 ts, *to = NULL;
|
||||
|
||||
if (timeout) {
|
||||
if (get_timespec64(&ts, timeout))
|
||||
return -EFAULT;
|
||||
to = &ts;
|
||||
if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return do_compat_epoll_pwait(epfd, events, maxevents, to,
|
||||
sigmask, sigsetsize);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int __init eventpoll_init(void)
|
||||
|
||||
Reference in New Issue
Block a user