ARM: integrator: Fix early initialization
Subsystems (4)
Linus Walleij
maintainerPATCH 1/1 ARM: integrator: Fix early initialization
From: Guenter Roeck <[email protected]>
Starting with commit bdb249fce9ad4 ("ARM: integrator: read counter using syscon/regmap"), intcp_init_early calls syscon_regmap_lookup_by_compatible which in turn calls of_syscon_register. This function allocates memory. Since the memory management code has not been initialized at that time, the call always fails. It either returns -ENOMEM or crashes as follows.
Unable to handle kernel NULL pointer dereference at virtual address 0000000c when read [0000000c] *pgd=00000000 Internal error: Oops: 5 [#1] ARM Modules linked in: CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.15.0-rc5-00026-g5fcc9bf84ee5 #1 PREEMPT Hardware name: ARM Integrator/CP (Device Tree) PC is at __kmalloc_cache_noprof+0xec/0x39c LR is at __kmalloc_cache_noprof+0x34/0x39c ... Call trace: __kmalloc_cache_noprof from of_syscon_register+0x7c/0x310 of_syscon_register from device_node_get_regmap+0xa4/0xb0 device_node_get_regmap from intcp_init_early+0xc/0x40 intcp_init_early from start_kernel+0x60/0x688 start_kernel from 0x0
The crash is seen due to a dereferenced pointer which is not supposed to be NULL but is NULL if the memory management subsystem has not been initialized. The crash is not seen with all versions of gcc. Some versions such as gcc 9.x apparently do not dereference the pointer, presumably if tracing is disabled. The problem has been reproduced with gcc 10.x, 11.x, and 13.x. Either case, if the crash is not seen, the call to syscon_regmap_lookup_by_compatible returns -ENOMEM, and sched_clock_register is never called.
Fix the problem by moving the early initialization code into the standard machine initialization code.
---
Hi SoC folks, please apply this directly for fixes. Got stuck on a sideways branch for way too long.
--- arch/arm/mach-versatile/integrator_cp.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
arch/arm/mach-versatile/integrator_cp.c +4 -9
@@ -86,14 +86,6 @@ static u64 notrace intcp_read_sched_clock(void)return val; } -static void __init intcp_init_early (void ) -{ - cm_map =syscon_regmap_lookup_by_compatible ("arm,core-module-integrator" ); -if (IS_ERR (cm_map)) -return ; -sched_clock_register (intcp_read_sched_clock,32 ,24000000 ); -} -static void __init intcp_init_irq_of (void ) {cm_init ();
@@ -119,6 +111,10 @@ static void __init intcp_init_of(void) {struct device_node *cpcon; + cm_map =syscon_regmap_lookup_by_compatible ("arm,core-module-integrator" ); +if (!IS_ERR (cm_map)) +sched_clock_register (intcp_read_sched_clock,32 ,24000000 ); + cpcon =of_find_matching_node (NULL , intcp_syscon_match);if (!cpcon)return ;
@@ -138,7 +134,6 @@ static const char * intcp_dt_board_compat[] = {DT_MACHINE_START (INTEGRATOR_CP_DT ,"ARM Integrator/CP (Device Tree)" ) .reserve = integrator_reserve, .map_io = intcp_map_io, - .init_early = intcp_init_early, .init_irq = intcp_init_irq_of, .init_machine = intcp_init_of, .dt_compat = intcp_dt_board_compat,
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20250603-integrator-fixes-a8345ddba610
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Quoted 36 lines · Linus Walleij
From: Guenter Roeck <[email protected]>
Starting with commit
bdb249fce9ad4("ARM: integrator: read counter using syscon/regmap"),intcp_init_earlycallssyscon_regmap_lookup_by_compatiblewhich in turn callsof_syscon_register. This function allocates memory. Since the memory management code has not been initialized at that time, the call always fails. It either returns-ENOMEMor crashes as follows.Unable to handle kernel NULL pointer dereference at virtual address 0000000c when read [0000000c] *pgd=00000000 Internal error: Oops: 5 [#1] ARM Modules linked in: CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.15.0-rc5-00026-g5fcc9bf84ee5 #1 PREEMPT Hardware name: ARM Integrator/CP (Device Tree) PC is at __kmalloc_cache_noprof+0xec/0x39c LR is at __kmalloc_cache_noprof+0x34/0x39c ... Call trace: __kmalloc_cache_noprof from of_syscon_register+0x7c/0x310 of_syscon_register from device_node_get_regmap+0xa4/0xb0 device_node_get_regmap from intcp_init_early+0xc/0x40 intcp_init_early from start_kernel+0x60/0x688 start_kernel from 0x0The crash is seen due to a dereferenced pointer which is not supposed to be NULL but is NULL if the memory management subsystem has not been initialized. The crash is not seen with all versions of gcc. Some versions such as gcc 9.x apparently do not dereference the pointer, presumably if tracing is disabled. The problem has been reproduced with gcc 10.x, 11.x, and 13.x. Either case, if the crash is not seen, the call to
syscon_regmap_lookup_by_compatiblereturns-ENOMEM, andsched_clock_registeris never called.Fix the problem by moving the early initialization code into the standard machine initialization code.
Quoted 8 lines
Fixes bdb249fce9ad4 ("ARM: integrator: read counter using syscon/regmap")Cc Linus Walleij <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Linus Walleij <[email protected]>---
Hi SoC folks, please apply this directly for fixes. Got stuck on a sideways branch for way too long.
I actually stopped testing the integratorcp qemu emulation because it no longer works reliably, not even with gcc 9.x, since the timer-sp804 patches were applied.
Given that apparently no one but me ever hit that problem, I wonder if it is time to remove support for that machine entirely.
Guenter
Linus Walleij
maintainerQuoted 6 lines · Guenter Roeck
I actually stopped testing the integratorcp qemu emulation because it no longer works reliably, not even with gcc 9.x, since the timer-sp804 patches were applied.
Given that apparently no one but me ever hit that problem, I wonder if it is time to remove support for that machine entirely.
I actually have the hardware, even several of them, I've been keeping them as a base reference for old 32bit ARM. Ethernet broke on the one I had out so I need to bring a new one (yeah, as in factory-new) from a box.
Yours,
Linus Walleij
Quoted 6 lines · Linus Walleij
Quoted 4 lines · Guenter Roeck
I actually stopped testing the integratorcp qemu emulation because it no longer works reliably, not even with gcc 9.x, since the timer-sp804 patches were applied.
Quoted 8 lines
Quoted 2 lines
Given that apparently no one but me ever hit that problem, I wonder if it is time to remove support for that machine entirely.
I actually have the hardware, even several of them, I've been keeping them as a base reference for old 32bit ARM. Ethernet broke on the one I had out so I need to bring a new one (yeah, as in factory-new) from a box.
If those still worked with recent kernels, it just kind of confirms that trying to run the integratorcp qemu emulation with a recent kernel is futile ...
Note: With this patch applied on top of mainline, I get the following backtrace when trying to boot from qemu.
=============================^M
[ BUG: Invalid wait context ]^M
7.1.0-rc1-00002-gdbd65c72b68b #1 Not tainted^M
-----------------------------^M
swapper/0/1 is trying to lock:^Mc1d25410 (syscon:117:(&syscon_config)->lock){....}-{3:3}, at: regmap_lock_spinlock+0xc/0x18^M other info that might help us debug this:^M
context-{2:2}^M
1 lock held by swapper/0/1:^M
#0: c12874b8 (&rq->__lock){-.-.}-{2:2}, at: raw_spin_rq_lock_nested+0x28/0x40^M
stack backtrace:^M CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.1.0-rc1-00002-gdbd65c72b68b #1 PREEMPT ^M Hardware name: ARM Integrator/CP (Device Tree)^M Call trace: ^M unwind_backtrace from show_stack+0x10/0x18^M show_stack from dump_stack_lvl+0x44/0x6c^M dump_stack_lvl from __lock_acquire+0x11b0/0x2dbc^M __lock_acquire from lock_acquire+0x114/0x3dc^M lock_acquire from _raw_spin_lock_irqsave+0x5c/0x7c^M _raw_spin_lock_irqsave from regmap_lock_spinlock+0xc/0x18^M regmap_lock_spinlock from regmap_read+0x30/0x6c^M regmap_read from intcp_read_sched_clock+0x34/0x6c^M intcp_read_sched_clock from sched_clock+0x48/0x114^M sched_clock from update_rq_clock+0x50/0x2f0^M update_rq_clock from sched_tick+0x64/0x32c^M sched_tick from update_process_times+0x7c/0x1a8^M update_process_times from tick_periodic.constprop.0+0x34/0x134^M tick_periodic.constprop.0 from tick_handle_periodic+0x20/0x8c^M tick_handle_periodic from sp804_timer_interrupt+0x28/0x38^M sp804_timer_interrupt from __handle_irq_event_percpu+0xb8/0x498^M
... and the image hangs randomly.
Guenter
This patch was applied to soc/soc.git (arm/fixes) by Arnd Bergmann <[email protected]>:
Hello:
This patch was applied to soc/soc.git (arm/fixes)
by Arnd Bergmann <[email protected]>:
Quoted 9 lines · On Tue, 05 May 2026 21:15:37 +0200 you wrote:
From: Guenter Roeck <[email protected]>
Starting with commit
bdb249fce9ad4("ARM: integrator: read counter using syscon/regmap"),intcp_init_earlycallssyscon_regmap_lookup_by_compatiblewhich in turn callsof_syscon_register. This function allocates memory. Since the memory management code has not been initialized at that time, the call always fails. It either returns-ENOMEMor crashes as follows.[...]
Here is the summary with links:
- ARM: integrator: Fix early initialization
https://git.kernel.org/soc/soc/c/90d77b30a666
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html