]> git.itanic.dy.fi Git - linux-stable/commitdiff
KVM: selftests: Move the function doing Hyper-V hypercall to a common header
authorVitaly Kuznetsov <vkuznets@redhat.com>
Tue, 1 Nov 2022 14:54:10 +0000 (15:54 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 18 Nov 2022 18:05:17 +0000 (13:05 -0500)
All Hyper-V specific tests issuing hypercalls need this.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221101145426.251680-33-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/x86_64/hyperv.h
tools/testing/selftests/kvm/x86_64/hyperv_features.c

index f0a8a93694b2b032babde1e5cd0d1dbcace7d0c9..7ed8f4f5f7d893848fcb168a6eb15bea2eb49c3a 100644 (file)
 /* hypercall options */
 #define HV_HYPERCALL_FAST_BIT          BIT(16)
 
+static inline uint8_t hyperv_hypercall(u64 control, vm_vaddr_t input_address,
+                                      vm_vaddr_t output_address,
+                                      uint64_t *hv_status)
+{
+       uint64_t error_code;
+       uint8_t vector;
+
+       /* Note both the hypercall and the "asm safe" clobber r9-r11. */
+       asm volatile("mov %[output_address], %%r8\n\t"
+                    KVM_ASM_SAFE("vmcall")
+                    : "=a" (*hv_status),
+                      "+c" (control), "+d" (input_address),
+                      KVM_ASM_SAFE_OUTPUTS(vector, error_code)
+                    : [output_address] "r"(output_address),
+                      "a" (-EFAULT)
+                    : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS);
+       return vector;
+}
+
 /* Proper HV_X64_MSR_GUEST_OS_ID value */
 #define HYPERV_LINUX_OS_ID ((u64)0x8100 << 48)
 
index 6558cc61cf69fa75cf5cd6e89e0e95348f5196ee..5ff4ff2365bb32e1738de0f21afae17f6186204a 100644 (file)
 #include "processor.h"
 #include "hyperv.h"
 
-static inline uint8_t hypercall(u64 control, vm_vaddr_t input_address,
-                               vm_vaddr_t output_address, uint64_t *hv_status)
-{
-       uint64_t error_code;
-       uint8_t vector;
-
-       /* Note both the hypercall and the "asm safe" clobber r9-r11. */
-       asm volatile("mov %[output_address], %%r8\n\t"
-                    KVM_ASM_SAFE("vmcall")
-                    : "=a" (*hv_status),
-                      "+c" (control), "+d" (input_address),
-                      KVM_ASM_SAFE_OUTPUTS(vector, error_code)
-                    : [output_address] "r"(output_address),
-                      "a" (-EFAULT)
-                    : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS);
-       return vector;
-}
-
 struct msr_data {
        uint32_t idx;
        bool available;
@@ -80,7 +62,7 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall)
                input = output = 0;
        }
 
-       vector = hypercall(hcall->control, input, output, &res);
+       vector = hyperv_hypercall(hcall->control, input, output, &res);
        if (hcall->ud_expected) {
                GUEST_ASSERT_2(vector == UD_VECTOR, hcall->control, vector);
        } else {