It is only used by Intel, not on AMD CPUs.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/arch/x86/include/asm/vcpu.h |  2 --
 hypervisor/arch/x86/vcpu.c             | 22 ----------------------
 hypervisor/arch/x86/vmx.c              | 23 ++++++++++++++++++++++-
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/hypervisor/arch/x86/include/asm/vcpu.h 
b/hypervisor/arch/x86/include/asm/vcpu.h
index f1d7a4d..3194bfc 100644
--- a/hypervisor/arch/x86/include/asm/vcpu.h
+++ b/hypervisor/arch/x86/include/asm/vcpu.h
@@ -114,8 +114,6 @@ bool vcpu_handle_msr_write(void);
 
 void vcpu_handle_cpuid(void);
 
-bool vcpu_handle_xsetbv(void);
-
 void vcpu_reset(unsigned int sipi_vector);
 void vcpu_vendor_reset(unsigned int sipi_vector);
 
diff --git a/hypervisor/arch/x86/vcpu.c b/hypervisor/arch/x86/vcpu.c
index 7c52afb..e6e2b1d 100644
--- a/hypervisor/arch/x86/vcpu.c
+++ b/hypervisor/arch/x86/vcpu.c
@@ -341,28 +341,6 @@ void vcpu_handle_cpuid(void)
        vcpu_skip_emulated_instruction(X86_INST_LEN_CPUID);
 }
 
-bool vcpu_handle_xsetbv(void)
-{
-       union registers *guest_regs = &this_cpu_data()->guest_regs;
-
-       this_cpu_data()->stats[JAILHOUSE_CPU_STAT_VMEXITS_XSETBV]++;
-
-       if (cpuid_ecx(1, 0) & X86_FEATURE_XSAVE &&
-           guest_regs->rax & X86_XCR0_FP &&
-           (guest_regs->rax & ~cpuid_eax(0x0d, 0)) == 0 &&
-            guest_regs->rcx == 0 && guest_regs->rdx == 0) {
-               vcpu_skip_emulated_instruction(X86_INST_LEN_XSETBV);
-               asm volatile(
-                       "xsetbv"
-                       : /* no output */
-                       : "a" (guest_regs->rax), "c" (0), "d" (0));
-               return true;
-       }
-       panic_printk("FATAL: Invalid xsetbv parameters: xcr[%d] = %08x:%08x\n",
-                    guest_regs->rcx, guest_regs->rdx, guest_regs->rax);
-       return false;
-}
-
 void vcpu_reset(unsigned int sipi_vector)
 {
        struct per_cpu *cpu_data = this_cpu_data();
diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c
index e77c97a..33f48b9 100644
--- a/hypervisor/arch/x86/vmx.c
+++ b/hypervisor/arch/x86/vmx.c
@@ -1029,6 +1029,26 @@ static bool vmx_handle_apic_access(void)
        return false;
 }
 
+static bool vmx_handle_xsetbv(void)
+{
+       union registers *guest_regs = &this_cpu_data()->guest_regs;
+
+       if (cpuid_ecx(1, 0) & X86_FEATURE_XSAVE &&
+           guest_regs->rax & X86_XCR0_FP &&
+           (guest_regs->rax & ~cpuid_eax(0x0d, 0)) == 0 &&
+            guest_regs->rcx == 0 && guest_regs->rdx == 0) {
+               vcpu_skip_emulated_instruction(X86_INST_LEN_XSETBV);
+               asm volatile(
+                       "xsetbv"
+                       : /* no output */
+                       : "a" (guest_regs->rax), "c" (0), "d" (0));
+               return true;
+       }
+       panic_printk("FATAL: Invalid xsetbv parameters: xcr[%d] = %08x:%08x\n",
+                    guest_regs->rcx, guest_regs->rdx, guest_regs->rax);
+       return false;
+}
+
 static void dump_vm_exit_details(u32 reason)
 {
        panic_printk("qualification %x\n", vmcs_read64(EXIT_QUALIFICATION));
@@ -1127,7 +1147,8 @@ void vcpu_handle_exit(struct per_cpu *cpu_data)
                        return;
                break;
        case EXIT_REASON_XSETBV:
-               if (vcpu_handle_xsetbv())
+               cpu_data->stats[JAILHOUSE_CPU_STAT_VMEXITS_XSETBV]++;
+               if (vmx_handle_xsetbv())
                        return;
                break;
        case EXIT_REASON_IO_INSTRUCTION:
-- 
2.1.4

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to