On 2020-04-01 13:17:41 Wed, Santosh Sivaraj wrote: > Subscribe to the MCE notification and add the physical address which > generated a memory error to nvdimm bad range. > > Signed-off-by: Santosh Sivaraj <sant...@fossix.org> > --- > > This patch depends on "powerpc/mce: Add MCE notification chain" [1]. > > Unlike the previous series[2], the patch adds badblock registration only for > pseries scm driver. Handling badblocks for baremetal (powernv) PMEM will be > done > later and if possible get the badblock handling as a common code. > > [1] > https://lore.kernel.org/linuxppc-dev/20200330071219.12284-1-ganes...@linux.ibm.com/ > [2] > https://lore.kernel.org/linuxppc-dev/20190820023030.18232-1-sant...@fossix.org/ > > arch/powerpc/platforms/pseries/papr_scm.c | 96 ++++++++++++++++++++++- > 1 file changed, 95 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/platforms/pseries/papr_scm.c > b/arch/powerpc/platforms/pseries/papr_scm.c > index 0b4467e378e5..5012cbf4606e 100644 > --- a/arch/powerpc/platforms/pseries/papr_scm.c > +++ b/arch/powerpc/platforms/pseries/papr_scm.c [...] > +static int handle_mce_ue(struct notifier_block *nb, unsigned long val, > + void *data) > +{ > + struct machine_check_event *evt = data; > + struct papr_scm_priv *p; > + u64 phys_addr; > + bool found = false; > + > + if (evt->error_type != MCE_ERROR_TYPE_UE) > + return NOTIFY_DONE; > + > + if (list_empty(&papr_nd_regions)) > + return NOTIFY_DONE;
Do you really need this check ? > + > + phys_addr = evt->u.ue_error.physical_address + > + (evt->u.ue_error.effective_address & ~PAGE_MASK); > + > + if (!evt->u.ue_error.physical_address_provided || > + !is_zone_device_page(pfn_to_page(phys_addr >> PAGE_SHIFT))) > + return NOTIFY_DONE; > + > + /* mce notifier is called from a process context, so mutex is safe */ > + mutex_lock(&papr_ndr_lock); > + list_for_each_entry(p, &papr_nd_regions, region_list) { > + struct resource res = p->res; > + > + if (phys_addr >= res.start && phys_addr <= res.end) { > + found = true; > + break; > + } > + } > + > + mutex_unlock(&papr_ndr_lock); > + > + if (!found) > + return NOTIFY_DONE; > + > + papr_scm_add_badblock(p->region, p->bus, phys_addr); > + > + return NOTIFY_OK; > +} > + > +static struct notifier_block mce_ue_nb = { > + .notifier_call = handle_mce_ue > +}; > + [...] > -module_platform_driver(papr_scm_driver); > +static int __init papr_scm_init(void) > +{ > + int ret; > + > + ret = platform_driver_register(&papr_scm_driver); > + if (!ret) > + mce_register_notifier(&mce_ue_nb); > + > + return ret; > +} > +module_init(papr_scm_init); > + > +static void __exit papr_scm_exit(void) > +{ > + mce_unregister_notifier(&mce_ue_nb); > + platform_driver_unregister(&papr_scm_driver); > +} > +module_exit(papr_scm_exit); Rest Looks good to me. Reviewed-by: Mahesh Salgaonkar <mah...@linux.ibm.com> Thanks, -Mahesh. > + > MODULE_DEVICE_TABLE(of, papr_scm_match); > MODULE_LICENSE("GPL"); > MODULE_AUTHOR("IBM Corporation"); > -- > 2.25.1 > -- Mahesh J Salgaonkar