diff options
author | Oleg Nesterov <oleg@redhat.com> | 2011-04-27 15:56:14 -0400 |
---|---|---|
committer | Oleg Nesterov <oleg@redhat.com> | 2011-04-28 07:01:39 -0400 |
commit | b182801ab35f7a0afb3cdf8ba5df464d04206b46 (patch) | |
tree | dcdda5843c6453b60fe4adcf004283ac5f8e315b /kernel | |
parent | 943df1485a8ff0e600729e082e568ece04d4de9e (diff) |
signal: do_sigtimedwait() needs retarget_shared_pending()
do_sigtimedwait() changes current->blocked and thus it needs
set_current_blocked()->retarget_shared_pending().
We could use set_current_blocked() directly. It is fine to change
->real_blocked from all-zeroes to ->blocked and vice versa lockless,
but this is not immediately clear, looks racy, and needs a huge
comment to explain why this is correct.
To keep the things simple this patch adds the new static helper,
__set_task_blocked() which should be called with ->siglock held. This
way we can change both ->real_blocked and ->blocked atomically under
->siglock as the current code does. This is more understandable.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Matt Fleming <matt.fleming@linux.intel.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/signal.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/kernel/signal.c b/kernel/signal.c index 1ab89f677424..4d97e11d7672 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -2299,6 +2299,18 @@ long do_no_restart_syscall(struct restart_block *param) | |||
2299 | return -EINTR; | 2299 | return -EINTR; |
2300 | } | 2300 | } |
2301 | 2301 | ||
2302 | static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset) | ||
2303 | { | ||
2304 | if (signal_pending(tsk) && !thread_group_empty(tsk)) { | ||
2305 | sigset_t newblocked; | ||
2306 | /* A set of now blocked but previously unblocked signals. */ | ||
2307 | signandsets(&newblocked, newset, ¤t->blocked); | ||
2308 | retarget_shared_pending(tsk, &newblocked); | ||
2309 | } | ||
2310 | tsk->blocked = *newset; | ||
2311 | recalc_sigpending(); | ||
2312 | } | ||
2313 | |||
2302 | /** | 2314 | /** |
2303 | * set_current_blocked - change current->blocked mask | 2315 | * set_current_blocked - change current->blocked mask |
2304 | * @newset: new mask | 2316 | * @newset: new mask |
@@ -2311,14 +2323,7 @@ void set_current_blocked(const sigset_t *newset) | |||
2311 | struct task_struct *tsk = current; | 2323 | struct task_struct *tsk = current; |
2312 | 2324 | ||
2313 | spin_lock_irq(&tsk->sighand->siglock); | 2325 | spin_lock_irq(&tsk->sighand->siglock); |
2314 | if (signal_pending(tsk) && !thread_group_empty(tsk)) { | 2326 | __set_task_blocked(tsk, newset); |
2315 | sigset_t newblocked; | ||
2316 | /* A set of now blocked but previously unblocked signals. */ | ||
2317 | signandsets(&newblocked, newset, ¤t->blocked); | ||
2318 | retarget_shared_pending(tsk, &newblocked); | ||
2319 | } | ||
2320 | tsk->blocked = *newset; | ||
2321 | recalc_sigpending(); | ||
2322 | spin_unlock_irq(&tsk->sighand->siglock); | 2327 | spin_unlock_irq(&tsk->sighand->siglock); |
2323 | } | 2328 | } |
2324 | 2329 | ||
@@ -2541,7 +2546,8 @@ int do_sigtimedwait(const sigset_t *which, siginfo_t *info, | |||
2541 | /* | 2546 | /* |
2542 | * None ready, temporarily unblock those we're interested | 2547 | * None ready, temporarily unblock those we're interested |
2543 | * while we are sleeping in so that we'll be awakened when | 2548 | * while we are sleeping in so that we'll be awakened when |
2544 | * they arrive. | 2549 | * they arrive. Unblocking is always fine, we can avoid |
2550 | * set_current_blocked(). | ||
2545 | */ | 2551 | */ |
2546 | tsk->real_blocked = tsk->blocked; | 2552 | tsk->real_blocked = tsk->blocked; |
2547 | sigandsets(&tsk->blocked, &tsk->blocked, &mask); | 2553 | sigandsets(&tsk->blocked, &tsk->blocked, &mask); |
@@ -2551,10 +2557,9 @@ int do_sigtimedwait(const sigset_t *which, siginfo_t *info, | |||
2551 | timeout = schedule_timeout_interruptible(timeout); | 2557 | timeout = schedule_timeout_interruptible(timeout); |
2552 | 2558 | ||
2553 | spin_lock_irq(&tsk->sighand->siglock); | 2559 | spin_lock_irq(&tsk->sighand->siglock); |
2554 | sig = dequeue_signal(tsk, &mask, info); | 2560 | __set_task_blocked(tsk, &tsk->real_blocked); |
2555 | tsk->blocked = tsk->real_blocked; | ||
2556 | siginitset(&tsk->real_blocked, 0); | 2561 | siginitset(&tsk->real_blocked, 0); |
2557 | recalc_sigpending(); | 2562 | sig = dequeue_signal(tsk, &mask, info); |
2558 | } | 2563 | } |
2559 | spin_unlock_irq(&tsk->sighand->siglock); | 2564 | spin_unlock_irq(&tsk->sighand->siglock); |
2560 | 2565 | ||