Skip to contentSkip to conversation

trace: Make FTRACE_MCOUNT_USE_RECORDMCOUNT configurable

RFC PATCH In review Alexey Kardashevskiy 5 participants 8 messages Feb 11, 2022 – Feb 16, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 trace: Make FTRACE_MCOUNT_USE_RECORDMCOUNT configurable

For whatever reason LLVM does not allow LTO (Link Time Optimization) if FTRACE_MCOUNT_USE_RECORDMCOUNT is enabled.

This allows disabling just this option instead of disabling all FTRACE options.

---

Or disabling FTRACE is the right thing to do if HAS_LTO_CLANG=y?

Came from arch/Kconfig:

config HAS_LTO_CLANG

        def_bool y
        depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
        depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
        depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
        depends on ARCH_SUPPORTS_LTO_CLANG
        depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT  <======
        depends on !KASAN || KASAN_HW_TAGS
        depends on !GCOV_KERNEL
---
 kernel/trace/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +2 -1
index a5eb5e7fd624..87d82d2b0b0b 100644
@@ -704,7 +704,8 @@ config FTRACE_MCOUNT_USE_OBJTOOL
 	depends on FTRACE_MCOUNT_RECORD
 
 config FTRACE_MCOUNT_USE_RECORDMCOUNT
-	def_bool y
+	bool "Enable FTRACE_MCOUNT_USE_RECORDMCOUNT"
+	default y
 	depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
 	depends on !FTRACE_MCOUNT_USE_CC
 	depends on !FTRACE_MCOUNT_USE_OBJTOOL
Signature · 1 line
2.30.2
#1 lore raw

+ Sami, Kees

Do you guys remember why we don't support
FTRACE_MCOUNT_USE_RECORDMCOUNT with LTO?
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/?

Quoted 46 lines · Alexey Kardashevskiy

For whatever reason LLVM does not allow LTO (Link Time Optimization) if FTRACE_MCOUNT_USE_RECORDMCOUNT is enabled.

This allows disabling just this option instead of disabling all FTRACE options.

---

Or disabling FTRACE is the right thing to do if HAS_LTO_CLANG=y?

Came from arch/Kconfig:

config HAS_LTO_CLANG

        def_bool y
        depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
        depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
        depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
        depends on ARCH_SUPPORTS_LTO_CLANG
        depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT  <======
        depends on !KASAN || KASAN_HW_TAGS
        depends on !GCOV_KERNEL
---
 kernel/trace/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +2 -2
index a5eb5e7fd624..87d82d2b0b0b 100644
@@ -704,7 +704,8 @@ config FTRACE_MCOUNT_USE_OBJTOOL
        depends on FTRACE_MCOUNT_RECORD
 
 config FTRACE_MCOUNT_USE_RECORDMCOUNT
-       def_bool y
+       bool "Enable FTRACE_MCOUNT_USE_RECORDMCOUNT"
+       default y
        depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
        depends on !FTRACE_MCOUNT_USE_CC
        depends on !FTRACE_MCOUNT_USE_OBJTOOL
--

2.30.2

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 5 lines · Nick Desaulniers

+ Sami, Kees

Do you guys remember why we don't support
FTRACE_MCOUNT_USE_RECORDMCOUNT with LTO?

It's because recordmcount cannot distinguish between calls and other references to mcount/fentry, which is a problem with LTO where we have to process the entire vmlinux.o and cannot ignore individual translation units. Instead of resorting to workarounds, Peter was kind enough to implement a smarter mcount pass in objtool, which we now use on x86_64 with LTO.

Alexey, which architecture are you trying to fix here?

Sami

#3 lore raw
Quoted 8 lines · Sami Tolvanen
Quoted 5 lines · Nick Desaulniers

+ Sami, Kees

Do you guys remember why we don't support
FTRACE_MCOUNT_USE_RECORDMCOUNT with LTO?

Quoted 6 lines

It's because recordmcount cannot distinguish between calls and other references to mcount/fentry, which is a problem with LTO where we have to process the entire vmlinux.o and cannot ignore individual translation units. Instead of resorting to workarounds, Peter was kind enough to implement a smarter mcount pass in objtool, which we now use on x86_64 with LTO.

So can x86_64 have both FTRACE_MCOUNT_USE_RECORDMCOUNT and LTO?

Quoted 1 line

Alexey, which architecture are you trying to fix here?

powerpc64le.

Quoted 2 lines

Sami

#4 lore raw
Quoted 11 lines · Alexey Kardashevskiy
Quoted 8 lines · Sami Tolvanen
Quoted 5 lines · Nick Desaulniers

+ Sami, Kees

Do you guys remember why we don't support
FTRACE_MCOUNT_USE_RECORDMCOUNT with LTO?

Quoted 6 lines
Quoted 6 lines

It's because recordmcount cannot distinguish between calls and other references to mcount/fentry, which is a problem with LTO where we have to process the entire vmlinux.o and cannot ignore individual translation units. Instead of resorting to workarounds, Peter was kind enough to implement a smarter mcount pass in objtool, which we now use on x86_64 with LTO.

I had responded on a different thread about this:
http://lkml.kernel.org/r/[email protected]

We are working on enabling 'objtool check --mcount' on powerpc.

Quoted 3 lines

So can x86_64 have both FTRACE_MCOUNT_USE_RECORDMCOUNT and LTO?

No. x86_64 now supports HAVE_OBJTOOL_MCOUNT, which enables FTRACE_MCOUNT_USE_OBJTOOL. That allows LTO to be used.

- Naveen

maintainer
#5 lore raw
In reply to Alexey Kardashevskiy
Quoted 5 lines · On Fri, 11 Feb 2022 12:43:13 +1100 Alexey Kardashevskiy <[email protected]> wrote:

For whatever reason LLVM does not allow LTO (Link Time Optimization) if FTRACE_MCOUNT_USE_RECORDMCOUNT is enabled.

This allows disabling just this option instead of disabling all FTRACE options.

What FTRACE options are you talking about?

Quoted 28 lines

---

Or disabling FTRACE is the right thing to do if HAS_LTO_CLANG=y?

Came from arch/Kconfig:

config HAS_LTO_CLANG

        def_bool y
        depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
        depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
        depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
        depends on ARCH_SUPPORTS_LTO_CLANG
        depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT  <======
        depends on !KASAN || KASAN_HW_TAGS
        depends on !GCOV_KERNEL
---
 kernel/trace/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +0 -0
index a5eb5e7fd624..87d82d2b0b0b 100644

kernel/trace/Kconfig config FTRACE_MCOUNT_USE_OBJTOOL · line 708

Quoted 6 lines
kernel/trace/Kconfig +2 -1
@@ -704,7 +704,8 @@ config FTRACE_MCOUNT_USE_OBJTOOL
 	depends on FTRACE_MCOUNT_RECORD
 
 config FTRACE_MCOUNT_USE_RECORDMCOUNT
-	def_bool y
+	bool "Enable FTRACE_MCOUNT_USE_RECORDMCOUNT"
+	default y

I don't think this does what you think it does.

This is not something that should be user selectable. What exactly are you trying to accomplish here?

-- Steve

Quoted 3 lines
kernel/trace/Kconfig +0 -0
 	depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
 	depends on !FTRACE_MCOUNT_USE_CC
 	depends on !FTRACE_MCOUNT_USE_OBJTOOL
#6 lore raw
Quoted 10 lines · Steven Rostedt
Quoted 5 lines · On Fri, 11 Feb 2022 12:43:13 +1100 Alexey Kardashevskiy <[email protected]> wrote:

For whatever reason LLVM does not allow LTO (Link Time Optimization) if FTRACE_MCOUNT_USE_RECORDMCOUNT is enabled.

This allows disabling just this option instead of disabling all FTRACE options.

What FTRACE options are you talking about?

LTO_CLANG_THIN => HAS_LTO_CLANG => !FTRACE_MCOUNT_USE_RECORDMCOUNT =>

FTRACE [=y] && !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY [=n] && !FTRACE_MCOUNT_USE_CC [=n] && !FTRACE_MCOUNT_USE_OBJTOOL [=n] && FTRACE_MCOUNT_RECORD [=y]

A bunch.

Quoted 31 lines
Quoted 31 lines

---

Or disabling FTRACE is the right thing to do if HAS_LTO_CLANG=y?

Came from arch/Kconfig:

config HAS_LTO_CLANG

         def_bool y
         depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
         depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
         depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
         depends on ARCH_SUPPORTS_LTO_CLANG
         depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT  <======
         depends on !KASAN || KASAN_HW_TAGS
         depends on !GCOV_KERNEL
---
  kernel/trace/Kconfig | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +0 -0
index a5eb5e7fd624..87d82d2b0b0b 100644
@@ -704,7 +704,8 @@ config FTRACE_MCOUNT_USE_OBJTOOL
  	depends on FTRACE_MCOUNT_RECORD
 
Quoted 6 lines

kernel/trace/Kconfig config FTRACE_MCOUNT_USE_OBJTOOL · line 708

Quoted 4 lines
kernel/trace/Kconfig +2 -1
  config FTRACE_MCOUNT_USE_RECORDMCOUNT
-	def_bool y
+	bool "Enable FTRACE_MCOUNT_USE_RECORDMCOUNT"
+	default y

I don't think this does what you think it does.

Sounds like it.

Quoted 2 lines

This is not something that should be user selectable. What exactly are you trying to accomplish here?

I am trying to

arch/powerpc/Kconfig +2 -0
index b779603978e1..91c122224f83 100644
@@ -153,6 +153,8 @@ config PPC
        select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
        select ARCH_WANT_LD_ORPHAN_WARN
        select ARCH_WEAK_RELEASE_ACQUIRE
+       select ARCH_SUPPORTS_LTO_CLANG          if PPC64
+       select ARCH_SUPPORTS_LTO_CLANG_THIN     if PPC64
 
 

to get LTO working on powerpc64le with minimal change to ppc64le_defconfig which has all these FTRACE_xxx enabled.

Quoted 8 lines

-- Steve

Quoted 3 lines
kernel/trace/Kconfig +0 -0
  	depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
  	depends on !FTRACE_MCOUNT_USE_CC
  	depends on !FTRACE_MCOUNT_USE_OBJTOOL
maintainer
#7 lore raw
Quoted 10 lines · On Wed, 16 Feb 2022 12:19:14 +1100 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 9 lines · Steven Rostedt
Quoted 5 lines · On Fri, 11 Feb 2022 12:43:13 +1100 Alexey Kardashevskiy <[email protected]> wrote:

For whatever reason LLVM does not allow LTO (Link Time Optimization) if FTRACE_MCOUNT_USE_RECORDMCOUNT is enabled.

This allows disabling just this option instead of disabling all FTRACE options.

Quoted 7 lines
Quoted 1 line

What FTRACE options are you talking about?

LTO_CLANG_THIN => HAS_LTO_CLANG => !FTRACE_MCOUNT_USE_RECORDMCOUNT =>

FTRACE [=y] && !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY [=n] && !FTRACE_MCOUNT_USE_CC [=n] && !FTRACE_MCOUNT_USE_OBJTOOL [=n] && FTRACE_MCOUNT_RECORD [=y]

So basically, turn off FUNCTION_TRACER and STACK_TRACER.

Quoted 61 lines

A bunch.

Quoted 31 lines
Quoted 31 lines

---

Or disabling FTRACE is the right thing to do if HAS_LTO_CLANG=y?

Came from arch/Kconfig:

config HAS_LTO_CLANG

         def_bool y
         depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
         depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
         depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
         depends on ARCH_SUPPORTS_LTO_CLANG
         depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT  <======
         depends on !KASAN || KASAN_HW_TAGS
         depends on !GCOV_KERNEL
---
  kernel/trace/Kconfig | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +0 -0
index a5eb5e7fd624..87d82d2b0b0b 100644
@@ -704,7 +704,8 @@ config FTRACE_MCOUNT_USE_OBJTOOL
  	depends on FTRACE_MCOUNT_RECORD
 
Quoted 6 lines

kernel/trace/Kconfig config FTRACE_MCOUNT_USE_OBJTOOL · line 708

Quoted 4 lines
kernel/trace/Kconfig +2 -1
  config FTRACE_MCOUNT_USE_RECORDMCOUNT
-	def_bool y
+	bool "Enable FTRACE_MCOUNT_USE_RECORDMCOUNT"
+	default y  

I don't think this does what you think it does.

Sounds like it.

Quoted 2 lines

This is not something that should be user selectable. What exactly are you trying to accomplish here?

I am trying to

arch/powerpc/Kconfig +2 -0
index b779603978e1..91c122224f83 100644
@@ -153,6 +153,8 @@ config PPC
         select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
         select ARCH_WANT_LD_ORPHAN_WARN
         select ARCH_WEAK_RELEASE_ACQUIRE
+       select ARCH_SUPPORTS_LTO_CLANG          if PPC64
+       select ARCH_SUPPORTS_LTO_CLANG_THIN     if PPC64
 
 
Quoted 2 lines

to get LTO working on powerpc64le with minimal change to ppc64le_defconfig which has all these FTRACE_xxx enabled.

Well, you can add a dependency against FUNCTION_TRACER. As that's what turns on the RECORD_MCOUNT, as RECORD_MCOUNT is needed by it.

-- Steve