kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86: emulator: Fix h_mem usage in tests_smsw
@ 2014-12-02 22:22 Chris J Arges
  2014-12-03  9:15 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Chris J Arges @ 2014-12-02 22:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, namit

In emulator.c/tests_smsw, smsw (3) fails because h_mem isn't being set correctly
before smsw is called. By declaring the h_mem function parameter as volatile,
the compiler no longer optimizes out the assignment before smsw.

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
---
 x86/emulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/emulator.c b/x86/emulator.c
index 5aa4dbf..570628f 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -337,7 +337,7 @@ void test_incdecnotneg(void *mem)
     report("lock notb", *mb == vb);
 }
 
-void test_smsw(uint64_t *h_mem)
+void test_smsw(volatile uint64_t *h_mem)
 {
 	char mem[16];
 	unsigned short msw, msw_orig, *pmsw;
-- 
1.9.1


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

* Re: [kvm-unit-tests PATCH] x86: emulator: Fix h_mem usage in tests_smsw
  2014-12-02 22:22 [kvm-unit-tests PATCH] x86: emulator: Fix h_mem usage in tests_smsw Chris J Arges
@ 2014-12-03  9:15 ` Paolo Bonzini
  2014-12-03 15:44   ` [kvm-unit-tests PATCH v2] " Chris J Arges
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2014-12-03  9:15 UTC (permalink / raw)
  To: Chris J Arges, kvm; +Cc: namit



On 02/12/2014 23:22, Chris J Arges wrote:
> In emulator.c/tests_smsw, smsw (3) fails because h_mem isn't being set correctly
> before smsw is called. By declaring the h_mem function parameter as volatile,
> the compiler no longer optimizes out the assignment before smsw.
> 
> Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
> ---
>  x86/emulator.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/x86/emulator.c b/x86/emulator.c
> index 5aa4dbf..570628f 100644
> --- a/x86/emulator.c
> +++ b/x86/emulator.c
> @@ -337,7 +337,7 @@ void test_incdecnotneg(void *mem)
>      report("lock notb", *mb == vb);
>  }
>  
> -void test_smsw(uint64_t *h_mem)
> +void test_smsw(volatile uint64_t *h_mem)
>  {
>  	char mem[16];
>  	unsigned short msw, msw_orig, *pmsw;
> 

What if you change

        asm volatile("smsw %0" : "=m"(*h_mem));

to

        asm volatile("smsw %0" : "+m"(*h_mem));

Paolo

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

* [kvm-unit-tests PATCH v2] x86: emulator: Fix h_mem usage in tests_smsw
  2014-12-03  9:15 ` Paolo Bonzini
@ 2014-12-03 15:44   ` Chris J Arges
  2014-12-03 15:46     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Chris J Arges @ 2014-12-03 15:44 UTC (permalink / raw)
  To: kvm; +Cc: namit, pbonzini, Chris J Arges

In emulator.c/tests_smsw, smsw (3) fails because h_mem isn't being set correctly
before smsw is called. By using the + constraint modifier for memory we can
ensure the compiler no longer optimizes out the assignment before smsw.

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
---
 x86/emulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/emulator.c b/x86/emulator.c
index 5aa4dbf..1e05574 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -359,7 +359,7 @@ void test_smsw(uint64_t *h_mem)
 
 	/* Trigger exit on smsw */
 	*h_mem = 0x12345678abcdeful;
-	asm volatile("smsw %0" : "=m"(*h_mem));
+	asm volatile("smsw %0" : "+m"(*h_mem));
 	report("smsw (3)", msw == (unsigned short)*h_mem &&
 		(*h_mem & ~0xfffful) == 0x12345678ab0000ul);
 }
-- 
2.1.3


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

* Re: [kvm-unit-tests PATCH v2] x86: emulator: Fix h_mem usage in tests_smsw
  2014-12-03 15:44   ` [kvm-unit-tests PATCH v2] " Chris J Arges
@ 2014-12-03 15:46     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-12-03 15:46 UTC (permalink / raw)
  To: Chris J Arges, kvm; +Cc: namit



On 03/12/2014 16:44, Chris J Arges wrote:
> In emulator.c/tests_smsw, smsw (3) fails because h_mem isn't being set correctly
> before smsw is called. By using the + constraint modifier for memory we can
> ensure the compiler no longer optimizes out the assignment before smsw.
> 
> Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
> ---
>  x86/emulator.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/x86/emulator.c b/x86/emulator.c
> index 5aa4dbf..1e05574 100644
> --- a/x86/emulator.c
> +++ b/x86/emulator.c
> @@ -359,7 +359,7 @@ void test_smsw(uint64_t *h_mem)
>  
>  	/* Trigger exit on smsw */
>  	*h_mem = 0x12345678abcdeful;
> -	asm volatile("smsw %0" : "=m"(*h_mem));
> +	asm volatile("smsw %0" : "+m"(*h_mem));
>  	report("smsw (3)", msw == (unsigned short)*h_mem &&
>  		(*h_mem & ~0xfffful) == 0x12345678ab0000ul);
>  }
> 

Applied, thanks.

Paolo

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

end of thread, other threads:[~2014-12-03 15:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 22:22 [kvm-unit-tests PATCH] x86: emulator: Fix h_mem usage in tests_smsw Chris J Arges
2014-12-03  9:15 ` Paolo Bonzini
2014-12-03 15:44   ` [kvm-unit-tests PATCH v2] " Chris J Arges
2014-12-03 15:46     ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).