Re: [PATCH] task_work: only grab task signal lock when needed
From: Peter Zijlstra
Date: Wed Aug 12 2020 - 16:07:01 EST
On Wed, Aug 12, 2020 at 04:54:23PM +0200, Oleg Nesterov wrote:
> I see nothing better than the additional change below. Peter, do you see
> another solution?
Nope -- although I don't claim to understand the signal code much.
> This needs a comment to explain that this mb() pairs with another barrier
> provided by cmpxchg() in task_work_add(). It ensures that either get_signal()
> sees the new work added by task_work_add(), or task_work_add() sees the
> result of "&= ~JOBCTL_TASK_WORK".
>
> Oleg.
>
> --- x/kernel/signal.c
> +++ x/kernel/signal.c
> @@ -2541,7 +2541,7 @@ bool get_signal(struct ksignal *ksig)
>
> relock:
> spin_lock_irq(&sighand->siglock);
> - current->jobctl &= ~JOBCTL_TASK_WORK;
> + smp_store_mb(current->jobctl, current->jobctl & ~JOBCTL_TASK_WORK);
> if (unlikely(current->task_works)) {
> spin_unlock_irq(&sighand->siglock);
> task_work_run();
>
I agree this should work; smp_store_mb() isn't my favourite primitive,
but yes, this seems as good a use of it as there is so why not.