From: Linus Torvalds on


On Wed, 30 Sep 2009, Eric Dumazet wrote:
> > +#define cmpxchg64(ptr, o, n) \
> > +({ \
> > + __typeof__(*(ptr)) __ret; \
> > + __typeof__(*(ptr)) __old = (o); \
> > + __typeof__(*(ptr)) __new = (n); \
> > + alternative_io("call cmpxchg8b_emu", \
> > + "lock; cmpxchg8b (%%esi)" , \
> > + X86_FEATURE_CX8, \
> > + "=A" (__ret), \
> > + "S" ((ptr)), "0" (__old), \
> > + "b" ((unsigned int)__new), \
> > + "c" ((unsigned int)(__new>>32))); \
>
> probably a "memory" clobber is needed, alternative_io() doesnt provide it.

Yeah, good catch.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Linus Torvalds on


On Wed, 30 Sep 2009, Arjan van de Ven wrote:
> +ENTRY(cmpxchg8b_emu)
> + CFI_STARTPROC
> +
> + push %edi
> + push %ebx
> + push %ecx
> + /* disable interrupts */
> + pushf
> + pop %edi
> + cli
> +
> + cmpl %edx, 4(%esi)
> + jne 1f
> + cmpl %eax, (%esi)
> + jne 1f
> +
> + xchg (%esi), %ebx
> + xchg 4(%esi), %ecx
> + mov %ebx, %eax
> + mov %ecx, %edx

Ok, so why do you do this? You've just checked that the 8 bytes at esi are
the same as edx:eax, why do you do that odd xchg?

Why isn't this part just

mov %ebx,(%esi)
mov %ecx,4(%esi)

and leave ebx/ecx alone?

I also don't see why you play games with eflags and %edi. Just leave the
flags on the stack. So it all would look like

#
# Emulate 'cmpxchg8b (%esi)' except we don't
# set the whole ZF thing (caller will just
# compare eax:edx with the expected value)
#
cmpxchg8b_emu:
pushfl
cli
cmpl (%esi),%eax
jne not_same
cmpl 4(%esi),%edx
jne not_same
movl %ebx,(%esi)
movl %ecx,4(%esi)
popfl
ret
not_same:
movl (%esi),%eax
movl 4(%esi),%edx
popfl
ret

I dunno. You _could_ use edi/ebp as a temporary for 'dest' to only do the
load once (and add push/pop to save the registers), but it's not like the
above is really atomic anyway, and it very much depends on 'cli' just
making sure that nothing else happens. So the above seems to be the
simplest emulation, considering the interfaces..

UNTESTED! I wrote this in an email editor. I haven't assembled it or
verified the semantics or workingness in any way, shape or form.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Ingo Molnar on

* Ingo Molnar <mingo(a)elte.hu> wrote:

> * Linus Torvalds <torvalds(a)linux-foundation.org> wrote:
>
> > On Wed, 30 Sep 2009, Eric Dumazet wrote:
> > > > +#define cmpxchg64(ptr, o, n) \
> > > > +({ \
> > > > + __typeof__(*(ptr)) __ret; \
> > > > + __typeof__(*(ptr)) __old = (o); \
> > > > + __typeof__(*(ptr)) __new = (n); \
> > > > + alternative_io("call cmpxchg8b_emu", \
> > > > + "lock; cmpxchg8b (%%esi)" , \
> > > > + X86_FEATURE_CX8, \
> > > > + "=A" (__ret), \
> > > > + "S" ((ptr)), "0" (__old), \
> > > > + "b" ((unsigned int)__new), \
> > > > + "c" ((unsigned int)(__new>>32))); \
> > >
> > > probably a "memory" clobber is needed, alternative_io() doesnt provide it.
> >
> > Yeah, good catch.
>
> Yeah - i'm testing this right now, it looks like something that could
> explain the hang.

Yeah - that was the cause of the hang.

I've pushed out the updated patches - they should show up in this thread
soon. I also updated the emulation implementation to your simpler
variant. (will test that too)

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Linus Torvalds on


On Wed, 30 Sep 2009, Eric Dumazet wrote:
>
> Yes, I provided following version in my first answer but apparently it
> was too complex :)

It wasn't too complex, but YOU QUOTED THE WHOL F*CKING EMAIL.

I don't know about anybody else, but if I see a couple of screenfuls of
quotes, with no actual interesting new data, I just move on. I suspect
everybody else did too.

I really don't understand people who can't edit down their answer and only
quote the relevant parts. It makes it impossible to read the reply,
because it's hidden by all the old quoting.

Please spend the time to edit quoting levels, because otherwise people
won't spend the time to look at your new text.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Ingo Molnar on

* Linus Torvalds <torvalds(a)linux-foundation.org> wrote:

> On Wed, 30 Sep 2009, Eric Dumazet wrote:
> >
> > Yes, I provided following version in my first answer but apparently
> > it was too complex :)
>
> It wasn't too complex, but YOU QUOTED THE WHOL F*CKING EMAIL.
>
> I don't know about anybody else, but if I see a couple of screenfuls
> of quotes, with no actual interesting new data, I just move on. I
> suspect everybody else did too.

Yeah, i too missed it while reading through the thread.

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/