Re: [patch 134/149] x86, paravirt: Add a global synchronization point for pvclock

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Tuesday, July 13, 2010 - 9:34 am

On Tue, Jul 13, 2010 at 8:57 AM, Avi Kivity <avi@redhat.com> wrote:

I bet it is the same. And I have a suspicion: because the only write
access to that variable is in an asm that uses the "memory" clobber to
say it wrote to it (rather than say it writes to it directly), and
because the variable is marked 'static', gcc decides that nothing ever
writes to it in that compilation unit, and it can be made read-only.

Look at our definition for "xchg()" in
arch/x86/include/asm/cmpxchg_64.h. It boils down to

                asm volatile("xchgq %0,%1"                              \
                             : "=r" (__x)                               \
                             : "m" (*__xg(ptr)), "0" (__x)              \
                             : "memory");                               \

for the 8-byte case (which is obviously what atomic64_xchg() uses).
And the _reason_ we do that thing where we use a memory _input_ and
then a clobber is that older versions of gcc did not accept the thing
we _want_ to use, namely using "+m" to say that we actually change the
memory.  So the above is "wrong", but has historical reasons - and
it's apparently never been changed.

However, the "+m" was fixed, and we use it elsewhere, so I think the
"m" plus memory clobber is now purely historical. Does a patch
something like the appended fix it? I also suspect we should look at
some other uses in this area. The atomic64_64.h file uses "=m" and
"m", which looks like another legacy thing (again, "+m" historically
wasn't allowed, and then later became the 'correct' way to do things).

NOTE NOTE NOTE! This is UNTESTED and INCOMPLETE. We should do cmpxchg
too, and the 32-bit versions. I'm adding Ingo and Peter to the cc.

                     Linus
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Linus Torvalds, (Tue Jul 13, 9:34 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Tue Jul 13, 11:21 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Tue Jul 13, 4:49 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 10:19 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 10:34 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 10:57 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 11:15 am)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 1:40 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 1:58 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 2:11 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 2:11 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Wed Jul 14, 2:11 pm)
Re: [patch 134/149] x86, paravirt: Add a global synchroniz ..., Jeremy Fitzhardinge, (Tue Jul 27, 10:46 am)
xchg() and cmpxchg(), H. Peter Anvin, (Tue Jul 27, 4:57 pm)
[tip:x86/urgent] x86: Add memory modify constraints to xch ..., tip-bot for H. Peter ..., (Tue Jul 27, 10:33 pm)
[tip:x86/asm] x86, asm: Clean up and simplify &lt;asm/cmpxchg.h&gt;, tip-bot for H. Peter ..., (Wed Jul 28, 4:28 pm)
[tip:x86/asm] x86, asm: Move cmpxchg emulation code to arc ..., tip-bot for H. Peter ..., (Thu Jul 29, 1:12 pm)
[tip:x86/asm] x86, asm: Merge cmpxchg_486_u64() and cmpxch ..., tip-bot for H. Peter ..., (Thu Jul 29, 1:13 pm)
Re: [tip:x86/urgent] x86: Add memory modify constraints to ..., Jeremy Fitzhardinge, (Mon Aug 2, 4:51 pm)
Re: [stable] [tip:x86/urgent] x86: Add memory modify const ..., Tomáš Janoušek, (Thu Sep 9, 12:53 pm)
Re: [stable] [tip:x86/urgent] x86: Add memory modify const ..., Tomáš Janoušek, (Thu Sep 9, 2:09 pm)
Re: [stable] [tip:x86/urgent] x86: Add memory modify const ..., Tomáš Janoušek, (Fri Sep 10, 6:10 am)
Re: [stable] [tip:x86/urgent] x86: Add memory modify const ..., Tomáš Janoušek, (Fri Sep 24, 12:17 am)