mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: cuilifei <cuilifei@xiaomi.com>
To: <linux-kernel@vger.kernel.org>
Cc: <miklos@szeredi.hu>, <rjw@rjwysocki.net>, <pavel@ucw.cz>,
	<len.brown@intel.com>, <linux-fsdevel@vger.kernel.org>,
	<viro@zeniv.linux.org.uk>, <piaoyingmin@xiaomi.com>,
	<liucai@xiaomi.com>, cuilifei <cuilifei@xiaomi.com>
Subject: [PATCH] fuse: freezing abort when use wait_event_killable{,_exclusive}().
Date: Mon, 5 Dec 2016 11:19:45 +0800	[thread overview]
Message-ID: <1480907985-1494-1-git-send-email-cuilifei@xiaomi.com> (raw)

Freezing process can abort when a client is waiting uninterruptibly
for a response. Add new macro wait_fatal_freezable to try to fix it.

Signed-off-by: cuilifei <cuilifei@xiaomi.com>
---
 fs/fuse/dev.c           | 30 ++++++++++++++++++++++++++----
 include/linux/freezer.h | 26 ++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 70ea57c..e33a081 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -19,6 +19,7 @@
 #include <linux/pipe_fs_i.h>
 #include <linux/swap.h>
 #include <linux/splice.h>
+#include <linux/freezer.h>
 
 MODULE_ALIAS_MISCDEV(FUSE_MINOR);
 MODULE_ALIAS("devname:fuse");
@@ -99,6 +100,19 @@ void fuse_request_free(struct fuse_req *req)
 	kmem_cache_free(fuse_req_cachep, req);
 }
 
+static void block_sigs(sigset_t *oldset)
+{
+	sigset_t mask;
+
+	siginitsetinv(&mask, sigmask(SIGKILL));
+	sigprocmask(SIG_BLOCK, &mask, oldset);
+}
+
+static void restore_sigs(sigset_t *oldset)
+{
+	sigprocmask(SIG_SETMASK, oldset, NULL);
+}
+
 void __fuse_get_request(struct fuse_req *req)
 {
 	atomic_inc(&req->count);
@@ -134,13 +148,18 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
 				       bool for_background)
 {
 	struct fuse_req *req;
+	sigset_t oldset;
+	int intr;
 	int err;
 	atomic_inc(&fc->num_waiting);
 
 	if (fuse_block_alloc(fc, for_background)) {
 		err = -EINTR;
-		if (wait_event_killable_exclusive(fc->blocked_waitq,
-				!fuse_block_alloc(fc, for_background)))
+		block_sigs(&oldset);
+		intr = wait_fatal_freezable(fc->blocked_waitq,
+				!fuse_block_alloc(fc, for_background), true);
+		restore_sigs(&oldset);
+		if (intr)
 			goto out;
 	}
 	/* Matches smp_wmb() in fuse_set_initialized() */
@@ -427,9 +446,12 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
 	}
 
 	if (!test_bit(FR_FORCE, &req->flags)) {
+		sigset_t oldset;
 		/* Only fatal signals may interrupt this */
-		err = wait_event_killable(req->waitq,
-					test_bit(FR_FINISHED, &req->flags));
+		block_sigs(&oldset);
+		err = wait_fatal_freezable(req->waitq,
+				test_bit(FR_FINISHED, &req->flags), false);
+		restore_sigs(&oldset);
 		if (!err)
 			return;
 
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index dd03e83..2504cd0 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -256,6 +256,22 @@ static inline int freezable_schedule_hrtimeout_range(ktime_t *expires,
 	__retval;							\
 })
 
+#define wait_fatal_freezable(wq, condition, exclusive)			\
+({									\
+	int __ret = 0;							\
+	do {								\
+		if (exclusive)						\
+			__ret = wait_event_interruptible_exclusive(wq,	\
+							condition);	\
+		else							\
+			__ret = wait_event_interruptible(wq,		\
+							condition);	\
+		if (!__ret || fatal_signal_pending(current))		\
+			break;						\
+	} while (try_to_freeze());					\
+	__ret;								\
+})
+
 #else /* !CONFIG_FREEZER */
 static inline bool frozen(struct task_struct *p) { return false; }
 static inline bool freezing(struct task_struct *p) { return false; }
@@ -296,6 +312,16 @@ static inline void set_freezable(void) {}
 #define wait_event_freezekillable_unsafe(wq, condition)			\
 		wait_event_killable(wq, condition)
 
+#define wait_fatal_freezable(wq, condition, exclusive)			\
+({									\
+	int __ret = 0;							\
+	if (exclusive)							\
+		__ret = wait_event_killable_exclusive(wq, condition);	\
+	else								\
+		__ret = wait_event_killable(wq,	condition);		\
+	__ret;								\
+})
+
 #endif /* !CONFIG_FREEZER */
 
 #endif	/* FREEZER_H_INCLUDED */
-- 
1.9.1

             reply	other threads:[~2016-12-05  3:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  3:19 cuilifei [this message]
2016-12-06 22:15 ` Rafael J. Wysocki
2016-12-08  6:31   ` 答复: " 崔立飞
2016-12-14 10:09     ` 崔立飞
2016-12-15 22:40       ` Rafael J. Wysocki
2016-12-16  1:34     ` 崔立飞
  -- strict thread matches above, loose matches on Subject: below --
2016-12-02  7:26 cuilifei
2016-12-03  8:54 ` kbuild test robot
2016-12-01  5:43 cuilifei
2016-12-02 16:16 ` kbuild test robot
2016-12-02 18:42 ` kbuild test robot
2016-12-01  5:37 cuilifei
2016-12-02 14:42 ` kbuild test robot
2016-12-02 14:51 ` kbuild test robot

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=1480907985-1494-1-git-send-email-cuilifei@xiaomi.com \
    --to=cuilifei@xiaomi.com \
    --cc=len.brown@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liucai@xiaomi.com \
    --cc=miklos@szeredi.hu \
    --cc=pavel@ucw.cz \
    --cc=piaoyingmin@xiaomi.com \
    --cc=rjw@rjwysocki.net \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®