[tip:,x86/bugs] x86/retpoline: Document some thunk handling aspects

Message ID 169780183267.3135.3911908270721154685.tip-bot2@tip-bot2
State New
Headers
Series [tip:,x86/bugs] x86/retpoline: Document some thunk handling aspects |

Commit Message

tip-bot2 for Thomas Gleixner Oct. 20, 2023, 11:37 a.m. UTC
  The following commit has been merged into the x86/bugs branch of tip:

Commit-ID:     9d9c22cc444af01ce254872b729af26864c43a3a
Gitweb:        https://git.kernel.org/tip/9d9c22cc444af01ce254872b729af26864c43a3a
Author:        Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate:    Fri, 20 Oct 2023 13:17:14 +02:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Fri, 20 Oct 2023 13:17:14 +02:00

x86/retpoline: Document some thunk handling aspects

After a lot of experimenting (see thread Link points to) document for
now the issues and requirements for future improvements to the thunk
handling and potential issuing of a diagnostic when the default thunk
hasn't been patched out.

This documentation is only temporary and that close before the merge
window it is only a placeholder for those future improvements.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20231010171020.462211-1-david.kaplan@amd.com
---
 arch/x86/lib/retpoline.S | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
  

Patch

diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index d410aba..a48077c 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -129,6 +129,13 @@  SYM_CODE_END(__x86_indirect_jump_thunk_array)
 
 #ifdef CONFIG_RETHUNK
 
+/*
+ * Be careful here: that label cannot really be removed because in
+ * some configurations and toolchains, the JMP __x86_return_thunk the
+ * compiler issues is either a short one or the compiler doesn't use
+ * relocations for same-section JMPs and that breaks the returns
+ * detection logic in apply_returns() and in objtool.
+ */
 	.section .text..__x86.return_thunk
 
 #ifdef CONFIG_CPU_SRSO
@@ -361,6 +368,14 @@  SYM_FUNC_END(call_depth_return_thunk)
  * This code is only used during kernel boot or module init.  All
  * 'JMP __x86_return_thunk' sites are changed to something else by
  * apply_returns().
+ *
+ * This should be converted eventually to call a warning function which
+ * should scream loudly when the default return thunk is called after
+ * alternatives have been applied.
+ *
+ * That warning function cannot BUG() because the bug splat cannot be
+ * displayed in all possible configurations, leading to users not really
+ * knowing why the machine froze.
  */
 SYM_CODE_START(__x86_return_thunk)
 	UNWIND_HINT_FUNC