Skip to content

Commit 9e0e3c5

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/speculation, objtool: Annotate indirect calls/jumps for objtool
Annotate the indirect calls/jumps in the CALL_NOSPEC/JUMP_NOSPEC alternatives. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Acked-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8735871 commit 9e0e3c5

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@
6767
.popsection
6868
.endm
6969

70+
/*
71+
* This should be used immediately before an indirect jump/call. It tells
72+
* objtool the subsequent indirect jump/call is vouched safe for retpoline
73+
* builds.
74+
*/
75+
.macro ANNOTATE_RETPOLINE_SAFE
76+
.Lannotate_\@:
77+
.pushsection .discard.retpoline_safe
78+
_ASM_PTR .Lannotate_\@
79+
.popsection
80+
.endm
81+
7082
/*
7183
* These are the bare retpoline primitives for indirect jmp and call.
7284
* Do not use these directly; they only exist to make the ALTERNATIVE
@@ -103,9 +115,9 @@
103115
.macro JMP_NOSPEC reg:req
104116
#ifdef CONFIG_RETPOLINE
105117
ANNOTATE_NOSPEC_ALTERNATIVE
106-
ALTERNATIVE_2 __stringify(jmp *\reg), \
118+
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *\reg), \
107119
__stringify(RETPOLINE_JMP \reg), X86_FEATURE_RETPOLINE, \
108-
__stringify(lfence; jmp *\reg), X86_FEATURE_RETPOLINE_AMD
120+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *\reg), X86_FEATURE_RETPOLINE_AMD
109121
#else
110122
jmp *\reg
111123
#endif
@@ -114,9 +126,9 @@
114126
.macro CALL_NOSPEC reg:req
115127
#ifdef CONFIG_RETPOLINE
116128
ANNOTATE_NOSPEC_ALTERNATIVE
117-
ALTERNATIVE_2 __stringify(call *\reg), \
129+
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *\reg), \
118130
__stringify(RETPOLINE_CALL \reg), X86_FEATURE_RETPOLINE,\
119-
__stringify(lfence; call *\reg), X86_FEATURE_RETPOLINE_AMD
131+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *\reg), X86_FEATURE_RETPOLINE_AMD
120132
#else
121133
call *\reg
122134
#endif
@@ -144,6 +156,12 @@
144156
".long 999b - .\n\t" \
145157
".popsection\n\t"
146158

159+
#define ANNOTATE_RETPOLINE_SAFE \
160+
"999:\n\t" \
161+
".pushsection .discard.retpoline_safe\n\t" \
162+
_ASM_PTR " 999b\n\t" \
163+
".popsection\n\t"
164+
147165
#if defined(CONFIG_X86_64) && defined(RETPOLINE)
148166

149167
/*
@@ -153,6 +171,7 @@
153171
# define CALL_NOSPEC \
154172
ANNOTATE_NOSPEC_ALTERNATIVE \
155173
ALTERNATIVE( \
174+
ANNOTATE_RETPOLINE_SAFE \
156175
"call *%[thunk_target]\n", \
157176
"call __x86_indirect_thunk_%V[thunk_target]\n", \
158177
X86_FEATURE_RETPOLINE)

0 commit comments

Comments
 (0)