public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues
@ 2026-01-27  8:49 Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 1/3] powerpc64: make clang cross-build friendly Hari Bathini
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hari Bathini @ 2026-01-27  8:49 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
	Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas

Support for -fpatchable-function-entry on ppc64le was added in Clang
with [1]. Faced a couple of issues while building the linux kernel
with Clang though. Patches 1 & 2 address those issues. The last patch
provides workaround to ensure, an open issue [2] in Clang with
-fpatchable-function-entry support, does not impact the linux
ftrace subsystem.

[1] https://github.com/llvm/llvm-project/pull/151569
[2] https://github.com/llvm/llvm-project/issues/163706


Hari Bathini (3):
  powerpc64: make clang cross-build friendly
  powerpc64/ftrace: fix OOL stub count with clang
  powerpc64/ftrace: workaround clang recording GEP in
    __patchable_function_entries

 arch/powerpc/Kconfig                          |  4 +--
 arch/powerpc/kernel/trace/ftrace.c            | 26 ++++++++++++++++---
 ....sh => check-fpatchable-function-entry.sh} |  0
 arch/powerpc/tools/ftrace-gen-ool-stubs.sh    |  4 +--
 4 files changed, 26 insertions(+), 8 deletions(-)
 rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] powerpc64: make clang cross-build friendly
  2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
@ 2026-01-27  8:49 ` Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 2/3] powerpc64/ftrace: fix OOL stub count with clang Hari Bathini
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hari Bathini @ 2026-01-27  8:49 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
	Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas

ARCH_USING_PATCHABLE_FUNCTION_ENTRY depends on toolchain support for
-fpatchable-function-entry option. The current script that checks
for this support only handles GCC. Rename the script and extend it
to detect support for -fpatchable-function-entry with Clang as well,
allowing clean cross-compilation with Clang toolchains.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---

* Changes in v2:
  - Use $(CLANG_FLAGS) instead of manually checking CC_IS_CLANG


 arch/powerpc/Kconfig                                          | 4 ++--
 ...e-function-entry.sh => check-fpatchable-function-entry.sh} | 0
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b8d36a261009..dcb9894e2004 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -571,8 +571,8 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
 	depends on FUNCTION_TRACER && (PPC32 || PPC64_ELF_ABI_V2)
 	depends on $(cc-option,-fpatchable-function-entry=2)
 	def_bool y if PPC32
-	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN
-	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
+	def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) $(CLANG_FLAGS) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN
+	def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
 
 config PPC_FTRACE_OUT_OF_LINE
 	def_bool PPC64 && ARCH_USING_PATCHABLE_FUNCTION_ENTRY
diff --git a/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh b/arch/powerpc/tools/check-fpatchable-function-entry.sh
similarity index 100%
rename from arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh
rename to arch/powerpc/tools/check-fpatchable-function-entry.sh
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] powerpc64/ftrace: fix OOL stub count with clang
  2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 1/3] powerpc64: make clang cross-build friendly Hari Bathini
@ 2026-01-27  8:49 ` Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hari Bathini @ 2026-01-27  8:49 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
	Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas

The total number of out-of-line (OOL) stubs required for function
tracing is determined using the following command:

    $(OBJDUMP) -r -j __patchable_function_entries vmlinux.o

While this works correctly with GNU objdump, llvm-objdump does not
list the expected relocation records for this section. Fix this by
using the -d option and counting R_PPC64_ADDR64 relocation entries.
This works as desired with both objdump and llvm-objdump.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---

* No changes since v1.


 arch/powerpc/tools/ftrace-gen-ool-stubs.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/tools/ftrace-gen-ool-stubs.sh b/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
index bac186bdf64a..9218d43aeb54 100755
--- a/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
+++ b/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
@@ -15,9 +15,9 @@ if [ -z "$is_64bit" ]; then
 	RELOCATION=R_PPC_ADDR32
 fi
 
-num_ool_stubs_total=$($objdump -r -j __patchable_function_entries "$vmlinux_o" |
+num_ool_stubs_total=$($objdump -r -j __patchable_function_entries -d "$vmlinux_o" |
 		      grep -c "$RELOCATION")
-num_ool_stubs_inittext=$($objdump -r -j __patchable_function_entries "$vmlinux_o" |
+num_ool_stubs_inittext=$($objdump -r -j __patchable_function_entries -d "$vmlinux_o" |
 			 grep -e ".init.text" -e ".text.startup" | grep -c "$RELOCATION")
 num_ool_stubs_text=$((num_ool_stubs_total - num_ool_stubs_inittext))
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
  2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 1/3] powerpc64: make clang cross-build friendly Hari Bathini
  2026-01-27  8:49 ` [PATCH v2 2/3] powerpc64/ftrace: fix OOL stub count with clang Hari Bathini
@ 2026-01-27  8:49 ` Hari Bathini
  2026-01-30  6:18 ` [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Venkat Rao Bagalkote
  2026-03-11  2:13 ` Madhavan Srinivasan
  4 siblings, 0 replies; 6+ messages in thread
From: Hari Bathini @ 2026-01-27  8:49 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
	Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas

Support for -fpatchable-function-entry on ppc64le was added in Clang
with [1]. However, when no prefix NOPs are specified - as is the case
with CONFIG_PPC_FTRACE_OUT_OF_LINE - the first NOP is emitted at LEP,
but Clang records the Global Entry Point (GEP) unlike GCC which does
record the Local Entry Point (LEP). Issue [2] has been raised to align
Clang's behavior with GCC. As a temporary workaround to ensure ftrace
initialization works as expected with Clang, derive the LEP using
ppc_function_entry() for kernel symbols and by looking for the below
module GEP sequence for module addresses, until [2] is resolved:

	ld	r2, -8(r12)
	add	r2, r2, r12

[1] https://github.com/llvm/llvm-project/pull/151569
[2] https://github.com/llvm/llvm-project/issues/163706

Cc: Maryam Moghadas <maryammo@ca.ibm.com>
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---

* No changes since v1.


 arch/powerpc/kernel/trace/ftrace.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index 841d077e2825..1b2f293e7dcb 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -37,11 +37,29 @@ unsigned long ftrace_call_adjust(unsigned long addr)
 	if (addr >= (unsigned long)__exittext_begin && addr < (unsigned long)__exittext_end)
 		return 0;
 
-	if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY) &&
-	    !IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) {
-		addr += MCOUNT_INSN_SIZE;
-		if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
+	if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY)) {
+		if (!IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) {
 			addr += MCOUNT_INSN_SIZE;
+			if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
+				addr += MCOUNT_INSN_SIZE;
+		} else if (IS_ENABLED(CONFIG_CC_IS_CLANG) && IS_ENABLED(CONFIG_PPC64)) {
+			/*
+			 * addr points to global entry point though the NOP was emitted at local
+			 * entry point due to https://github.com/llvm/llvm-project/issues/163706
+			 * Handle that here with ppc_function_entry() for kernel symbols while
+			 * adjusting module addresses in the else case, by looking for the below
+			 * module global entry point sequence:
+			 *	ld    r2, -8(r12)
+			 *	add   r2, r2, r12
+			 */
+			if (is_kernel_text(addr) || is_kernel_inittext(addr))
+				addr = ppc_function_entry((void *)addr);
+			else if ((ppc_inst_val(ppc_inst_read((u32 *)addr)) ==
+				  PPC_RAW_LD(_R2, _R12, -8)) &&
+				 (ppc_inst_val(ppc_inst_read((u32 *)(addr+4))) ==
+				  PPC_RAW_ADD(_R2, _R2, _R12)))
+				addr += 8;
+		}
 	}
 
 	return addr;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues
  2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
                   ` (2 preceding siblings ...)
  2026-01-27  8:49 ` [PATCH v2 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
@ 2026-01-30  6:18 ` Venkat Rao Bagalkote
  2026-03-11  2:13 ` Madhavan Srinivasan
  4 siblings, 0 replies; 6+ messages in thread
From: Venkat Rao Bagalkote @ 2026-01-30  6:18 UTC (permalink / raw)
  To: Hari Bathini, linuxppc-dev
  Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
	Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas


On 27/01/26 2:19 pm, Hari Bathini wrote:
> Support for -fpatchable-function-entry on ppc64le was added in Clang
> with [1]. Faced a couple of issues while building the linux kernel
> with Clang though. Patches 1 & 2 address those issues. The last patch
> provides workaround to ensure, an open issue [2] in Clang with
> -fpatchable-function-entry support, does not impact the linux
> ftrace subsystem.
>
> [1] https://github.com/llvm/llvm-project/pull/151569
> [2] https://github.com/llvm/llvm-project/issues/163706
>
>
> Hari Bathini (3):
>    powerpc64: make clang cross-build friendly
>    powerpc64/ftrace: fix OOL stub count with clang
>    powerpc64/ftrace: workaround clang recording GEP in
>      __patchable_function_entries
>
>   arch/powerpc/Kconfig                          |  4 +--
>   arch/powerpc/kernel/trace/ftrace.c            | 26 ++++++++++++++++---
>   ....sh => check-fpatchable-function-entry.sh} |  0
>   arch/powerpc/tools/ftrace-gen-ool-stubs.sh    |  4 +--
>   4 files changed, 26 insertions(+), 8 deletions(-)
>   rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)
>
Tested this patch series, and bulild is successful with both GCC and 
clang23.x version.


KERNEL PARAMETER enabled:

CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY=y
CONFIG_PPC_FTRACE_OUT_OF_LINE=y
CONFIG_PPC_FTRACE_OUT_OF_LINE_NUM_RESERVE=32768


clang version 23.0.0git


Please add below tag for the series.


Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>




Regards,

Venkat.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues
  2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
                   ` (3 preceding siblings ...)
  2026-01-30  6:18 ` [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Venkat Rao Bagalkote
@ 2026-03-11  2:13 ` Madhavan Srinivasan
  4 siblings, 0 replies; 6+ messages in thread
From: Madhavan Srinivasan @ 2026-03-11  2:13 UTC (permalink / raw)
  To: linuxppc-dev, Hari Bathini
  Cc: Naveen N. Rao, Michael Ellerman, linux-trace-kernel, Mark Rutland,
	Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas,
	Christophe Leroy

On Tue, 27 Jan 2026 14:19:23 +0530, Hari Bathini wrote:
> Support for -fpatchable-function-entry on ppc64le was added in Clang
> with [1]. Faced a couple of issues while building the linux kernel
> with Clang though. Patches 1 & 2 address those issues. The last patch
> provides workaround to ensure, an open issue [2] in Clang with
> -fpatchable-function-entry support, does not impact the linux
> ftrace subsystem.
> 
> [...]

Applied to powerpc/fixes.

[1/3] powerpc64: make clang cross-build friendly
      https://git.kernel.org/powerpc/c/73cdf24e81e4eba52a40a6b10c6cf285d0ac23fd
[2/3] powerpc64/ftrace: fix OOL stub count with clang
      https://git.kernel.org/powerpc/c/875612a7745013a43c67493cb0583ee3f7476344
[3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
      https://git.kernel.org/powerpc/c/db54c28702f7270e74dce36c84cb0db4cec96389

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-11  2:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27  8:49 [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
2026-01-27  8:49 ` [PATCH v2 1/3] powerpc64: make clang cross-build friendly Hari Bathini
2026-01-27  8:49 ` [PATCH v2 2/3] powerpc64/ftrace: fix OOL stub count with clang Hari Bathini
2026-01-27  8:49 ` [PATCH v2 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
2026-01-30  6:18 ` [PATCH v2 0/3] powerpc64/ftrace: fixes clang build issues Venkat Rao Bagalkote
2026-03-11  2:13 ` Madhavan Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox