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

[Xen-devel] [PATCH v2] x86emul: avoid triggering assertions with VME/PVI early #GP check



In commit efe9cba66c ("x86emul: VME and PVI modes require a #GP(0) check
first thing") I neglected the fact that the retire flags get zapped only
in x86_decode(), which hasn't been invoked yet at the point of the #GP(0)
check added. Move output state initialization into a helper function,
and invoke it from the callers of x86_decode() instead of doing it
(possibly too late) in that function.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Different approach, different title and description.

--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1866,6 +1866,13 @@ static bool vcpu_has(
 #define host_and_vcpu_must_have(feat) vcpu_must_have(feat)
 #endif
 
+/* Initialise output state in x86_emulate_ctxt */
+static void init_context(struct x86_emulate_ctxt *ctxt)
+{
+    ctxt->retire.raw = 0;
+    x86_emul_reset_event(ctxt);
+}
+
 static int
 realmode_load_seg(
     enum x86_segment seg,
@@ -2713,10 +2720,6 @@ x86_decode(
     state->regs = ctxt->regs;
     state->ip = ctxt->regs->r(ip);
 
-    /* Initialise output state in x86_emulate_ctxt */
-    ctxt->retire.raw = 0;
-    x86_emul_reset_event(ctxt);
-
     op_bytes = def_op_bytes = ad_bytes = def_ad_bytes = ctxt->addr_size/8;
     if ( op_bytes == 8 )
     {
@@ -3400,6 +3403,8 @@ x86_emulate(
 
     ASSERT(ops->read);
 
+    init_context(ctxt);
+
     generate_exception_if((mode_vif() &&
                            (_regs.eflags & X86_EFLAGS_VIF) &&
                            (_regs.eflags & X86_EFLAGS_VIP)),
@@ -9791,8 +9796,11 @@ x86_decode_insn(
         .insn_fetch = insn_fetch,
         .read       = x86emul_unhandleable_rw,
     };
-    int rc = x86_decode(state, ctxt, &ops);
+    int rc;
+
+    init_context(ctxt);
 
+    rc = x86_decode(state, ctxt, &ops);
     if ( unlikely(rc != X86EMUL_OKAY) )
         return ERR_PTR(-rc);
 





_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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