Skip to content

Commit 58169a5

Browse files
wdebruijtorvalds
authored andcommitted
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 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>
1 parent 7cdf7c2 commit 58169a5

1 file changed

Lines changed: 73 additions & 14 deletions

File tree

‎fs/eventpoll.c‎

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,11 +2237,10 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
22372237
* Implement the event wait interface for the eventpoll file. It is the kernel
22382238
* part of the user space epoll_pwait(2).
22392239
*/
2240-
SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
2241-
int, maxevents, int, timeout, const sigset_t __user *, sigmask,
2242-
size_t, sigsetsize)
2240+
static int do_epoll_pwait(int epfd, struct epoll_event __user *events,
2241+
int maxevents, struct timespec64 *to,
2242+
const sigset_t __user *sigmask, size_t sigsetsize)
22432243
{
2244-
struct timespec64 to;
22452244
int error;
22462245

22472246
/*
@@ -2252,22 +2251,48 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
22522251
if (error)
22532252
return error;
22542253

2255-
error = do_epoll_wait(epfd, events, maxevents,
2256-
ep_timeout_to_timespec(&to, timeout));
2254+
error = do_epoll_wait(epfd, events, maxevents, to);
22572255

22582256
restore_saved_sigmask_unless(error == -EINTR);
22592257

22602258
return error;
22612259
}
22622260

2263-
#ifdef CONFIG_COMPAT
2264-
COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
2265-
struct epoll_event __user *, events,
2266-
int, maxevents, int, timeout,
2267-
const compat_sigset_t __user *, sigmask,
2268-
compat_size_t, sigsetsize)
2261+
SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
2262+
int, maxevents, int, timeout, const sigset_t __user *, sigmask,
2263+
size_t, sigsetsize)
22692264
{
22702265
struct timespec64 to;
2266+
2267+
return do_epoll_pwait(epfd, events, maxevents,
2268+
ep_timeout_to_timespec(&to, timeout),
2269+
sigmask, sigsetsize);
2270+
}
2271+
2272+
SYSCALL_DEFINE6(epoll_pwait2, int, epfd, struct epoll_event __user *, events,
2273+
int, maxevents, const struct __kernel_timespec __user *, timeout,
2274+
const sigset_t __user *, sigmask, size_t, sigsetsize)
2275+
{
2276+
struct timespec64 ts, *to = NULL;
2277+
2278+
if (timeout) {
2279+
if (get_timespec64(&ts, timeout))
2280+
return -EFAULT;
2281+
to = &ts;
2282+
if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
2283+
return -EINVAL;
2284+
}
2285+
2286+
return do_epoll_pwait(epfd, events, maxevents, to,
2287+
sigmask, sigsetsize);
2288+
}
2289+
2290+
#ifdef CONFIG_COMPAT
2291+
static int do_compat_epoll_pwait(int epfd, struct epoll_event __user *events,
2292+
int maxevents, struct timespec64 *timeout,
2293+
const compat_sigset_t __user *sigmask,
2294+
compat_size_t sigsetsize)
2295+
{
22712296
long err;
22722297

22732298
/*
@@ -2278,13 +2303,47 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
22782303
if (err)
22792304
return err;
22802305

2281-
err = do_epoll_wait(epfd, events, maxevents,
2282-
ep_timeout_to_timespec(&to, timeout));
2306+
err = do_epoll_wait(epfd, events, maxevents, timeout);
22832307

22842308
restore_saved_sigmask_unless(err == -EINTR);
22852309

22862310
return err;
22872311
}
2312+
2313+
COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
2314+
struct epoll_event __user *, events,
2315+
int, maxevents, int, timeout,
2316+
const compat_sigset_t __user *, sigmask,
2317+
compat_size_t, sigsetsize)
2318+
{
2319+
struct timespec64 to;
2320+
2321+
return do_compat_epoll_pwait(epfd, events, maxevents,
2322+
ep_timeout_to_timespec(&to, timeout),
2323+
sigmask, sigsetsize);
2324+
}
2325+
2326+
COMPAT_SYSCALL_DEFINE6(epoll_pwait2, int, epfd,
2327+
struct epoll_event __user *, events,
2328+
int, maxevents,
2329+
const struct __kernel_timespec __user *, timeout,
2330+
const compat_sigset_t __user *, sigmask,
2331+
compat_size_t, sigsetsize)
2332+
{
2333+
struct timespec64 ts, *to = NULL;
2334+
2335+
if (timeout) {
2336+
if (get_timespec64(&ts, timeout))
2337+
return -EFAULT;
2338+
to = &ts;
2339+
if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
2340+
return -EINVAL;
2341+
}
2342+
2343+
return do_compat_epoll_pwait(epfd, events, maxevents, to,
2344+
sigmask, sigsetsize);
2345+
}
2346+
22882347
#endif
22892348

22902349
static int __init eventpoll_init(void)

0 commit comments

Comments
 (0)