Skip to content

Commit 1a29b5b

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
KVM: x86: Make indirect calls in emulator speculation safe
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]
1 parent 1df3738 commit 1a29b5b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kvm/emulate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <asm/kvm_emulate.h>
2626
#include <linux/stringify.h>
2727
#include <asm/debugreg.h>
28+
#include <asm/nospec-branch.h>
2829

2930
#include "x86.h"
3031
#include "tss.h"
@@ -1021,8 +1022,8 @@ static __always_inline u8 test_cc(unsigned int condition, unsigned long flags)
10211022
void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);
10221023

10231024
flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF;
1024-
asm("push %[flags]; popf; call *%[fastop]"
1025-
: "=a"(rc) : [fastop]"r"(fop), [flags]"r"(flags));
1025+
asm("push %[flags]; popf; " CALL_NOSPEC
1026+
: "=a"(rc) : [thunk_target]"r"(fop), [flags]"r"(flags));
10261027
return rc;
10271028
}
10281029

@@ -5305,9 +5306,9 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
53055306
if (!(ctxt->d & ByteOp))
53065307
fop += __ffs(ctxt->dst.bytes) * FASTOP_SIZE;
53075308

5308-
asm("push %[flags]; popf; call *%[fastop]; pushf; pop %[flags]\n"
5309+
asm("push %[flags]; popf; " CALL_NOSPEC " ; pushf; pop %[flags]\n"
53095310
: "+a"(ctxt->dst.val), "+d"(ctxt->src.val), [flags]"+D"(flags),
5310-
[fastop]"+S"(fop), ASM_CALL_CONSTRAINT
5311+
[thunk_target]"+S"(fop), ASM_CALL_CONSTRAINT
53115312
: "c"(ctxt->src2.val));
53125313

53135314
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);

0 commit comments

Comments
 (0)