All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: fix rdtsc() for vmx_tsc_adjust_test
@ 2020-06-01 15:47 Vitaly Kuznetsov
  2020-06-01 15:59 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Kuznetsov @ 2020-06-01 15:47 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Makarand Sonare

vmx_tsc_adjust_test fails with:

IA32_TSC_ADJUST is -4294969448 (-1 * TSC_ADJUST_VALUE + -2152).
IA32_TSC_ADJUST is -4294969448 (-1 * TSC_ADJUST_VALUE + -2152).
IA32_TSC_ADJUST is 281470681738540 (65534 * TSC_ADJUST_VALUE + 4294962476).
==== Test Assertion Failure ====
  x86_64/vmx_tsc_adjust_test.c:153: false
  pid=19738 tid=19738 - Interrupted system call
     1	0x0000000000401192: main at vmx_tsc_adjust_test.c:153
     2	0x00007fe1ef8583d4: ?? ??:0
     3	0x0000000000401201: _start at ??:?
  Failed guest assert: (adjust <= max)

The problem is that is 'tsc_val' should be u64, not u32 or the reading
gets truncated.

Fixes: 8d7fbf01f9afc ("KVM: selftests: VMX preemption timer migration test")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 tools/testing/selftests/kvm/include/x86_64/processor.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 7cb19eca6c72..82b7fe16a824 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -79,7 +79,7 @@ static inline uint64_t get_desc64_base(const struct desc64 *desc)
 static inline uint64_t rdtsc(void)
 {
 	uint32_t eax, edx;
-	uint32_t tsc_val;
+	uint64_t tsc_val;
 	/*
 	 * The lfence is to wait (on Intel CPUs) until all previous
 	 * instructions have been executed. If software requires RDTSC to be
-- 
2.25.4


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

* Re: [PATCH] KVM: selftests: fix rdtsc() for vmx_tsc_adjust_test
  2020-06-01 15:47 [PATCH] KVM: selftests: fix rdtsc() for vmx_tsc_adjust_test Vitaly Kuznetsov
@ 2020-06-01 15:59 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-06-01 15:59 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Makarand Sonare

On 01/06/20 17:47, Vitaly Kuznetsov wrote:
> vmx_tsc_adjust_test fails with:
> 
> IA32_TSC_ADJUST is -4294969448 (-1 * TSC_ADJUST_VALUE + -2152).
> IA32_TSC_ADJUST is -4294969448 (-1 * TSC_ADJUST_VALUE + -2152).
> IA32_TSC_ADJUST is 281470681738540 (65534 * TSC_ADJUST_VALUE + 4294962476).
> ==== Test Assertion Failure ====
>   x86_64/vmx_tsc_adjust_test.c:153: false
>   pid=19738 tid=19738 - Interrupted system call
>      1	0x0000000000401192: main at vmx_tsc_adjust_test.c:153
>      2	0x00007fe1ef8583d4: ?? ??:0
>      3	0x0000000000401201: _start at ??:?
>   Failed guest assert: (adjust <= max)
> 
> The problem is that is 'tsc_val' should be u64, not u32 or the reading
> gets truncated.
> 
> Fixes: 8d7fbf01f9afc ("KVM: selftests: VMX preemption timer migration test")
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  tools/testing/selftests/kvm/include/x86_64/processor.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
> index 7cb19eca6c72..82b7fe16a824 100644
> --- a/tools/testing/selftests/kvm/include/x86_64/processor.h
> +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
> @@ -79,7 +79,7 @@ static inline uint64_t get_desc64_base(const struct desc64 *desc)
>  static inline uint64_t rdtsc(void)
>  {
>  	uint32_t eax, edx;
> -	uint32_t tsc_val;
> +	uint64_t tsc_val;
>  	/*
>  	 * The lfence is to wait (on Intel CPUs) until all previous
>  	 * instructions have been executed. If software requires RDTSC to be
> 

Pushed, thanks.

Paolo


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

end of thread, other threads:[~2020-06-01 15:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 15:47 [PATCH] KVM: selftests: fix rdtsc() for vmx_tsc_adjust_test Vitaly Kuznetsov
2020-06-01 15:59 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.