Re: [RESEND][v2][PATCH] Fix a race between try_to_wake_up() and a woken up task
From: Benjamin Herrenschmidt
Date: Mon Sep 05 2016 - 03:15:08 EST
On Mon, 2016-09-05 at 13:16 +1000, Balbir Singh wrote:
Â.../...
>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Nicholas Piggin <npiggin@xxxxxxxxx>
Acked-by: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Balbir Singh <bsingharora@xxxxxxxxx>
> ---
> Âkernel/sched/core.c | 11 +++++++++++
> Â1 file changed, 11 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 2a906f2..582c684 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2016,6 +2016,17 @@ try_to_wake_up(struct task_struct *p, unsigned
> int state, int wake_flags)
> Â success = 1; /* we're going to change ->state */
> Â cpu = task_cpu(p);
> Â
> + /*
> + Â* Ensure we see on_rq and p_state consistently
> + Â*
> + Â* For example in __rwsem_down_write_failed(), we have
> + Â*ÂÂÂÂ[S] ->on_rq = 1 [L]
> ->state
> + Â*ÂÂÂÂMB ÂRMB
> + Â*ÂÂÂÂ[S] ->state = TASK_UNINTERRUPTIBLE [L] ->on_rq
> + Â* In the absence of the RMB p->on_rq can be observed to be
> 0
> + Â* and we end up spinning indefinitely in while (p->on_cpu)
> + Â*/
> + smp_rmb();
> Â if (p->on_rq && ttwu_remote(p, wake_flags))
> Â goto stat;
> Â