[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210604153609.GF1676809@rowland.harvard.edu>
Date:   Fri, 4 Jun 2021 11:36:09 -0400
From:   Alan Stern <stern@...land.harvard.edu>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Will Deacon <will@...nel.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        paulmck@...nel.org, parri.andrea@...il.com, boqun.feng@...il.com,
        npiggin@...il.com, dhowells@...hat.com, j.alglave@....ac.uk,
        luc.maranget@...ia.fr, akiyks@...il.com,
        linux-kernel@...r.kernel.org, linux-toolchains@...r.kernel.org,
        linux-arch@...r.kernel.org
Subject: Re: [RFC] LKMM: Add volatile_if()
On Fri, Jun 04, 2021 at 05:22:04PM +0200, Peter Zijlstra wrote:
> On Fri, Jun 04, 2021 at 04:13:57PM +0100, Will Deacon wrote:
> 
> > In fact, maybe it's actually necessary to bundle the load and branch
> > together. I looked at some of the examples of compilers breaking control
> > dependencies from memory-barriers.txt and the "boolean short-circuit"
> > example seems to defeat volatile_if:
> > 
> > void foo(int *x, int *y)
> > {
> >         volatile_if (READ_ONCE(*x) || 1 > 0)
> >                 WRITE_ONCE(*y, 42);
> > }  
> 
> Yeah, I'm not too bothered about this. Broken is broken.
> 
> If this were a compiler feature, the above would be a compile error. But
> alas, we're not there yet :/ and the best we get to say at this point
> is: don't do that then.
This is an example of a "syntactic" dependency versus a "semantic" 
dependency.  We shouldn't expect syntactic control dependencies to be 
preserved.
As a rule, people don't write non-semantic dependencies on purpose.  But 
they can occur in some situations, thanks to definitions the programmer 
isn't aware of.  One example would be:
(In some obscure header file): #define NUM_FOO 1
(Then in real code): if (READ_ONCE(*x) % NUM_FOO) ...
Alan
Powered by blists - more mailing lists
 
