Re: Potentially missing "memory" clobbers in bitops.h for x86

From: H. Peter Anvin
Date: Fri Mar 29 2019 - 17:51:49 EST


On 3/29/19 2:09 PM, Paul E. McKenney wrote:
>>
>> Note: the atomic versions of these functions obviously need to have
>> "volatile" and the clobber anyway, as they are by definition barriers
>> and moving memory operations around them would be a very serious error.
>
> The atomic functions that return void don't need to order anything except
> the input and output arguments. The oddness with clear_bit() is that the
> memory changed isn't necessarily the quantity referenced by the argument,
> if the number of bits specified is large.
>
> So (for example) atomic_inc() does not need a "memory" clobber, right?
>

I don't believe that is true: the code calling it has a reasonable
expectation that previous memory operations have finished and later
memory operations have not started from the point of view of another
processor. You are more of an expert on memory ordering than I am, but
I'm 89% sure that there is plenty of code in the kernel which makes that
assumption.

-hpa