kernel_optimize_test/tools/objtool
Peter Zijlstra e68db6f780 x86/alternatives: Optimize optimize_nops()
commit 23c1ad538f4f371bdb67d8a112314842d5db7e5a upstream.

Currently, optimize_nops() scans to see if the alternative starts with
NOPs. However, the emit pattern is:

  141:	\oldinstr
  142:	.skip (len-(142b-141b)), 0x90

That is, when 'oldinstr' is short, the tail is padded with NOPs. This case
never gets optimized.

Rewrite optimize_nops() to replace any trailing string of NOPs inside
the alternative to larger NOPs. Also run it irrespective of patching,
replacing NOPs in both the original and replaced code.

A direct consequence is that 'padlen' becomes superfluous, so remove it.

 [ bp:
   - Adjust commit message
   - remove a stale comment about needing to pad
   - add a comment in optimize_nops()
   - exit early if the NOP verif. loop catches a mismatch - function
     should not not add NOPs in that case
   - fix the "optimized NOPs" offsets output ]

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20210326151259.442992235@infradead.org
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-07-25 11:26:12 +02:00
..
arch/x86 x86/alternatives: Optimize optimize_nops() 2022-07-25 11:26:12 +02:00
Documentation objtool: Support stack layout changes in alternatives 2022-07-25 11:26:06 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
arch.h objtool: Refactor ORC section generation 2022-07-25 11:26:05 +02:00
Build objtool: Enable compilation of objtool for all architectures 2020-05-20 09:17:28 -05:00
builtin-check.c objtool: Move ORC logic out of check() 2020-09-01 17:19:11 -05:00
builtin-orc.c objtool: Refactor ORC section generation 2022-07-25 11:26:05 +02:00
builtin.h objtool: Implement noinstr validation 2020-04-22 10:53:50 +02:00
cfi.h objtool: Fix !CFI insn_state propagation 2020-04-22 10:53:50 +02:00
check.c objtool: Combine UNWIND_HINT_RET_OFFSET and UNWIND_HINT_FUNC 2022-07-25 11:26:07 +02:00
check.h objtool: Combine UNWIND_HINT_RET_OFFSET and UNWIND_HINT_FUNC 2022-07-25 11:26:07 +02:00
elf.c objtool: Fix seg fault with Clang non-section symbols 2021-02-17 11:02:20 +01:00
elf.h objtool: Fix seg fault with Clang non-section symbols 2021-02-17 11:02:20 +01:00
Makefile objtool: Refactor ORC section generation 2022-07-25 11:26:05 +02:00
objtool.c objtool: Move object file loading out of check() 2020-09-01 17:19:07 -05:00
objtool.h objtool: Refactor ORC section generation 2022-07-25 11:26:05 +02:00
orc_dump.c objtool: Make unwind hint definitions available to other architectures 2020-09-10 10:43:13 -05:00
orc_gen.c objtool: Support stack layout changes in alternatives 2022-07-25 11:26:06 +02:00
special.c objtool: Abstract alternative special case handling 2020-09-10 10:43:13 -05:00
special.h objtool: Refactor jump table code to support other architectures 2020-09-10 10:43:13 -05:00
sync-check.sh x86/insn: Add a __ignore_sync_check__ marker 2022-07-25 11:26:11 +02:00
warn.h objtool: Rename find_containing_func() 2020-03-25 18:28:29 +01:00
weak.c objtool: Refactor ORC section generation 2022-07-25 11:26:05 +02:00