arm64: ftrace: Define ftrace_stub_graph only with FUNCTION_GRAPH_TRACER

Message ID 20221109192831.3057131-1-samitolvanen@google.com
State New
Headers
Series arm64: ftrace: Define ftrace_stub_graph only with FUNCTION_GRAPH_TRACER |

Commit Message

Sami Tolvanen Nov. 9, 2022, 7:28 p.m. UTC
  The 0-day bot reports that arm64 builds with CONFIG_CFI_CLANG +
CONFIG_FTRACE are broken when CONFIG_FUNCTION_GRAPH_TRACER is not
enabled:

 ld.lld: error: undefined symbol: __kcfi_typeid_ftrace_stub_graph
 >>> referenced by entry-ftrace.S:299 (arch/arm64/kernel/entry-ftrace.S:299)
 >>>               arch/arm64/kernel/entry-ftrace.o:(.text+0x48) in archive vmlinux.a

This is caused by ftrace_stub_graph using SYM_TYPE_FUNC_START when
the address of the function is not taken in any C translation unit.

Fix the build by only defining ftrace_stub_graph when it's actually
needed, i.e. with CONFIG_FUNCTION_GRAPH_TRACER.

Link: https://lore.kernel.org/lkml/202210251659.tRMs78RH-lkp@intel.com/
Fixes: 883bbbffa5a4 ("ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/kernel/entry-ftrace.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: f141df371335645ce29a87d9683a3f79fba7fd67
  

Comments

Masami Hiramatsu (Google) Nov. 11, 2022, 1:29 p.m. UTC | #1
On Wed,  9 Nov 2022 19:28:31 +0000
Sami Tolvanen <samitolvanen@google.com> wrote:

> The 0-day bot reports that arm64 builds with CONFIG_CFI_CLANG +
> CONFIG_FTRACE are broken when CONFIG_FUNCTION_GRAPH_TRACER is not
> enabled:
> 
>  ld.lld: error: undefined symbol: __kcfi_typeid_ftrace_stub_graph
>  >>> referenced by entry-ftrace.S:299 (arch/arm64/kernel/entry-ftrace.S:299)
>  >>>               arch/arm64/kernel/entry-ftrace.o:(.text+0x48) in archive vmlinux.a
> 
> This is caused by ftrace_stub_graph using SYM_TYPE_FUNC_START when
> the address of the function is not taken in any C translation unit.
> 
> Fix the build by only defining ftrace_stub_graph when it's actually
> needed, i.e. with CONFIG_FUNCTION_GRAPH_TRACER.
> 
> Link: https://lore.kernel.org/lkml/202210251659.tRMs78RH-lkp@intel.com/
> Fixes: 883bbbffa5a4 ("ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph()")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

This looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks!

> ---
>  arch/arm64/kernel/entry-ftrace.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
> index 795344ab4ec4..322a831f8ede 100644
> --- a/arch/arm64/kernel/entry-ftrace.S
> +++ b/arch/arm64/kernel/entry-ftrace.S
> @@ -299,11 +299,11 @@ SYM_TYPED_FUNC_START(ftrace_stub)
>  	ret
>  SYM_FUNC_END(ftrace_stub)
>  
> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>  SYM_TYPED_FUNC_START(ftrace_stub_graph)
>  	ret
>  SYM_FUNC_END(ftrace_stub_graph)
>  
> -#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>  /*
>   * void return_to_handler(void)
>   *
> 
> base-commit: f141df371335645ce29a87d9683a3f79fba7fd67
> -- 
> 2.38.1.431.g37b22c650d-goog
>
  
Mark Rutland Nov. 11, 2022, 4:09 p.m. UTC | #2
On Wed, Nov 09, 2022 at 07:28:31PM +0000, Sami Tolvanen wrote:
> The 0-day bot reports that arm64 builds with CONFIG_CFI_CLANG +
> CONFIG_FTRACE are broken when CONFIG_FUNCTION_GRAPH_TRACER is not
> enabled:
> 
>  ld.lld: error: undefined symbol: __kcfi_typeid_ftrace_stub_graph
>  >>> referenced by entry-ftrace.S:299 (arch/arm64/kernel/entry-ftrace.S:299)
>  >>>               arch/arm64/kernel/entry-ftrace.o:(.text+0x48) in archive vmlinux.a
> 
> This is caused by ftrace_stub_graph using SYM_TYPE_FUNC_START when
> the address of the function is not taken in any C translation unit.
> 
> Fix the build by only defining ftrace_stub_graph when it's actually
> needed, i.e. with CONFIG_FUNCTION_GRAPH_TRACER.
> 
> Link: https://lore.kernel.org/lkml/202210251659.tRMs78RH-lkp@intel.com/
> Fixes: 883bbbffa5a4 ("ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph()")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/kernel/entry-ftrace.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
> index 795344ab4ec4..322a831f8ede 100644
> --- a/arch/arm64/kernel/entry-ftrace.S
> +++ b/arch/arm64/kernel/entry-ftrace.S
> @@ -299,11 +299,11 @@ SYM_TYPED_FUNC_START(ftrace_stub)
>  	ret
>  SYM_FUNC_END(ftrace_stub)
>  
> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>  SYM_TYPED_FUNC_START(ftrace_stub_graph)
>  	ret
>  SYM_FUNC_END(ftrace_stub_graph)
>  
> -#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>  /*
>   * void return_to_handler(void)
>   *
> 
> base-commit: f141df371335645ce29a87d9683a3f79fba7fd67
> -- 
> 2.38.1.431.g37b22c650d-goog
>
  
Kees Cook Nov. 11, 2022, 6:32 p.m. UTC | #3
On Wed, Nov 09, 2022 at 07:28:31PM +0000, Sami Tolvanen wrote:
> The 0-day bot reports that arm64 builds with CONFIG_CFI_CLANG +
> CONFIG_FTRACE are broken when CONFIG_FUNCTION_GRAPH_TRACER is not
> enabled:
> 
>  ld.lld: error: undefined symbol: __kcfi_typeid_ftrace_stub_graph
>  >>> referenced by entry-ftrace.S:299 (arch/arm64/kernel/entry-ftrace.S:299)
>  >>>               arch/arm64/kernel/entry-ftrace.o:(.text+0x48) in archive vmlinux.a
> 
> This is caused by ftrace_stub_graph using SYM_TYPE_FUNC_START when
> the address of the function is not taken in any C translation unit.
> 
> Fix the build by only defining ftrace_stub_graph when it's actually
> needed, i.e. with CONFIG_FUNCTION_GRAPH_TRACER.
> 
> Link: https://lore.kernel.org/lkml/202210251659.tRMs78RH-lkp@intel.com/
> Fixes: 883bbbffa5a4 ("ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph()")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>
  
Catalin Marinas Nov. 14, 2022, 1:28 p.m. UTC | #4
On Wed, 9 Nov 2022 19:28:31 +0000, Sami Tolvanen wrote:
> The 0-day bot reports that arm64 builds with CONFIG_CFI_CLANG +
> CONFIG_FTRACE are broken when CONFIG_FUNCTION_GRAPH_TRACER is not
> enabled:
> 
>  ld.lld: error: undefined symbol: __kcfi_typeid_ftrace_stub_graph
>  >>> referenced by entry-ftrace.S:299 (arch/arm64/kernel/entry-ftrace.S:299)
>  >>>               arch/arm64/kernel/entry-ftrace.o:(.text+0x48) in archive vmlinux.a
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: ftrace: Define ftrace_stub_graph only with FUNCTION_GRAPH_TRACER
      https://git.kernel.org/arm64/c/2598ac6ec493
  

Patch

diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 795344ab4ec4..322a831f8ede 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -299,11 +299,11 @@  SYM_TYPED_FUNC_START(ftrace_stub)
 	ret
 SYM_FUNC_END(ftrace_stub)
 
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 SYM_TYPED_FUNC_START(ftrace_stub_graph)
 	ret
 SYM_FUNC_END(ftrace_stub_graph)
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /*
  * void return_to_handler(void)
  *