Skip to contentSkip to conversation

powerpc/book3s64/kexec: Clear CIABR on kexec

PATCH Applied Jordan Niethe 2 participants 3 messages Dec 7, 2020 – Dec 10, 2020 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 powerpc/book3s64/kexec: Clear CIABR on kexec

The value in CIABR persists across kexec which can lead to unintended results when the new kernel hits the old kernel's breakpoint. For example:

0:mon> bi $loadavg_proc_show
0:mon> b
type address
1 inst c000000000519060 loadavg_proc_show+0x0/0x130
0:mon> x

$ kexec -l /mnt/vmlinux --initrd=/mnt/rootfs.cpio.gz --append='xmon=off'
$ kexec -e
$ cat /proc/loadavg
Trace/breakpoint trap

Make sure CIABR is cleared so this does not happen.

---
 arch/powerpc/include/asm/book3s/64/kexec.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/powerpc/include/asm/book3s/64/kexec.h +5 -0
index 6b5c3a248ba2..d4b9d476ecba 100644
@@ -3,6 +3,7 @@
 #ifndef _ASM_POWERPC_BOOK3S_64_KEXEC_H_
 #define _ASM_POWERPC_BOOK3S_64_KEXEC_H_
 
+#include <asm/plpar_wrappers.h>
 
 #define reset_sprs reset_sprs
 static inline void reset_sprs(void)
@@ -14,6 +15,10 @@ static inline void reset_sprs(void)
 
 	if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
 		mtspr(SPRN_IAMR, 0);
+		if (cpu_has_feature(CPU_FTR_HVMODE))
+			mtspr(SPRN_CIABR, 0);
+		else
+			plpar_set_ciabr(0);
 	}
 
 	/*  Do we need isync()? We are going via a kexec reset */
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 powerpc/powernv/idle: Restore CIABR after idle for Power9

On Power9, CIABR is lost after idle. This means that instruction breakpoints set by xmon which use CIABR do not work. Fix this by restoring CIABR after idle.

---
 arch/powerpc/platforms/powernv/idle.c | 3 +++
 1 file changed, 3 insertions(+)
arch/powerpc/platforms/powernv/idle.c +3 -0
index 1ed7c5286487..e6f461812856 100644
@@ -589,6 +589,7 @@ struct p9_sprs {
 	u64 spurr;
 	u64 dscr;
 	u64 wort;
+	u64 ciabr;
 
 	u64 mmcra;
 	u32 mmcr0;
@@ -668,6 +669,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 		sprs.spurr	= mfspr(SPRN_SPURR);
 		sprs.dscr	= mfspr(SPRN_DSCR);
 		sprs.wort	= mfspr(SPRN_WORT);
+		sprs.ciabr	= mfspr(SPRN_CIABR);
 
 		sprs.mmcra	= mfspr(SPRN_MMCRA);
 		sprs.mmcr0	= mfspr(SPRN_MMCR0);
@@ -785,6 +787,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 	mtspr(SPRN_SPURR,	sprs.spurr);
 	mtspr(SPRN_DSCR,	sprs.dscr);
 	mtspr(SPRN_WORT,	sprs.wort);
+	mtspr(SPRN_CIABR,	sprs.ciabr);
 
 	mtspr(SPRN_MMCRA,	sprs.mmcra);
 	mtspr(SPRN_MMCR0,	sprs.mmcr0);
Signature · 1 line
2.17.1
#2 lore raw
In reply to Jordan Niethe
Quoted 11 lines · Jordan Niethe

The value in CIABR persists across kexec which can lead to unintended results when the new kernel hits the old kernel's breakpoint. For example:

0:mon> bi $loadavg_proc_show
0:mon> b
type address
1 inst c000000000519060 loadavg_proc_show+0x0/0x130
0:mon> x

[...]

Applied to powerpc/next.

[1/2] powerpc/book3s64/kexec: Clear CIABR on kexec

      https://git.kernel.org/powerpc/c/4bb3219837a3dcf58bce96c27db6e0cd48f3d9b2
[2/2] powerpc/powernv/idle: Restore CIABR after idle for Power9
      https://git.kernel.org/powerpc/c/250ad7a45b1e58d580decfb935fc063c4cf56f91

cheers