All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Woodhouse <dwmw2@infradead.org>,
	Felipe Balbi <balbi@ti.com>, Markus Pargmann <mpa@pengutronix.de>,
	Tejun Heo <tj@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org
Subject: [PATCH 2/3] signal: introduce kernel_signal_stop() to fix jffs2_garbage_collect_thread()
Date: Sat, 3 Oct 2015 20:13:38 +0200	[thread overview]
Message-ID: <20151003181338.GA1057@redhat.com> (raw)
In-Reply-To: <20151003181319.GA1036@redhat.com>

jffs2_garbage_collect_thread() can race with SIGCONT and sleep in
TASK_STOPPED state after it was already sent. Add the new helper,
kernel_signal_stop(), which does this correctly.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 fs/jffs2/background.c |  3 +--
 include/linux/sched.h | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/jffs2/background.c b/fs/jffs2/background.c
index f3145fd..53cc735 100644
--- a/fs/jffs2/background.c
+++ b/fs/jffs2/background.c
@@ -132,8 +132,7 @@ static int jffs2_garbage_collect_thread(void *_c)
 			case SIGSTOP:
 				jffs2_dbg(1, "%s(): SIGSTOP received\n",
 					  __func__);
-				set_current_state(TASK_STOPPED);
-				schedule();
+				kernel_signal_stop();
 				break;
 
 			case SIGKILL:
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e714539..56e688c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2477,6 +2477,16 @@ static inline int kernel_dequeue_signal(siginfo_t *info)
 	return ret;
 }
 
+static inline void kernel_signal_stop(void)
+{
+	spin_lock_irq(&current->sighand->siglock);
+	if (current->jobctl & JOBCTL_STOP_DEQUEUED)
+		__set_current_state(TASK_STOPPED);
+	spin_unlock_irq(&current->sighand->siglock);
+
+	schedule();
+}
+
 extern void release_task(struct task_struct * p);
 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
 extern int force_sigsegv(int, struct task_struct *);
-- 
2.4.3

  parent reply	other threads:[~2015-10-03 18:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-03 18:13 [PATCH -mm 0/3] minor kthread/signals cleanups and fix Oleg Nesterov
2015-10-03 18:13 ` [PATCH 1/3] signal: turn dequeue_signal_lock() into kernel_dequeue_signal() Oleg Nesterov
2015-10-04 16:38   ` Tejun Heo
2015-10-25 13:33   ` [PATCH -mm] signal-turn-dequeue_signal_lock-into-kernel_dequeue_signal-fix Oleg Nesterov
2015-10-03 18:13 ` Oleg Nesterov [this message]
2015-10-04 17:28   ` [PATCH 2/3] signal: introduce kernel_signal_stop() to fix jffs2_garbage_collect_thread() Tejun Heo
2015-10-03 18:13 ` [PATCH 3/3] signal: remove jffs2_garbage_collect_thread()->allow_signal(SIGCONT) Oleg Nesterov
2015-10-04 17:28   ` Tejun Heo

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=20151003181338.GA1057@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbi@ti.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mpa@pengutronix.de \
    --cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.