Skip to contentSkip to conversation

ARM BCM53573 SoC hangs/lockups caused by locks/clock/random changes

PATCH Rafał Miłecki 7 participants 12 messages Sep 4, 2023 – Nov 14

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

I made a second attempt on debugging some longstanding stability issues affecting BCM53753 SoCs. Those are single CPU core ARM Cortex-A7 boards with a pretty slow arch timer running at 36,8 kHz.

After 0 to 20 minutes of close to zero activity I experience hangs and I need to wait a minute for watchdog to kick in and reboot device.

First debugging attempt:
https://lore.kernel.org/netdev/[email protected]/T/ ("ARM board lockups/hangs triggered by locks and mutexes")

After a lot of bisecting, testing & hacking I believe there are 3 types of kernel aspects that affect BCM53573 stability. I'd like to describe them below to document my debugging work. I'm clueless at this point. Maybe someone can come up with an idea of actual issue & ideally a solution.

#####

1. Locking

During my first bisecting attempts I found multiple locking-related commit that regressed stability.

Bisected commits:

131287ff833d ("once: add DO_ONCE_SLOW() for sleepable contexts").

and a following group:

d0d583484d2e ("locking/refcount: Consolidate implementations of refcount_t")
dab787c73f6e ("locking/refcount: Consolidate REFCOUNT_{MAX,SATURATED} definitions")
0d3182fbe689 ("locking/refcount: Move saturation warnings out of line")
809554147d60 ("locking/refcount: Improve performance of generic REFCOUNT_FULL code")
9c9269977f03 ("locking/refcount: Move the bulk of the REFCOUNT_FULL implementation into the <linux/refcount.h> header") 04bff7d7b808 ("locking/refcount: Remove unused refcount_*_checked() variants")
513b19a43bec ("locking/refcount: Ensure integer operands are treated as signed")
68b4ee68e8c8 ("locking/refcount: Define constants for saturation and max refcount values")

I don't believe there is actually anything wrong about above changes. Maybe it's some tiny timing thing that my board just doesn't like?

#####

2. Clock (arm,armv7-timer)

While comparing main clock in Broadcom's SDK with upstream one I noticed a tiny difference: mask value. I don't know it it makes any sense but switching from CLOCKSOURCE_MASK(56) to CLOCKSOURCE_MASK(64) in arm_arch_timer.c (to match SDK) increases average uptime (time before a hang/lockup happens) from 4 minutes to 36 minutes.

#####

3. Random code changes

During my bisecting attempts I found one commit that regressed kernel stability but actual changes were meaningless in context of locking. It was commit ad9b10d1eaad ("mtd: core: introduce of support for dynamic partitions"):
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ad9b10d1eaada169bd764abcab58f08538877e26

I thought that maybe it was all about making add_mtd_device() bigger and changing addresses of a lot of symbols (looking at System.map). So I reverted that mtd commit and developed a dummy change relocating as few symbols (System.map) as possible while still breaking stability:

kernel/sched/idle.c +15 -0
@@ -94,6 +94,21 @@ void __cpuidle default_idle_call(void)
 		arch_cpu_idle();
 		start_critical_timings();
 	}
+
+	if (cpu_idle_force_poll == 1234)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 5678)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 1234)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 5678)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 1234)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 5678)
+		arch_cpu_idle();
+	if (cpu_idle_force_poll == 1234)
+		arch_cpu_idle();
 }
 
 static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device *dev,

Above dummy change didn't relocate thousands of symbols but only about 20 of them. They happened to be lock symbols however. Does it make any sense for above diff to regress kernel stability for me and cause hangs/lockups?

System.map.bad renamed from System.map.good +30 -30

66 lines not on this page · raw message

###

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

#1 lore raw

Hi Rafał,

Quoted 7 lines · Rafał Miłecki

2. Clock (arm,armv7-timer)

While comparing main clock in Broadcom's SDK with upstream one I noticed a tiny difference: mask value. I don't know it it makes any sense but switching from CLOCKSOURCE_MASK(56) to CLOCKSOURCE_MASK(64) in arm_arch_timer.c (to match SDK) increases average uptime (time before a hang/lockup happens) from 4 minutes to 36 minutes.

That code path is used only for type != ARCH_TIMER_TYPE_CP15, but your kernel log

arch_timer: cp15 timer(s) running at 0.03MHz (virt).

suggest that type == ARCH_TIMER_TYPE_CP15?!?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#2 lore raw
In reply to Rafał Miłecki
Quoted 10 lines · Rafał Miłecki

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Quoted 7 lines

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

All the locking operations rely on the fact that the instruction to acquire or release a lock is atomic. Is it possible that it may not be the case under certain circumstances for this ARM BCM53573 SoC? Or maybe some Kconfig options are not set correctly like missing some errata that are needed.

I don't know enough about the 32-bit arm architecture to say whether this is the case or not, but that is my best guess.

Cheers,
Longman

#3 lore raw
Quoted 20 lines · Waiman Long
Quoted 10 lines · Rafał Miłecki

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Quoted 7 lines

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

Quoted 7 lines

All the locking operations rely on the fact that the instruction to acquire or release a lock is atomic. Is it possible that it may not be the case under certain circumstances for this ARM BCM53573 SoC? Or maybe some Kconfig options are not set correctly like missing some errata that are needed.

I don't know enough about the 32-bit arm architecture to say whether this is the case or not, but that is my best guess.

So, BCM53573 is Cortex-A7, which is ARMv7, which has the exclusive load/store instructions. Whether the SoC has the necessary exclusive monitors to support these instructions is another matter, and I suspect someone with documentation would need to check that.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#4 lore raw
Quoted 24 lines · Russell King (Oracle)
Quoted 23 lines · Waiman Long
Quoted 10 lines · Rafał Miłecki

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Quoted 7 lines

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

All the locking operations rely on the fact that the instruction to acquire or release a lock is atomic. Is it possible that it may not be the case under certain circumstances for this ARM BCM53573 SoC? Or maybe some Kconfig options are not set correctly like missing some errata that are needed.

Quoted 6 lines
Quoted 2 lines

I don't know enough about the 32-bit arm architecture to say whether this is the case or not, but that is my best guess.

So, BCM53573 is Cortex-A7, which is ARMv7, which has the exclusive load/store instructions. Whether the SoC has the necessary exclusive monitors to support these instructions is another matter, and I suspect someone with documentation would need to check that.

To clarify, it is not necessary to use atomic instruction as in x86, but the LL/SC style of synchronization instructions with proper hardware support should also be enough. Again the hardware needs to have the proper support for the correct operation of those synchronization instructions.

Cheers,
Longman

#5 lore raw
In reply to Russell King (Oracle)
Quoted 26 lines · Russell King (Oracle)
Quoted 25 lines · Waiman Long
Quoted 10 lines · Rafał Miłecki

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Quoted 7 lines

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

All the locking operations rely on the fact that the instruction to acquire or release a lock is atomic. Is it possible that it may not be the case under certain circumstances for this ARM BCM53573 SoC? Or maybe some Kconfig options are not set correctly like missing some errata that are needed.

Quoted 7 lines
Quoted 2 lines

I don't know enough about the 32-bit arm architecture to say whether this is the case or not, but that is my best guess.

So, BCM53573 is Cortex-A7, which is ARMv7, which has the exclusive load/store instructions. Whether the SoC has the necessary exclusive monitors to support these instructions is another matter, and I suspect someone with documentation would need to check that.

Finding documentation about this SoC has been very difficult unfortunately...

Would any of the lock or mutex debugging self test catch hardware designed without proper support for exclusive monitors in the DRAM controller? Keep in mind this is an uni-processor system however, does that mean we may have issues in our SMP_ON_UP alternative patching?

Signature · 1 line
Florian
#6 lore raw
Quoted 32 lines · Florian Fainelli
Quoted 29 lines · Russell King (Oracle)
Quoted 27 lines · Waiman Long
Quoted 10 lines · Rafał Miłecki

As those hangs/lockups are related to so many different changes it's really hard to debug them.

This bug seems to be specific to the slow arch clock that affects stability only when kernel locking code and symbols layout trigger some very specific timing.

Enabling CONFIG_PROVE_LOCKING seems to make issue go away but it affects so much code it's hard to tell why it actually matters.

Quoted 7 lines

Same for disabling CONFIG_SMP. I noticed Broadcom's SDK keeps it disabled. I tried it and it improves stability (I had 3 devices with 6 days of uptime and counting) indeed. Again it affects a lot of kernel parts so it's hard to tell why it helps.

Unless someone comes up with some magic solution I'll probably try building BCM53573 images without CONFIG_SMP for my personal needs.

All the locking operations rely on the fact that the instruction to acquire or release a lock is atomic. Is it possible that it may not be the case under certain circumstances for this ARM BCM53573 SoC? Or maybe some Kconfig options are not set correctly like missing some errata that are needed.

I don't know enough about the 32-bit arm architecture to say whether this is the case or not, but that is my best guess.

Quoted 8 lines
Quoted 4 lines

So, BCM53573 is Cortex-A7, which is ARMv7, which has the exclusive load/store instructions. Whether the SoC has the necessary exclusive monitors to support these instructions is another matter, and I suspect someone with documentation would need to check that.

Finding documentation about this SoC has been very difficult unfortunately...

Would any of the lock or mutex debugging self test catch hardware designed without proper support for exclusive monitors in the DRAM controller? Keep in mind this is an uni-processor system however, does that mean we may have issues in our SMP_ON_UP alternative patching?

Usually this kind of locking problem is timing related and it happens once in a while. It is not easy to have a test to reliably figure out if there is a problem. I am not sure about the SMP_ON_UP thing.

Cheers,
Longman

#7 lore raw
In reply to Rafał Miłecki

Hi Rafal,

Quoted 3 lines · Rafał Miłecki

I'm clueless at this point.
Maybe someone can come up with an idea of actual issue & ideally a solution.

Damn this is frustrating.

Quoted 7 lines

2. Clock (arm,armv7-timer)

While comparing main clock in Broadcom's SDK with upstream one I noticed a tiny difference: mask value. I don't know it it makes any sense but switching from CLOCKSOURCE_MASK(56) to CLOCKSOURCE_MASK(64) in arm_arch_timer.c (to match SDK) increases average uptime (time before a hang/lockup happens) from 4 minutes to 36 minutes.

This could be related to how often the system goes to idle.

Quoted 4 lines
kernel/sched/idle.c +4 -0
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();

kernel/sched/idle.c void __cpuidle default_idle_call(void) · line 111

Quoted 10 lines
kernel/sched/idle.c +10 -0
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();

Idle again.

I would have tried to see what arch_cpu_idle() is doing.

arm_pm_idle() or cpu_do_idle()?

What happens if you just put return in arch_cpu_idle() so it does nothing?

Yours,
Linus Walleij

#8 lore raw

Hi,

it's a late reply but I didn't find enough determination earlier.

Quoted 33 lines · Linus Walleij
Quoted 3 lines · Rafał Miłecki

I'm clueless at this point.
Maybe someone can come up with an idea of actual issue & ideally a solution.

Damn this is frustrating.

Quoted 7 lines

2. Clock (arm,armv7-timer)

While comparing main clock in Broadcom's SDK with upstream one I noticed a tiny difference: mask value. I don't know it it makes any sense but switching from CLOCKSOURCE_MASK(56) to CLOCKSOURCE_MASK(64) in arm_arch_timer.c (to match SDK) increases average uptime (time before a hang/lockup happens) from 4 minutes to 36 minutes.

This could be related to how often the system goes to idle.

Quoted 4 lines
kernel/sched/idle.c +4 -0
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();

kernel/sched/idle.c void __cpuidle default_idle_call(void) · line 111

Quoted 10 lines
kernel/sched/idle.c +10 -0
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 5678)
+               arch_cpu_idle();
+       if (cpu_idle_force_poll == 1234)
+               arch_cpu_idle();
Quoted 5 lines

Idle again.

I would have tried to see what arch_cpu_idle() is doing.

arm_pm_idle() or cpu_do_idle()?

In my case arm_pm_idle is NULL.

Quoted 2 lines

What happens if you just put return in arch_cpu_idle() so it does nothing?

Doesn't help. I also tried putting:
udelay(10);
and
udelay(1000);
at the arch_cpu_idle() beginning. None helped.

Here comes more interesting experiment though. Putting there:

if (!(foo++ % 10000)) {
	pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}

doesn't seem to help.

Putting following however seems to make kernel/device stable:

if (!(foo++ % 100)) {
	pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}

I think I'm just going to assume those chipsets are simply hw broken.

#9 lore raw
Quoted 6 lines · Rafał Miłecki

Here comes more interesting experiment though. Putting there:

if (!(foo++ % 10000)) {
        pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}
Quoted 8 lines

doesn't seem to help.

Putting following however seems to make kernel/device stable:

if (!(foo++ % 100)) {
        pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}

That's just too weird.

Quoted 1 line

I think I'm just going to assume those chipsets are simply hw broken.

If disabling CPU idle on these altogether stabilize them, then maybe that is what we need to do?

Yours,
Linus Walleij

#10 lore raw
Quoted 11 lines · Linus Walleij
Quoted 9 lines · Rafał Miłecki

Here comes more interesting experiment though. Putting there:

if (!(foo++ % 10000)) {
         pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}

doesn't seem to help.

Quoted 7 lines
Quoted 5 lines

Putting following however seems to make kernel/device stable:

if (!(foo++ % 100)) {
         pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle);
}

That's just too weird.

It does seem to indicate that idling for too long wrecks havoc, but it is indeed not making much sense. Not having proper documentation for this SoC, it is hard to figure out what impact does stopping the ARM CPU clock has on the rest of the memory subsystem, especially outside of the CPU. I do not believe that this SoC has any form of PLL clock gating or pulse skipping.

Quoted 5 lines
Quoted 2 lines

I think I'm just going to assume those chipsets are simply hw broken.

If disabling CPU idle on these altogether stabilize them, then maybe that is what we need to do?

Yes, please try booting with "nohlt" set on the kernel command line and see how that fares.

Also useful would be to dump the L2 CTLR and L2 ECTLR, this is a complete shot in the dark, though was initially wondering if there could be some retention issues, and would have recommended disabling the L2 retention policy completely just for testing.

MRC p15, 1, <Rt>, c9, c0, 2;

of particular interest here would be bit at position 0, try to see if changing it to 1 (3 cycles) or 0 (2 cycles) changes anything.

MRC p15, 1, <Rt>, c9, c0, 3;

the lower bits are reserved, so I would not necessarily expect them to be mapping to configurable latencies, but if you see non-zero values in bits [28:0], try changing them to 0 and see if that changes anything.

Thanks for your persistence!

Signature · 1 line
Florian
#11 lore raw

Rafal!

Quoted 34 lines · Florian Fainelli
Quoted 11 lines · Linus Walleij
Quoted 9 lines · Rafał Miłecki

Here comes more interesting experiment though. Putting there:

if (!(foo++ % 10000)) {
         pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle); }

doesn't seem to help.

Quoted 7 lines
Quoted 5 lines

Putting following however seems to make kernel/device stable:

if (!(foo++ % 100)) {
         pr_info("[%s] arm_pm_idle:%ps\n", __func__, arm_pm_idle); }

That's just too weird.

It does seem to indicate that idling for too long wrecks havoc, but it is indeed not making much sense. Not having proper documentation for this SoC, it is hard to figure out what impact does stopping the ARM CPU clock has on the rest of the memory subsystem, especially outside of the CPU. I do not believe that this SoC has any form of PLL clock gating or pulse skipping.

Quoted 5 lines
Quoted 2 lines

I think I'm just going to assume those chipsets are simply hw broken.

If disabling CPU idle on these altogether stabilize them, then maybe that is what we need to do?

Yes, please try booting with "nohlt" set on the kernel command line and see how that fares.

Also useful would be to dump the L2 CTLR and L2 ECTLR, this is a complete shot in the dark, though was initially wondering if there could be some retention issues, and would have recommended disabling the L2 retention policy completely just for testing.

MRC p15, 1, <Rt>, c9, c0, 2;

Quoted 7 lines

of particular interest here would be bit at position 0, try to see if changing it to 1 (3 cycles) or 0 (2 cycles) changes anything.

MRC p15, 1, <Rt>, c9, c0, 3;

the lower bits are reserved, so I would not necessarily expect them to be mapping to configurable latencies, but if you see non-zero values in bits [28:0], try changing them to 0 and see if that changes anything.

Thanks for your persistence!

Thankfully now we have MCPs and it did not take look to identify a lead that was actually documented into an internal bug tracker! Would you be able to test this branch:

https://github.com/ffainelli/linux/pull/new/rfc/bcm53573-counter-wa

Signature · 1 line
Florian