Commit c240837f authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

signals: jffs2: fix the wrong usage of disallow_signal()

jffs2_garbage_collect_thread() does disallow_signal(SIGHUP) around
jffs2_garbage_collect_pass() and the comment says "We don't want SIGHUP
to interrupt us".

But disallow_signal() can't ensure that jffs2_garbage_collect_pass()
won't be interrupted by SIGHUP, the problem is that SIGHUP can be
already pending when disallow_signal() is called, and in this case any
interruptible sleep won't block.

Note: this is in fact because disallow_signal() is buggy and should be
fixed, see the next changes.

But there is another reason why disallow_signal() is wrong: SIG_IGN set
by disallow_signal() silently discards any SIGHUP which can be sent
before the next allow_signal(SIGHUP).

Change this code to use sigprocmask(SIG_UNBLOCK/SIG_BLOCK, SIGHUP).
This even matches the old (and wrong) semantics allow/disallow had when
this logic was written.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0341729b
...@@ -75,10 +75,13 @@ void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) ...@@ -75,10 +75,13 @@ void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
static int jffs2_garbage_collect_thread(void *_c) static int jffs2_garbage_collect_thread(void *_c)
{ {
struct jffs2_sb_info *c = _c; struct jffs2_sb_info *c = _c;
sigset_t hupmask;
siginitset(&hupmask, sigmask(SIGHUP));
allow_signal(SIGKILL); allow_signal(SIGKILL);
allow_signal(SIGSTOP); allow_signal(SIGSTOP);
allow_signal(SIGCONT); allow_signal(SIGCONT);
allow_signal(SIGHUP);
c->gc_task = current; c->gc_task = current;
complete(&c->gc_thread_start); complete(&c->gc_thread_start);
...@@ -87,7 +90,7 @@ static int jffs2_garbage_collect_thread(void *_c) ...@@ -87,7 +90,7 @@ static int jffs2_garbage_collect_thread(void *_c)
set_freezable(); set_freezable();
for (;;) { for (;;) {
allow_signal(SIGHUP); sigprocmask(SIG_UNBLOCK, &hupmask, NULL);
again: again:
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
if (!jffs2_thread_should_wake(c)) { if (!jffs2_thread_should_wake(c)) {
...@@ -95,10 +98,9 @@ static int jffs2_garbage_collect_thread(void *_c) ...@@ -95,10 +98,9 @@ static int jffs2_garbage_collect_thread(void *_c)
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
jffs2_dbg(1, "%s(): sleeping...\n", __func__); jffs2_dbg(1, "%s(): sleeping...\n", __func__);
schedule(); schedule();
} else } else {
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
}
/* Problem - immediately after bootup, the GCD spends a lot /* Problem - immediately after bootup, the GCD spends a lot
* of time in places like jffs2_kill_fragtree(); so much so * of time in places like jffs2_kill_fragtree(); so much so
* that userspace processes (like gdm and X) are starved * that userspace processes (like gdm and X) are starved
...@@ -150,7 +152,7 @@ static int jffs2_garbage_collect_thread(void *_c) ...@@ -150,7 +152,7 @@ static int jffs2_garbage_collect_thread(void *_c)
} }
} }
/* We don't want SIGHUP to interrupt us. STOP and KILL are OK though. */ /* We don't want SIGHUP to interrupt us. STOP and KILL are OK though. */
disallow_signal(SIGHUP); sigprocmask(SIG_BLOCK, &hupmask, NULL);
jffs2_dbg(1, "%s(): pass\n", __func__); jffs2_dbg(1, "%s(): pass\n", __func__);
if (jffs2_garbage_collect_pass(c) == -ENOSPC) { if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment