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 <[email protected]> --- 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
