mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors
@ 2026-11-20 19:33 Matt Turner
  2026-11-20 19:33 ` [PATCH 1/4] powerpc/32: Decode MPC745x L2 and L3 cache machine checks Matt Turner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Matt Turner @ 2026-11-20 19:33 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
	Shrikanth Hegde, Borislav Petkov, Tony Luck, Matt Turner
  Cc: linuxppc-dev, linux-kernel, linux-edac

The MPC7448 has ECC on its L2 cache, but Linux never enables or reads
the L2 error registers. L2ERRINTEN resets to 0, so multi-bit errors go
unreported, and the single-bit error counter is never read.

Patch 1 decodes MSSSR0 for L2 and L3 cache machine checks on all 745x
parts, which are currently all reported as "L2 data cache parity
error". Patch 2 enables machine checks for multi-bit ECC and tag parity
errors on the 7448 and adds the L2 error registers to the decode.
Patch 3 adds an EDAC driver that reports the single-bit count, the
machine checks, and uncorrectable errors latched without one. Patch 4
adds error injection to the driver; it is separate because it is the
part most likely to need changes.

L2 machine checks clear SRR1[RI], so they are never recoverable. The
injection code masks reporting while it runs and reads the errors back
itself. Tag injection hung the machine, so it is not offered.

Tested on an iMac G4 (PowerMac6,1) with a 7448 (PVR 0x80040202):

- L2ERRINTEN is 0x18 after boot.
- An injected single-bit error is corrected and reported as CEs.
- An injected multi-bit error is reported as a UE at the target address,
  without a machine check.
- With the injection's masking removed, a multi-bit error raises a
  machine check, decoded as in patch 2, and the writing task oopses. The
  error in the target line raised a second machine check while the first
  oops was being printed, and the driver then reported both as UEs.

Suspend to RAM and resume were tested: L2ERRINTEN is still 0x18 after
resume, and injection still works. With CONFIG_STRICT_KERNEL_RWX enabled,
PMU sleep oopses in low_sleep_handler with or without this series; that
was tested with "powerpc/powermac: Fix low_sleep_handler with
STRICT_KERNEL_RWX", which is sent separately. No other 745x part was
tested.

Patches 3 and 4 use symbols exported by patch 2, so I'd suggest the
series goes through the powerpc tree with an ack from the EDAC
maintainers.

---
Matt Turner (4):
      powerpc/32: Decode MPC745x L2 and L3 cache machine checks
      powerpc/32: Enable and decode MPC7448 L2 ECC machine checks
      EDAC/mpc7448_l2: Add a driver for the MPC7448 L2 cache
      EDAC/mpc7448_l2: Add error injection

 MAINTAINERS                               |   9 +
 arch/powerpc/include/asm/cpu_setup.h      |   1 +
 arch/powerpc/include/asm/cputable.h       |   2 +
 arch/powerpc/include/asm/mpc7448_l2.h     |  31 +++
 arch/powerpc/include/asm/reg.h            |  38 +++
 arch/powerpc/kernel/Makefile              |   3 +-
 arch/powerpc/kernel/cpu_setup_6xx.S       |  38 ++-
 arch/powerpc/kernel/cpu_specs_book3s_32.h |  24 +-
 arch/powerpc/kernel/mpc7448_l2.c          | 124 +++++++++
 arch/powerpc/kernel/traps.c               |  28 ++
 drivers/edac/Kconfig                      |   9 +
 drivers/edac/Makefile                     |   1 +
 drivers/edac/mpc7448_l2_edac.c            | 442 ++++++++++++++++++++++++++++++
 13 files changed, 736 insertions(+), 14 deletions(-)
---
base-commit: d68ce4e71248e1ff5af9654b407541d9260b3ba5
change-id: 20261109-ppc32-l2-ecc-9217e1ccfde0

Best regards,
--  
Matt Turner <mattst88@gmail.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] powerpc/32: Decode MPC745x L2 and L3 cache machine checks
  2026-11-20 19:33 [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors Matt Turner
@ 2026-11-20 19:33 ` Matt Turner
  2026-11-20 19:33 ` [PATCH 2/4] powerpc/32: Enable and decode MPC7448 L2 ECC " Matt Turner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Matt Turner @ 2026-11-20 19:33 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
	Shrikanth Hegde, Borislav Petkov, Tony Luck, Matt Turner
  Cc: linuxppc-dev, linux-kernel, linux-edac

On the 745x, SRR1[MSS] means the memory subsystem detected an error, and
MSSSR0 says which: L2 tag or data parity, MPC7448 L2 ECC, or L3 tag or
data parity.  machine_check_generic() reports these cache errors as "L2
data cache parity error" and never clears MSSSR0, whose bits are sticky.

Add machine_check_745x(), which decodes and clears the MSSSR0 cache
error bits, and use it for every 745x.  Machine checks without one of
those bits still go to machine_check_generic().

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/powerpc/include/asm/cputable.h       |  1 +
 arch/powerpc/include/asm/reg.h            |  5 +++++
 arch/powerpc/kernel/cpu_specs_book3s_32.h | 22 +++++++++++-----------
 arch/powerpc/kernel/traps.c               | 28 ++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h
index a3be81c47df3..8445533c946b 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -34,6 +34,7 @@ extern int machine_check_e500(struct pt_regs *regs);
 extern int machine_check_47x(struct pt_regs *regs);
 int machine_check_8xx(struct pt_regs *regs);
 int machine_check_83xx(struct pt_regs *regs);
+int machine_check_745x(struct pt_regs *regs);
 
 extern void cpu_down_flush_e500v2(void);
 extern void cpu_down_flush_e500mc(void);
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 541a493e13bf..82a85d44776e 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -729,6 +729,10 @@
 
 #define SPRN_MSSCR0	0x3f6	/* Memory Subsystem Control Register 0 */
 #define SPRN_MSSSR0	0x3f7	/* Memory Subsystem Status Register 1 */
+#define   MSSSR0_L2TAG	0x00040000	/* L2 tag parity error */
+#define   MSSSR0_L2DAT	0x00020000	/* L2 data parity/ECC error */
+#define   MSSSR0_L3TAG	0x00010000	/* L3 tag parity error */
+#define   MSSSR0_L3DAT	0x00008000	/* L3 data parity error */
 #define SPRN_LDSTCR	0x3f8	/* Load/Store control register */
 #define SPRN_LDSTDB	0x3f4	/* */
 #define SPRN_LR		0x008	/* Link Register */
@@ -801,6 +805,7 @@
 #define   SRR1_PROGTRAP		0x00020000 /* Trap */
 #define   SRR1_PROGADDR		0x00010000 /* SRR0 contains subsequent addr */
 
+#define   SRR1_MCE_MSS		0x00100000 /* 745x memory subsystem error (MSSSR0) */
 #define   SRR1_MCE_MCP		0x00080000 /* Machine check signal caused interrupt */
 #define   SRR1_BOUNDARY		0x10000000 /* Prefixed instruction crosses 64-byte boundary */
 #define   SRR1_PREFIXED		0x20000000 /* Exception caused by prefixed instruction */
diff --git a/arch/powerpc/kernel/cpu_specs_book3s_32.h b/arch/powerpc/kernel/cpu_specs_book3s_32.h
index 3714634d194a..90ca26405c1d 100644
--- a/arch/powerpc/kernel/cpu_specs_book3s_32.h
+++ b/arch/powerpc/kernel/cpu_specs_book3s_32.h
@@ -426,7 +426,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7450 2.1 */
@@ -442,7 +442,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7450 2.3 and newer */
@@ -458,7 +458,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7455 rev 1.x */
@@ -474,7 +474,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7455 rev 2.0 */
@@ -490,7 +490,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7455 others */
@@ -506,7 +506,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7447/7457 Rev 1.0 */
@@ -522,7 +522,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7447/7457 Rev 1.1 */
@@ -538,7 +538,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7447/7457 Rev 1.2 and later */
@@ -554,7 +554,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7447A */
@@ -570,7 +570,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* 7448 */
@@ -586,7 +586,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
 		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_generic,
+		.machine_check		= machine_check_745x,
 		.platform		= "ppc7450",
 	},
 	{	/* default match, we assume split I/D cache & TB (non-601)... */
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 3a8f5416e3f6..4fb1610baa51 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -788,6 +788,34 @@ int machine_check_generic(struct pt_regs *regs)
 	}
 	return 0;
 }
+
+#ifdef CONFIG_PPC_BOOK3S_32
+#define MSSSR0_CACHE_ERR	(MSSSR0_L2TAG | MSSSR0_L2DAT | MSSSR0_L3TAG | MSSSR0_L3DAT)
+
+/*
+ * On the 745x, SRR1[MSS] means the memory subsystem detected an error, and
+ * MSSSR0 says which.  The MSSSR0 bits are sticky, so clear them.
+ */
+int machine_check_745x(struct pt_regs *regs)
+{
+	unsigned long reason = regs->msr;
+	unsigned long msssr0 = mfspr(SPRN_MSSSR0);
+
+	if (!(reason & SRR1_MCE_MSS) || !(msssr0 & MSSSR0_CACHE_ERR))
+		return machine_check_generic(regs);
+
+	mtspr(SPRN_MSSSR0, msssr0 & ~MSSSR0_CACHE_ERR);
+
+	pr_err("Machine check in kernel mode.\n");
+	pr_err("Caused by (from SRR1=%lx, MSSSR0=%lx):%s%s%s%s\n",
+	       reason, msssr0,
+	       msssr0 & MSSSR0_L2TAG ? " [L2 tag parity]" : "",
+	       msssr0 & MSSSR0_L2DAT ? " [L2 data parity/ECC]" : "",
+	       msssr0 & MSSSR0_L3TAG ? " [L3 tag parity]" : "",
+	       msssr0 & MSSSR0_L3DAT ? " [L3 data parity]" : "");
+	return 0;
+}
+#endif
 #endif /* everything else */
 
 void die_mce(const char *str, struct pt_regs *regs, long err)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] powerpc/32: Enable and decode MPC7448 L2 ECC machine checks
  2026-11-20 19:33 [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors Matt Turner
  2026-11-20 19:33 ` [PATCH 1/4] powerpc/32: Decode MPC745x L2 and L3 cache machine checks Matt Turner
@ 2026-11-20 19:33 ` Matt Turner
  2026-11-20 19:33 ` [PATCH 3/4] EDAC/mpc7448_l2: Add a driver for the MPC7448 L2 cache Matt Turner
  2026-11-20 19:33 ` [PATCH 4/4] EDAC/mpc7448_l2: Add error injection Matt Turner
  3 siblings, 0 replies; 5+ messages in thread
From: Matt Turner @ 2026-11-20 19:33 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
	Shrikanth Hegde, Borislav Petkov, Tony Luck, Matt Turner
  Cc: linuxppc-dev, linux-kernel, linux-edac

The MPC7448 has ECC on its L2 data array and parity on its tag array,
but L2ERRINTEN resets to 0, so uncorrectable L2 errors are never
reported and the bad data is used.

Enable machine checks for multi-bit ECC and tag parity errors at boot,
and save and restore L2ERRINTEN across sleep.  These errors now oops
instead of silently corrupting data.  Single-bit errors stay disabled:
there is no threshold to set, since L2ERRCTL[L2CTHRESH] is read-only and
0, and they are counted in L2ERRCTL[L2CCOUNT] anyway.

Add machine_check_7448(), which adds the L2 error registers to what
machine_check_745x() prints, and counts these machine checks per CPU for
the EDAC driver added in the next patch.  The CPU clears SRR1[RI] for
them, so they are never recoverable.

A multi-bit error injected with reporting enabled is decoded as

  Machine check in kernel mode.
  Caused by (from SRR1=101030, MSSSR0=20000): [L2 data parity/ECC]
  MPC7448 L2 error: L2ERRDET=80000008 [multi-bit ECC] [multiple errors]
    address 0x0054e1100 (dw 0): data read, 32 bytes burst
    data 00000000_00000003 syndrome 81 ECC 00
  Oops: Machine check, sig: 7 [#1]

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 MAINTAINERS                               |   8 ++
 arch/powerpc/include/asm/cpu_setup.h      |   1 +
 arch/powerpc/include/asm/cputable.h       |   1 +
 arch/powerpc/include/asm/mpc7448_l2.h     |  31 ++++++++
 arch/powerpc/include/asm/reg.h            |  32 ++++++++
 arch/powerpc/kernel/Makefile              |   3 +-
 arch/powerpc/kernel/cpu_setup_6xx.S       |  38 ++++++++-
 arch/powerpc/kernel/cpu_specs_book3s_32.h |   4 +-
 arch/powerpc/kernel/mpc7448_l2.c          | 124 ++++++++++++++++++++++++++++++
 9 files changed, 238 insertions(+), 4 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index fde7147bfa1e..4ea66ea2be2d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9747,6 +9747,14 @@ L:	linux-edac@vger.kernel.org
 S:	Maintained
 F:	drivers/edac/intel-bff.c
 
+EDAC-MPC7448-L2
+M:	Matt Turner <mattst88@gmail.com>
+L:	linux-edac@vger.kernel.org
+L:	linuxppc-dev@lists.ozlabs.org
+S:	Maintained
+F:	arch/powerpc/include/asm/mpc7448_l2.h
+F:	arch/powerpc/kernel/mpc7448_l2.c
+
 EDAC-MPC85XX
 L:	linux-edac@vger.kernel.org
 S:	Orphan
diff --git a/arch/powerpc/include/asm/cpu_setup.h b/arch/powerpc/include/asm/cpu_setup.h
index 26d2c0e2c99c..c4d7f49027df 100644
--- a/arch/powerpc/include/asm/cpu_setup.h
+++ b/arch/powerpc/include/asm/cpu_setup.h
@@ -37,6 +37,7 @@ void __setup_cpu_750fx(unsigned long offset, struct cpu_spec *spec);
 void __setup_cpu_7400(unsigned long offset, struct cpu_spec *spec);
 void __setup_cpu_7410(unsigned long offset, struct cpu_spec *spec);
 void __setup_cpu_745x(unsigned long offset, struct cpu_spec *spec);
+void __setup_cpu_7448(unsigned long offset, struct cpu_spec *spec);
 
 void __setup_cpu_ppc970(unsigned long offset, struct cpu_spec *spec);
 void __setup_cpu_ppc970MP(unsigned long offset, struct cpu_spec *spec);
diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h
index 8445533c946b..648e72fe7e6c 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -35,6 +35,7 @@ extern int machine_check_47x(struct pt_regs *regs);
 int machine_check_8xx(struct pt_regs *regs);
 int machine_check_83xx(struct pt_regs *regs);
 int machine_check_745x(struct pt_regs *regs);
+int machine_check_7448(struct pt_regs *regs);
 
 extern void cpu_down_flush_e500v2(void);
 extern void cpu_down_flush_e500mc(void);
diff --git a/arch/powerpc/include/asm/mpc7448_l2.h b/arch/powerpc/include/asm/mpc7448_l2.h
new file mode 100644
index 000000000000..a10c694b8583
--- /dev/null
+++ b/arch/powerpc/include/asm/mpc7448_l2.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * MPC7448 L2 cache error capture and reporting.
+ */
+#ifndef _ASM_POWERPC_MPC7448_L2_H
+#define _ASM_POWERPC_MPC7448_L2_H
+
+#include <linux/types.h>
+
+/* Snapshot of the L2 error detect and capture registers */
+struct mpc7448_l2_err {
+	u32 det;	/* L2ERRDET */
+	u32 attr;	/* L2ERRATTR */
+	u32 eaddr;	/* L2ERREADDR */
+	u32 addr;	/* L2ERRADDR */
+	u32 capt_hi;	/* L2CAPTDATAHI */
+	u32 capt_lo;	/* L2CAPTDATALO */
+	u32 capt_ecc;	/* L2CAPTECC */
+};
+
+/* 36-bit physical address of the double word that took the error */
+static inline u64 mpc7448_l2_err_paddr(const struct mpc7448_l2_err *e)
+{
+	return ((u64)(e->eaddr & 0xf) << 32) | e->addr;
+}
+
+void mpc7448_l2_err_capture(struct mpc7448_l2_err *e);
+void mpc7448_l2_err_print(const struct mpc7448_l2_err *e);
+unsigned int mpc7448_l2_mce_take(void);
+
+#endif /* _ASM_POWERPC_MPC7448_L2_H */
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 82a85d44776e..2f4adf5a606e 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -706,6 +706,38 @@
 #define L2CR_L2DO_745x		0x00010000	/* L2 data only (745x) */
 #define L2CR_L2REP_745x		0x00001000	/* L2 repl. algorithm (745x) */
 #define L2CR_L2HWF_745x		0x00000800	/* L2 hardware flush (745x) */
+
+/* MPC7448 L2 error injection, capture and reporting registers */
+#define SPRN_L2ERRINJHI		0x3D9	/* L2 error injection mask, data high */
+#define SPRN_L2ERRINJLO		0x3DA	/* L2 error injection mask, data low */
+#define SPRN_L2ERRINJCTL	0x3DB	/* L2 error injection control */
+#define   L2ERRINJCTL_ECCMB	0x00000200	/* Mirror data MSB onto ECC */
+#define   L2ERRINJCTL_DERRIEN	0x00000100	/* Data/ECC error injection */
+#define   L2ERRINJCTL_ECCERRIM	0x000000ff	/* ECC bit injection mask */
+#define SPRN_L2CAPTDATAHI	0x3DC	/* L2 error capture data, high word */
+#define SPRN_L2CAPTDATALO	0x3DD	/* L2 error capture data, low word */
+#define SPRN_L2CAPTECC		0x3DE	/* L2 error syndrome */
+#define   L2CAPTECC_ECCSYND	0xff000000	/* Calculated syndrome */
+#define   L2CAPTECC_ECCCHKSUM	0x000000ff	/* Datapath ECC */
+#define SPRN_L2ERRDET		0x3DF	/* L2 error detect (write 1 to clear) */
+#define SPRN_L2ERRINTEN		0x3E1	/* L2 error interrupt enable */
+/* Error bits shared by L2ERRDET and L2ERRINTEN */
+#define   L2ERR_MULL2ERR	0x80000000	/* Multiple errors (DET only) */
+#define   L2ERR_TPARERR		0x00000010	/* Tag parity error */
+#define   L2ERR_MBECCERR	0x00000008	/* Multiple-bit ECC error */
+#define   L2ERR_SBECCERR	0x00000004	/* Single-bit ECC error */
+#define SPRN_L2ERRATTR		0x3E2	/* L2 error attributes capture */
+#define   L2ERRATTR_DWNUM	0x30000000	/* Double word number */
+#define   L2ERRATTR_TRANSSIZ	0x07000000	/* Transaction size */
+#define   L2ERRATTR_BURST	0x00800000	/* Burst transaction */
+#define   L2ERRATTR_TRANSSRC	0x001f0000	/* Transaction source */
+#define   L2ERRATTR_TRANSTYPE	0x00003000	/* Transaction type */
+#define   L2ERRATTR_VALINFO	0x00000001	/* Capture registers valid */
+#define SPRN_L2ERRADDR		0x3E3	/* L2 error address, bits 4-35 */
+#define SPRN_L2ERREADDR		0x3E4	/* L2 error address, bits 0-3 */
+#define SPRN_L2ERRCTL		0x3E5	/* L2 error control */
+#define   L2ERRCTL_L2CCOUNT	0x000000ff	/* SBE count */
+
 #define SPRN_L3CR		0x3FA	/* Level 3 Cache Control Register */
 #define L3CR_L3E		0x80000000	/* L3 enable */
 #define L3CR_L3PE		0x40000000	/* L3 data parity enable */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 7bf6b16b2d93..3681dd45a056 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -106,7 +106,8 @@ obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_FA_DUMP)		+= fadump.o
 obj-$(CONFIG_PRESERVE_FA_DUMP)	+= fadump.o
 obj-$(CONFIG_PPC_85xx)		+= idle_85xx.o
-obj-$(CONFIG_PPC_BOOK3S_32)	+= idle_6xx.o l2cr_6xx.o cpu_setup_6xx.o
+obj-$(CONFIG_PPC_BOOK3S_32)	+= idle_6xx.o l2cr_6xx.o cpu_setup_6xx.o \
+				   mpc7448_l2.o
 obj-$(CONFIG_TAU)		+= tau_6xx.o
 obj-$(CONFIG_HIBERNATION)	+= swsusp.o suspend.o
 ifdef CONFIG_PPC_85xx
diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S b/arch/powerpc/kernel/cpu_setup_6xx.S
index ab3ca74e6730..dc17d5a8bd79 100644
--- a/arch/powerpc/kernel/cpu_setup_6xx.S
+++ b/arch/powerpc/kernel/cpu_setup_6xx.S
@@ -90,6 +90,13 @@ _GLOBAL(__setup_cpu_745x)
 	bl	setup_745x_specifics
 	mtlr	r5
 	blr
+_GLOBAL(__setup_cpu_7448)
+	mflr	r5
+	bl	setup_common_caches
+	bl	setup_745x_specifics
+	bl	setup_7448_l2_errors
+	mtlr	r5
+	blr
 
 /* Enable caches for 603's, 604, 750 & 7400 */
 SYM_FUNC_START_LOCAL(setup_common_caches)
@@ -300,6 +307,23 @@ END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
 	blr
 SYM_FUNC_END(setup_745x_specifics)
 
+/*
+ * Clear L2 errors left by firmware and raise a machine check for
+ * uncorrectable ones.
+ */
+SYM_FUNC_START_LOCAL(setup_7448_l2_errors)
+	li	r3,-1
+	mtspr	SPRN_L2ERRDET,r3	/* write 1 to clear */
+	li	r3,0
+	mtspr	SPRN_L2ERRATTR,r3	/* clear VALINFO: re-arm capture */
+	li	r3,L2ERR_TPARERR | L2ERR_MBECCERR
+	sync
+	mtspr	SPRN_L2ERRINTEN,r3
+	sync
+	isync
+	blr
+SYM_FUNC_END(setup_7448_l2_errors)
+
 /*
  * Initialize the FPU registers. This is needed to work around an errata
  * in some 750 cpus where using a not yet initialized FPU register after
@@ -329,7 +353,8 @@ _ASM_NOKPROBE_SYMBOL(__init_fpu_registers)
 #define CS_ICTRL	20
 #define CS_LDSTCR	24
 #define CS_LDSTDB	28
-#define CS_SIZE		32
+#define CS_L2ERRINTEN	32
+#define CS_SIZE		36
 
 	.data
 	.balign	L1_CACHE_BYTES
@@ -391,6 +416,10 @@ _GLOBAL(__save_cpu_setup)
 	stw	r4,CS_LDSTCR(r5)
 	mfspr	r4,SPRN_LDSTDB
 	stw	r4,CS_LDSTDB(r5)
+	bne	cr7,1f
+	/* Backup 7448 specific registers */
+	mfspr	r4,SPRN_L2ERRINTEN
+	stw	r4,CS_L2ERRINTEN(r5)
 1:
 	bne	cr6,1f
 	/* Backup 750FX specific registers */
@@ -484,6 +513,13 @@ _GLOBAL(__restore_cpu_setup)
 	mtspr	SPRN_LDSTDB,r4
 	isync
 	sync
+	bne	cr7,2f
+	/* Restore 7448 specific registers */
+	lwz	r4,CS_L2ERRINTEN(r5)
+	sync
+	mtspr	SPRN_L2ERRINTEN,r4
+	isync
+	sync
 2:	bne	cr6,1f
 	/* Restore 750FX specific registers
 	 * that is restore HID2 on rev 2.x and PLL config & switch
diff --git a/arch/powerpc/kernel/cpu_specs_book3s_32.h b/arch/powerpc/kernel/cpu_specs_book3s_32.h
index 90ca26405c1d..039094c1c245 100644
--- a/arch/powerpc/kernel/cpu_specs_book3s_32.h
+++ b/arch/powerpc/kernel/cpu_specs_book3s_32.h
@@ -585,8 +585,8 @@ static struct cpu_spec cpu_specs[] __initdata = {
 		.dcache_bsize		= 32,
 		.num_pmcs		= 6,
 		.pmc_type		= PPC_PMC_G4,
-		.cpu_setup		= __setup_cpu_745x,
-		.machine_check		= machine_check_745x,
+		.cpu_setup		= __setup_cpu_7448,
+		.machine_check		= machine_check_7448,
 		.platform		= "ppc7450",
 	},
 	{	/* default match, we assume split I/D cache & TB (non-601)... */
diff --git a/arch/powerpc/kernel/mpc7448_l2.c b/arch/powerpc/kernel/mpc7448_l2.c
new file mode 100644
index 000000000000..4ec3c6a0558e
--- /dev/null
+++ b/arch/powerpc/kernel/mpc7448_l2.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MPC7448 L2 cache error capture and machine check decode.
+ *
+ * The MPC7448 protects its L2 data array with SEC-DED ECC and its tag
+ * array with parity.  Detected errors are latched in L2ERRDET and, for
+ * the error types enabled in L2ERRINTEN, raise a machine check with
+ * SRR1[MSS] and MSSSR0[L2DAT] or MSSSR0[L2TAG] set.  See the MPC7450 RISC
+ * Microprocessor Family Reference Manual, rev. 5, sections 2.2.5.5 and
+ * 3.6.3.4.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/export.h>
+#include <linux/kernel.h>
+#include <linux/percpu.h>
+#include <linux/printk.h>
+
+#include <asm/cputable.h>
+#include <asm/local.h>
+#include <asm/mpc7448_l2.h>
+#include <asm/ptrace.h>
+#include <asm/reg.h>
+
+/* L2 machine checks not yet collected by mpc7448_l2_mce_take() */
+static DEFINE_PER_CPU(local_t, mpc7448_l2_mce_count);
+
+/*
+ * Read the error detect and capture registers, then clear the detected
+ * errors and re-arm capture.  Must run on the CPU whose L2 is of interest.
+ */
+void mpc7448_l2_err_capture(struct mpc7448_l2_err *e)
+{
+	e->det = mfspr(SPRN_L2ERRDET);
+	e->attr = mfspr(SPRN_L2ERRATTR);
+	e->eaddr = mfspr(SPRN_L2ERREADDR);
+	e->addr = mfspr(SPRN_L2ERRADDR);
+	e->capt_hi = mfspr(SPRN_L2CAPTDATAHI);
+	e->capt_lo = mfspr(SPRN_L2CAPTDATALO);
+	e->capt_ecc = mfspr(SPRN_L2CAPTECC);
+
+	if (e->det)
+		mtspr(SPRN_L2ERRDET, e->det);	/* write 1 to clear */
+	if (e->attr & L2ERRATTR_VALINFO)
+		mtspr(SPRN_L2ERRATTR, 0);	/* unfreeze capture */
+}
+EXPORT_SYMBOL_GPL(mpc7448_l2_err_capture);
+
+static const char *transsrc_str(u32 attr)
+{
+	switch (FIELD_GET(L2ERRATTR_TRANSSRC, attr)) {
+	case 0x00:
+		return "external";
+	case 0x10:
+		return "instruction";
+	case 0x11:
+		return "data";
+	default:
+		return "unknown source";
+	}
+}
+
+static const char *transtype_str(u32 attr)
+{
+	static const char * const types[] = {
+		"snoop", "write", "read", "reserved"
+	};
+
+	return types[FIELD_GET(L2ERRATTR_TRANSTYPE, attr)];
+}
+
+static unsigned int transsize(u32 attr)
+{
+	unsigned int siz = FIELD_GET(L2ERRATTR_TRANSSIZ, attr);
+
+	if (attr & L2ERRATTR_BURST)
+		return siz * 16;
+	return siz ?: 8;
+}
+
+void mpc7448_l2_err_print(const struct mpc7448_l2_err *e)
+{
+	pr_err("MPC7448 L2 error: L2ERRDET=%08x%s%s%s%s\n", e->det,
+	       e->det & L2ERR_TPARERR ? " [tag parity]" : "",
+	       e->det & L2ERR_MBECCERR ? " [multi-bit ECC]" : "",
+	       e->det & L2ERR_SBECCERR ? " [single-bit ECC]" : "",
+	       e->det & L2ERR_MULL2ERR ? " [multiple errors]" : "");
+	pr_err("  address 0x%09llx (dw %u): %s %s, %u bytes%s%s\n",
+	       mpc7448_l2_err_paddr(e),
+	       (unsigned int)FIELD_GET(L2ERRATTR_DWNUM, e->attr),
+	       transsrc_str(e->attr), transtype_str(e->attr), transsize(e->attr),
+	       e->attr & L2ERRATTR_BURST ? " burst" : "",
+	       e->attr & L2ERRATTR_VALINFO ? "" : " (not latched)");
+	pr_err("  data %08x_%08x syndrome %02x ECC %02x\n",
+	       e->capt_hi, e->capt_lo,
+	       (unsigned int)FIELD_GET(L2CAPTECC_ECCSYND, e->capt_ecc),
+	       (unsigned int)FIELD_GET(L2CAPTECC_ECCCHKSUM, e->capt_ecc));
+}
+EXPORT_SYMBOL_GPL(mpc7448_l2_err_print);
+
+/* Return the number of L2 machine checks on this CPU since the last call */
+unsigned int mpc7448_l2_mce_take(void)
+{
+	return local_xchg(this_cpu_ptr(&mpc7448_l2_mce_count), 0);
+}
+EXPORT_SYMBOL_GPL(mpc7448_l2_mce_take);
+
+int machine_check_7448(struct pt_regs *regs)
+{
+	struct mpc7448_l2_err e;
+	bool l2 = (regs->msr & SRR1_MCE_MSS) &&
+		  (mfspr(SPRN_MSSSR0) & (MSSSR0_L2TAG | MSSSR0_L2DAT));
+
+	machine_check_745x(regs);
+
+	if (l2) {
+		mpc7448_l2_err_capture(&e);
+		mpc7448_l2_err_print(&e);
+		local_inc(this_cpu_ptr(&mpc7448_l2_mce_count));
+	}
+
+	/* Never recoverable: the CPU clears SRR1[RI] for L2 errors. */
+	return 0;
+}

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] EDAC/mpc7448_l2: Add a driver for the MPC7448 L2 cache
  2026-11-20 19:33 [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors Matt Turner
  2026-11-20 19:33 ` [PATCH 1/4] powerpc/32: Decode MPC745x L2 and L3 cache machine checks Matt Turner
  2026-11-20 19:33 ` [PATCH 2/4] powerpc/32: Enable and decode MPC7448 L2 ECC " Matt Turner
@ 2026-11-20 19:33 ` Matt Turner
  2026-11-20 19:33 ` [PATCH 4/4] EDAC/mpc7448_l2: Add error injection Matt Turner
  3 siblings, 0 replies; 5+ messages in thread
From: Matt Turner @ 2026-11-20 19:33 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
	Shrikanth Hegde, Borislav Petkov, Tony Luck, Matt Turner
  Cc: linuxppc-dev, linux-kernel, linux-edac

Report MPC7448 L2 errors through EDAC, with one instance per CPU.

Single-bit errors are corrected by the hardware and only counted, so
poll L2ERRCTL[L2CCOUNT] and L2ERRDET and report the count as
correctable errors.  Report the L2 machine checks counted by the arch
code as uncorrectable errors, along with any multi-bit ECC or tag parity
error found in L2ERRDET without one, since clearing L2ERRDET would
otherwise lose it.

PowerMacs have no device tree node for the L2, so bind to a faux
device.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 MAINTAINERS                    |   1 +
 drivers/edac/Kconfig           |   9 +++
 drivers/edac/Makefile          |   1 +
 drivers/edac/mpc7448_l2_edac.c | 160 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 171 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4ea66ea2be2d..0d02f0a7316c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9754,6 +9754,7 @@ L:	linuxppc-dev@lists.ozlabs.org
 S:	Maintained
 F:	arch/powerpc/include/asm/mpc7448_l2.h
 F:	arch/powerpc/kernel/mpc7448_l2.c
+F:	drivers/edac/mpc7448_l2_edac.c
 
 EDAC-MPC85XX
 L:	linux-edac@vger.kernel.org
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 4c70729b0d3a..c3256da3d6fd 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -320,6 +320,15 @@ config EDAC_MPC85XX
 	  Support for error detection and correction on the Freescale
 	  MPC8349, MPC8560, MPC8540, MPC8548, T4240
 
+config EDAC_MPC7448_L2
+	tristate "Freescale MPC7448 L2 cache"
+	depends on PPC_BOOK3S_32
+	help
+	  Support for error detection and correction on the L2 cache of
+	  the Freescale MPC7448 processor.  Correctable errors are found
+	  by polling the L2 error counter, and uncorrectable errors are
+	  reported by the machine check handler.
+
 config EDAC_LAYERSCAPE
 	tristate "Freescale Layerscape DDR"
 	depends on ARCH_LAYERSCAPE || SOC_LS1021A
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 4020ea60738a..06c951d680f7 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_EDAC_PASEMI)		+= pasemi_edac.o
 
 mpc85xx_edac_mod-y			:= fsl_ddr_edac.o mpc85xx_edac.o
 obj-$(CONFIG_EDAC_MPC85XX)		+= mpc85xx_edac_mod.o
+obj-$(CONFIG_EDAC_MPC7448_L2)		+= mpc7448_l2_edac.o
 
 layerscape_edac_mod-y			:= fsl_ddr_edac.o layerscape_edac.o
 obj-$(CONFIG_EDAC_LAYERSCAPE)		+= layerscape_edac_mod.o
diff --git a/drivers/edac/mpc7448_l2_edac.c b/drivers/edac/mpc7448_l2_edac.c
new file mode 100644
index 000000000000..a62c7a2e7147
--- /dev/null
+++ b/drivers/edac/mpc7448_l2_edac.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * EDAC driver for the MPC7448 on-chip L2 cache.
+ *
+ * Single-bit ECC errors are corrected by the hardware and only counted in
+ * L2ERRCTL[L2CCOUNT], so they are found by polling.  Multi-bit ECC and tag
+ * parity errors raise a machine check (arch/powerpc/kernel/mpc7448_l2.c)
+ * and are reported here at the next poll, if the system survived it.
+ * Errors latched in L2ERRDET without a machine check are reported as
+ * uncorrectable too.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/cpu.h>
+#include <linux/device/faux.h>
+#include <linux/edac.h>
+#include <linux/module.h>
+#include <linux/smp.h>
+#include <linux/sprintf.h>
+
+#include <asm/mpc7448_l2.h>
+#include <asm/reg.h>
+
+#include "edac_module.h"
+
+#define DRV_NAME	"mpc7448_l2_edac"
+
+static struct faux_device *mpc7448_l2_fdev;
+
+struct mpc7448_l2_poll {
+	struct mpc7448_l2_err err;
+	u32 ctl;
+	unsigned int mce_ue;
+};
+
+static void mpc7448_l2_poll_cpu(void *info)
+{
+	struct mpc7448_l2_poll *p = info;
+
+	p->ctl = mfspr(SPRN_L2ERRCTL);
+	if (p->ctl & L2ERRCTL_L2CCOUNT)
+		mtspr(SPRN_L2ERRCTL, p->ctl & ~L2ERRCTL_L2CCOUNT);
+
+	mpc7448_l2_err_capture(&p->err);
+
+	p->mce_ue = mpc7448_l2_mce_take();
+}
+
+static void mpc7448_l2_report(struct edac_device_ctl_info *edac_dev,
+			      unsigned int cpu, const struct mpc7448_l2_poll *p)
+{
+	unsigned int ce, ue;
+	char msg[64];
+
+	ce = FIELD_GET(L2ERRCTL_L2CCOUNT, p->ctl) ?:
+	     !!(p->err.det & L2ERR_SBECCERR);
+	if (ce) {
+		if (p->err.det & L2ERR_SBECCERR)
+			snprintf(msg, sizeof(msg), "single-bit ECC at 0x%09llx",
+				 mpc7448_l2_err_paddr(&p->err));
+		else
+			snprintf(msg, sizeof(msg), "single-bit ECC");
+		edac_device_handle_ce_count(edac_dev, ce, cpu, 0, msg);
+	}
+
+	/* Errors latched without a machine check */
+	ue = !!(p->err.det & L2ERR_MBECCERR) + !!(p->err.det & L2ERR_TPARERR);
+	if (ue) {
+		mpc7448_l2_err_print(&p->err);
+		snprintf(msg, sizeof(msg), "%s at 0x%09llx",
+			 p->err.det & L2ERR_TPARERR ? "tag parity" : "multi-bit ECC",
+			 mpc7448_l2_err_paddr(&p->err));
+		edac_device_handle_ue_count(edac_dev, ue, cpu, 0, msg);
+	}
+
+	/* The machine check handler has already printed the details */
+	if (p->mce_ue)
+		edac_device_handle_ue_count(edac_dev, p->mce_ue, cpu, 0,
+					    "machine check");
+}
+
+static void mpc7448_l2_check_cpu(struct edac_device_ctl_info *edac_dev,
+				 unsigned int cpu)
+{
+	struct mpc7448_l2_poll p;
+
+	if (!smp_call_function_single(cpu, mpc7448_l2_poll_cpu, &p, 1))
+		mpc7448_l2_report(edac_dev, cpu, &p);
+}
+
+static void mpc7448_l2_check(struct edac_device_ctl_info *edac_dev)
+{
+	unsigned int cpu;
+
+	cpus_read_lock();
+	for_each_online_cpu(cpu)
+		mpc7448_l2_check_cpu(edac_dev, cpu);
+	cpus_read_unlock();
+}
+
+static int mpc7448_l2_probe(struct faux_device *fdev)
+{
+	struct edac_device_ctl_info *edac_dev;
+
+	edac_dev = edac_device_alloc_ctl_info(0, "cpu", nr_cpu_ids, "L", 1, 2,
+					      edac_device_alloc_index());
+	if (!edac_dev)
+		return -ENOMEM;
+
+	edac_dev->dev = &fdev->dev;
+	edac_dev->mod_name = DRV_NAME;
+	edac_dev->ctl_name = "MPC7448_L2";
+	edac_dev->dev_name = dev_name(&fdev->dev);
+	edac_dev->edac_check = mpc7448_l2_check;
+
+	if (edac_device_add_device(edac_dev)) {
+		edac_device_free_ctl_info(edac_dev);
+		return -ENXIO;
+	}
+
+	faux_device_set_drvdata(fdev, edac_dev);
+	return 0;
+}
+
+static void mpc7448_l2_remove(struct faux_device *fdev)
+{
+	struct edac_device_ctl_info *edac_dev = faux_device_get_drvdata(fdev);
+
+	edac_device_del_device(&fdev->dev);
+	edac_device_free_ctl_info(edac_dev);
+}
+
+static const struct faux_device_ops mpc7448_l2_ops = {
+	.probe = mpc7448_l2_probe,
+	.remove = mpc7448_l2_remove,
+};
+
+static int __init mpc7448_l2_edac_init(void)
+{
+	if (PVR_VER(mfspr(SPRN_PVR)) != PVR_VER_7448)
+		return -ENODEV;
+
+	opstate_init();
+
+	mpc7448_l2_fdev = faux_device_create(DRV_NAME, NULL, &mpc7448_l2_ops);
+	if (!mpc7448_l2_fdev)
+		return -ENODEV;
+
+	return 0;
+}
+module_init(mpc7448_l2_edac_init);
+
+static void __exit mpc7448_l2_edac_exit(void)
+{
+	faux_device_destroy(mpc7448_l2_fdev);
+}
+module_exit(mpc7448_l2_edac_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MPC7448 L2 cache EDAC driver");

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] EDAC/mpc7448_l2: Add error injection
  2026-11-20 19:33 [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors Matt Turner
                   ` (2 preceding siblings ...)
  2026-11-20 19:33 ` [PATCH 3/4] EDAC/mpc7448_l2: Add a driver for the MPC7448 L2 cache Matt Turner
@ 2026-11-20 19:33 ` Matt Turner
  3 siblings, 0 replies; 5+ messages in thread
From: Matt Turner @ 2026-11-20 19:33 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
	Shrikanth Hegde, Borislav Petkov, Tony Luck, Matt Turner
  Cc: linuxppc-dev, linux-kernel, linux-edac

Expose the L2 error injection registers as inject_data_hi,
inject_data_lo and inject_ctrl.  Writing a CPU number to inject_trigger
injects the error into a private buffer on that CPU and reports what
was detected.

L2 machine checks are not recoverable, so machine check reporting is
masked while the injected errors are consumed.  Tag injection is not
offered: it corrupts the tags of unrelated lines too, and hung the
machine in testing.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/powerpc/include/asm/reg.h |   1 +
 drivers/edac/mpc7448_l2_edac.c | 284 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 284 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 2f4adf5a606e..15c97ff8b12a 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -760,6 +760,7 @@
 #define L3CR_PMSIZ		0x00000001	/* L3 private memory size */
 
 #define SPRN_MSSCR0	0x3f6	/* Memory Subsystem Control Register 0 */
+#define   MSSCR0_L2PFE	0x00000003	/* L2 prefetch engines */
 #define SPRN_MSSSR0	0x3f7	/* Memory Subsystem Status Register 1 */
 #define   MSSSR0_L2TAG	0x00040000	/* L2 tag parity error */
 #define   MSSSR0_L2DAT	0x00020000	/* L2 data parity/ECC error */
diff --git a/drivers/edac/mpc7448_l2_edac.c b/drivers/edac/mpc7448_l2_edac.c
index a62c7a2e7147..157f6ff99cf6 100644
--- a/drivers/edac/mpc7448_l2_edac.c
+++ b/drivers/edac/mpc7448_l2_edac.c
@@ -11,12 +11,17 @@
  */
 
 #include <linux/bitfield.h>
+#include <linux/cache.h>
 #include <linux/cpu.h>
 #include <linux/device/faux.h>
 #include <linux/edac.h>
+#include <linux/gfp.h>
+#include <linux/io.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/smp.h>
 #include <linux/sprintf.h>
+#include <linux/sysfs.h>
 
 #include <asm/mpc7448_l2.h>
 #include <asm/reg.h>
@@ -25,6 +30,32 @@
 
 #define DRV_NAME	"mpc7448_l2_edac"
 
+/*
+ * Injection buffer layout.  The target line is followed by aliases one
+ * L1 way (4 KB) apart, which map to the same L1 set and evict the target
+ * from the 8-way L1 into the L2.  With the L1's PLRU replacement, eight
+ * misses evict the target when nothing else touches its set; INJ_NALIAS
+ * is twice that.  The L2 is filled in 64-byte lines of two 32-byte blocks.
+ */
+#define INJ_STRIDE	4096
+#define INJ_NALIAS	16
+#define INJ_ORDER	get_order((INJ_NALIAS + 1) * INJ_STRIDE)
+#define INJ_PATTERN	0x12345678
+
+/*
+ * Tag injection (L2ERRINJCTL[TERRIEN]) is not offered: it also corrupts
+ * the tags of unrelated lines sharing the L2 sets that are written while
+ * injection is enabled, which hung the machine in testing.
+ */
+#define INJ_CTL_MASK	(L2ERRINJCTL_ECCMB | L2ERRINJCTL_DERRIEN | \
+			 L2ERRINJCTL_ECCERRIM)
+
+struct mpc7448_l2_pdata {
+	u32 inj_hi;
+	u32 inj_lo;
+	u32 inj_ctl;
+};
+
 static struct faux_device *mpc7448_l2_fdev;
 
 struct mpc7448_l2_poll {
@@ -98,11 +129,261 @@ static void mpc7448_l2_check(struct edac_device_ctl_info *edac_dev)
 	cpus_read_unlock();
 }
 
+struct mpc7448_l2_inj {
+	u32 *buf;
+	u32 hi;
+	u32 lo;
+	u32 ctl;
+	u32 val;
+	struct mpc7448_l2_poll poll;
+};
+
+static u32 *inj_alias(u32 *a, unsigned int i)
+{
+	return (u32 *)((char *)a + i * INJ_STRIDE);
+}
+
+/* Flush the L2 lines of aliases first to last from the L1 and L2 */
+static void inj_flush(u32 *a, unsigned int first, unsigned int last)
+{
+	unsigned int i;
+
+	for (i = first; i <= last; i++) {
+		dcbf(inj_alias(a, i));
+		dcbf((char *)inj_alias(a, i) + 32);
+	}
+	mb();	/* wait for the flushes to complete */
+}
+
+/* Change a mode SPR with no cache operations or stores in flight */
+#define inj_mtspr(rn, v)					\
+do {								\
+	mb();	/* complete earlier accesses first */		\
+	mtspr(rn, v);						\
+	mb();	/* and the SPR write itself */			\
+	isync();						\
+} while (0)
+
+/*
+ * Every L2 write while injection is enabled is corrupted, so keep the
+ * window short: modify the target in the L1, enable injection, cast the
+ * target out to the L2 by loading its aliases, and disable injection.
+ * The aliases are filled into the L2 during the window and take the error
+ * too.  Then flush the aliases, read the target back, and flush it.
+ */
+static noinline u32 mpc7448_l2_inject_window(u32 *a, u32 hi, u32 lo, u32 ctl)
+{
+	unsigned int i;
+	u32 val;
+
+	inj_flush(a, 0, INJ_NALIAS);
+
+	/*
+	 * A castout that misses in the L2 goes to memory, so load the target
+	 * to allocate its L2 line before modifying it in the L1.
+	 */
+	READ_ONCE(*a);
+	WRITE_ONCE(*a, INJ_PATTERN);
+	mb();	/* modify the target before injection starts */
+
+	mtspr(SPRN_L2ERRINJHI, hi);
+	mtspr(SPRN_L2ERRINJLO, lo);
+	mtspr(SPRN_L2ERRINJCTL, ctl);
+	mb();	/* start injection before the castout */
+
+	for (i = 1; i <= INJ_NALIAS; i++)
+		READ_ONCE(*inj_alias(a, i));
+	mb();	/* wait for the castout and the alias fills */
+
+	mtspr(SPRN_L2ERRINJCTL, 0);
+	mtspr(SPRN_L2ERRINJHI, 0);
+	mtspr(SPRN_L2ERRINJLO, 0);
+	mb();	/* stop injection before anything else reaches the L2 */
+
+	inj_flush(a, 1, INJ_NALIAS);
+	val = READ_ONCE(*a);
+	inj_flush(a, 0, 0);
+
+	return val;
+}
+
+static void mpc7448_l2_inject_cpu(void *info)
+{
+	struct mpc7448_l2_inj *inj = info;
+	u32 inten = mfspr(SPRN_L2ERRINTEN);
+	u32 msscr0 = mfspr(SPRN_MSSCR0);
+	u32 *a = inj->buf;
+
+	/* The prefetch engines would fill (and corrupt) other lines */
+	if (msscr0 & MSSCR0_L2PFE)
+		inj_mtspr(SPRN_MSSCR0, msscr0 & ~MSSCR0_L2PFE);
+
+	/*
+	 * A dry run without injection leaves only the buffer in the
+	 * target's L1 set and the window's code in the L1 instruction
+	 * cache, so nothing else is cast out to the L2 during the window.
+	 */
+	mpc7448_l2_inject_window(a, 0, 0, 0);
+
+	/* L2 machine checks are not recoverable, so poll for these errors */
+	inj_mtspr(SPRN_L2ERRINTEN, 0);
+
+	inj->val = mpc7448_l2_inject_window(a, inj->hi, inj->lo, inj->ctl);
+	mpc7448_l2_poll_cpu(&inj->poll);
+
+	inj_mtspr(SPRN_L2ERRINTEN, inten);
+	if (msscr0 & MSSCR0_L2PFE)
+		inj_mtspr(SPRN_MSSCR0, msscr0);
+}
+
+static ssize_t inject_show(u32 val, char *data)
+{
+	return sysfs_emit(data, "0x%08x\n", val);
+}
+
+static ssize_t inject_store(u32 *val, u32 mask, const char *data,
+			    size_t count)
+{
+	u32 v;
+	int ret;
+
+	ret = kstrtou32(data, 0, &v);
+	if (ret)
+		return ret;
+	if (v & ~mask)
+		return -EINVAL;
+
+	*val = v;
+	return count;
+}
+
+static ssize_t inject_data_hi_show(struct edac_device_ctl_info *edac_dev,
+				   char *data)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_show(pdata->inj_hi, data);
+}
+
+static ssize_t inject_data_hi_store(struct edac_device_ctl_info *edac_dev,
+				    const char *data, size_t count)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_store(&pdata->inj_hi, ~0U, data, count);
+}
+
+static ssize_t inject_data_lo_show(struct edac_device_ctl_info *edac_dev,
+				   char *data)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_show(pdata->inj_lo, data);
+}
+
+static ssize_t inject_data_lo_store(struct edac_device_ctl_info *edac_dev,
+				    const char *data, size_t count)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_store(&pdata->inj_lo, ~0U, data, count);
+}
+
+static ssize_t inject_ctrl_show(struct edac_device_ctl_info *edac_dev,
+				char *data)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_show(pdata->inj_ctl, data);
+}
+
+static ssize_t inject_ctrl_store(struct edac_device_ctl_info *edac_dev,
+				 const char *data, size_t count)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+
+	return inject_store(&pdata->inj_ctl, INJ_CTL_MASK, data, count);
+}
+
+static ssize_t inject_trigger_store(struct edac_device_ctl_info *edac_dev,
+				    const char *data, size_t count)
+{
+	struct mpc7448_l2_pdata *pdata = edac_dev->pvt_info;
+	struct mpc7448_l2_inj inj;
+	struct page *page;
+	unsigned int cpu;
+	int ret;
+
+	ret = kstrtouint(data, 0, &cpu);
+	if (ret)
+		return ret;
+	if (cpu >= nr_cpu_ids)
+		return -EINVAL;
+
+	page = alloc_pages(GFP_KERNEL, INJ_ORDER);
+	if (!page)
+		return -ENOMEM;
+
+	inj.buf = page_address(page);
+	inj.hi = pdata->inj_hi;
+	inj.lo = pdata->inj_lo;
+	inj.ctl = pdata->inj_ctl;
+
+	cpus_read_lock();
+	if (cpu_online(cpu))
+		ret = smp_call_function_single(cpu, mpc7448_l2_inject_cpu,
+					       &inj, 1);
+	else
+		ret = -ENXIO;
+	cpus_read_unlock();
+
+	if (!ret)
+		edac_device_printk(edac_dev, KERN_INFO,
+				   "cpu%u: injected ctl 0x%08x data 0x%08x_%08x at 0x%llx: read 0x%08x (wrote 0x%08x)\n",
+				   cpu, inj.ctl, inj.hi, inj.lo,
+				   (unsigned long long)virt_to_phys(inj.buf),
+				   inj.val, INJ_PATTERN);
+
+	__free_pages(page, INJ_ORDER);
+
+	if (ret)
+		return ret;
+
+	mpc7448_l2_report(edac_dev, cpu, &inj.poll);
+	return count;
+}
+
+static const struct edac_dev_sysfs_attribute mpc7448_l2_sysfs_attributes[] = {
+	{
+		.attr = { .name = "inject_data_hi", .mode = 0600 },
+		.show = inject_data_hi_show,
+		.store = inject_data_hi_store,
+	},
+	{
+		.attr = { .name = "inject_data_lo", .mode = 0600 },
+		.show = inject_data_lo_show,
+		.store = inject_data_lo_store,
+	},
+	{
+		.attr = { .name = "inject_ctrl", .mode = 0600 },
+		.show = inject_ctrl_show,
+		.store = inject_ctrl_store,
+	},
+	{
+		.attr = { .name = "inject_trigger", .mode = 0200 },
+		.store = inject_trigger_store,
+	},
+	{
+		.attr = { .name = NULL },
+	},
+};
+
 static int mpc7448_l2_probe(struct faux_device *fdev)
 {
 	struct edac_device_ctl_info *edac_dev;
 
-	edac_dev = edac_device_alloc_ctl_info(0, "cpu", nr_cpu_ids, "L", 1, 2,
+	edac_dev = edac_device_alloc_ctl_info(sizeof(struct mpc7448_l2_pdata),
+					      "cpu", nr_cpu_ids, "L", 1, 2,
 					      edac_device_alloc_index());
 	if (!edac_dev)
 		return -ENOMEM;
@@ -112,6 +393,7 @@ static int mpc7448_l2_probe(struct faux_device *fdev)
 	edac_dev->ctl_name = "MPC7448_L2";
 	edac_dev->dev_name = dev_name(&fdev->dev);
 	edac_dev->edac_check = mpc7448_l2_check;
+	edac_dev->sysfs_attributes = mpc7448_l2_sysfs_attributes;
 
 	if (edac_device_add_device(edac_dev)) {
 		edac_device_free_ctl_info(edac_dev);

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-20 19:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 19:33 [PATCH 0/4] powerpc/32: Report MPC7448 L2 cache errors Matt Turner
2026-11-20 19:33 ` [PATCH 1/4] powerpc/32: Decode MPC745x L2 and L3 cache machine checks Matt Turner
2026-11-20 19:33 ` [PATCH 2/4] powerpc/32: Enable and decode MPC7448 L2 ECC " Matt Turner
2026-11-20 19:33 ` [PATCH 3/4] EDAC/mpc7448_l2: Add a driver for the MPC7448 L2 cache Matt Turner
2026-11-20 19:33 ` [PATCH 4/4] EDAC/mpc7448_l2: Add error injection Matt Turner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®