Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr

H. Peter Anvin
2008-06-26T00:17:28Z

Jeremy Fitzhardinge wrote:
>>
>> Actually, I believe the barrier(); before is actually incorrect, since
>> it would affect the wrmsr() register arguments rather than the wrmsr
>> instruction itself.
>
> How so? What kind of failure do think might occur? Some effect on how
> the wrmsr arguments are evaluated?
>
> barrier() is specifically a compiler optimisation barrier, so the
> barrier before would prevent the compiler from moving anything logically
> before the wrmsr to afterwards.
>

The barrier() before prevents the compiler from optimizing the access to
the arguments (before they go into registers), not the actual wrmsr;
this has to do with the ordering of operations around the barrier above.
The barrier *after* does what you just describe.

> That said, making the wrmsr itself a memory clobber may be simpler
> understand with a comment, rather than separate barriers...

This should be functionally equivalent to a barrier(); after, and given
that this is clearly a point of confusion *already*, I think the memory
clobber is better.

-hpa