zhang / rpms / kernel

Forked from rpms/kernel 5 years ago
Clone
e293be
diff -up ./arch/x86/include/asm/mshyperv.h.retp ./arch/x86/include/asm/mshyperv.h
e293be
--- ./arch/x86/include/asm/mshyperv.h.retp	2018-03-22 06:40:12.000000000 +0900
e293be
+++ ./arch/x86/include/asm/mshyperv.h	2018-04-21 01:29:24.000000000 +0900
e293be
@@ -200,13 +200,13 @@ static inline u64 hv_do_hypercall(u64 co
e293be
 	if (!hv_hypercall_pg)
e293be
 		return U64_MAX;
e293be
 
e293be
-	__asm__ __volatile__(CALL_NOSPEC
e293be
+	__asm__ __volatile__(CALL_NOSPEC_FULL
e293be
 			     : "=A" (hv_status),
e293be
 			       "+c" (input_address_lo), "+r" (__sp)
e293be
 			     : "A" (control),
e293be
 			       "b" (input_address_hi),
e293be
 			       "D"(output_address_hi), "S"(output_address_lo),
e293be
-			       THUNK_TARGET(hv_hypercall_pg)
e293be
+			       THUNK_TARGET_FULL(hv_hypercall_pg)
e293be
 			     : "cc", "memory");
e293be
 #endif /* !x86_64 */
e293be
 	return hv_status;
e293be
diff -up ./arch/x86/include/asm/nospec-branch.h.retp ./arch/x86/include/asm/nospec-branch.h
e293be
--- ./arch/x86/include/asm/nospec-branch.h.retp	2018-03-22 06:40:12.000000000 +0900
e293be
+++ ./arch/x86/include/asm/nospec-branch.h	2018-04-21 01:27:33.000000000 +0900
e293be
@@ -160,6 +160,67 @@
e293be
 	"call __x86_indirect_thunk_%V[thunk_target]\n"
e293be
 #define THUNK_TARGET(addr) [thunk_target] "r" (addr)
e293be
 
e293be
+#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE)
e293be
+/*
e293be
+ * Redefinition of STATIC_JUMP in arch/x86/include/asm/jump_label.h
e293be
+ * as inline asm code.
e293be
+ */
e293be
+# define STATIC_JUMP(target, key) \
e293be
+	"911: .byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"	\
e293be
+	".pushsection __jump_table, \"aw\" \n\t"		\
e293be
+	_ASM_ALIGN "\n\t"					\
e293be
+	_ASM_PTR "911b, " target ", " #key "\n\t" /*jump_entry*/\
e293be
+	".popsection\n"
e293be
+/*
e293be
+ * For i386 we use the original ret-equivalent retpoline, because
e293be
+ * otherwise we'll run out of registers. We don't care about CET
e293be
+ * here, anyway.
e293be
+ */
e293be
+# define CALL_NOSPEC STATIC_JUMP("912f", retp_enabled_key)	\
e293be
+	"	call *%[thunk_target]\n"			\
e293be
+	"	jmp    913f\n"					\
e293be
+	"912:	\n"						\
e293be
+	"       jmp    904f;\n"					\
e293be
+	"       .align 16\n"					\
e293be
+	"901:	call   903f;\n"					\
e293be
+	"902:	pause;\n"					\
e293be
+	"    	lfence;\n"					\
e293be
+	"       jmp    902b;\n"					\
e293be
+	"       .align 16\n"					\
e293be
+	"903:	addl   $4, %%esp;\n"				\
e293be
+	"       pushl  %[thunk_target];\n"			\
e293be
+	"       ret;\n"						\
e293be
+	"       .align 16\n"					\
e293be
+	"904:	call   901b;\n"					\
e293be
+	"913:	\n"					
e293be
+
e293be
+# define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
e293be
+/*
e293be
+ * CALL_NOSPEC doesn't work if [thunk_target] was *(%esp),
e293be
+ * when all registers except %ebp is used up, as in
e293be
+ * drivers/hv/hv.c:hv_do_hypercall().
e293be
+ */
e293be
+# define CALL_NOSPEC_FULL STATIC_JUMP("912f", retp_enabled_key)	\
e293be
+	"	call *%[thunk_target]\n"			\
e293be
+	"	jmp    913f\n"					\
e293be
+	"912:	\n"						\
e293be
+	"	pushl  %[thunk_target];\n"			\
e293be
+	"       jmp    904f;\n"					\
e293be
+	"       .align 16\n"					\
e293be
+	"901:	call   903f;\n"					\
e293be
+	"902:	pause;\n"					\
e293be
+	"    	lfence;\n"					\
e293be
+	"       jmp    902b;\n"					\
e293be
+	"       .align 16\n"					\
e293be
+	"903:	addl   $4, %%esp;\n"				\
e293be
+	"       pushl  4(%%esp);\n"				\
e293be
+	"       ret;\n"						\
e293be
+	"       .align 16\n"					\
e293be
+	"904:	call   901b;\n"					\
e293be
+	"	addl   $4, %%esp;\n"				\
e293be
+	"913:	\n"					
e293be
+
e293be
+# define THUNK_TARGET_FULL(addr) [thunk_target] "rm" (addr)
e293be
 #else /* No retpoline for C / inline asm */
e293be
 # define CALL_NOSPEC "call *%[thunk_target]\n"
e293be
 # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
e293be
diff -up ./arch/x86/kernel/i386_ksyms_32.c.retp ./arch/x86/kernel/i386_ksyms_32.c
e293be
--- ./arch/x86/kernel/i386_ksyms_32.c.retp	2018-03-22 06:40:12.000000000 +0900
e293be
+++ ./arch/x86/kernel/i386_ksyms_32.c	2018-04-21 01:26:08.000000000 +0900
e293be
@@ -4,6 +4,7 @@
e293be
 #include <asm/pgtable.h>
e293be
 #include <asm/desc.h>
e293be
 #include <asm/ftrace.h>
e293be
+#include <asm/asm.h>
e293be
 
e293be
 #ifdef CONFIG_FUNCTION_TRACER
e293be
 /* mcount is defined in assembly */
e293be
@@ -37,3 +38,17 @@ EXPORT_SYMBOL(strstr);
e293be
 
e293be
 EXPORT_SYMBOL(csum_partial);
e293be
 EXPORT_SYMBOL(empty_zero_page);
e293be
+
e293be
+#ifdef CONFIG_RETPOLINE
e293be
+#define EXPORT_THUNK(reg)						\
e293be
+	extern void __x86_indirect_thunk_ ## reg(void);			\
e293be
+	EXPORT_SYMBOL(__x86_indirect_thunk_ ## reg)
e293be
+
e293be
+EXPORT_THUNK(eax);
e293be
+EXPORT_THUNK(ebx);
e293be
+EXPORT_THUNK(ecx);
e293be
+EXPORT_THUNK(edx);
e293be
+EXPORT_THUNK(esi);
e293be
+EXPORT_THUNK(edi);
e293be
+EXPORT_THUNK(ebp);
e293be
+#endif /* CONFIG_RETPOLINE */
e293be
diff -up ./drivers/hv/hv.c.retp ./drivers/hv/hv.c