----- On Sep 25, 2017, at 8:25 AM, Peter Zijlstra peterz@xxxxxxxxxxxxx wrote: > On Mon, Sep 25, 2017 at 08:10:54PM +0800, Boqun Feng wrote: >> > static void membarrier_register_private_expedited(void) >> > { >> > struct task_struct *p = current; >> > >> > if (READ_ONCE(p->mm->membarrier_private_expedited)) >> > return; >> > membarrier_arch_register_private_expedited(p); > > Should we not then also do: > > barrier(); > >> > WRITE_ONCE(p->mm->membarrier_private_expedited, 1); >> > } > > to avoid the compiler lifting that store? membarrier_arch_register_private_expedited() being a function call, I recall compilers cannot move load/stores across those. Moreover, even if that function would happen to be eventually inlined, synchronize_sched() is needed at the end of the function to ensure the scheduler will observe the thread flags before it returns. That too would then act as a compiler barrier if that function is ever inlined in the future. So do you think we should still add the barrier() as documentation, or is having synchronize_sched() in the callee enough ? By the way, I think I should add a READ_ONCE() in membarrier_private_expedited to pair with the WRITE_ONCE() in registration, such as: if (!READ_ONCE(current->mm->membarrier_private_expedited)) return -EPERM; Thanks! Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com