public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
@ 2011-06-16  3:50 Zachary Amsden
  2011-06-19 12:44 ` Avi Kivity
  0 siblings, 1 reply; 8+ messages in thread
From: Zachary Amsden @ 2011-06-16  3:50 UTC (permalink / raw)
  To: Avi Kivity, kvm, Linux-kernel, Ulrich Obergfell

[-- Attachment #1: Type: text/plain, Size: 256 bytes --]

The 128-bit multiply in pvclock.h was missing an output constraint for 
EDX which caused a register corruption to appear.  Thanks to Ulrich for 
diagnosing the EDX corruption and Avi for providing this fix (which now 
I am sending back to you Avi..)

Zach

[-- Attachment #2: x86-kvm-pvclock-scale-delta-constraint-fix.patch --]
[-- Type: text/plain, Size: 957 bytes --]

>From Avi and Ulrich, fix constraints for 128-bit multiply

Signed-off-by: Zachary Amsden <zamsden@redhat.com>

diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 31d84ac..a518c0a 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -22,6 +22,8 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
 	u64 product;
 #ifdef __i386__
 	u32 tmp1, tmp2;
+#else
+	ulong tmp;
 #endif
 
 	if (shift < 0)
@@ -42,8 +44,11 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
 		: "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
 #elif defined(__x86_64__)
 	__asm__ (
-		"mul %%rdx ; shrd $32,%%rdx,%%rax"
-		: "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
+		"mul %[mul_frac] ; shrd $32, %[hi], %[lo]"
+		: [lo]"=a"(product),
+		  [hi]"=d"(tmp)
+		: "0"(delta),
+		  [mul_frac]"rm"((u64)mul_frac));
 #else
 #error implement me!
 #endif

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-06-16  3:50 Zachary Amsden
@ 2011-06-19 12:44 ` Avi Kivity
  2011-06-22  9:35   ` Ian Campbell
  0 siblings, 1 reply; 8+ messages in thread
From: Avi Kivity @ 2011-06-19 12:44 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: kvm, Linux-kernel, Ulrich Obergfell

On 06/16/2011 06:50 AM, Zachary Amsden wrote:
> The 128-bit multiply in pvclock.h was missing an output constraint for 
> EDX which caused a register corruption to appear.  Thanks to Ulrich 
> for diagnosing the EDX corruption and Avi for providing this fix 
> (which now I am sending back to you Avi..)

Applied and queued, thanks.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-06-19 12:44 ` Avi Kivity
@ 2011-06-22  9:35   ` Ian Campbell
  2011-06-22  9:39     ` Avi Kivity
  2011-06-22  9:40     ` Avi Kivity
  0 siblings, 2 replies; 8+ messages in thread
From: Ian Campbell @ 2011-06-22  9:35 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Zachary Amsden, kvm, Linux-kernel, Ulrich Obergfell

On Sun, 2011-06-19 at 15:44 +0300, Avi Kivity wrote:
> On 06/16/2011 06:50 AM, Zachary Amsden wrote:
> > The 128-bit multiply in pvclock.h was missing an output constraint for 
> > EDX which caused a register corruption to appear.

Was there any particular symptom associated with corruption at that
particular point or just general badness?

>   Thanks to Ulrich 
> > for diagnosing the EDX corruption and Avi for providing this fix 
> > (which now I am sending back to you Avi..)
> 
> Applied and queued, thanks.

Seems like a stable candidate also?

Ian.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-06-22  9:35   ` Ian Campbell
@ 2011-06-22  9:39     ` Avi Kivity
  2011-06-22  9:40     ` Avi Kivity
  1 sibling, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2011-06-22  9:39 UTC (permalink / raw)
  To: Ian Campbell, Marcelo Tosatti
  Cc: Zachary Amsden, kvm, Linux-kernel, Ulrich Obergfell

On 06/22/2011 12:35 PM, Ian Campbell wrote:
> On Sun, 2011-06-19 at 15:44 +0300, Avi Kivity wrote:
> >  On 06/16/2011 06:50 AM, Zachary Amsden wrote:
> >  >  The 128-bit multiply in pvclock.h was missing an output constraint for
> >  >  EDX which caused a register corruption to appear.
>
> Was there any particular symptom associated with corruption at that
> particular point or just general badness?
>
> >    Thanks to Ulrich
> >  >  for diagnosing the EDX corruption and Avi for providing this fix
> >  >  (which now I am sending back to you Avi..)
> >
> >  Applied and queued, thanks.
>
> Seems like a stable candidate also?

Yes.  I see it's merged; Marcelo, can you backport it?

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-06-22  9:35   ` Ian Campbell
  2011-06-22  9:39     ` Avi Kivity
@ 2011-06-22  9:40     ` Avi Kivity
  2011-06-22  9:52       ` Ian Campbell
  1 sibling, 1 reply; 8+ messages in thread
From: Avi Kivity @ 2011-06-22  9:40 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Zachary Amsden, kvm, Linux-kernel, Ulrich Obergfell

On 06/22/2011 12:35 PM, Ian Campbell wrote:
> On Sun, 2011-06-19 at 15:44 +0300, Avi Kivity wrote:
> >  On 06/16/2011 06:50 AM, Zachary Amsden wrote:
> >  >  The 128-bit multiply in pvclock.h was missing an output constraint for
> >  >  EDX which caused a register corruption to appear.
>
> Was there any particular symptom associated with corruption at that
> particular point or just general badness?
>

Time went backwards and forwards as vcpus were migrated across cpus.

The problem was in the host, not the guest, so Xen should not be affected.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-06-22  9:40     ` Avi Kivity
@ 2011-06-22  9:52       ` Ian Campbell
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Campbell @ 2011-06-22  9:52 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Zachary Amsden, kvm, Linux-kernel, Ulrich Obergfell

On Wed, 2011-06-22 at 10:40 +0100, Avi Kivity wrote:
> On 06/22/2011 12:35 PM, Ian Campbell wrote:
> > On Sun, 2011-06-19 at 15:44 +0300, Avi Kivity wrote:
> > >  On 06/16/2011 06:50 AM, Zachary Amsden wrote:
> > >  >  The 128-bit multiply in pvclock.h was missing an output constraint for
> > >  >  EDX which caused a register corruption to appear.
> >
> > Was there any particular symptom associated with corruption at that
> > particular point or just general badness?
> >
> 
> Time went backwards and forwards as vcpus were migrated across cpus.

Oops!

> The problem was in the host, not the guest, so Xen should not be affected.

Good to know, thanks!

Ian.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
@ 2011-08-30  8:58 Duncan Sands
  2011-08-30 11:39 ` Avi Kivity
  0 siblings, 1 reply; 8+ messages in thread
From: Duncan Sands @ 2011-08-30  8:58 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Linux Kernel Mailing List

Hi Zachary, this patch can cause a compile failure if the compiler chooses to
use a memory location for mul_frac rather than a register (as allowed by the
"m" in the constraints):

   pvclock.s:229: Error: no instruction mnemonic suffix given and no register 
operands; can't size instruction

In this example the assembler is:

         #APP
         mul -48(%rbp) ; shrd $32, %rdx, %rax
         #NO_APP

A simple solution is to use mulq, as in the following patch:

Signed-off-by: Duncan Sands <baldrick@free.fr>

--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -44,7 +44,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, 
int shift)
                 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
  #elif defined(__x86_64__)
         __asm__ (
-               "mul %[mul_frac] ; shrd $32, %[hi], %[lo]"
+               "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
                 : [lo]"=a"(product),
                   [hi]"=d"(tmp)
                 : "0"(delta),

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta
  2011-08-30  8:58 [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta Duncan Sands
@ 2011-08-30 11:39 ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2011-08-30 11:39 UTC (permalink / raw)
  To: Duncan Sands
  Cc: Zachary Amsden, Linux Kernel Mailing List, KVM list,
	Marcelo Tosatti

On 08/30/2011 11:58 AM, Duncan Sands wrote:
> Hi Zachary, this patch can cause a compile failure if the compiler 
> chooses to
> use a memory location for mul_frac rather than a register (as allowed 
> by the
> "m" in the constraints):
>
>   pvclock.s:229: Error: no instruction mnemonic suffix given and no 
> register operands; can't size instruction
>
> In this example the assembler is:
>
>         #APP
>         mul -48(%rbp) ; shrd $32, %rdx, %rax
>         #NO_APP
>
> A simple solution is to use mulq, as in the following patch:
>
> Signed-off-by: Duncan Sands <baldrick@free.fr>
>
> --- a/arch/x86/include/asm/pvclock.h
> +++ b/arch/x86/include/asm/pvclock.h
> @@ -44,7 +44,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 
> mul_frac, int shift)
>                 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" 
> (mul_frac) );
>  #elif defined(__x86_64__)
>         __asm__ (
> -               "mul %[mul_frac] ; shrd $32, %[hi], %[lo]"
> +               "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
>                 : [lo]"=a"(product),
>                   [hi]"=d"(tmp)
>                 : "0"(delta),

Thanks, applied.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-08-30 11:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-30  8:58 [PATCH x86 kvm] Fix register corruption in pvclock_scale_delta Duncan Sands
2011-08-30 11:39 ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2011-06-16  3:50 Zachary Amsden
2011-06-19 12:44 ` Avi Kivity
2011-06-22  9:35   ` Ian Campbell
2011-06-22  9:39     ` Avi Kivity
2011-06-22  9:40     ` Avi Kivity
2011-06-22  9:52       ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox