x86/emul: Implement the STAC and CLAC instructions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 18 Oct 2016 15:55:26 +0000 (16:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 13 Dec 2016 09:58:33 +0000 (09:58 +0000)
Note that unlike most privilege restricted instructions, STAC and CLAC are
documented to raise #UD rather than #GP[0], and indeed do so.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/x86_emulate/x86_emulate.c

index fe055cff8b4aa4b70751a0c6001676ed02a6a83d..43c4a9d4b69883ed53fc84086ec6608806812f4f 100644 (file)
@@ -1295,6 +1295,7 @@ static bool vcpu_has(
 #define vcpu_has_bmi1()        vcpu_has(         7, EBX,  3, ctxt, ops)
 #define vcpu_has_hle()         vcpu_has(         7, EBX,  4, ctxt, ops)
 #define vcpu_has_rtm()         vcpu_has(         7, EBX, 11, ctxt, ops)
+#define vcpu_has_smap()        vcpu_has(         7, EBX, 20, ctxt, ops)
 
 #define vcpu_must_have(feat) \
     generate_exception_if(!vcpu_has_##feat(), EXC_UD)
@@ -4354,6 +4355,17 @@ x86_emulate(
 
         switch( modrm )
         {
+        case 0xca: /* clac */
+        case 0xcb: /* stac */
+            vcpu_must_have(smap);
+            generate_exception_if(lock_prefix || vex.pfx || !mode_ring0(),
+                                  EXC_UD);
+
+            _regs.eflags &= ~EFLG_AC;
+            if ( modrm == 0xcb )
+                _regs.eflags |= EFLG_AC;
+            goto no_writeback;
+
 #ifdef __XEN__
         case 0xd1: /* xsetbv */
         {