Skip to content

Commit bb81700

Browse files
author
Peter Zijlstra
committed
objtool: Collect more annotations in objtool.h
Suggested-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a8a330d commit bb81700

File tree

4 files changed

+55
-50
lines changed

4 files changed

+55
-50
lines changed

arch/x86/include/asm/alternative.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@
5555
#define LOCK_PREFIX ""
5656
#endif
5757

58-
/*
59-
* objtool annotation to ignore the alternatives and only consider the original
60-
* instruction(s).
61-
*/
62-
#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS)
63-
6458
/*
6559
* The patching flags are part of the upper bits of the @ft_flags parameter when
6660
* specifying them. The split is currently like this:
@@ -307,12 +301,6 @@ void nop_func(void);
307301
.endm
308302
#endif
309303

310-
/*
311-
* objtool annotation to ignore the alternatives and only consider the original
312-
* instruction(s).
313-
*/
314-
#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=ANNOTYPE_IGNORE_ALTS
315-
316304
/*
317305
* Issue one struct alt_instr descriptor entry (need to put it into
318306
* the section .altinstructions, see below). This entry contains

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,6 @@
179179

180180
#ifdef __ASSEMBLY__
181181

182-
/*
183-
* This should be used immediately before an indirect jump/call. It tells
184-
* objtool the subsequent indirect jump/call is vouched safe for retpoline
185-
* builds.
186-
*/
187-
#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=ANNOTYPE_RETPOLINE_SAFE
188-
189182
/*
190183
* (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions
191184
* vs RETBleed validation.
@@ -345,8 +338,6 @@
345338

346339
#else /* __ASSEMBLY__ */
347340

348-
#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE)
349-
350341
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];
351342
extern retpoline_thunk_t __x86_indirect_thunk_array[];
352343
extern retpoline_thunk_t __x86_indirect_call_thunk_array[];

include/linux/instrumentation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/* Begin/end of an instrumentation safe region */
1111
#define __instrumentation_begin(c) ({ \
1212
asm volatile(__stringify(c) ": nop\n\t" \
13-
__ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_BEGIN)\
13+
ANNOTATE_INSTR_BEGIN(__ASM_BREF(c)) \
1414
: : "i" (c)); \
1515
})
1616
#define instrumentation_begin() __instrumentation_begin(__COUNTER__)
@@ -48,7 +48,7 @@
4848
*/
4949
#define __instrumentation_end(c) ({ \
5050
asm volatile(__stringify(c) ": nop\n\t" \
51-
__ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_END) \
51+
ANNOTATE_INSTR_END(__ASM_BREF(c)) \
5252
: : "i" (c)); \
5353
})
5454
#define instrumentation_end() __instrumentation_end(__COUNTER__)

include/linux/objtool.h

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
"911:\n\t" \
6464
__ASM_ANNOTATE(911b, type)
6565

66-
#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR)
67-
6866
#else /* __ASSEMBLY__ */
6967

7068
/*
@@ -113,19 +111,6 @@
113111
#endif
114112
.endm
115113

116-
/*
117-
* Use objtool to validate the entry requirement that all code paths do
118-
* VALIDATE_UNRET_END before RET.
119-
*
120-
* NOTE: The macro must be used at the beginning of a global symbol, otherwise
121-
* it will be ignored.
122-
*/
123-
#if defined(CONFIG_NOINSTR_VALIDATION) && \
124-
(defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO))
125-
#define VALIDATE_UNRET_BEGIN ANNOTATE type=ANNOTYPE_UNRET_BEGIN
126-
#else
127-
#define VALIDATE_UNRET_BEGIN
128-
#endif
129114

130115
.macro REACHABLE
131116
.Lhere_\@:
@@ -142,14 +127,6 @@
142127
.popsection
143128
.endm
144129

145-
#define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR
146-
147-
/*
148-
* This macro indicates that the following intra-function call is valid.
149-
* Any non-annotated intra-function call will cause objtool to issue a warning.
150-
*/
151-
#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=ANNOTYPE_INTRA_FUNCTION_CALL
152-
153130
#endif /* __ASSEMBLY__ */
154131

155132
#else /* !CONFIG_OBJTOOL */
@@ -161,16 +138,12 @@
161138
#define STACK_FRAME_NON_STANDARD_FP(func)
162139
#define __ASM_ANNOTATE(label, type)
163140
#define ASM_ANNOTATE(type)
164-
#define ANNOTATE_NOENDBR
165141
#define ASM_REACHABLE
166142
#else
167-
#define ANNOTATE_INTRA_FUNCTION_CALL
168143
.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0
169144
.endm
170145
.macro STACK_FRAME_NON_STANDARD func:req
171146
.endm
172-
.macro ANNOTATE_NOENDBR
173-
.endm
174147
.macro REACHABLE
175148
.endm
176149
.macro ANNOTATE type:req
@@ -179,4 +152,57 @@
179152

180153
#endif /* CONFIG_OBJTOOL */
181154

155+
#ifndef __ASSEMBLY__
156+
/*
157+
* Annotate away the various 'relocation to !ENDBR` complaints; knowing that
158+
* these relocations will never be used for indirect calls.
159+
*/
160+
#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR)
161+
/*
162+
* This should be used immediately before an indirect jump/call. It tells
163+
* objtool the subsequent indirect jump/call is vouched safe for retpoline
164+
* builds.
165+
*/
166+
#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE)
167+
/*
168+
* See linux/instrumentation.h
169+
*/
170+
#define ANNOTATE_INSTR_BEGIN(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_BEGIN)
171+
#define ANNOTATE_INSTR_END(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_END)
172+
/*
173+
* objtool annotation to ignore the alternatives and only consider the original
174+
* instruction(s).
175+
*/
176+
#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS)
177+
/*
178+
* This macro indicates that the following intra-function call is valid.
179+
* Any non-annotated intra-function call will cause objtool to issue a warning.
180+
*/
181+
#define ANNOTATE_INTRA_FUNCTION_CALL ASM_ANNOTATE(ANNOTYPE_INTRA_FUNCTION_CALL)
182+
/*
183+
* Use objtool to validate the entry requirement that all code paths do
184+
* VALIDATE_UNRET_END before RET.
185+
*
186+
* NOTE: The macro must be used at the beginning of a global symbol, otherwise
187+
* it will be ignored.
188+
*/
189+
#define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN)
190+
191+
#else
192+
#define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR
193+
#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=ANNOTYPE_RETPOLINE_SAFE
194+
/* ANNOTATE_INSTR_BEGIN ANNOTATE type=ANNOTYPE_INSTR_BEGIN */
195+
/* ANNOTATE_INSTR_END ANNOTATE type=ANNOTYPE_INSTR_END */
196+
#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=ANNOTYPE_IGNORE_ALTS
197+
#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=ANNOTYPE_INTRA_FUNCTION_CALL
198+
#define ANNOTATE_UNRET_BEGIN ANNOTATE type=ANNOTYPE_UNRET_BEGIN
199+
#endif
200+
201+
#if defined(CONFIG_NOINSTR_VALIDATION) && \
202+
(defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO))
203+
#define VALIDATE_UNRET_BEGIN ANNOTATE_UNRET_BEGIN
204+
#else
205+
#define VALIDATE_UNRET_BEGIN
206+
#endif
207+
182208
#endif /* _LINUX_OBJTOOL_H */

0 commit comments

Comments
 (0)