Skip to contentSkip to conversation

KVM retpoline fixes

PATCH New Peter Zijlstra 2 participants 6 messages Jan 25, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover KVM retpoline fixes

Here the two KVM retpoline fixes that should get into tip/x86/pti asap.

#1 lore raw

PATCH 1/2 x86,kvm: Fix indirect calls in emulator

Replace the indirect calls with CALL_NOSPEC.

---
 arch/x86/kvm/emulate.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/emulate.c +5 -4
@@ -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(unsign
 	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;
 }
 
@@ -5335,9 +5336,9 @@ static int fastop(struct x86_emulate_ctx
 	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);
#2 lore raw

[tip:x86/pti] KVM: x86: Make indirect calls in emulator speculation safe

KVM: x86: Make indirect calls in emulator speculation safe
Commit-ID:  1a29b5b7f347a1a9230c1e0af5b37e3e571588ab
Gitweb:     https://git.kernel.org/tip/1a29b5b7f347a1a9230c1e0af5b37e3e571588ab
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Thu, 25 Jan 2018 10:58:13 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 25 Jan 2018 11:30:07 +0100

KVM: x86: Make indirect calls in emulator speculation safe

Replace the indirect calls with CALL_NOSPEC.

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 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]>
---
 arch/x86/kvm/emulate.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/emulate.c +5 -4
index d90cdc7..453d8c9 100644
@@ -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);
#3 lore raw

PATCH 2/2 x86,vmx: Fix indirect call

In reply to Peter Zijlstra

Replace indirect call with CALL_NOSPEC.

---
 arch/x86/kvm/vmx.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +2 -2
@@ -9129,14 +9129,14 @@ static void vmx_handle_external_intr(str
 #endif
 			"pushf\n\t"
 			__ASM_SIZE(push) " $%c[cs]\n\t"
-			"call *%[entry]\n\t"
+			CALL_NOSPEC
 			:
 #ifdef CONFIG_X86_64
 			[sp]"=&r"(tmp),
 #endif
 			ASM_CALL_CONSTRAINT
 			:
-			[entry]"r"(entry),
+			THUNK_TARGET(entry),
 			[ss]"i"(__KERNEL_DS),
 			[cs]"i"(__KERNEL_CS)
 			);
#4 lore raw

[tip:x86/pti] KVM: VMX: Make indirect call specualation safe

KVM: VMX: Make indirect call specualation safe
Commit-ID:  34cc5034b57b81f789ad4714533ca921a9b1c9d7
Gitweb:     https://git.kernel.org/tip/34cc5034b57b81f789ad4714533ca921a9b1c9d7
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Thu, 25 Jan 2018 10:58:14 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 25 Jan 2018 11:30:07 +0100

KVM: VMX: Make indirect call specualation safe

Replace indirect call with CALL_NOSPEC.

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 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]>
---
 arch/x86/kvm/vmx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +2 -2
index d1e25db..924589c 100644
@@ -9064,14 +9064,14 @@ static void vmx_handle_external_intr(struct kvm_vcpu *vcpu)
 #endif
 			"pushf\n\t"
 			__ASM_SIZE(push) " $%c[cs]\n\t"
-			"call *%[entry]\n\t"
+			CALL_NOSPEC
 			:
 #ifdef CONFIG_X86_64
 			[sp]"=&r"(tmp),
 #endif
 			ASM_CALL_CONSTRAINT
 			:
-			[entry]"r"(entry),
+			THUNK_TARGET(entry),
 			[ss]"i"(__KERNEL_DS),
 			[cs]"i"(__KERNEL_CS)
 			);
#5 lore raw

[tip:x86/pti] KVM: VMX: Make indirect call speculation safe

In reply to Peter Zijlstra
KVM: VMX: Make indirect call speculation safe
Commit-ID:  c940a3fb1e2e9b7d03228ab28f375fb5a47ff699
Gitweb:     https://git.kernel.org/tip/c940a3fb1e2e9b7d03228ab28f375fb5a47ff699
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Thu, 25 Jan 2018 10:58:14 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 25 Jan 2018 14:14:42 +0100

KVM: VMX: Make indirect call speculation safe

Replace indirect call with CALL_NOSPEC.

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 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]>
---
 arch/x86/kvm/vmx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +2 -2
index d1e25db..924589c 100644
@@ -9064,14 +9064,14 @@ static void vmx_handle_external_intr(struct kvm_vcpu *vcpu)
 #endif
 			"pushf\n\t"
 			__ASM_SIZE(push) " $%c[cs]\n\t"
-			"call *%[entry]\n\t"
+			CALL_NOSPEC
 			:
 #ifdef CONFIG_X86_64
 			[sp]"=&r"(tmp),
 #endif
 			ASM_CALL_CONSTRAINT
 			:
-			[entry]"r"(entry),
+			THUNK_TARGET(entry),
 			[ss]"i"(__KERNEL_DS),
 			[cs]"i"(__KERNEL_CS)
 			);