mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/2] x86/retpoline: Add X86_FEATURE_RETPOLINE_COMMON and split RETPLINE/RETPOLINE_AMD
@ 2018-01-10  1:56 Andi Kleen
  2018-01-10  1:56 ` [PATCH v2 2/2] x86/retpoline: Use X86_RETPOLINE_COMMON to enable 32bit retpoline Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2018-01-10  1:56 UTC (permalink / raw)
  To: tglx
  Cc: x86, linux-kernel, torvalds, dwmw, pjt, luto, peterz,
	thomas.lendacky, tim.c.chen, gregkh, dave.hansen, jikos,
	Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

On 64bit we want to split X86_FEATURE_RETPOLINE and X86_FEATURE_RETPOLINE_AMD,
so that only one is set. This enables new simpler ALTERNATIVE sequences.

But 32bit requires a common flag because it uses common code for both.

So add a new X86_FEATURE_RETPOLINE_COMMON that is always set
when either X86_FEATURE_RETPOLINE or X86_FEATURE_RETPOLINE_AMD are set.

And then unset X86_FEATURE_RETPOLINE for AMD.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/cpufeatures.h | 1 +
 arch/x86/kernel/cpu/bugs.c         | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index f275447862f4..54ec16ef08d8 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -211,6 +211,7 @@
 #define X86_FEATURE_AVX512_4FMAPS	( 7*32+17) /* AVX-512 Multiply Accumulation Single precision */
 
 #define X86_FEATURE_MBA			( 7*32+18) /* Memory Bandwidth Allocation */
+#define X86_FEATURE_RETPOLINE_COMMON	( 7*32+19) /* Common code for both RETPOLINE and RETPOLINE_AMD */
 
 /* Virtualization flags: Linux defined, word 8 */
 #define X86_FEATURE_TPR_SHADOW		( 8*32+ 0) /* Intel TPR Shadow */
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index b957f771a5b7..241eae66a86b 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -155,8 +155,10 @@ void __init spectre_v2_check_boottime_disable(void)
 	retpoline_generic:
 		spectre_v2_enabled = retp_compiler() ?
 			SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL;
+		setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
 	}
-	setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
+	setup_force_cpu_cap(X86_FEATURE_RETPOLINE_COMMON);
+
 	return;
 #else
 retpoline:
@@ -167,6 +169,7 @@ void __init spectre_v2_check_boottime_disable(void)
 disable:
 	setup_clear_cpu_cap(X86_FEATURE_RETPOLINE);
 	setup_clear_cpu_cap(X86_FEATURE_RETPOLINE_AMD);
+	setup_clear_cpu_cap(X86_FEATURE_RETPOLINE_COMMON);
 	return;
 }
 
-- 
2.14.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] x86/retpoline: Use X86_RETPOLINE_COMMON to enable 32bit retpoline
  2018-01-10  1:56 [PATCH v2 1/2] x86/retpoline: Add X86_FEATURE_RETPOLINE_COMMON and split RETPLINE/RETPOLINE_AMD Andi Kleen
@ 2018-01-10  1:56 ` Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2018-01-10  1:56 UTC (permalink / raw)
  To: tglx
  Cc: x86, linux-kernel, torvalds, dwmw, pjt, luto, peterz,
	thomas.lendacky, tim.c.chen, gregkh, dave.hansen, jikos,
	Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

32bit uses a single retpoline sequence for AMD/Intel. Previously
X86_RETPOLINE was always set for AMD/Intel but that's not true anymore.
So now use the new X86_FEATURE_RETPOLINE_COMMON flag that is set
for both.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/nospec-branch.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index c1cef78f0e12..bbd5343f2fea 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -116,7 +116,7 @@
 # define CALL_NOSPEC ALTERNATIVE(				\
 	"call *%[thunk_target]\n",				\
 	"call __x86_indirect_thunk_%V[thunk_target]\n",		\
-	X86_FEATURE_RETPOLINE)
+	X86_FEATURE_RETPOLINE_COMMON)
 # define THUNK_TARGET(addr) [thunk_target] "r" (addr)
 #elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE)
 /*
@@ -142,7 +142,7 @@
 	"       .align 16\n"					\
 	"do_call%=:\n"						\
 	"	call   do_retpoline%=;\n",			\
-	X86_FEATURE_RETPOLINE)
+	X86_FEATURE_RETPOLINE_COMMON)
 
 # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
 #else /* No retpoline */
-- 
2.14.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-10  1:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10  1:56 [PATCH v2 1/2] x86/retpoline: Add X86_FEATURE_RETPOLINE_COMMON and split RETPLINE/RETPOLINE_AMD Andi Kleen
2018-01-10  1:56 ` [PATCH v2 2/2] x86/retpoline: Use X86_RETPOLINE_COMMON to enable 32bit retpoline Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome