Skip to contentSkip to conversation

clocksource/drivers/arm_arch_timer: Force inlining of erratum_set_next_event_generic()

PATCH Applied Marc Zyngier 4 participants 4 messages Nov 17, 2021 – Dec 11, 2021

Subsystems (2)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 clocksource/drivers/arm_arch_timer: Force inlining of erratum_set_next_event_generic()

With some specific kernel configuration and Clang, the kernel fails to like with something like:

ld.lld: error: undefined symbol: __compiletime_assert_200

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:156 (./arch/arm64/include/asm/arch_timer.h:156)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

ld.lld: error: undefined symbol: __compiletime_assert_197

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:133 (./arch/arm64/include/asm/arch_timer.h:133)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

make: *** [Makefile:1161: vmlinux] Error 1

These are due to the BUILD_BUG() macros contained in the low-level accessors (arch_timer_reg_{write,read}_cp15) being emitted, as the access type wasn't known at compile time.

Fix this by making erratum_set_next_event_generic() __force_inline, resulting in the 'access' parameter to be resolved at compile time, similarly to what is already done for set_next_event().

Fixes 4775bc63f880 ("Add build-time guards for unhandled register accesses")
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 drivers/clocksource/arm_arch_timer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clocksource/arm_arch_timer.c +7 -2
index 9a04eacc4412..1ecd52f903b8 100644
@@ -394,8 +394,13 @@ EXPORT_SYMBOL_GPL(timer_unstable_counter_workaround);
 
 static atomic_t timer_unstable_counter_workaround_in_use = ATOMIC_INIT(0);
 
-static void erratum_set_next_event_generic(const int access, unsigned long evt,
-						struct clock_event_device *clk)
+/*
+ * Force the inlining of this function so that the register accesses
+ * can be themselves correctly inlined.
+ */
+static __always_inline
+void erratum_set_next_event_generic(const int access, unsigned long evt,
+				    struct clock_event_device *clk)
 {
 	unsigned long ctrl;
 	u64 cval;
Signature · 1 line
2.30.2
Tested-by on v1 1/1
#1 lore raw
Quoted 28 lines · Marc Zyngier

With some specific kernel configuration and Clang, the kernel fails to like with something like:

ld.lld: error: undefined symbol: __compiletime_assert_200

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:156 (./arch/arm64/include/asm/arch_timer.h:156)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

ld.lld: error: undefined symbol: __compiletime_assert_197

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:133 (./arch/arm64/include/asm/arch_timer.h:133)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

make: *** [Makefile:1161: vmlinux] Error 1

These are due to the BUILD_BUG() macros contained in the low-level accessors (arch_timer_reg_{write,read}_cp15) being emitted, as the access type wasn't known at compile time.

Fix this by making erratum_set_next_event_generic() __force_inline, resulting in the 'access' parameter to be resolved at compile time, similarly to what is already done for set_next_event().

Fixes 4775bc63f880 ("Add build-time guards for unhandled register accesses")
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nick Desaulniers <[email protected]>
Quoted 3 lines
---
 drivers/clocksource/arm_arch_timer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Thanks, Marc. I can confirm that this fixes the build issue for me.

Sami

Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Marc Zyngier
Quoted 2 lines · Marc Zyngier

With some specific kernel configuration and Clang, the kernel fails to like with something like:

Specifically, CONFIG_CFI_CLANG=y from what I could tell from looking into this: https://github.com/ClangBuiltLinux/linux/issues/1503

Quoted 13 lines

ld.lld: error: undefined symbol: __compiletime_assert_200

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:156 (./arch/arm64/include/asm/arch_timer.h:156)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

ld.lld: error: undefined symbol: __compiletime_assert_197

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:133 (./arch/arm64/include/asm/arch_timer.h:133)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

make: *** [Makefile:1161: vmlinux] Error 1

These are due to the BUILD_BUG() macros contained in the low-level accessors (arch_timer_reg_{write,read}_cp15) being emitted, as the access type wasn't known at compile time.

Quoted 5 lines

Fix this by making erratum_set_next_event_generic() __force_inline, resulting in the 'access' parameter to be resolved at compile time, similarly to what is already done for set_next_event().

Fixes 4775bc63f880 ("Add build-time guards for unhandled register accesses")

It looks like the prefix was removed? Shouldn't it be:

Fixes 4775bc63f880 ("clocksource/arm_arch_timer: Add build-time guards for unhandled register accesses")
Quoted 6 lines
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nick Desaulniers <[email protected]>
Quoted 27 lines
---
 drivers/clocksource/arm_arch_timer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clocksource/arm_arch_timer.c +7 -2
index 9a04eacc4412..1ecd52f903b8 100644
@@ -394,8 +394,13 @@ EXPORT_SYMBOL_GPL(timer_unstable_counter_workaround);
 
 static atomic_t timer_unstable_counter_workaround_in_use = ATOMIC_INIT(0);
 
-static void erratum_set_next_event_generic(const int access, unsigned long evt,
-						struct clock_event_device *clk)
+/*
+ * Force the inlining of this function so that the register accesses
+ * can be themselves correctly inlined.
+ */
+static __always_inline
+void erratum_set_next_event_generic(const int access, unsigned long evt,
+				    struct clock_event_device *clk)
 {
 	unsigned long ctrl;
 	u64 cval;
Signature · 1 line
2.30.2
merge bot Applied
#3 lore raw
In reply to Marc Zyngier
The following commit has been merged into the timers/urgent branch of tip:

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     1edb7e74a7d3d64dc4e69e7059b4eea526d19a10
Gitweb:        https://git.kernel.org/tip/1edb7e74a7d3d64dc4e69e7059b4eea526d19a10
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 17 Nov 2021 11:35:32 
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Fri, 10 Dec 2021 17:47:00 +01:00

clocksource/drivers/arm_arch_timer: Force inlining of erratum_set_next_event_generic()

With some specific kernel configuration and Clang, the kernel fails to like with something like:

ld.lld: error: undefined symbol: __compiletime_assert_200

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:156 (./arch/arm64/include/asm/arch_timer.h:156)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

ld.lld: error: undefined symbol: __compiletime_assert_197

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by arch_timer.h:133 (./arch/arm64/include/asm/arch_timer.h:133)
clocksource/arm_arch_timer.o:(erratum_set_next_event_generic) in archive drivers/built-in.a

make: *** [Makefile:1161: vmlinux] Error 1

These are due to the BUILD_BUG() macros contained in the low-level accessors (arch_timer_reg_{write,read}_cp15) being emitted, as the access type wasn't known at compile time.

Fix this by making erratum_set_next_event_generic() __force_inline, resulting in the 'access' parameter to be resolved at compile time, similarly to what is already done for set_next_event().

Fixes 4775bc63f880 ("Add build-time guards for unhandled register accesses")
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 drivers/clocksource/arm_arch_timer.c |  9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clocksource/arm_arch_timer.c +7 -2
index 9a04eac..1ecd52f 100644
@@ -394,8 +394,13 @@ EXPORT_SYMBOL_GPL(timer_unstable_counter_workaround);
 
 static atomic_t timer_unstable_counter_workaround_in_use = ATOMIC_INIT(0);
 
-static void erratum_set_next_event_generic(const int access, unsigned long evt,
-						struct clock_event_device *clk)
+/*
+ * Force the inlining of this function so that the register accesses
+ * can be themselves correctly inlined.
+ */
+static __always_inline
+void erratum_set_next_event_generic(const int access, unsigned long evt,
+				    struct clock_event_device *clk)
 {
 	unsigned long ctrl;
 	u64 cval;