All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.7] x86/hvm: Correct emulation of invlpg instruction
@ 2016-04-22  8:59 Andrew Cooper
  2016-04-22  9:31 ` Jan Beulich
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Cooper @ 2016-04-22  8:59 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich

`invlpg` and `invlpga` are specified to be NOPs when issued on non-canonical
addresses.

These instructions are not normally intercepted.  They are however intercepted
for HVM guests running in shadow paging mode.  AMD hardware lacking decode
hardware assistance uses the general instruction emulator to handle the
interception.

Alter hvmemul_invlpg() to swallow the #GP exception resulting from a
non-canonical address, rather than reporting it back to the guest.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>

Note: Ideally this should be caught in the instruction emulator itself, but it
is the hvmemul_virtual_to_linear() which completes the memory calculation
including a possible non-zero %fs/%gs base.
---
 xen/arch/x86/hvm/emulate.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index cc0b841..897724e 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1598,8 +1598,27 @@ static int hvmemul_invlpg(
     rc = hvmemul_virtual_to_linear(
         seg, offset, 1, &reps, hvm_access_none, hvmemul_ctxt, &addr);
 
-    if ( rc == X86EMUL_OKAY )
+    switch ( rc )
+    {
+    case X86EMUL_OKAY:
         hvm_funcs.invlpg_intercept(addr);
+        break;
+
+    case X86EMUL_EXCEPTION:
+        ASSERT(hvmemul_ctxt->trap.vector == TRAP_gp_fault);
+        /*
+         * `invlpg` and `invlpga` are specified to be NOPs when issued on a
+         * non-canonical address.  hvmemul_virtual_to_linear() latches a #GP
+         * which is the useful behaviour for most of its callers.
+         *
+         * Clear the pending exception to match avoid delivering a #GP fault
+         * to the guest.
+         */
+        hvmemul_ctxt->exn_pending = 0;
+        hvmemul_ctxt->trap = (struct hvm_trap){};
+        rc = X86EMUL_OKAY;
+        break;
+    }
 
     return rc;
 }
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-04-22 13:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-22  8:59 [PATCH for-4.7] x86/hvm: Correct emulation of invlpg instruction Andrew Cooper
2016-04-22  9:31 ` Jan Beulich
2016-04-22  9:48   ` Paul Durrant
2016-04-22  9:57     ` Jan Beulich
2016-04-22 10:16       ` Andrew Cooper
2016-04-22 10:30         ` Jan Beulich
2016-04-22 11:18           ` Andrew Cooper
2016-04-22 11:47             ` Jan Beulich
2016-04-22 13:40               ` Andrew Cooper
2016-04-22 13:59                 ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.