Skip to content

Commit bf5febe

Browse files
author
Peter Zijlstra
committed
objtool: Convert ANNOTATE_RETPOLINE_SAFE to ANNOTATE
Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 22c3d58 commit bf5febe

File tree

4 files changed

+22
-45
lines changed

4 files changed

+22
-45
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@
184184
* objtool the subsequent indirect jump/call is vouched safe for retpoline
185185
* builds.
186186
*/
187-
.macro ANNOTATE_RETPOLINE_SAFE
188-
.Lhere_\@:
189-
.pushsection .discard.retpoline_safe
190-
.long .Lhere_\@
191-
.popsection
192-
.endm
187+
#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=ANNOTYPE_RETPOLINE_SAFE
193188

194189
/*
195190
* (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions
@@ -350,11 +345,7 @@
350345

351346
#else /* __ASSEMBLY__ */
352347

353-
#define ANNOTATE_RETPOLINE_SAFE \
354-
"999:\n\t" \
355-
".pushsection .discard.retpoline_safe\n\t" \
356-
".long 999b\n\t" \
357-
".popsection\n\t"
348+
#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE)
358349

359350
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];
360351
extern retpoline_thunk_t __x86_indirect_thunk_array[];

include/linux/objtool_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ struct unwind_hint {
5858
* Annotate types
5959
*/
6060
#define ANNOTYPE_NOENDBR 1
61+
#define ANNOTYPE_RETPOLINE_SAFE 2
6162

6263
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/include/linux/objtool_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ struct unwind_hint {
5858
* Annotate types
5959
*/
6060
#define ANNOTYPE_NOENDBR 1
61+
#define ANNOTYPE_RETPOLINE_SAFE 2
6162

6263
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/objtool/check.c

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,12 +2373,12 @@ static int read_unwind_hints(struct objtool_file *file)
23732373
return 0;
23742374
}
23752375

2376-
static int read_annotate(struct objtool_file *file, void (*func)(int type, struct instruction *insn))
2376+
static int read_annotate(struct objtool_file *file, int (*func)(int type, struct instruction *insn))
23772377
{
23782378
struct section *sec;
23792379
struct instruction *insn;
23802380
struct reloc *reloc;
2381-
int type;
2381+
int type, ret;
23822382

23832383
sec = find_section_by_name(file->elf, ".discard.annotate_insn");
23842384
if (!sec)
@@ -2406,53 +2406,37 @@ static int read_annotate(struct objtool_file *file, void (*func)(int type, struc
24062406
return -1;
24072407
}
24082408

2409-
func(type, insn);
2409+
ret = func(type, insn);
2410+
if (ret < 0)
2411+
return ret;
24102412
}
24112413

24122414
return 0;
24132415
}
24142416

2415-
static void __annotate_noendbr(int type, struct instruction *insn)
2417+
static int __annotate_noendbr(int type, struct instruction *insn)
24162418
{
24172419
if (type != ANNOTYPE_NOENDBR)
2418-
return;
2420+
return 0;
24192421

24202422
insn->noendbr = 1;
2423+
return 0;
24212424
}
24222425

2423-
static int read_retpoline_hints(struct objtool_file *file)
2426+
static int __annotate_retpoline_safe(int type, struct instruction *insn)
24242427
{
2425-
struct section *rsec;
2426-
struct instruction *insn;
2427-
struct reloc *reloc;
2428-
2429-
rsec = find_section_by_name(file->elf, ".rela.discard.retpoline_safe");
2430-
if (!rsec)
2428+
if (type != ANNOTYPE_RETPOLINE_SAFE)
24312429
return 0;
24322430

2433-
for_each_reloc(rsec, reloc) {
2434-
if (reloc->sym->type != STT_SECTION) {
2435-
WARN("unexpected relocation symbol type in %s", rsec->name);
2436-
return -1;
2437-
}
2438-
2439-
insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
2440-
if (!insn) {
2441-
WARN("bad .discard.retpoline_safe entry");
2442-
return -1;
2443-
}
2444-
2445-
if (insn->type != INSN_JUMP_DYNAMIC &&
2446-
insn->type != INSN_CALL_DYNAMIC &&
2447-
insn->type != INSN_RETURN &&
2448-
insn->type != INSN_NOP) {
2449-
WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop");
2450-
return -1;
2451-
}
2452-
2453-
insn->retpoline_safe = true;
2431+
if (insn->type != INSN_JUMP_DYNAMIC &&
2432+
insn->type != INSN_CALL_DYNAMIC &&
2433+
insn->type != INSN_RETURN &&
2434+
insn->type != INSN_NOP) {
2435+
WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop");
2436+
return -1;
24542437
}
24552438

2439+
insn->retpoline_safe = true;
24562440
return 0;
24572441
}
24582442

@@ -2742,7 +2726,7 @@ static int decode_sections(struct objtool_file *file)
27422726
if (ret)
27432727
return ret;
27442728

2745-
ret = read_retpoline_hints(file);
2729+
ret = read_annotate(file, __annotate_retpoline_safe);
27462730
if (ret)
27472731
return ret;
27482732

0 commit comments

Comments
 (0)