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

[Xen-changelog] [xen master] x86/emul: Move CPUID Faulting fault generation into the emulator



commit 9f47f3d69f4dcb2b33ccb8fb20057152302ea1ad
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Oct 26 12:06:44 2016 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Oct 26 14:41:37 2016 +0100

    x86/emul: Move CPUID Faulting fault generation into the emulator
    
    In hindsight, this is a better position for it, as it avoids opencoding
    hvmemul_inject_hw_exception() in hvmemul_cpuid(), and reduces the 
requirements
    on other ops->cpuid() hooks wanting to implement cpuid faulting in the 
future.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Release-acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/hvm/emulate.c             | 11 -----------
 xen/arch/x86/x86_emulate/x86_emulate.c |  5 ++++-
 xen/arch/x86/x86_emulate/x86_emulate.h |  7 ++++++-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 70c8d44..5b408f8 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1556,18 +1556,7 @@ static int hvmemul_cpuid(
      */
     if ( ctxt->opcode == X86EMUL_OPC(0x0f, 0xa2) &&
          hvm_check_cpuid_faulting(current) )
-    {
-        struct hvm_emulate_ctxt *hvmemul_ctxt =
-            container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
-
-        hvmemul_ctxt->exn_pending = 1;
-        hvmemul_ctxt->trap.vector = TRAP_gp_fault;
-        hvmemul_ctxt->trap.type = X86_EVENTTYPE_HW_EXCEPTION;
-        hvmemul_ctxt->trap.error_code = 0;
-        hvmemul_ctxt->trap.insn_len = 0;
-
         return X86EMUL_EXCEPTION;
-    }
 
     hvm_funcs.cpuid_intercept(eax, ebx, ecx, edx);
     return X86EMUL_OKAY;
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 94886be..7a707dc 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4995,7 +4995,10 @@ x86_emulate(
         unsigned int eax = _regs.eax, ebx = _regs.ebx;
         unsigned int ecx = _regs.ecx, edx = _regs.edx;
         fail_if(ops->cpuid == NULL);
-        if ( (rc = ops->cpuid(&eax, &ebx, &ecx, &edx, ctxt)) != 0 )
+        rc = ops->cpuid(&eax, &ebx, &ecx, &edx, ctxt);
+        generate_exception_if(rc == X86EMUL_EXCEPTION,
+                              EXC_GP, 0); /* CPUID Faulting? */
+        if ( rc != X86EMUL_OKAY )
             goto done;
         _regs.eax = eax; _regs.ebx = ebx;
         _regs.ecx = ecx; _regs.edx = edx;
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h 
b/xen/arch/x86/x86_emulate/x86_emulate.h
index 7435f42..993c576 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.h
+++ b/xen/arch/x86/x86_emulate/x86_emulate.h
@@ -352,7 +352,12 @@ struct x86_emulate_ops
     int (*wbinvd)(
         struct x86_emulate_ctxt *ctxt);
 
-    /* cpuid: Emulate CPUID via given set of EAX-EDX inputs/outputs. */
+    /*
+     * cpuid: Emulate CPUID via given set of EAX-EDX inputs/outputs.
+     *
+     * May return X86EMUL_EXCEPTION, which causes the emulator to inject
+     * #GP[0].  Used to implement CPUID faulting.
+     */
     int (*cpuid)(
         unsigned int *eax,
         unsigned int *ebx,
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
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®.