Re: [PATCH v2] locking/rwsem: add acquire barrier to read_slowpath exit when queue is empty

From: Peter Zijlstra
Date: Thu Jul 18 2019 - 07:04:53 EST


On Thu, Jul 18, 2019 at 06:50:52AM -0400, Jan Stancek wrote:
> > In writing this, I also noticed that we don't have any explicit ordering
> > at the end of the reader slowpath when we wait on the queue but get woken
> > immediately:
> >
> > if (!waiter.task)
> > break;
> >
> > Am I missing something?
>
> I'm assuming this isn't problem, because set_current_state() on line above
> is using smp_store_mb().


X = 0;

X = 1;
rwsem_down_read() rwsem_up_write();

for (;;) {
set_current_state(TASK_UNINTERRUPTIBLE);

rwsem_mark_wake()
atomic_long_add(adjustment, &sem->count);
smp_store_release(&waiter->task, NULL);

if (!waiter.task)
break;

...
}


r = X;


can I think result in r==0 just fine, because there's nothing ordering
the load of waiter.task with the store of X.

It is exceedingly unlikely, but not impossible afaict.