From: Oleg Nesterov Date: Wed, 21 Oct 2015 22:03:58 +0000 (+1100) Subject: signal: introduce kernel_signal_stop() to fix jffs2_garbage_collect_thread() X-Git-Tag: KARO-TX6UL-2015-11-03~14^2~19 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=7080397e8eaad25e44281ab3d54b93d0eab5a675;p=karo-tx-linux.git signal: introduce kernel_signal_stop() to fix jffs2_garbage_collect_thread() 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 Reviewed-by: Tejun Heo Cc: David Woodhouse Cc: Felipe Balbi Cc: Markus Pargmann Signed-off-by: Andrew Morton --- diff --git a/fs/jffs2/background.c b/fs/jffs2/background.c index f3145fd86d86..53cc7350af33 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 ecd9409640c6..02b63957a721 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2478,6 +2478,16 @@ static inline int kernel_dequeue_signal(siginfo_t *info) return ret; } +static inline void kernel_signal_stop(void) +{ + spin_lock_irq(¤t->sighand->siglock); + if (current->jobctl & JOBCTL_STOP_DEQUEUED) + __set_current_state(TASK_STOPPED); + spin_unlock_irq(¤t->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 *);