Re: [x86, build] 6dafca9780: WARNING:at_arch/x86/kernel/ftrace.c:#ftrace_verify_code

From: Sami Tolvanen
Date: Tue Mar 02 2021 - 02:12:27 EST


On Sun, Feb 28, 2021 at 11:25 PM kernel test robot
<oliver.sang@xxxxxxxxx> wrote:
>
>
> Greeting,
>
> FYI, we noticed the following commit (built with clang-13):
>
> commit: 6dafca97803309c3cb5148d449bfa711e41ddef2 ("x86, build: use objtool mcount")
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git master

Thanks for the report, I'm able to reproduce the warning.

> [ 4.764496] ------------[ ftrace bug ]------------
> [ 4.764847] ftrace failed to modify
> [ 4.764852] do_sys_open (kbuild/src/consumer/fs/open.c:1186)
> [ 4.765483] actual: 0f:1f:44:00:00
> [ 4.765784] Setting ftrace call site to call ftrace function
> [ 4.766193] ftrace record flags: 50000001
> [ 4.766490] (1) R
> [ 4.766490] expected tramp: ffffffff81037af0
> [ 4.766959] ------------[ cut here ]------------

Basically, the problem is that ftrace_replace_code() expects to find
ideal_nops[NOP_ATOMIC5] here, which in this case is 66:66:66:66:90,
while objtool has replaced the __fentry__ call with 0f:1f:44:00:00.

As ideal_nops changes depending on kernel config and hardware, when
CC_USING_NOP_MCOUNT is defined we could either change
ftrace_nop_replace() to always use P6_NOP5, or skip
ftrace_verify_code() in ftrace_replace_code() for
FTRACE_UPDATE_MAKE_CALL.

Steven, Peter, any thoughts?

Sami