Skip to contentSkip to conversation

arm64: ftrace: Don't forbid CALL_OPS+CC_OPTIMIZE_FOR_SIZE with Clang

PATCH Applied Stephen Boyd 3 participants 3 messages Feb 23, 2024 – Feb 28, 2024 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: ftrace: Don't forbid CALL_OPS+CC_OPTIMIZE_FOR_SIZE with Clang

Per commit b3f11af9b2ce ("arm64: ftrace: forbid CALL_OPS with CC_OPTIMIZE_FOR_SIZE"), GCC is silently ignoring -falign-functions=N when passed -Os, causing functions to be improperly aligned. This doesn't seem to be a problem with Clang though, where enabling CALL_OPS with CC_OPTIMIZE_FOR_SIZE doesn't spit out any warnings at boot about misaligned patch-sites. Only forbid CALL_OPS if GCC is used and we're optimizing for size so that CALL_OPS can be used with clang optimizing for size.

Cc Jason Ling <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Bill Wendling <[email protected]>
Cc Justin Stitt <[email protected]>
Fixes b3f11af9b2ce ("arm64: ftrace: forbid CALL_OPS with CC_OPTIMIZE_FOR_SIZE")
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -1
index aa7c1d435139..6b96d75a3a3d 100644
@@ -198,7 +198,7 @@ config ARM64
 		if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS
 	select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \
 		if (DYNAMIC_FTRACE_WITH_ARGS && !CFI_CLANG && \
-		    !CC_OPTIMIZE_FOR_SIZE)
+		    (CC_IS_CLANG || !CC_OPTIMIZE_FOR_SIZE))
 	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
 		if DYNAMIC_FTRACE_WITH_ARGS
 	select HAVE_SAMPLE_FTRACE_DIRECT

base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d

Signature · 1 line
https://chromeos.dev
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Stephen Boyd

Per commit b3f11af9b2ce ("arm64: ftrace: forbid CALL_OPS with CC_OPTIMIZE_FOR_SIZE"), GCC is silently ignoring -falign-functions=N when passed -Os, causing functions to be improperly aligned. This doesn't seem to be a problem with Clang though, where enabling CALL_OPS with CC_OPTIMIZE_FOR_SIZE doesn't spit out any warnings at boot about misaligned patch-sites. Only forbid CALL_OPS if GCC is used and we're optimizing for size so that CALL_OPS can be used with clang optimizing for size.

Quoted 10 lines
Cc Jason Ling <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Bill Wendling <[email protected]>
Cc Justin Stitt <[email protected]>
Fixes b3f11af9b2ce ("arm64: ftrace: forbid CALL_OPS with CC_OPTIMIZE_FOR_SIZE")

Seems reasonable to me.

I wonder if that GCC issue is resolved with '-fmin-function-alignment' that is being introduced in GCC 14 [1]. If it is, I suspect this conditional could actually be CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT instead of CONFIG_CC_IS_CLANG, but that can obviously happen as a clean up later down the road (more just food for thought for the arm64 folks, not sure how much '-Os' is used in general)

[1]: https://git.kernel.org/masahiroy/linux-kbuild/c/5270316c9fec8cc99aa0e0a258509c5c7f789d12

Quoted 22 lines
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -1
index aa7c1d435139..6b96d75a3a3d 100644
@@ -198,7 +198,7 @@ config ARM64
 		if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS
 	select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \
 		if (DYNAMIC_FTRACE_WITH_ARGS && !CFI_CLANG && \
-		    !CC_OPTIMIZE_FOR_SIZE)
+		    (CC_IS_CLANG || !CC_OPTIMIZE_FOR_SIZE))
 	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
 		if DYNAMIC_FTRACE_WITH_ARGS
 	select HAVE_SAMPLE_FTRACE_DIRECT

base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d

Signature · 1 line
https://chromeos.dev
maintainer Applied
#2 lore raw
In reply to Stephen Boyd
Quoted 10 lines · Stephen Boyd

Per commit b3f11af9b2ce ("arm64: ftrace: forbid CALL_OPS with CC_OPTIMIZE_FOR_SIZE"), GCC is silently ignoring -falign-functions=N when passed -Os, causing functions to be improperly aligned. This doesn't seem to be a problem with Clang though, where enabling CALL_OPS with CC_OPTIMIZE_FOR_SIZE doesn't spit out any warnings at boot about misaligned patch-sites. Only forbid CALL_OPS if GCC is used and we're optimizing for size so that CALL_OPS can be used with clang optimizing for size.

[...]

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

[1/1] arm64: ftrace: Don't forbid CALL_OPS+CC_OPTIMIZE_FOR_SIZE with Clang

      https://git.kernel.org/arm64/c/a743f26d03a9
Signature · 1 line
Catalin