[PATCH 3.16 44/76] KVM: x86: Make indirect calls in emulator speculation safe

2018-03-11 Thread Ben Hutchings
3.16.56-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Peter Zijlstra 

commit 1a29b5b7f347a1a9230c1e0af5b37e3e571588ab upstream.

Replace the indirect calls with CALL_NOSPEC.

Signed-off-by: Peter Zijlstra (Intel) 
Signed-off-by: Thomas Gleixner 
Reviewed-by: David Woodhouse 
Cc: Andrea Arcangeli 
Cc: Andi Kleen 
Cc: Ashok Raj 
Cc: Greg KH 
Cc: Jun Nakajima 
Cc: David Woodhouse 
Cc: Linus Torvalds 
Cc: r...@amazon.de
Cc: Dave Hansen 
Cc: Asit Mallick 
Cc: Andy Lutomirski 
Cc: Josh Poimboeuf 
Cc: Jason Baron 
Cc: Paolo Bonzini 
Cc: Dan Williams 
Cc: Arjan Van De Ven 
Cc: Tim Chen 
Link: https://lkml.kernel.org/r/20180125095843.595615...@infradead.org
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings 
---
 arch/x86/kvm/emulate.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "x86.h"
 #include "tss.h"
@@ -906,8 +907,8 @@ static u8 test_cc(unsigned int condition
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;
 }
 
@@ -4622,9 +4623,9 @@ static int fastop(struct x86_emulate_ctx
ulong flags = (ctxt->eflags & EFLAGS_MASK) | X86_EFLAGS_IF;
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)
+ [thunk_target]"+S"(fop), ASM_CALL_CONSTRAINT
: "c"(ctxt->src2.val));
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);
if (!fop) /* exception is returned in fop variable */



[PATCH 3.16 44/76] KVM: x86: Make indirect calls in emulator speculation safe

2018-03-11 Thread Ben Hutchings
3.16.56-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Peter Zijlstra 

commit 1a29b5b7f347a1a9230c1e0af5b37e3e571588ab upstream.

Replace the indirect calls with CALL_NOSPEC.

Signed-off-by: Peter Zijlstra (Intel) 
Signed-off-by: Thomas Gleixner 
Reviewed-by: David Woodhouse 
Cc: Andrea Arcangeli 
Cc: Andi Kleen 
Cc: Ashok Raj 
Cc: Greg KH 
Cc: Jun Nakajima 
Cc: David Woodhouse 
Cc: Linus Torvalds 
Cc: r...@amazon.de
Cc: Dave Hansen 
Cc: Asit Mallick 
Cc: Andy Lutomirski 
Cc: Josh Poimboeuf 
Cc: Jason Baron 
Cc: Paolo Bonzini 
Cc: Dan Williams 
Cc: Arjan Van De Ven 
Cc: Tim Chen 
Link: https://lkml.kernel.org/r/20180125095843.595615...@infradead.org
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings 
---
 arch/x86/kvm/emulate.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "x86.h"
 #include "tss.h"
@@ -906,8 +907,8 @@ static u8 test_cc(unsigned int condition
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;
 }
 
@@ -4622,9 +4623,9 @@ static int fastop(struct x86_emulate_ctx
ulong flags = (ctxt->eflags & EFLAGS_MASK) | X86_EFLAGS_IF;
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)
+ [thunk_target]"+S"(fop), ASM_CALL_CONSTRAINT
: "c"(ctxt->src2.val));
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);
if (!fop) /* exception is returned in fop variable */