]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
x86/HVM: use x86emul_write_xcr()
authorJan Beulich <jbeulich@suse.com>
Thu, 22 Mar 2018 09:42:31 +0000 (10:42 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 22 Mar 2018 09:42:31 +0000 (10:42 +0100)
...  instead of directly calling handle_xsetbv(), to make use of the
additional checking there.

Also don't call hvm_monitor_crX(XCR0, ...) for indexes other than zero
anymore.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/hvm/vmx/vmx.c
xen/arch/x86/x86_emulate.c

index 5759c73dd4313b3458a79d8b6e06f0add055de6a..db52312882205e65b32e587106ca795f4bfab2eb 100644 (file)
@@ -1960,10 +1960,11 @@ int hvm_handle_xsetbv(u32 index, u64 new_bv)
 {
     int rc;
 
-    hvm_monitor_crX(XCR0, new_bv, current->arch.xcr0);
+    if ( index == 0 )
+        hvm_monitor_crX(XCR0, new_bv, current->arch.xcr0);
 
-    rc = handle_xsetbv(index, new_bv);
-    if ( rc )
+    rc = x86emul_write_xcr(index, new_bv, NULL);
+    if ( rc != X86EMUL_OKAY )
         hvm_inject_hw_exception(TRAP_gp_fault, 0);
 
     return rc;
index c34f5b53cec8865af5686343fe7639230b12c31f..8538232f68a4ad124982cce383f2c85a12a7d41a 100644 (file)
@@ -2902,7 +2902,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
         if ( vmcb_get_cpl(vmcb) )
             hvm_inject_hw_exception(TRAP_gp_fault, 0);
         else if ( (inst_len = __get_instruction_length(v, INSTR_XSETBV)) &&
-                  hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == 0 )
+                  hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == X86EMUL_OKAY )
             __update_guest_eip(regs, inst_len);
         break;
 
index c5cc96339e0180c1ae7ffcde7937dcc3e4d3c75a..b2fdbf0ef03818c794b68d028c03fdea52b9bccc 100644 (file)
@@ -4078,7 +4078,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
         break;
 
     case EXIT_REASON_XSETBV:
-        if ( hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == 0 )
+        if ( hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == X86EMUL_OKAY )
             update_guest_eip(); /* Safe: XSETBV */
         break;
 
index b086104efd2a3cdfa4a3596e5e9cf2a01ba51d29..0729edca7bc84c88660f8730ba6396f6766ce614 100644 (file)
@@ -66,6 +66,7 @@ int x86emul_read_xcr(unsigned int reg, uint64_t *val,
     return X86EMUL_OKAY;
 }
 
+/* Note: May be called with ctxt=NULL. */
 int x86emul_write_xcr(unsigned int reg, uint64_t val,
                       struct x86_emulate_ctxt *ctxt)
 {
@@ -76,7 +77,8 @@ int x86emul_write_xcr(unsigned int reg, uint64_t val,
 
     default:
     gp_fault:
-        x86_emul_hw_exception(TRAP_gp_fault, 0, ctxt);
+        if ( ctxt )
+            x86_emul_hw_exception(TRAP_gp_fault, 0, ctxt);
         return X86EMUL_EXCEPTION;
     }