x86: Rewrite the retpoline rewrite logic
Status from this message: The following commit has been merged into the objtool/core branch of tip:
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest16 patches 15 repliesApplied
- v214 patches 30 repliesSuperseded
- v19 patches 42 repliesSuperseded
Changes in v3 from the cover letter
- rewrite the __x86_indirect_thunk_array[] stuff again
- rewrite the retpoline,amd rewrite logic, it now also supports rewriting the Jcc case, if the original instruction is long enough, but more importantly, it's simpler code.
- bpf label simplification patch
- random assorted cleanups
- actually managed to get bpf selftests working
Patches in v3 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/16 | objtool: Classify symbolstools/ tools/ | +26 | 1 reply | |
| 2/16 | objtool: Explicitly avoid self modifying code in .altinstr_replacementtools/ | +31 | 1 reply | |
| 3/16 | objtool: Shrink struct instructiontools/ tools/ | +3 | 0 replies | |
| 4/16 | objtool,x86: Replace alternatives with .retpoline_sitesarch/ tools/ tools/ +3 more | +107 | 0 replies | |
| 5/16 | x86/retpoline: Remove unused replacement symbolsarch/ arch/ | +0 | 0 replies | |
| 6/16 | x86/asm: Fix register orderarch/ | +10 | 0 replies | |
| 7/16 | x86/asm: Fixup odd GEN-for-each-reg.h usagearch/ arch/ | +3 | 0 replies | |
| 8/16 | x86/retpoline: Move the retpoline thunk declarations to nospec-branch.harch/ arch/ arch/ | +7 | 0 replies | |
| 9/16 | x86/retpoline: Create a retpoline thunk arrayarch/ arch/ | +16 | 0 replies | |
| 10/16 | x86/alternative: Implement .retpoline_sites supportarch/ arch/ arch/ +1 more | +150 | 2 replies | |
| 11/16 | x86/alternative: Handle Jcc __x86_indirect_thunk_\regarch/ | +34 | 1 reply | |
| 12/16 | x86/alternative: Try inline spectre_v2=retpoline,amdarch/ | +14 | 0 replies | |
| 13/16 | x86/alternative: Add debug prints to apply_retpolines()arch/ | +6 | 0 replies | |
| 14/16 | x86,bugs: Unconditionally allow spectre_v2=retpoline,amdarch/ | +0 | 0 replies | |
| 15/16 | bpf, x86: Simplify computing label offsetsarch/ | +42 | 0 replies | |
| 16/16 | bpf,x86: Respect X86_FEATURE_RETPOLINE*arch/ arch/ arch/ | +41 | 0 replies |
Reviews trailers per patch
None of the 16 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Alexei Starovoitov | Josh Poimboeuf | Borislav Petkov | Miroslav Benes |
|---|---|---|---|---|
| Series | A-b T-b | A-b | R-b | R-b |
| 1/16 | ||||
| 2/16 | ||||
| 3/16 | ||||
| 4/16 | ||||
| 5/16 | ||||
| 6/16 | ||||
| 7/16 | ||||
| 8/16 | ||||
| 9/16 | ||||
| 10/16 | ||||
| 11/16 | ||||
| 12/16 | ||||
| 13/16 | ||||
| 14/16 | ||||
| 15/16 | ||||
| 16/16 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [PATCH v3 00/16] x86: Rewrite the retpoline rewrite logic
Hi,
These patches rewrite the way retpolines are rewritten. Currently objtool emits alternative entries for most retpoline calls. However trying to extend that led to trouble (ELF files are horrid).
Therefore completely overhaul this and have objtool emit a .retpoline_sites section that lists all compiler generated retpoline thunk calls. Then the kernel can do with them as it pleases.
Notably it will:
- rewrite them to indirect instructions for !RETPOLINE
- rewrite them to lfence; indirect; for RETPOLINE_AMD, where size allows (boo clang!)
Specifically, the !RETPOLINE case can now also deal with the clang-special conditional-indirect-tail-call:
Jcc __x86_indirect_thunk_\reg.
Finally, also update the x86 BPF jit to catch up to recent times and do these same things.
All this should help improve performance by removing an indirection.
Patches can (soon) be found here:
git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git objtool/core
Changes since v2:
- rewrite the __x86_indirect_thunk_array[] stuff again
- rewrite the retpoline,amd rewrite logic, it now also supports rewriting the Jcc case, if the original instruction is long enough, but more importantly, it's simpler code.
- bpf label simplification patch
- random assorted cleanups
- actually managed to get bpf selftests working
--- arch/um/kernel/um_arch.c | 4 + arch/x86/include/asm/GEN-for-each-reg.h | 14 ++- arch/x86/include/asm/alternative.h | 1 + arch/x86/include/asm/asm-prototypes.h | 18 --- arch/x86/include/asm/nospec-branch.h | 72 ++--------- arch/x86/kernel/alternative.c | 189 ++++++++++++++++++++++++++++- arch/x86/kernel/cpu/bugs.c | 7 -- arch/x86/kernel/module.c | 9 +- arch/x86/kernel/vmlinux.lds.S | 14 +++ arch/x86/lib/retpoline.S | 56 ++------- arch/x86/net/bpf_jit_comp.c | 160 +++++++++--------------- arch/x86/net/bpf_jit_comp32.c | 22 +++- tools/objtool/arch/x86/decode.c | 120 ------------------ tools/objtool/check.c | 208 ++++++++++++++++++++++---------- tools/objtool/elf.c | 84 ------------- tools/objtool/include/objtool/check.h | 1 - tools/objtool/include/objtool/elf.h | 6 +- tools/objtool/special.c | 8 -- 18 files changed, 472 insertions(+), 521 deletions(-)