Message ID | 20220915000448.1674802-8-vannapurve@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Execute hypercalls from guests according to cpu type | expand |
On Thu, Sep 15, 2022 at 12:04:47AM +0000, Vishal Annapurve wrote: > Update the vmcall instruction invocation to happen according to the cpu > type. > > Suggested-by: Sean Christopherson <seanjc@google.com> > Signed-off-by: Vishal Annapurve <vannapurve@google.com> > --- > tools/testing/selftests/kvm/include/x86_64/processor.h | 8 ++++++++ > tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c | 2 +- > .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- > tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- What's the reason to use kvm_hypercall() for these tests? All of these are Intel-specific. i.e. is_amd_cpu() will always return false. > 4 files changed, 11 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h > index 18a8a6a2b786..74893a7a80f8 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/processor.h > +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h > @@ -833,6 +833,14 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, > uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, > uint64_t a3); > > +/* > + * Execute vmcall instruction. > + */ > +static inline void vmcall(void) > +{ > + kvm_hypercall(0, 0, 0, 0, 0); > +} > + > void nested_guest_vmcall(void); > > void __vm_xsave_require_permission(int bit, const char *name); > diff --git a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c > index 5abecf06329e..8180711c8684 100644 > --- a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c > +++ b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c > @@ -31,7 +31,7 @@ > static void l2_guest_code(void) > { > /* Exit to L1 */ > - __asm__ __volatile__("vmcall"); > + vmcall(); > } > > static void l1_guest_code(struct vmx_pages *vmx_pages, unsigned long high_gpa) > diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c > index 465a9434d61c..37da9d01d5d6 100644 > --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c > +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c > @@ -76,7 +76,7 @@ static void l2_guest_code(void) > check_tsc_freq(UCHECK_L2); > > /* exit to L1 */ > - __asm__ __volatile__("vmcall"); > + vmcall(); > } > > static void l1_guest_code(struct vmx_pages *vmx_pages) > diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c > index 5943187e8594..00192f564d9b 100644 > --- a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c > +++ b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c > @@ -74,7 +74,7 @@ static void l2_guest_code(void) > check_ia32_tsc_adjust(-2 * TSC_ADJUST_VALUE); > > /* Exit to L1 */ > - __asm__ __volatile__("vmcall"); > + vmcall(); > } > > static void l1_guest_code(struct vmx_pages *vmx_pages) > -- > 2.37.2.789.g6183377224-goog >
On Wed, Sep 21, 2022 at 2:43 PM David Matlack <dmatlack@google.com> wrote: > > On Thu, Sep 15, 2022 at 12:04:47AM +0000, Vishal Annapurve wrote: > > Update the vmcall instruction invocation to happen according to the cpu > > type. > > > > Suggested-by: Sean Christopherson <seanjc@google.com> > > Signed-off-by: Vishal Annapurve <vannapurve@google.com> > > --- > > tools/testing/selftests/kvm/include/x86_64/processor.h | 8 ++++++++ > > tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c | 2 +- > > .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- > > tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- > > What's the reason to use kvm_hypercall() for these tests? All of these > are Intel-specific. i.e. is_amd_cpu() will always return false. > That's right. This change is attempting to have hypercalls from guest code done via a common API as far as possible. > > 4 files changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h > > ... > > -- > > 2.37.2.789.g6183377224-goog > >
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 18a8a6a2b786..74893a7a80f8 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -833,6 +833,14 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); +/* + * Execute vmcall instruction. + */ +static inline void vmcall(void) +{ + kvm_hypercall(0, 0, 0, 0, 0); +} + void nested_guest_vmcall(void); void __vm_xsave_require_permission(int bit, const char *name); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c index 5abecf06329e..8180711c8684 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c @@ -31,7 +31,7 @@ static void l2_guest_code(void) { /* Exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages, unsigned long high_gpa) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c index 465a9434d61c..37da9d01d5d6 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c @@ -76,7 +76,7 @@ static void l2_guest_code(void) check_tsc_freq(UCHECK_L2); /* exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c index 5943187e8594..00192f564d9b 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c @@ -74,7 +74,7 @@ static void l2_guest_code(void) check_ia32_tsc_adjust(-2 * TSC_ADJUST_VALUE); /* Exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages)
Update the vmcall instruction invocation to happen according to the cpu type. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Vishal Annapurve <vannapurve@google.com> --- tools/testing/selftests/kvm/include/x86_64/processor.h | 8 ++++++++ tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c | 2 +- .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-)