Re: [RFC][PATCH] Fix a race between rwsem and the scheduler

From: Oleg Nesterov
Date: Tue Aug 30 2016 - 09:05:10 EST


On 08/30, Peter Zijlstra wrote:
>
> /*
> * Ensure we load p->on_rq _after_ p->state, otherwise it would
> * be possible to, falsely, observe p->on_rq == 0 and get stuck
> * in smp_cond_load_acquire() below.
> *
> * sched_ttwu_pending() try_to_wake_up()
> * [S] p->on_rq = 1; [L] P->state
> * UNLOCK rq->lock
> *
> * schedule() RMB
> * LOCK rq->lock
> * UNLOCK rq->lock
> *
> * [task p]
> * [S] p->state = UNINTERRUPTIBLE [L] p->on_rq
> *
> * Pairs with the UNLOCK+LOCK on rq->lock from the
> * last wakeup of our task and the schedule that got our task
> * current.
> */

Confused... how this connects to UNLOCK+LOCK on rq->lock? A LOAD can
leak into the critical section.

But context switch should imply mb() we can rely on?

Oleg.