x86/ftrace: Remove OBJECT_FILES_NON_STANDARD usage

The file-wide OBJECT_FILES_NON_STANDARD annotation is used with
CONFIG_FRAME_POINTER to tell objtool to skip the entire file when frame
pointers are enabled. However that annotation is now deprecated because
it doesn't work with IBT, where objtool runs on vmlinux.o instead of
individual translation units.

Instead, use more fine-grained function-specific annotations:

- The 'save_mcount_regs' macro does funny things with the frame pointer.
Use STACK_FRAME_NON_STANDARD_FP to tell objtool to ignore the
functions using it.

- The return_to_handler() "function" isn't actually a callable function.
Instead of being called, it's returned to. The real return address
isn't on the stack, so unwinding is already doomed no matter which
unwinder is used. So just remove the STT_FUNC annotation, telling
objtool to ignore it. That also removes the implicit
ANNOTATE_NOENDBR, which now needs to be made explicit.

Fixes the following warning:

vmlinux.o: warning: objtool: __fentry__+0x16: return with modified stack frame

Fixes: ed53a0d97192 ("x86/alternative: Use .ibt_endbr_seal to seal indirect calls")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/b7a7a42fe306aca37826043dac89e113a1acdbac.1654268610.git.jpoimboe@kernel.org

Changed files
+20 -7
arch
x86
include
linux
tools
include
linux
-4
arch/x86/kernel/Makefile
··· 36 36 37 37 OBJECT_FILES_NON_STANDARD_test_nx.o := y 38 38 39 - ifdef CONFIG_FRAME_POINTER 40 - OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y 41 - endif 42 - 43 39 # If instrumentation of this dir is enabled, boot hangs during first second. 44 40 # Probably could be more selective here, but note that files related to irqs, 45 41 # boot, dumpstack/stacktrace, etc are either non-interesting or can lead to
+8 -3
arch/x86/kernel/ftrace_64.S
··· 175 175 176 176 jmp ftrace_epilogue 177 177 SYM_FUNC_END(ftrace_caller); 178 + STACK_FRAME_NON_STANDARD_FP(ftrace_caller) 178 179 179 180 SYM_FUNC_START(ftrace_epilogue) 180 181 /* ··· 283 282 jmp ftrace_epilogue 284 283 285 284 SYM_FUNC_END(ftrace_regs_caller) 285 + STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller) 286 286 287 287 288 288 #else /* ! CONFIG_DYNAMIC_FTRACE */ ··· 313 311 jmp ftrace_stub 314 312 SYM_FUNC_END(__fentry__) 315 313 EXPORT_SYMBOL(__fentry__) 314 + STACK_FRAME_NON_STANDARD_FP(__fentry__) 315 + 316 316 #endif /* CONFIG_DYNAMIC_FTRACE */ 317 317 318 318 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 319 - SYM_FUNC_START(return_to_handler) 319 + SYM_CODE_START(return_to_handler) 320 + UNWIND_HINT_EMPTY 321 + ANNOTATE_NOENDBR 320 322 subq $16, %rsp 321 323 322 324 /* Save the return values */ ··· 345 339 int3 346 340 .Ldo_rop: 347 341 mov %rdi, (%rsp) 348 - UNWIND_HINT_FUNC 349 342 RET 350 - SYM_FUNC_END(return_to_handler) 343 + SYM_CODE_END(return_to_handler) 351 344 #endif
+6
include/linux/objtool.h
··· 143 143 .popsection 144 144 .endm 145 145 146 + .macro STACK_FRAME_NON_STANDARD_FP func:req 147 + #ifdef CONFIG_FRAME_POINTER 148 + STACK_FRAME_NON_STANDARD \func 149 + #endif 150 + .endm 151 + 146 152 .macro ANNOTATE_NOENDBR 147 153 .Lhere_\@: 148 154 .pushsection .discard.noendbr
+6
tools/include/linux/objtool.h
··· 143 143 .popsection 144 144 .endm 145 145 146 + .macro STACK_FRAME_NON_STANDARD_FP func:req 147 + #ifdef CONFIG_FRAME_POINTER 148 + STACK_FRAME_NON_STANDARD \func 149 + #endif 150 + .endm 151 + 146 152 .macro ANNOTATE_NOENDBR 147 153 .Lhere_\@: 148 154 .pushsection .discard.noendbr