aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/signal.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2011-04-01 14:12:38 -0400
committerTejun Heo <tj@kernel.org>2011-04-03 20:11:05 -0400
commitee77f075921730b2b465880f9fd4367003bdab39 (patch)
treedfae10b9718b79650477f912de148c903bc1bbd0 /kernel/signal.c
parent780006eac2fe7f4d2582da16a096e5a44c4767ff (diff)
signal: Turn SIGNAL_STOP_DEQUEUED into GROUP_STOP_DEQUEUED
This patch moves SIGNAL_STOP_DEQUEUED from signal_struct->flags to task_struct->group_stop, and thus makes it per-thread. Like SIGNAL_STOP_DEQUEUED, GROUP_STOP_DEQUEUED can be false-positive after return from get_signal_to_deliver(), this is fine. The only purpose of this bit is: we can drop ->siglock after __dequeue_signal() returns the sig_kernel_stop() signal and before we call do_signal_stop(), in this case we must not miss SIGCONT if it comes in between. But, unlike SIGNAL_STOP_DEQUEUED, GROUP_STOP_DEQUEUED can not be false-positive in do_signal_stop() if multiple threads dequeue the sig_kernel_stop() signal at the same time. Consider two threads T1 and T2, SIGTTIN has a hanlder. - T1 dequeues SIGTSTP and sets SIGNAL_STOP_DEQUEUED, then it drops ->siglock - SIGCONT comes and clears SIGNAL_STOP_DEQUEUED, SIGTSTP should be cancelled. - T2 dequeues SIGTTIN and sets SIGNAL_STOP_DEQUEUED again. Since we have a handler we should not stop, T2 returns to usermode to run the handler. - T1 continues, calls do_signal_stop() and wrongly starts the group stop because SIGNAL_STOP_DEQUEUED was restored in between. With or without this change: - we need to do something with ptrace_signal() which can return SIGSTOP, but this needs another discussion - SIGSTOP can be lost if it races with the mt exec, will be fixed later. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/signal.c')
-rw-r--r--kernel/signal.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/kernel/signal.c b/kernel/signal.c
index e9abc69dc0d8..4f7312b49b2d 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -254,7 +254,8 @@ static void task_clear_group_stop_trapping(struct task_struct *task)
254 */ 254 */
255void task_clear_group_stop_pending(struct task_struct *task) 255void task_clear_group_stop_pending(struct task_struct *task)
256{ 256{
257 task->group_stop &= ~(GROUP_STOP_PENDING | GROUP_STOP_CONSUME); 257 task->group_stop &= ~(GROUP_STOP_PENDING | GROUP_STOP_CONSUME |
258 GROUP_STOP_DEQUEUED);
258} 259}
259 260
260/** 261/**
@@ -602,7 +603,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
602 * is to alert stop-signal processing code when another 603 * is to alert stop-signal processing code when another
603 * processor has come along and cleared the flag. 604 * processor has come along and cleared the flag.
604 */ 605 */
605 tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; 606 current->group_stop |= GROUP_STOP_DEQUEUED;
606 } 607 }
607 if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { 608 if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
608 /* 609 /*
@@ -821,13 +822,6 @@ static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns)
821 signal->flags = why | SIGNAL_STOP_CONTINUED; 822 signal->flags = why | SIGNAL_STOP_CONTINUED;
822 signal->group_stop_count = 0; 823 signal->group_stop_count = 0;
823 signal->group_exit_code = 0; 824 signal->group_exit_code = 0;
824 } else {
825 /*
826 * We are not stopped, but there could be a stop
827 * signal in the middle of being processed after
828 * being removed from the queue. Clear that too.
829 */
830 signal->flags &= ~SIGNAL_STOP_DEQUEUED;
831 } 825 }
832 } 826 }
833 827
@@ -1855,7 +1849,7 @@ static int do_signal_stop(int signr)
1855 /* signr will be recorded in task->group_stop for retries */ 1849 /* signr will be recorded in task->group_stop for retries */
1856 WARN_ON_ONCE(signr & ~GROUP_STOP_SIGMASK); 1850 WARN_ON_ONCE(signr & ~GROUP_STOP_SIGMASK);
1857 1851
1858 if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || 1852 if (!likely(current->group_stop & GROUP_STOP_DEQUEUED) ||
1859 unlikely(signal_group_exit(sig))) 1853 unlikely(signal_group_exit(sig)))
1860 return 0; 1854 return 0;
1861 /* 1855 /*