kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test
@ 2020-01-22  7:39 Oliver Upton
  2020-01-22  9:47 ` Vitaly Kuznetsov
  2020-01-22 14:26 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Oliver Upton @ 2020-01-22  7:39 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Jim Mattson, Oliver Upton, Aaron Lewis

The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based
VM-execution control be allowed on the host. Check this precondition
before running the test rather than asserting it later on to avoid
erroneous failures on a host without TSC offsetting.

Cc: Aaron Lewis <aaronlewis@google.com>
Signed-off-by: Oliver Upton <oupton@google.com>
---
 x86/vmx_tests.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 3b150323b325..de9a931216e2 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
  */
 static void reset_guest_tsc_to_zero(void)
 {
-	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
-			"Expected support for 'use TSC offsetting'");
-
 	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
 	vmcs_write(TSC_OFFSET, -rdtsc());
 }
@@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
 	int fail = 0;
 	int i;
 
+	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
+		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+		return;
+	}
+
 	test_set_guest(rdtsc_vmexit_diff_test_guest);
 
 	reset_guest_tsc_to_zero();
-- 
2.25.0.341.g760bfbb309-goog


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

* Re: [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test
  2020-01-22  7:39 [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test Oliver Upton
@ 2020-01-22  9:47 ` Vitaly Kuznetsov
  2020-01-22  9:51   ` Oliver Upton
  2020-01-22 14:26 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-01-22  9:47 UTC (permalink / raw)
  To: Oliver Upton, kvm; +Cc: Paolo Bonzini, Jim Mattson, Oliver Upton, Aaron Lewis

Oliver Upton <oupton@google.com> writes:

> The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based
> VM-execution control be allowed on the host. Check this precondition
> before running the test rather than asserting it later on to avoid
> erroneous failures on a host without TSC offsetting.
>
> Cc: Aaron Lewis <aaronlewis@google.com>
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>  x86/vmx_tests.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 3b150323b325..de9a931216e2 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
>   */
>  static void reset_guest_tsc_to_zero(void)
>  {
> -	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
> -			"Expected support for 'use TSC offsetting'");
> -
>  	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
>  	vmcs_write(TSC_OFFSET, -rdtsc());
>  }
> @@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
>  	int fail = 0;
>  	int i;
>  
> +	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
> +		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
> +		return;
> +	}
> +

Can we use test_skip() instead, something like

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index dd32b3aef08b..bfecf36d37ef 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -9166,6 +9166,9 @@ static void rdtsc_vmexit_diff_test(void)
        int fail = 0;
        int i;
 
+       if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET))
+               test_skip("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+
        test_set_guest(rdtsc_vmexit_diff_test_guest);
 
        reset_guest_tsc_to_zero();

?

>  	test_set_guest(rdtsc_vmexit_diff_test_guest);
>  
>  	reset_guest_tsc_to_zero();

-- 
Vitaly


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

* Re: [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test
  2020-01-22  9:47 ` Vitaly Kuznetsov
@ 2020-01-22  9:51   ` Oliver Upton
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Upton @ 2020-01-22  9:51 UTC (permalink / raw)
  To: Vitaly Kuznetsov; +Cc: kvm, Paolo Bonzini, Jim Mattson, Aaron Lewis

On Wed, Jan 22, 2020 at 10:47:28AM +0100, Vitaly Kuznetsov wrote:
> Oliver Upton <oupton@google.com> writes:
> 
> > The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based
> > VM-execution control be allowed on the host. Check this precondition
> > before running the test rather than asserting it later on to avoid
> > erroneous failures on a host without TSC offsetting.
> >
> > Cc: Aaron Lewis <aaronlewis@google.com>
> > Signed-off-by: Oliver Upton <oupton@google.com>
> > ---
> >  x86/vmx_tests.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> > index 3b150323b325..de9a931216e2 100644
> > --- a/x86/vmx_tests.c
> > +++ b/x86/vmx_tests.c
> > @@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
> >   */
> >  static void reset_guest_tsc_to_zero(void)
> >  {
> > -	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
> > -			"Expected support for 'use TSC offsetting'");
> > -
> >  	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
> >  	vmcs_write(TSC_OFFSET, -rdtsc());
> >  }
> > @@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
> >  	int fail = 0;
> >  	int i;
> >  
> > +	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
> > +		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
> > +		return;
> > +	}
> > +
> 
> Can we use test_skip() instead, something like
> 
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index dd32b3aef08b..bfecf36d37ef 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -9166,6 +9166,9 @@ static void rdtsc_vmexit_diff_test(void)
>         int fail = 0;
>         int i;
>  
> +       if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET))
> +               test_skip("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
> +
>         test_set_guest(rdtsc_vmexit_diff_test_guest);
>  
>         reset_guest_tsc_to_zero();
> 
> ?

Even better :) Thanks Vitaly!

> >  	test_set_guest(rdtsc_vmexit_diff_test_guest);
> >  
> >  	reset_guest_tsc_to_zero();
> 
> -- 
> Vitaly
> 

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

* Re: [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test
  2020-01-22  7:39 [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test Oliver Upton
  2020-01-22  9:47 ` Vitaly Kuznetsov
@ 2020-01-22 14:26 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-01-22 14:26 UTC (permalink / raw)
  To: Oliver Upton, kvm; +Cc: Jim Mattson, Aaron Lewis

On 22/01/20 08:39, Oliver Upton wrote:
> The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based
> VM-execution control be allowed on the host. Check this precondition
> before running the test rather than asserting it later on to avoid
> erroneous failures on a host without TSC offsetting.
> 
> Cc: Aaron Lewis <aaronlewis@google.com>
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>  x86/vmx_tests.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 3b150323b325..de9a931216e2 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
>   */
>  static void reset_guest_tsc_to_zero(void)
>  {
> -	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
> -			"Expected support for 'use TSC offsetting'");
> -
>  	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
>  	vmcs_write(TSC_OFFSET, -rdtsc());
>  }
> @@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
>  	int fail = 0;
>  	int i;
>  
> +	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
> +		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
> +		return;
> +	}
> +
>  	test_set_guest(rdtsc_vmexit_diff_test_guest);
>  
>  	reset_guest_tsc_to_zero();
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2020-01-22 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-22  7:39 [kvm-unit-tests PATCH] x86: VMX: Check preconditions for RDTSC test Oliver Upton
2020-01-22  9:47 ` Vitaly Kuznetsov
2020-01-22  9:51   ` Oliver Upton
2020-01-22 14:26 ` 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).