]> xenbits.xensource.com Git - xen.git/commitdiff
x86/emul: Move CPUID Faulting fault generation into the emulator
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 26 Oct 2016 11:06:44 +0000 (12:06 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 26 Oct 2016 13:41:37 +0000 (14:41 +0100)
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@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/hvm/emulate.c
xen/arch/x86/x86_emulate/x86_emulate.c
xen/arch/x86/x86_emulate/x86_emulate.h

index 70c8d44716ca0701314a841cb33ca39829466e93..5b408f8eb97200b3e3965df369457a390878533b 100644 (file)
@@ -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;
index 94886befc15403148770a2011c2725db05db5bb6..7a707dcda3f21fbaa59df6b620ac5298fd84f486 100644 (file)
@@ -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;
index 7435f42b22eae8c5d174caf2aedce64743ee7250..993c576083be8db6170c0f831033bd51634a8878 100644 (file)
@@ -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,