Skip to content

Commit 64e1672

Browse files
suryasaimadhuKAGA-KOKO
authored andcommitted
x86/speculation: Simplify indirect_branch_prediction_barrier()
Make it all a function which does the WRMSR instead of having a hairy inline asm. [dwmw2: export it, fix CONFIG_RETPOLINE issues] Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 1dde741 commit 64e1672

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,10 @@ static inline void vmexit_fill_RSB(void)
164164

165165
static inline void indirect_branch_prediction_barrier(void)
166166
{
167-
asm volatile(ALTERNATIVE("",
168-
"movl %[msr], %%ecx\n\t"
169-
"movl %[val], %%eax\n\t"
170-
"movl $0, %%edx\n\t"
171-
"wrmsr",
172-
X86_FEATURE_USE_IBPB)
173-
: : [msr] "i" (MSR_IA32_PRED_CMD),
174-
[val] "i" (PRED_CMD_IBPB)
175-
: "eax", "ecx", "edx", "memory");
167+
alternative_input("",
168+
"call __ibp_barrier",
169+
X86_FEATURE_USE_IBPB,
170+
ASM_NO_INPUT_CLOBBER("eax", "ecx", "edx", "memory"));
176171
}
177172

178173
#endif /* __ASSEMBLY__ */

arch/x86/include/asm/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,4 +970,7 @@ bool xen_set_default_idle(void);
970970

971971
void stop_this_cpu(void *dummy);
972972
void df_debug(struct pt_regs *regs, long error_code);
973+
974+
void __ibp_barrier(void);
975+
973976
#endif /* _ASM_X86_PROCESSOR_H */

arch/x86/kernel/cpu/bugs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,9 @@ ssize_t cpu_show_spectre_v2(struct device *dev,
311311
spectre_v2_module_string());
312312
}
313313
#endif
314+
315+
void __ibp_barrier(void)
316+
{
317+
__wrmsr(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, 0);
318+
}
319+
EXPORT_SYMBOL_GPL(__ibp_barrier);

0 commit comments

Comments
 (0)