Skip to content

Commit d45476d

Browse files
Peter Zijlstra (Intel)suryasaimadhu
authored andcommitted
x86/speculation: Rename RETPOLINE_AMD to RETPOLINE_LFENCE
The RETPOLINE_AMD name is unfortunate since it isn't necessarily AMD only, in fact Hygon also uses it. Furthermore it will likely be sufficient for some Intel processors. Therefore rename the thing to RETPOLINE_LFENCE to better describe what it is. Add the spectre_v2=retpoline,lfence option as an alias to spectre_v2=retpoline,amd to preserve existing setups. However, the output of /sys/devices/system/cpu/vulnerabilities/spectre_v2 will be changed. [ bp: Fix typos, massage. ] Co-developed-by: Josh Poimboeuf <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]>
1 parent cfb9244 commit d45476d

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
/* FREE! ( 7*32+10) */
205205
#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
206206
#define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */
207-
#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
207+
#define X86_FEATURE_RETPOLINE_LFENCE ( 7*32+13) /* "" Use LFENCE for Spectre variant 2 */
208208
#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
209209
#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */
210210
#define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16) /* "" MSR SPEC_CTRL is implemented */

arch/x86/include/asm/nospec-branch.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#ifdef CONFIG_RETPOLINE
8585
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
8686
__stringify(jmp __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
87-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_AMD
87+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE
8888
#else
8989
jmp *%\reg
9090
#endif
@@ -94,7 +94,7 @@
9494
#ifdef CONFIG_RETPOLINE
9595
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \
9696
__stringify(call __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
97-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_AMD
97+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_LFENCE
9898
#else
9999
call *%\reg
100100
#endif
@@ -146,7 +146,7 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
146146
"lfence;\n" \
147147
ANNOTATE_RETPOLINE_SAFE \
148148
"call *%[thunk_target]\n", \
149-
X86_FEATURE_RETPOLINE_AMD)
149+
X86_FEATURE_RETPOLINE_LFENCE)
150150

151151
# define THUNK_TARGET(addr) [thunk_target] "r" (addr)
152152

@@ -176,7 +176,7 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
176176
"lfence;\n" \
177177
ANNOTATE_RETPOLINE_SAFE \
178178
"call *%[thunk_target]\n", \
179-
X86_FEATURE_RETPOLINE_AMD)
179+
X86_FEATURE_RETPOLINE_LFENCE)
180180

181181
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
182182
#endif
@@ -188,8 +188,8 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
188188
/* The Spectre V2 mitigation variants */
189189
enum spectre_v2_mitigation {
190190
SPECTRE_V2_NONE,
191-
SPECTRE_V2_RETPOLINE_GENERIC,
192-
SPECTRE_V2_RETPOLINE_AMD,
191+
SPECTRE_V2_RETPOLINE,
192+
SPECTRE_V2_LFENCE,
193193
SPECTRE_V2_IBRS_ENHANCED,
194194
};
195195

arch/x86/kernel/alternative.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int emit_indirect(int op, int reg, u8 *bytes)
389389
*
390390
* CALL *%\reg
391391
*
392-
* It also tries to inline spectre_v2=retpoline,amd when size permits.
392+
* It also tries to inline spectre_v2=retpoline,lfence when size permits.
393393
*/
394394
static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
395395
{
@@ -407,7 +407,7 @@ static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
407407
BUG_ON(reg == 4);
408408

409409
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE) &&
410-
!cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD))
410+
!cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE))
411411
return -1;
412412

413413
op = insn->opcode.bytes[0];
@@ -438,9 +438,9 @@ static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
438438
}
439439

440440
/*
441-
* For RETPOLINE_AMD: prepend the indirect CALL/JMP with an LFENCE.
441+
* For RETPOLINE_LFENCE: prepend the indirect CALL/JMP with an LFENCE.
442442
*/
443-
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {
443+
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
444444
bytes[i++] = 0x0f;
445445
bytes[i++] = 0xae;
446446
bytes[i++] = 0xe8; /* LFENCE */

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ enum spectre_v2_mitigation_cmd {
664664
SPECTRE_V2_CMD_FORCE,
665665
SPECTRE_V2_CMD_RETPOLINE,
666666
SPECTRE_V2_CMD_RETPOLINE_GENERIC,
667-
SPECTRE_V2_CMD_RETPOLINE_AMD,
667+
SPECTRE_V2_CMD_RETPOLINE_LFENCE,
668668
};
669669

670670
enum spectre_v2_user_cmd {
@@ -824,8 +824,8 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
824824

825825
static const char * const spectre_v2_strings[] = {
826826
[SPECTRE_V2_NONE] = "Vulnerable",
827-
[SPECTRE_V2_RETPOLINE_GENERIC] = "Mitigation: Full generic retpoline",
828-
[SPECTRE_V2_RETPOLINE_AMD] = "Mitigation: Full AMD retpoline",
827+
[SPECTRE_V2_RETPOLINE] = "Mitigation: Retpolines",
828+
[SPECTRE_V2_LFENCE] = "Mitigation: LFENCE",
829829
[SPECTRE_V2_IBRS_ENHANCED] = "Mitigation: Enhanced IBRS",
830830
};
831831

@@ -837,7 +837,8 @@ static const struct {
837837
{ "off", SPECTRE_V2_CMD_NONE, false },
838838
{ "on", SPECTRE_V2_CMD_FORCE, true },
839839
{ "retpoline", SPECTRE_V2_CMD_RETPOLINE, false },
840-
{ "retpoline,amd", SPECTRE_V2_CMD_RETPOLINE_AMD, false },
840+
{ "retpoline,amd", SPECTRE_V2_CMD_RETPOLINE_LFENCE, false },
841+
{ "retpoline,lfence", SPECTRE_V2_CMD_RETPOLINE_LFENCE, false },
841842
{ "retpoline,generic", SPECTRE_V2_CMD_RETPOLINE_GENERIC, false },
842843
{ "auto", SPECTRE_V2_CMD_AUTO, false },
843844
};
@@ -875,13 +876,19 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
875876
}
876877

877878
if ((cmd == SPECTRE_V2_CMD_RETPOLINE ||
878-
cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||
879+
cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
879880
cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) &&
880881
!IS_ENABLED(CONFIG_RETPOLINE)) {
881882
pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option);
882883
return SPECTRE_V2_CMD_AUTO;
883884
}
884885

886+
if ((cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE) &&
887+
!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
888+
pr_err("%s selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n", mitigation_options[i].option);
889+
return SPECTRE_V2_CMD_AUTO;
890+
}
891+
885892
spec_v2_print_cond(mitigation_options[i].option,
886893
mitigation_options[i].secure);
887894
return cmd;
@@ -916,9 +923,9 @@ static void __init spectre_v2_select_mitigation(void)
916923
if (IS_ENABLED(CONFIG_RETPOLINE))
917924
goto retpoline_auto;
918925
break;
919-
case SPECTRE_V2_CMD_RETPOLINE_AMD:
926+
case SPECTRE_V2_CMD_RETPOLINE_LFENCE:
920927
if (IS_ENABLED(CONFIG_RETPOLINE))
921-
goto retpoline_amd;
928+
goto retpoline_lfence;
922929
break;
923930
case SPECTRE_V2_CMD_RETPOLINE_GENERIC:
924931
if (IS_ENABLED(CONFIG_RETPOLINE))
@@ -935,17 +942,17 @@ static void __init spectre_v2_select_mitigation(void)
935942
retpoline_auto:
936943
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
937944
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
938-
retpoline_amd:
945+
retpoline_lfence:
939946
if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
940947
pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");
941948
goto retpoline_generic;
942949
}
943-
mode = SPECTRE_V2_RETPOLINE_AMD;
944-
setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD);
950+
mode = SPECTRE_V2_LFENCE;
951+
setup_force_cpu_cap(X86_FEATURE_RETPOLINE_LFENCE);
945952
setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
946953
} else {
947954
retpoline_generic:
948-
mode = SPECTRE_V2_RETPOLINE_GENERIC;
955+
mode = SPECTRE_V2_RETPOLINE;
949956
setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
950957
}
951958

arch/x86/lib/retpoline.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL)
3434

3535
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
3636
__stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \
37-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg; int3), X86_FEATURE_RETPOLINE_AMD
37+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg; int3), X86_FEATURE_RETPOLINE_LFENCE
3838

3939
.endm
4040

arch/x86/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip)
394394
u8 *prog = *pprog;
395395

396396
#ifdef CONFIG_RETPOLINE
397-
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {
397+
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
398398
EMIT_LFENCE();
399399
EMIT2(0xFF, 0xE0 + reg);
400400
} else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {

tools/arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
/* FREE! ( 7*32+10) */
205205
#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
206206
#define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */
207-
#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
207+
#define X86_FEATURE_RETPOLINE_LFENCE ( 7*32+13) /* "" Use LFENCEs for Spectre variant 2 */
208208
#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
209209
#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */
210210
#define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16) /* "" MSR SPEC_CTRL is implemented */

0 commit comments

Comments
 (0)