]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
x86emul: avoid triggering assertions with VME/PVI early #GP check
authorJan Beulich <jbeulich@suse.com>
Tue, 18 Dec 2018 14:21:17 +0000 (15:21 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 18 Dec 2018 14:21:17 +0000 (15:21 +0100)
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@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/x86_emulate/x86_emulate.c

index a3d7e33385d23ab3329f278893b41dfc2260e7c8..20510151c89f41d0af579949875edc85b29adecc 100644 (file)
@@ -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)),
@@ -9800,8 +9805,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);