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>
This commit is contained in:
@@ -2299,6 +2299,18 @@ long do_no_restart_syscall(struct restart_block *param)
|
|||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
|
||||||
|
{
|
||||||
|
if (signal_pending(tsk) && !thread_group_empty(tsk)) {
|
||||||
|
sigset_t newblocked;
|
||||||
|
/* A set of now blocked but previously unblocked signals. */
|
||||||
|
signandsets(&newblocked, newset, ¤t->blocked);
|
||||||
|
retarget_shared_pending(tsk, &newblocked);
|
||||||
|
}
|
||||||
|
tsk->blocked = *newset;
|
||||||
|
recalc_sigpending();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set_current_blocked - change current->blocked mask
|
* set_current_blocked - change current->blocked mask
|
||||||
* @newset: new mask
|
* @newset: new mask
|
||||||
@@ -2311,14 +2323,7 @@ void set_current_blocked(const sigset_t *newset)
|
|||||||
struct task_struct *tsk = current;
|
struct task_struct *tsk = current;
|
||||||
|
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
spin_lock_irq(&tsk->sighand->siglock);
|
||||||
if (signal_pending(tsk) && !thread_group_empty(tsk)) {
|
__set_task_blocked(tsk, newset);
|
||||||
sigset_t newblocked;
|
|
||||||
/* A set of now blocked but previously unblocked signals. */
|
|
||||||
signandsets(&newblocked, newset, ¤t->blocked);
|
|
||||||
retarget_shared_pending(tsk, &newblocked);
|
|
||||||
}
|
|
||||||
tsk->blocked = *newset;
|
|
||||||
recalc_sigpending();
|
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
spin_unlock_irq(&tsk->sighand->siglock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2541,7 +2546,8 @@ int do_sigtimedwait(const sigset_t *which, siginfo_t *info,
|
|||||||
/*
|
/*
|
||||||
* None ready, temporarily unblock those we're interested
|
* None ready, temporarily unblock those we're interested
|
||||||
* while we are sleeping in so that we'll be awakened when
|
* while we are sleeping in so that we'll be awakened when
|
||||||
* they arrive.
|
* they arrive. Unblocking is always fine, we can avoid
|
||||||
|
* set_current_blocked().
|
||||||
*/
|
*/
|
||||||
tsk->real_blocked = tsk->blocked;
|
tsk->real_blocked = tsk->blocked;
|
||||||
sigandsets(&tsk->blocked, &tsk->blocked, &mask);
|
sigandsets(&tsk->blocked, &tsk->blocked, &mask);
|
||||||
@@ -2551,10 +2557,9 @@ int do_sigtimedwait(const sigset_t *which, siginfo_t *info,
|
|||||||
timeout = schedule_timeout_interruptible(timeout);
|
timeout = schedule_timeout_interruptible(timeout);
|
||||||
|
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
spin_lock_irq(&tsk->sighand->siglock);
|
||||||
sig = dequeue_signal(tsk, &mask, info);
|
__set_task_blocked(tsk, &tsk->real_blocked);
|
||||||
tsk->blocked = tsk->real_blocked;
|
|
||||||
siginitset(&tsk->real_blocked, 0);
|
siginitset(&tsk->real_blocked, 0);
|
||||||
recalc_sigpending();
|
sig = dequeue_signal(tsk, &mask, info);
|
||||||
}
|
}
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
spin_unlock_irq(&tsk->sighand->siglock);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user