[PATCH 5/7] x86/speculation: Annotate intra-function calls

From: Alexandre Chartre
Date: Thu Apr 02 2020 - 04:20:36 EST


Some speculative execution mitigations (like retpoline) use intra-
function calls. Provide a macro to annotate such intra-function calls
so they can be properly handled by objtool, and use this macro to
annotate intra-function calls.

Signed-off-by: Alexandre Chartre <alexandre.chartre@xxxxxxxxxx>
---
arch/x86/include/asm/nospec-branch.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 5c24a7b35166..a2885f801e13 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -77,13 +77,27 @@
.popsection
.endm

+/*
+ * Intra-function call instruction. This should be used as a substitute
+ * for the call instruction when doing an intra-function call. It is
+ * similar to the call instruction but it tells objtool that this is
+ * an intra-function call.
+ */
+.macro INTRA_FUNCTION_CALL dst:req
+ .Lannotate_\@:
+ .pushsection .discard.intra_function_call
+ _ASM_PTR .Lannotate_\@
+ .popsection
+ call \dst
+.endm
+
/*
* These are the bare retpoline primitives for indirect jmp and call.
* Do not use these directly; they only exist to make the ALTERNATIVE
* invocation below less ugly.
*/
.macro RETPOLINE_JMP reg:req
- call .Ldo_rop_\@
+ INTRA_FUNCTION_CALL .Ldo_rop_\@
.Lspec_trap_\@:
pause
lfence
@@ -102,7 +116,7 @@
.Ldo_retpoline_jmp_\@:
RETPOLINE_JMP \reg
.Ldo_call_\@:
- call .Ldo_retpoline_jmp_\@
+ INTRA_FUNCTION_CALL .Ldo_retpoline_jmp_\@
.endm

/*
--
2.18.2