lkml.org 
[lkml]   [2015]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kernel: fix data race in put_pid
On Fri, Sep 18, 2015 at 03:44:53PM +0200, Oleg Nesterov wrote:
> On 09/18, Peter Zijlstra wrote:
> > +static inline int atomic_read_ctrl(atomic_t *v)
> > +{
> > + int val = atomic_read(v);
> > + smp_read_barrier_depends(); /* Enforce control dependency. */
> > + return val;
> > +}
>
> Help. I am starting to think that the control dependencies is even more
> hard to understand that memory barriers...

Hehe, think of then as a load-store barrier; due to the 'impossibility'
of speculative stores (we'd see all kinds of random crap if you could
speculate stores).

> So I assume that if we have
>
> int X = 0;
> atomic_t Y = ATOMIC_INIT(0);
>
> void w(void)
> {
> X = 1;
> atomic_inc_return(&Y);
> }
>
> then
>
> void r(void)
> {
> if (atomic_read_ctrl(&Y))
> BUG_ON(X == 0);
> }
>
> should be correct? Why?

Nope, because its (again) a load-load order you have there.


\
 
 \ /
  Last update: 2015-09-18 16:21    [W:0.092 / U:0.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site