Commit 1b30d6fd authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Jialin Zhang
Browse files

x86/cpu: Cleanup the untrain mess

stable inclusion
from stable-v5.10.192
commit 06597b650beb49bffc61e077f41e39b830d72128
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I7RQ67

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=06597b650beb49bffc61e077f41e39b830d72128



--------------------------------

commit e7c25c44 upstream.

Since there can only be one active return_thunk, there only needs be
one (matching) untrain_ret. It fundamentally doesn't make sense to
allow multiple untrain_ret at the same time.

Fold all the 3 different untrain methods into a single (temporary)
helper stub.

Fixes: fb3bd914 ("x86/srso: Add a Speculative RAS Overflow mitigation")
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230814121149.042774962@infradead.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parent 01aee51c
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -156,9 +156,9 @@
.endm

#ifdef CONFIG_CPU_UNRET_ENTRY
#define CALL_ZEN_UNTRAIN_RET	"call retbleed_untrain_ret"
#define CALL_UNTRAIN_RET	"call entry_untrain_ret"
#else
#define CALL_ZEN_UNTRAIN_RET	""
#define CALL_UNTRAIN_RET	""
#endif

/*
@@ -177,14 +177,9 @@
	defined(CONFIG_CPU_SRSO)
	ANNOTATE_UNRET_END
	ALTERNATIVE_2 "",						\
	              CALL_ZEN_UNTRAIN_RET, X86_FEATURE_UNRET,		\
		      CALL_UNTRAIN_RET, X86_FEATURE_UNRET,		\
		      "call entry_ibpb", X86_FEATURE_ENTRY_IBPB
#endif

#ifdef CONFIG_CPU_SRSO
	ALTERNATIVE_2 "", "call srso_untrain_ret", X86_FEATURE_SRSO, \
			  "call srso_alias_untrain_ret", X86_FEATURE_SRSO_ALIAS
#endif
.endm

#else /* __ASSEMBLY__ */
@@ -209,6 +204,7 @@ extern void retbleed_untrain_ret(void);
extern void srso_untrain_ret(void);
extern void srso_alias_untrain_ret(void);

extern void entry_untrain_ret(void);
extern void entry_ibpb(void);

#ifdef CONFIG_RETPOLINE
+1 −0
Original line number Diff line number Diff line
@@ -2408,6 +2408,7 @@ static void __init srso_select_mitigation(void)
			 * like ftrace, static_call, etc.
			 */
			setup_force_cpu_cap(X86_FEATURE_RETHUNK);
			setup_force_cpu_cap(X86_FEATURE_UNRET);

			if (boot_cpu_data.x86 == 0x19) {
				setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS);
+7 −0
Original line number Diff line number Diff line
@@ -230,6 +230,13 @@ SYM_CODE_START(srso_return_thunk)
	ud2
SYM_CODE_END(srso_return_thunk)

SYM_FUNC_START(entry_untrain_ret)
	ALTERNATIVE_2 "jmp retbleed_untrain_ret", \
		      "jmp srso_untrain_ret", X86_FEATURE_SRSO, \
		      "jmp srso_alias_untrain_ret", X86_FEATURE_SRSO_ALIAS
SYM_FUNC_END(entry_untrain_ret)
__EXPORT_THUNK(entry_untrain_ret)

SYM_CODE_START(__x86_return_thunk)
	UNWIND_HINT_FUNC
	ANNOTATE_NOENDBR