Commit ff05ab23 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/nospec, objtool: Introduce ANNOTATE_IGNORE_ALTERNATIVE

To facillitate other usage of ignoring alternatives; rename
ANNOTATE_NOSPEC_IGNORE to ANNOTATE_IGNORE_ALTERNATIVE.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent b69656fa
...@@ -19,6 +19,17 @@ ...@@ -19,6 +19,17 @@
.endm .endm
#endif #endif
/*
* objtool annotation to ignore the alternatives and only consider the original
* instruction(s).
*/
.macro ANNOTATE_IGNORE_ALTERNATIVE
.Lannotate_\@:
.pushsection .discard.ignore_alts
.long .Lannotate_\@ - .
.popsection
.endm
/* /*
* Issue one struct alt_instr descriptor entry (need to put it into * Issue one struct alt_instr descriptor entry (need to put it into
* the section .altinstructions, see below). This entry contains * the section .altinstructions, see below). This entry contains
......
...@@ -45,6 +45,16 @@ ...@@ -45,6 +45,16 @@
#define LOCK_PREFIX "" #define LOCK_PREFIX ""
#endif #endif
/*
* objtool annotation to ignore the alternatives and only consider the original
* instruction(s).
*/
#define ANNOTATE_IGNORE_ALTERNATIVE \
"999:\n\t" \
".pushsection .discard.ignore_alts\n\t" \
".long 999b - .\n\t" \
".popsection\n\t"
struct alt_instr { struct alt_instr {
s32 instr_offset; /* original instruction */ s32 instr_offset; /* original instruction */
s32 repl_offset; /* offset to replacement instruction */ s32 repl_offset; /* offset to replacement instruction */
......
...@@ -10,6 +10,15 @@ ...@@ -10,6 +10,15 @@
#include <asm/cpufeatures.h> #include <asm/cpufeatures.h>
#include <asm/msr-index.h> #include <asm/msr-index.h>
/*
* This should be used immediately before a retpoline alternative. It tells
* objtool where the retpolines are so that it can make sense of the control
* flow by just reading the original instruction(s) and ignoring the
* alternatives.
*/
#define ANNOTATE_NOSPEC_ALTERNATIVE \
ANNOTATE_IGNORE_ALTERNATIVE
/* /*
* Fill the CPU return stack buffer. * Fill the CPU return stack buffer.
* *
...@@ -56,19 +65,6 @@ ...@@ -56,19 +65,6 @@
#ifdef __ASSEMBLY__ #ifdef __ASSEMBLY__
/*
* This should be used immediately before a retpoline alternative. It tells
* objtool where the retpolines are so that it can make sense of the control
* flow by just reading the original instruction(s) and ignoring the
* alternatives.
*/
.macro ANNOTATE_NOSPEC_ALTERNATIVE
.Lannotate_\@:
.pushsection .discard.nospec
.long .Lannotate_\@ - .
.popsection
.endm
/* /*
* This should be used immediately before an indirect jump/call. It tells * This should be used immediately before an indirect jump/call. It tells
* objtool the subsequent indirect jump/call is vouched safe for retpoline * objtool the subsequent indirect jump/call is vouched safe for retpoline
...@@ -152,12 +148,6 @@ ...@@ -152,12 +148,6 @@
#else /* __ASSEMBLY__ */ #else /* __ASSEMBLY__ */
#define ANNOTATE_NOSPEC_ALTERNATIVE \
"999:\n\t" \
".pushsection .discard.nospec\n\t" \
".long 999b - .\n\t" \
".popsection\n\t"
#define ANNOTATE_RETPOLINE_SAFE \ #define ANNOTATE_RETPOLINE_SAFE \
"999:\n\t" \ "999:\n\t" \
".pushsection .discard.retpoline_safe\n\t" \ ".pushsection .discard.retpoline_safe\n\t" \
......
...@@ -457,13 +457,13 @@ static void add_ignores(struct objtool_file *file) ...@@ -457,13 +457,13 @@ static void add_ignores(struct objtool_file *file)
* But it at least allows objtool to understand the control flow *around* the * But it at least allows objtool to understand the control flow *around* the
* retpoline. * retpoline.
*/ */
static int add_nospec_ignores(struct objtool_file *file) static int add_ignore_alternatives(struct objtool_file *file)
{ {
struct section *sec; struct section *sec;
struct rela *rela; struct rela *rela;
struct instruction *insn; struct instruction *insn;
sec = find_section_by_name(file->elf, ".rela.discard.nospec"); sec = find_section_by_name(file->elf, ".rela.discard.ignore_alts");
if (!sec) if (!sec)
return 0; return 0;
...@@ -475,7 +475,7 @@ static int add_nospec_ignores(struct objtool_file *file) ...@@ -475,7 +475,7 @@ static int add_nospec_ignores(struct objtool_file *file)
insn = find_insn(file, rela->sym->sec, rela->addend); insn = find_insn(file, rela->sym->sec, rela->addend);
if (!insn) { if (!insn) {
WARN("bad .discard.nospec entry"); WARN("bad .discard.ignore_alts entry");
return -1; return -1;
} }
...@@ -1239,7 +1239,7 @@ static int decode_sections(struct objtool_file *file) ...@@ -1239,7 +1239,7 @@ static int decode_sections(struct objtool_file *file)
add_ignores(file); add_ignores(file);
ret = add_nospec_ignores(file); ret = add_ignore_alternatives(file);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment