[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86/HVM: use x86emul_write_xcr()



commit 3025581f3ad70c153db830d0d80377c294033f63
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Mar 22 10:42:31 2018 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Mar 22 10:42:31 2018 +0100

    x86/HVM: use x86emul_write_xcr()
    
    ...  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@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
    Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
---
 xen/arch/x86/hvm/hvm.c     | 7 ++++---
 xen/arch/x86/hvm/svm/svm.c | 2 +-
 xen/arch/x86/hvm/vmx/vmx.c | 2 +-
 xen/arch/x86/x86_emulate.c | 4 +++-
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 5759c73dd4..db52312882 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -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;
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index c34f5b53ce..8538232f68 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -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;
 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index c5cc96339e..b2fdbf0ef0 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -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;
 
diff --git a/xen/arch/x86/x86_emulate.c b/xen/arch/x86/x86_emulate.c
index b086104efd..0729edca7b 100644
--- a/xen/arch/x86/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate.c
@@ -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;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.