linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	akpm@linux-foundation.org, willy@infradead.org, arnd@kernel.org,
	Willem de Bruijn <willemb@google.com>
Subject: [PATCH 4/6] epoll: deduplicate compat logic
Date: Mon, 11 Jan 2021 19:30:15 -0500	[thread overview]
Message-ID: <20210112003017.4010304-5-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20210112003017.4010304-1-willemdebruijn.kernel@gmail.com>

From: Willem de Bruijn <willemb@google.com>

Apply the same compat deduplication strategy to epoll that was
previously applied to (p)select and ppoll.

Make do_epoll_wait handle both variants of sigmask. This removes
the need for near duplicate do_compat_epoll_pwait.

Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 fs/eventpoll.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index a829af074eb5..c9dcffba2da1 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -2239,7 +2239,7 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
  */
 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)
+			  const void __user *sigmask, size_t sigsetsize)
 {
 	int error;
 
@@ -2247,7 +2247,10 @@ static int do_epoll_pwait(int epfd, struct epoll_event __user *events,
 	 * If the caller wants a certain signal mask to be set during the wait,
 	 * we apply it here.
 	 */
-	error = set_user_sigmask(sigmask, sigsetsize);
+	if (!in_compat_syscall())
+		error = set_user_sigmask(sigmask, sigsetsize);
+	else
+		error = set_compat_user_sigmask(sigmask, sigsetsize);
 	if (error)
 		return error;
 
@@ -2288,28 +2291,6 @@ SYSCALL_DEFINE6(epoll_pwait2, int, epfd, struct epoll_event __user *, events,
 }
 
 #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;
-
-	/*
-	 * If the caller wants a certain signal mask to be set during the wait,
-	 * we apply it here.
-	 */
-	err = set_compat_user_sigmask(sigmask, sigsetsize);
-	if (err)
-		return err;
-
-	err = do_epoll_wait(epfd, events, maxevents, timeout);
-
-	restore_saved_sigmask_unless(err == -EINTR);
-
-	return err;
-}
-
 COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
 		       struct epoll_event __user *, events,
 		       int, maxevents, int, timeout,
@@ -2318,9 +2299,9 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
 {
 	struct timespec64 to;
 
-	return do_compat_epoll_pwait(epfd, events, maxevents,
-				     ep_timeout_to_timespec(&to, timeout),
-				     sigmask, sigsetsize);
+	return do_epoll_pwait(epfd, events, maxevents,
+			      ep_timeout_to_timespec(&to, timeout),
+			      sigmask, sigsetsize);
 }
 
 COMPAT_SYSCALL_DEFINE6(epoll_pwait2, int, epfd,
@@ -2340,8 +2321,7 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait2, int, epfd,
 			return -EINVAL;
 	}
 
-	return do_compat_epoll_pwait(epfd, events, maxevents, to,
-				     sigmask, sigsetsize);
+	return do_epoll_pwait(epfd, events, maxevents, to, sigmask, sigsetsize);
 }
 
 #endif
-- 
2.30.0.284.gd98b1dd5eaa7-goog


  parent reply	other threads:[~2021-01-12  0:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  0:30 [PATCH 0/6] fs: deduplicate compat logic Willem de Bruijn
2021-01-12  0:30 ` [PATCH 1/6] selftests/filesystems: add initial select and poll selftest Willem de Bruijn
2021-01-12  0:30 ` [PATCH 2/6] select: deduplicate compat logic Willem de Bruijn
2021-01-12  0:30 ` [PATCH 3/6] ppoll: " Willem de Bruijn
2021-01-12  0:30 ` Willem de Bruijn [this message]
2021-01-12  0:30 ` [PATCH 5/6] compat: add set_maybe_compat_user_sigmask helper Willem de Bruijn
2021-01-12  7:11   ` kernel test robot
2021-01-12  0:30 ` [PATCH 6/6] io_pgetevents: deduplicate compat logic Willem de Bruijn
2021-01-12  0:58 ` [PATCH 0/6] fs: " Al Viro
2021-01-12  1:16   ` Willem de Bruijn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210112003017.4010304-5-willemdebruijn.kernel@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemb@google.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).