KVM: x86: Make indirect calls in emulator speculation safe
authorPeter Zijlstra <[email protected]>
Thu, 25 Jan 2018 09:58:13 +0000 (10:58 +0100)
committerThomas Gleixner <[email protected]>
Thu, 25 Jan 2018 10:30:07 +0000 (11:30 +0100)
Replace the indirect calls with CALL_NOSPEC.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: David Woodhouse <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ashok Raj <[email protected]>
Cc: Greg KH <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: [email protected]
Cc: Dave Hansen <[email protected]>
Cc: Asit Mallick <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Arjan Van De Ven <[email protected]>
Cc: Tim Chen <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
arch/x86/kvm/emulate.c

index d90cdc77e077354f1407235e6b73f2fda21c430c..453d8c99010822222b8a1d9433d0bdfc6dc50fd9 100644 (file)
@@ -25,6 +25,7 @@
 #include <asm/kvm_emulate.h>
 #include <linux/stringify.h>
 #include <asm/debugreg.h>
+#include <asm/nospec-branch.h>
 
 #include "x86.h"
 #include "tss.h"
@@ -1021,8 +1022,8 @@ static __always_inline u8 test_cc(unsigned int condition, unsigned long flags)
        void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);
 
        flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF;
-       asm("push %[flags]; popf; call *%[fastop]"
-           : "=a"(rc) : [fastop]"r"(fop), [flags]"r"(flags));
+       asm("push %[flags]; popf; " CALL_NOSPEC
+           : "=a"(rc) : [thunk_target]"r"(fop), [flags]"r"(flags));
        return rc;
 }
 
@@ -5305,9 +5306,9 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
        if (!(ctxt->d & ByteOp))
                fop += __ffs(ctxt->dst.bytes) * FASTOP_SIZE;
 
-       asm("push %[flags]; popf; call *%[fastop]; pushf; pop %[flags]\n"
+       asm("push %[flags]; popf; " CALL_NOSPEC " ; pushf; pop %[flags]\n"
            : "+a"(ctxt->dst.val), "+d"(ctxt->src.val), [flags]"+D"(flags),
-             [fastop]"+S"(fop), ASM_CALL_CONSTRAINT
+             [thunk_target]"+S"(fop), ASM_CALL_CONSTRAINT
            : "c"(ctxt->src2.val));
 
        ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);