Skip to content

Commit

Permalink
x86/ftrace: Remove OBJECT_FILES_NON_STANDARD usage
Browse files Browse the repository at this point in the history
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: ed53a0d ("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
  • Loading branch information
Josh Poimboeuf committed Jun 6, 2022
1 parent dcea997 commit 7b6c7a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 0 additions & 4 deletions arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ KCSAN_SANITIZE := n

OBJECT_FILES_NON_STANDARD_test_nx.o := y

ifdef CONFIG_FRAME_POINTER
OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
endif

# If instrumentation of this dir is enabled, boot hangs during first second.
# Probably could be more selective here, but note that files related to irqs,
# boot, dumpstack/stacktrace, etc are either non-interesting or can lead to
Expand Down
11 changes: 8 additions & 3 deletions arch/x86/kernel/ftrace_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL)

jmp ftrace_epilogue
SYM_FUNC_END(ftrace_caller);
STACK_FRAME_NON_STANDARD_FP(ftrace_caller)

SYM_FUNC_START(ftrace_epilogue)
/*
Expand Down Expand Up @@ -282,6 +283,7 @@ SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
jmp ftrace_epilogue

SYM_FUNC_END(ftrace_regs_caller)
STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)


#else /* ! CONFIG_DYNAMIC_FTRACE */
Expand Down Expand Up @@ -311,10 +313,14 @@ trace:
jmp ftrace_stub
SYM_FUNC_END(__fentry__)
EXPORT_SYMBOL(__fentry__)
STACK_FRAME_NON_STANDARD_FP(__fentry__)

#endif /* CONFIG_DYNAMIC_FTRACE */

#ifdef CONFIG_FUNCTION_GRAPH_TRACER
SYM_FUNC_START(return_to_handler)
SYM_CODE_START(return_to_handler)
UNWIND_HINT_EMPTY
ANNOTATE_NOENDBR
subq $16, %rsp

/* Save the return values */
Expand All @@ -339,7 +345,6 @@ SYM_FUNC_START(return_to_handler)
int3
.Ldo_rop:
mov %rdi, (%rsp)
UNWIND_HINT_FUNC
RET
SYM_FUNC_END(return_to_handler)
SYM_CODE_END(return_to_handler)
#endif
6 changes: 6 additions & 0 deletions include/linux/objtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ struct unwind_hint {
.popsection
.endm

.macro STACK_FRAME_NON_STANDARD_FP func:req
#ifdef CONFIG_FRAME_POINTER
STACK_FRAME_NON_STANDARD \func
#endif
.endm

.macro ANNOTATE_NOENDBR
.Lhere_\@:
.pushsection .discard.noendbr
Expand Down
6 changes: 6 additions & 0 deletions tools/include/linux/objtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ struct unwind_hint {
.popsection
.endm

.macro STACK_FRAME_NON_STANDARD_FP func:req
#ifdef CONFIG_FRAME_POINTER
STACK_FRAME_NON_STANDARD \func
#endif
.endm

.macro ANNOTATE_NOENDBR
.Lhere_\@:
.pushsection .discard.noendbr
Expand Down

0 comments on commit 7b6c7a8

Please sign in to comment.