linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Benjamin LaHaise <bcrl@kvack.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	David Laight <David.Laight@ACULAB.COM>,
	Deepa Dinamani <deepa.kernel@gmail.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Eric Wong <e@80x24.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-aio@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] aio: simplify the usage of restore_saved_sigmask_unless()
Date: Fri, 7 Jun 2019 12:31:54 +0200	[thread overview]
Message-ID: <20190607103154.GA22159@redhat.com> (raw)
In-Reply-To: <20190607103122.GA22167@redhat.com>

Move the signal_pending() check and restore_saved_sigmask_unless()
into do_io_getevents() and simplify the callers.

The only complication is that non-restartable io_getevents() and
io_getevents_time32() have to translate ERESTARTNOHAND into EINTR.
They do not need restore_saved_sigmask_unless(), but it is harmless
and WARN_ON(!TIF_SIGPENDING) will be usefule after the next patch.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 fs/aio.c | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 8200f97..944eef7 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -2034,6 +2034,7 @@ static long do_io_getevents(aio_context_t ctx_id,
 {
 	ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
 	struct kioctx *ioctx = lookup_ioctx(ctx_id);
+	bool interrupted;
 	long ret = -EINVAL;
 
 	if (likely(ioctx)) {
@@ -2042,6 +2043,11 @@ static long do_io_getevents(aio_context_t ctx_id,
 		percpu_ref_put(&ioctx->users);
 	}
 
+	interrupted = signal_pending(current);
+	restore_saved_sigmask_unless(interrupted);
+	if (interrupted && !ret)
+		ret = -ERESTARTNOHAND;
+
 	return ret;
 }
 
@@ -2072,7 +2078,7 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
 		return -EFAULT;
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
-	if (!ret && signal_pending(current))
+	if (ret == -ERESTARTNOHAND)
 		ret = -EINTR;
 	return ret;
 }
@@ -2094,7 +2100,6 @@ SYSCALL_DEFINE6(io_pgetevents,
 {
 	struct __aio_sigset	ksig = { NULL, };
 	struct timespec64	ts;
-	bool interrupted;
 	int ret;
 
 	if (timeout && unlikely(get_timespec64(&ts, timeout)))
@@ -2109,11 +2114,6 @@ SYSCALL_DEFINE6(io_pgetevents,
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
 
-	interrupted = signal_pending(current);
-	restore_saved_sigmask_unless(interrupted);
-	if (interrupted && !ret)
-		ret = -ERESTARTNOHAND;
-
 	return ret;
 }
 
@@ -2129,7 +2129,6 @@ SYSCALL_DEFINE6(io_pgetevents_time32,
 {
 	struct __aio_sigset	ksig = { NULL, };
 	struct timespec64	ts;
-	bool interrupted;
 	int ret;
 
 	if (timeout && unlikely(get_old_timespec32(&ts, timeout)))
@@ -2145,11 +2144,6 @@ SYSCALL_DEFINE6(io_pgetevents_time32,
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
 
-	interrupted = signal_pending(current);
-	restore_saved_sigmask_unless(interrupted);
-	if (interrupted && !ret)
-		ret = -ERESTARTNOHAND;
-
 	return ret;
 }
 
@@ -2170,7 +2164,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,
 		return -EFAULT;
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
-	if (!ret && signal_pending(current))
+	if (ret == -ERESTARTNOHAND)
 		ret = -EINTR;
 	return ret;
 }
@@ -2196,7 +2190,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
 {
 	struct __compat_aio_sigset ksig = { NULL, };
 	struct timespec64 t;
-	bool interrupted;
 	int ret;
 
 	if (timeout && get_old_timespec32(&t, timeout))
@@ -2211,11 +2204,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
 
-	interrupted = signal_pending(current);
-	restore_saved_sigmask_unless(interrupted);
-	if (interrupted && !ret)
-		ret = -ERESTARTNOHAND;
-
 	return ret;
 }
 
@@ -2231,7 +2219,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
 {
 	struct __compat_aio_sigset ksig = { NULL, };
 	struct timespec64 t;
-	bool interrupted;
 	int ret;
 
 	if (timeout && get_timespec64(&t, timeout))
@@ -2246,11 +2233,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
 
 	ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
 
-	interrupted = signal_pending(current);
-	restore_saved_sigmask_unless(interrupted);
-	if (interrupted && !ret)
-		ret = -ERESTARTNOHAND;
-
 	return ret;
 }
 #endif
-- 
2.5.0



  reply	other threads:[~2019-06-07 10:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-07 10:31 [PATCH -mm 0/2] aio: simplify/fix the usage of restore_saved_sigmask_unless() Oleg Nesterov
2019-06-07 10:31 ` Oleg Nesterov [this message]
2019-06-07 17:33   ` [PATCH 1/2] aio: simplify " Linus Torvalds
2019-06-07 17:37     ` Linus Torvalds
2019-06-07 18:02       ` Eric W. Biederman
2019-06-07 18:09         ` Linus Torvalds
2019-06-07 10:32 ` [PATCH 2/2] aio: fix " Oleg Nesterov

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=20190607103154.GA22159@redhat.com \
    --to=oleg@redhat.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bcrl@kvack.org \
    --cc=deepa.kernel@gmail.com \
    --cc=e@80x24.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).