Skip to contentSkip to conversation

ARM: hw_breakpoint: blacklist Scorpion CPUs

PATCH New Mark Rutland 4 participants 6 messages Jan 5, 2017 – Jan 10, 2017

Subsystems (3)
lore
Share & tools
lore

Mark Rutland

author maintainer
#0 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

On APQ8060, the kernel crashes in arch_hw_breakpoint_init, taking an undefined instruction trap within write_wb_reg. This is because Scorpion CPUs erroneously appear to set DBGPRSR.SPD when WFI is issued, even if the core is not powered down. When DBGPRSR.SPD is set, breakpoint and watchpoint registers are treated as undefined.

It's possible to trigger similar crashes later on from userspace, by requesting the kernel to install a breakpoint or watchpoint, as we can go idle at any point between the reset of the debug registers and their later use. This has always been the case.

Given that this has always been broken, no-one has complained until now, and there is no clear workaround, disable hardware breakpoints and watchpoints on Scorpion to avoid these issues.

Cc Russell King <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Will Deacon <[email protected]>
Cc stable at vger.kernel.org
---
 arch/arm/include/asm/cputype.h  |  3 +++
 arch/arm/kernel/hw_breakpoint.c | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)
arch/arm/include/asm/cputype.h +3 -0
index 522b5fe..b62eaeb 100644
@@ -94,6 +94,9 @@
 #define ARM_CPU_XSCALE_ARCH_V2		0x4000
 #define ARM_CPU_XSCALE_ARCH_V3		0x6000
 
+/* Qualcomm implemented cores */
+#define ARM_CPU_PART_SCORPION		0x510002d0
+
 extern unsigned int processor_id;
 
 #ifdef CONFIG_CPU_CP15
arch/arm/kernel/hw_breakpoint.c +16 -0
index 188180b..5d68ff9 100644
@@ -1063,6 +1063,22 @@ static int __init arch_hw_breakpoint_init(void)
 		return 0;
 	}
 
+	/*
+	 * Scorpion CPUs (at least those in APQ8060) seem to set DBGPRSR.SPD
+	 * whenever a WFI is issued, even if the core is not powered down, in
+	 * violation of the architecture.  When DBGPRSR.SPD is set, accesses to
+	 * breakpoint and watchpoint registers are treated as undefined, so
+	 * this results in boot time and runtime failures when these are
+	 * accessed and we unexpectedly take a trap.
+	 *
+	 * It's not clear if/how this can be worked around, so we blacklist
+	 * Scorpion CPUs to avoid these issues.
+	*/
+	if (read_cpuid_part() == ARM_CPU_PART_SCORPION) {
+		pr_info("Scorpion CPU detected. Breakpoints and watchpoints disabled\n");
+		return 0;
+	}
+
 	has_ossr = core_has_os_save_restore();
 
 	/* Determine how many BRPs/WRPs are available. */
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

Quoted 6 lines · Mark Rutland

On APQ8060, the kernel crashes in arch_hw_breakpoint_init, taking an undefined instruction trap within write_wb_reg. This is because Scorpion CPUs erroneously appear to set DBGPRSR.SPD when WFI is issued, even if the core is not powered down. When DBGPRSR.SPD is set, breakpoint and watchpoint registers are treated as undefined.

Quoted 8 lines

It's possible to trigger similar crashes later on from userspace, by requesting the kernel to install a breakpoint or watchpoint, as we can go idle at any point between the reset of the debug registers and their later use. This has always been the case.

Given that this has always been broken, no-one has complained until now, and there is no clear workaround, disable hardware breakpoints and watchpoints on Scorpion to avoid these issues.

I believe the workaround is to read DBGPRSR after exit from WFI? I'm fine with the blacklisting approach though.

Quoted 8 lines
Cc Russell King <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Will Deacon <[email protected]>
Cc stable at vger.kernel.org

---

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

Quoted 12 lines · Stephen Boyd
Quoted 11 lines · Mark Rutland

On APQ8060, the kernel crashes in arch_hw_breakpoint_init, taking an undefined instruction trap within write_wb_reg. This is because Scorpion CPUs erroneously appear to set DBGPRSR.SPD when WFI is issued, even if the core is not powered down. When DBGPRSR.SPD is set, breakpoint and watchpoint registers are treated as undefined.

It's possible to trigger similar crashes later on from userspace, by requesting the kernel to install a breakpoint or watchpoint, as we can go idle at any point between the reset of the debug registers and their later use. This has always been the case.

Quoted 5 lines
Quoted 3 lines

Given that this has always been broken, no-one has complained until now, and there is no clear workaround, disable hardware breakpoints and watchpoints on Scorpion to avoid these issues.

I believe the workaround is to read DBGPRSR after exit from WFI?

That might be do-able via cpuidle, but it's probably better for somebody familiar with the SoC PM to write that patch.

Quoted 3 lines

I'm fine with the blacklisting approach though.

Thanks,

Will

#3 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

In reply to Mark Rutland
Quoted 51 lines · Mark Rutland

On APQ8060, the kernel crashes in arch_hw_breakpoint_init, taking an undefined instruction trap within write_wb_reg. This is because Scorpion CPUs erroneously appear to set DBGPRSR.SPD when WFI is issued, even if the core is not powered down. When DBGPRSR.SPD is set, breakpoint and watchpoint registers are treated as undefined.

It's possible to trigger similar crashes later on from userspace, by requesting the kernel to install a breakpoint or watchpoint, as we can go idle at any point between the reset of the debug registers and their later use. This has always been the case.

Given that this has always been broken, no-one has complained until now, and there is no clear workaround, disable hardware breakpoints and watchpoints on Scorpion to avoid these issues.

Cc Russell King <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Will Deacon <[email protected]>
Cc stable at vger.kernel.org
---
 arch/arm/include/asm/cputype.h  |  3 +++
 arch/arm/kernel/hw_breakpoint.c | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)
arch/arm/include/asm/cputype.h +3 -0
index 522b5fe..b62eaeb 100644
@@ -94,6 +94,9 @@
 #define ARM_CPU_XSCALE_ARCH_V2		0x4000
 #define ARM_CPU_XSCALE_ARCH_V3		0x6000
 
+/* Qualcomm implemented cores */
+#define ARM_CPU_PART_SCORPION		0x510002d0
+
 extern unsigned int processor_id;
 
 #ifdef CONFIG_CPU_CP15
arch/arm/kernel/hw_breakpoint.c +3 -0
index 188180b..5d68ff9 100644
@@ -1063,6 +1063,22 @@ static int __init arch_hw_breakpoint_init(void)
 		return 0;
 	}
 
+	/*
+	 * Scorpion CPUs (at least those in APQ8060) seem to set DBGPRSR.SPD
+	 * whenever a WFI is issued, even if the core is not powered down, in

arch/arm/kernel/hw_breakpoint.c static int __init arch_hw_breakpoint_init(void) · line 1078

Quoted 10 lines
arch/arm/kernel/hw_breakpoint.c +10 -0
+	 * violation of the architecture.  When DBGPRSR.SPD is set, accesses to
+	 * breakpoint and watchpoint registers are treated as undefined, so
+	 * this results in boot time and runtime failures when these are
+	 * accessed and we unexpectedly take a trap.
+	 *
+	 * It's not clear if/how this can be worked around, so we blacklist
+	 * Scorpion CPUs to avoid these issues.
+	*/
+	if (read_cpuid_part() == ARM_CPU_PART_SCORPION) {
+		pr_info("Scorpion CPU detected. Breakpoints and watchpoints disabled\n");

nit: we're disabling *hardware* breakpoints and watchpoints, so it's worth mentioning that in the print.

With that:

Please put this into Russell's patch system.

Will

author maintainer
#4 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

Quoted 6 lines · Will Deacon

arch/arm/kernel/hw_breakpoint.c static int __init arch_hw_breakpoint_init(void) · line 1078

Quoted 2 lines · Mark Rutland
arch/arm/kernel/hw_breakpoint.c +2 -0
+	if (read_cpuid_part() == ARM_CPU_PART_SCORPION) {
+		pr_info("Scorpion CPU detected. Breakpoints and watchpoints disabled\n");

nit: we're disabling *hardware* breakpoints and watchpoints, so it's worth mentioning that in the print.

True. I've fixed up the message.

Quoted 5 lines

With that:

Please put this into Russell's patch system.

Cheers.

I've dropped this in the patch system as 8634/1.

Thanks,
Mark.

#5 lore raw

PATCH 1/1 ARM: hw_breakpoint: blacklist Scorpion CPUs

In reply to Mark Rutland
Quoted 15 lines · Mark Rutland

On APQ8060, the kernel crashes in arch_hw_breakpoint_init, taking an undefined instruction trap within write_wb_reg. This is because Scorpion CPUs erroneously appear to set DBGPRSR.SPD when WFI is issued, even if the core is not powered down. When DBGPRSR.SPD is set, breakpoint and watchpoint registers are treated as undefined.

It's possible to trigger similar crashes later on from userspace, by requesting the kernel to install a breakpoint or watchpoint, as we can go idle at any point between the reset of the debug registers and their later use. This has always been the case.

Given that this has always been broken, no-one has complained until now, and there is no clear workaround, disable hardware breakpoints and watchpoints on Scorpion to avoid these issues.

Quoted 6 lines
Cc Russell King <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Will Deacon <[email protected]>
Cc stable at vger.kernel.org

Dammit git send-email does not add people on Reported-by to the CC list so I missed this.

It works like a charm however, thanks for looking into this:

Yours,
Linus Walleij