From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linda Knippers Subject: Re: [PATCH v2 2/3] nfit, libnvdimm: allow an ARS scrub to be triggered on demand Date: Thu, 21 Jul 2016 15:40:02 -0400 Message-ID: <57912512.5060202@hpe.com> References: <1469065850-32401-1-git-send-email-vishal.l.verma@intel.com> <1469065850-32401-3-git-send-email-vishal.l.verma@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1469065850-32401-3-git-send-email-vishal.l.verma-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" To: Vishal Verma , linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Cc: linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Tony Luck , "Rafael J. Wysocki" , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-acpi@vger.kernel.org On 07/20/2016 09:50 PM, Vishal Verma wrote: > Normally, an ARS (Address Range Scrub) only happens at > boot/initialization time. There can however arise situations where a > bus-wide rescan is needed - notably, in the case of discovering a latent > media error, we should do a full rescan to figure out what other sectors > are bad, and thus potentially avoid triggering an mce on them in the > future. Also provide a sysfs trigger to start a bus-wide scrub. I don't see anything in here that checks to see if the platform actually supports ARS before setting all this stuff up. Setting up an MCE handler and exposing a sysfs trigger for something that is optional and perhaps not implemented doesn't seem helpful. Or is there a check that I missed? -- ljk > > Cc: Dan Williams > Cc: Rafael J. Wysocki > Cc: > Cc: > Signed-off-by: Vishal Verma > --- > drivers/acpi/nfit.c | 123 +++++++++++++++++++++++++++++++++------ > drivers/acpi/nfit.h | 4 +- > drivers/nvdimm/core.c | 7 +++ > include/linux/libnvdimm.h | 1 + > tools/testing/nvdimm/test/nfit.c | 16 +++++ > 5 files changed, 131 insertions(+), 20 deletions(-) > > diff --git a/drivers/acpi/nfit.c b/drivers/acpi/nfit.c > index ac6ddcc0..4e65255 100644 > --- a/drivers/acpi/nfit.c > +++ b/drivers/acpi/nfit.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -806,8 +807,41 @@ static ssize_t revision_show(struct device *dev, > } > static DEVICE_ATTR_RO(revision); > > +/* > + * This shows the number of full Address Range Scrubs that have been > + * completed since driver load time. Userspace can wait on this using > + * select/poll etc. > + */ > +static ssize_t scrub_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + > + return sprintf(buf, "%d\n", acpi_desc->scrub_count); > +} > + > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc); > + > +static ssize_t scrub_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t size) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + int rc; > + > + rc = acpi_nfit_ars_rescan(acpi_desc); > + if (rc) > + return rc; > + return size; > +} > +static DEVICE_ATTR_RW(scrub); > + > static struct attribute *acpi_nfit_attributes[] = { > &dev_attr_revision.attr, > + &dev_attr_scrub.attr, > NULL, > }; > > @@ -2138,7 +2172,7 @@ static void acpi_nfit_async_scrub(struct acpi_nfit_desc *acpi_desc, > unsigned int tmo = scrub_timeout; > int rc; > > - if (nfit_spa->ars_done || !nfit_spa->nd_region) > + if (!(nfit_spa->ars_required && nfit_spa->nd_region)) > return; > > rc = ars_start(acpi_desc, nfit_spa); > @@ -2227,7 +2261,9 @@ static void acpi_nfit_scrub(struct work_struct *work) > * firmware initiated scrubs to complete and then we go search for the > * affected spa regions to mark them scanned. In the second phase we > * initiate a directed scrub for every range that was not scrubbed in > - * phase 1. > + * phase 1. If we're called for a 'rescan', we harmlessly pass through > + * the first phase, but really only care about running phase 2, where > + * regions can be notified of new poison. > */ > > /* process platform firmware initiated scrubs */ > @@ -2330,14 +2366,17 @@ static void acpi_nfit_scrub(struct work_struct *work) > * Flag all the ranges that still need scrubbing, but > * register them now to make data available. > */ > - if (nfit_spa->nd_region) > - nfit_spa->ars_done = 1; > - else > + if (!nfit_spa->nd_region) { > + nfit_spa->ars_required = 1; > acpi_nfit_register_region(acpi_desc, nfit_spa); > + } > } > > list_for_each_entry(nfit_spa, &acpi_desc->spas, list) > acpi_nfit_async_scrub(acpi_desc, nfit_spa); > + acpi_desc->scrub_count++; > + if (acpi_desc->scrub_count_state) > + sysfs_notify_dirent(acpi_desc->scrub_count_state); > mutex_unlock(&acpi_desc->init_mutex); > } > > @@ -2495,6 +2534,27 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc, > return 0; > } > > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc) > +{ > + struct device *dev = acpi_desc->dev; > + struct nfit_spa *nfit_spa; > + > + if (work_busy(&acpi_desc->work)) > + return -EBUSY; > + > + list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { > + struct acpi_nfit_system_address *spa = nfit_spa->spa; > + > + if (nfit_spa_type(spa) != NFIT_SPA_PM) > + continue; > + > + nfit_spa->ars_required = 1; > + } > + queue_work(nfit_wq, &acpi_desc->work); > + dev_info(dev, "%s: ars_scan triggered\n", __func__); > + return 0; > +} > + > void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > { > struct nvdimm_bus_descriptor *nd_desc; > @@ -2523,6 +2583,37 @@ void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > } > EXPORT_SYMBOL_GPL(acpi_nfit_desc_init); > > +static struct acpi_nfit_desc *acpi_nfit_desc_alloc_register(struct device *dev) > +{ > + struct acpi_nfit_desc *acpi_desc; > + struct kernfs_node *nfit; > + struct device *bus_dev; > + > + acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > + if (!acpi_desc) > + return ERR_PTR(-ENOMEM); > + > + acpi_nfit_desc_init(acpi_desc, dev); > + > + acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > + if (!acpi_desc->nvdimm_bus) > + return ERR_PTR(-ENOMEM); > + > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + > + return acpi_desc; > +} > + > static int acpi_nfit_add(struct acpi_device *adev) > { > struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; > @@ -2540,13 +2631,9 @@ static int acpi_nfit_add(struct acpi_device *adev) > return 0; > } > > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - return -ENOMEM; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - return -ENOMEM; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + return PTR_ERR(acpi_desc); > > /* > * Save the acpi header for later and then skip it, > @@ -2587,6 +2674,7 @@ static int acpi_nfit_remove(struct acpi_device *adev) > > acpi_desc->cancel = 1; > flush_workqueue(nfit_wq); > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > return 0; > } > @@ -2611,13 +2699,10 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event) > } > > if (!acpi_desc) { > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - goto out_unlock; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - goto out_unlock; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + dev_err(dev, "%s: failed to alloc acpi_desc (%ld)\n", > + __func__, PTR_ERR(acpi_desc)); > } else { > /* > * Finish previous registration before considering new > diff --git a/drivers/acpi/nfit.h b/drivers/acpi/nfit.h > index 02b9ea1..954d2aa 100644 > --- a/drivers/acpi/nfit.h > +++ b/drivers/acpi/nfit.h > @@ -77,7 +77,7 @@ struct nfit_spa { > struct acpi_nfit_system_address *spa; > struct list_head list; > struct nd_region *nd_region; > - unsigned int ars_done:1; > + unsigned int ars_required:1; > u32 clear_err_unit; > u32 max_ars; > }; > @@ -146,6 +146,8 @@ struct acpi_nfit_desc { > struct nd_cmd_ars_status *ars_status; > size_t ars_status_size; > struct work_struct work; > + struct kernfs_node *scrub_count_state; > + unsigned int scrub_count; > unsigned int cancel:1; > unsigned long dimm_cmd_force_en; > unsigned long bus_cmd_force_en; > diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c > index be89764..d81db3ac 100644 > --- a/drivers/nvdimm/core.c > +++ b/drivers/nvdimm/core.c > @@ -99,6 +99,13 @@ struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus) > } > EXPORT_SYMBOL_GPL(to_nd_desc); > > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus) > +{ > + /* struct nvdimm_bus definition is private to libnvdimm */ > + return &nvdimm_bus->dev; > +} > +EXPORT_SYMBOL_GPL(to_nvdimm_bus_dev); > + > struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev) > { > struct device *dev; > diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h > index 0c3c30c..27cecc2 100644 > --- a/include/linux/libnvdimm.h > +++ b/include/linux/libnvdimm.h > @@ -129,6 +129,7 @@ struct nvdimm *to_nvdimm(struct device *dev); > struct nd_region *to_nd_region(struct device *dev); > struct nd_blk_region *to_nd_blk_region(struct device *dev); > struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus); > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus); > const char *nvdimm_name(struct nvdimm *nvdimm); > unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm); > void *nvdimm_provider_data(struct nvdimm *nvdimm); > diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c > index c919866..74231de 100644 > --- a/tools/testing/nvdimm/test/nfit.c > +++ b/tools/testing/nvdimm/test/nfit.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1409,6 +1410,8 @@ static int nfit_test_probe(struct platform_device *pdev) > struct acpi_nfit_desc *acpi_desc; > struct device *dev = &pdev->dev; > struct nfit_test *nfit_test; > + struct kernfs_node *nfit; > + struct device *bus_dev; > int rc; > > nfit_test = to_nfit_test(&pdev->dev); > @@ -1471,6 +1474,18 @@ static int nfit_test_probe(struct platform_device *pdev) > if (!acpi_desc->nvdimm_bus) > return -ENXIO; > > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return -ENODEV; > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return -ENODEV; > + } > + > rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); > if (rc) { > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > @@ -1497,6 +1512,7 @@ static int nfit_test_remove(struct platform_device *pdev) > struct nfit_test *nfit_test = to_nfit_test(&pdev->dev); > struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc; > > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > > return 0; > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0711.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::711]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CB7251A1E20 for ; Thu, 21 Jul 2016 12:41:26 -0700 (PDT) Message-ID: <57912512.5060202@hpe.com> Date: Thu, 21 Jul 2016 15:40:02 -0400 From: Linda Knippers MIME-Version: 1.0 Subject: Re: [PATCH v2 2/3] nfit, libnvdimm: allow an ARS scrub to be triggered on demand References: <1469065850-32401-1-git-send-email-vishal.l.verma@intel.com> <1469065850-32401-3-git-send-email-vishal.l.verma@intel.com> In-Reply-To: <1469065850-32401-3-git-send-email-vishal.l.verma@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" To: Vishal Verma , linux-nvdimm@lists.01.org Cc: linux-acpi@vger.kernel.org, Tony Luck , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org List-ID: On 07/20/2016 09:50 PM, Vishal Verma wrote: > Normally, an ARS (Address Range Scrub) only happens at > boot/initialization time. There can however arise situations where a > bus-wide rescan is needed - notably, in the case of discovering a latent > media error, we should do a full rescan to figure out what other sectors > are bad, and thus potentially avoid triggering an mce on them in the > future. Also provide a sysfs trigger to start a bus-wide scrub. I don't see anything in here that checks to see if the platform actually supports ARS before setting all this stuff up. Setting up an MCE handler and exposing a sysfs trigger for something that is optional and perhaps not implemented doesn't seem helpful. Or is there a check that I missed? -- ljk > > Cc: Dan Williams > Cc: Rafael J. Wysocki > Cc: > Cc: > Signed-off-by: Vishal Verma > --- > drivers/acpi/nfit.c | 123 +++++++++++++++++++++++++++++++++------ > drivers/acpi/nfit.h | 4 +- > drivers/nvdimm/core.c | 7 +++ > include/linux/libnvdimm.h | 1 + > tools/testing/nvdimm/test/nfit.c | 16 +++++ > 5 files changed, 131 insertions(+), 20 deletions(-) > > diff --git a/drivers/acpi/nfit.c b/drivers/acpi/nfit.c > index ac6ddcc0..4e65255 100644 > --- a/drivers/acpi/nfit.c > +++ b/drivers/acpi/nfit.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -806,8 +807,41 @@ static ssize_t revision_show(struct device *dev, > } > static DEVICE_ATTR_RO(revision); > > +/* > + * This shows the number of full Address Range Scrubs that have been > + * completed since driver load time. Userspace can wait on this using > + * select/poll etc. > + */ > +static ssize_t scrub_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + > + return sprintf(buf, "%d\n", acpi_desc->scrub_count); > +} > + > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc); > + > +static ssize_t scrub_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t size) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + int rc; > + > + rc = acpi_nfit_ars_rescan(acpi_desc); > + if (rc) > + return rc; > + return size; > +} > +static DEVICE_ATTR_RW(scrub); > + > static struct attribute *acpi_nfit_attributes[] = { > &dev_attr_revision.attr, > + &dev_attr_scrub.attr, > NULL, > }; > > @@ -2138,7 +2172,7 @@ static void acpi_nfit_async_scrub(struct acpi_nfit_desc *acpi_desc, > unsigned int tmo = scrub_timeout; > int rc; > > - if (nfit_spa->ars_done || !nfit_spa->nd_region) > + if (!(nfit_spa->ars_required && nfit_spa->nd_region)) > return; > > rc = ars_start(acpi_desc, nfit_spa); > @@ -2227,7 +2261,9 @@ static void acpi_nfit_scrub(struct work_struct *work) > * firmware initiated scrubs to complete and then we go search for the > * affected spa regions to mark them scanned. In the second phase we > * initiate a directed scrub for every range that was not scrubbed in > - * phase 1. > + * phase 1. If we're called for a 'rescan', we harmlessly pass through > + * the first phase, but really only care about running phase 2, where > + * regions can be notified of new poison. > */ > > /* process platform firmware initiated scrubs */ > @@ -2330,14 +2366,17 @@ static void acpi_nfit_scrub(struct work_struct *work) > * Flag all the ranges that still need scrubbing, but > * register them now to make data available. > */ > - if (nfit_spa->nd_region) > - nfit_spa->ars_done = 1; > - else > + if (!nfit_spa->nd_region) { > + nfit_spa->ars_required = 1; > acpi_nfit_register_region(acpi_desc, nfit_spa); > + } > } > > list_for_each_entry(nfit_spa, &acpi_desc->spas, list) > acpi_nfit_async_scrub(acpi_desc, nfit_spa); > + acpi_desc->scrub_count++; > + if (acpi_desc->scrub_count_state) > + sysfs_notify_dirent(acpi_desc->scrub_count_state); > mutex_unlock(&acpi_desc->init_mutex); > } > > @@ -2495,6 +2534,27 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc, > return 0; > } > > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc) > +{ > + struct device *dev = acpi_desc->dev; > + struct nfit_spa *nfit_spa; > + > + if (work_busy(&acpi_desc->work)) > + return -EBUSY; > + > + list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { > + struct acpi_nfit_system_address *spa = nfit_spa->spa; > + > + if (nfit_spa_type(spa) != NFIT_SPA_PM) > + continue; > + > + nfit_spa->ars_required = 1; > + } > + queue_work(nfit_wq, &acpi_desc->work); > + dev_info(dev, "%s: ars_scan triggered\n", __func__); > + return 0; > +} > + > void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > { > struct nvdimm_bus_descriptor *nd_desc; > @@ -2523,6 +2583,37 @@ void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > } > EXPORT_SYMBOL_GPL(acpi_nfit_desc_init); > > +static struct acpi_nfit_desc *acpi_nfit_desc_alloc_register(struct device *dev) > +{ > + struct acpi_nfit_desc *acpi_desc; > + struct kernfs_node *nfit; > + struct device *bus_dev; > + > + acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > + if (!acpi_desc) > + return ERR_PTR(-ENOMEM); > + > + acpi_nfit_desc_init(acpi_desc, dev); > + > + acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > + if (!acpi_desc->nvdimm_bus) > + return ERR_PTR(-ENOMEM); > + > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + > + return acpi_desc; > +} > + > static int acpi_nfit_add(struct acpi_device *adev) > { > struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; > @@ -2540,13 +2631,9 @@ static int acpi_nfit_add(struct acpi_device *adev) > return 0; > } > > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - return -ENOMEM; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - return -ENOMEM; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + return PTR_ERR(acpi_desc); > > /* > * Save the acpi header for later and then skip it, > @@ -2587,6 +2674,7 @@ static int acpi_nfit_remove(struct acpi_device *adev) > > acpi_desc->cancel = 1; > flush_workqueue(nfit_wq); > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > return 0; > } > @@ -2611,13 +2699,10 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event) > } > > if (!acpi_desc) { > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - goto out_unlock; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - goto out_unlock; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + dev_err(dev, "%s: failed to alloc acpi_desc (%ld)\n", > + __func__, PTR_ERR(acpi_desc)); > } else { > /* > * Finish previous registration before considering new > diff --git a/drivers/acpi/nfit.h b/drivers/acpi/nfit.h > index 02b9ea1..954d2aa 100644 > --- a/drivers/acpi/nfit.h > +++ b/drivers/acpi/nfit.h > @@ -77,7 +77,7 @@ struct nfit_spa { > struct acpi_nfit_system_address *spa; > struct list_head list; > struct nd_region *nd_region; > - unsigned int ars_done:1; > + unsigned int ars_required:1; > u32 clear_err_unit; > u32 max_ars; > }; > @@ -146,6 +146,8 @@ struct acpi_nfit_desc { > struct nd_cmd_ars_status *ars_status; > size_t ars_status_size; > struct work_struct work; > + struct kernfs_node *scrub_count_state; > + unsigned int scrub_count; > unsigned int cancel:1; > unsigned long dimm_cmd_force_en; > unsigned long bus_cmd_force_en; > diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c > index be89764..d81db3ac 100644 > --- a/drivers/nvdimm/core.c > +++ b/drivers/nvdimm/core.c > @@ -99,6 +99,13 @@ struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus) > } > EXPORT_SYMBOL_GPL(to_nd_desc); > > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus) > +{ > + /* struct nvdimm_bus definition is private to libnvdimm */ > + return &nvdimm_bus->dev; > +} > +EXPORT_SYMBOL_GPL(to_nvdimm_bus_dev); > + > struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev) > { > struct device *dev; > diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h > index 0c3c30c..27cecc2 100644 > --- a/include/linux/libnvdimm.h > +++ b/include/linux/libnvdimm.h > @@ -129,6 +129,7 @@ struct nvdimm *to_nvdimm(struct device *dev); > struct nd_region *to_nd_region(struct device *dev); > struct nd_blk_region *to_nd_blk_region(struct device *dev); > struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus); > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus); > const char *nvdimm_name(struct nvdimm *nvdimm); > unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm); > void *nvdimm_provider_data(struct nvdimm *nvdimm); > diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c > index c919866..74231de 100644 > --- a/tools/testing/nvdimm/test/nfit.c > +++ b/tools/testing/nvdimm/test/nfit.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1409,6 +1410,8 @@ static int nfit_test_probe(struct platform_device *pdev) > struct acpi_nfit_desc *acpi_desc; > struct device *dev = &pdev->dev; > struct nfit_test *nfit_test; > + struct kernfs_node *nfit; > + struct device *bus_dev; > int rc; > > nfit_test = to_nfit_test(&pdev->dev); > @@ -1471,6 +1474,18 @@ static int nfit_test_probe(struct platform_device *pdev) > if (!acpi_desc->nvdimm_bus) > return -ENXIO; > > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return -ENODEV; > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return -ENODEV; > + } > + > rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); > if (rc) { > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > @@ -1497,6 +1512,7 @@ static int nfit_test_remove(struct platform_device *pdev) > struct nfit_test *nfit_test = to_nfit_test(&pdev->dev); > struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc; > > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > > return 0; > _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754023AbcGUUNH (ORCPT ); Thu, 21 Jul 2016 16:13:07 -0400 Received: from mail-bl2nam02on0120.outbound.protection.outlook.com ([104.47.38.120]:59732 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753926AbcGUUNF (ORCPT ); Thu, 21 Jul 2016 16:13:05 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=linda.knippers@hpe.com; Message-ID: <57912512.5060202@hpe.com> Date: Thu, 21 Jul 2016 15:40:02 -0400 From: Linda Knippers User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Vishal Verma , CC: Tony Luck , "Rafael J. Wysocki" , , Subject: Re: [PATCH v2 2/3] nfit, libnvdimm: allow an ARS scrub to be triggered on demand References: <1469065850-32401-1-git-send-email-vishal.l.verma@intel.com> <1469065850-32401-3-git-send-email-vishal.l.verma@intel.com> In-Reply-To: <1469065850-32401-3-git-send-email-vishal.l.verma@intel.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [50.187.52.22] X-ClientProxiedBy: BLUPR11CA0041.namprd11.prod.outlook.com (10.141.240.51) To TU4PR84MB0238.NAMPRD84.PROD.OUTLOOK.COM (10.162.187.28) X-MS-Office365-Filtering-Correlation-Id: b03325de-c153-4563-da05-08d3b19ee1a1 X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0238;2:Rh591AXYhZRYY7YKgGLFfr1QPpKSzixk60DSocrS3/JesD5Hd6kmeHy8B8DoPe85o1wBF3I33nkT6lkSXalZDcRGwdDin2NLTnlk/1taIBooy2Vfu+rc3F9IufAgZUFF5su9+ZwVPbKfXWp8uo5+gHis4O2qjDTJAbwAmCuKP2vSXz7fE0OuDnICQ+DLWKdf;3:f896kGtR5wIDmbkOJAifJYDK7hqSlXsx5JqxC0jBGiPakzU5fWlpye2zRR5/VxaKnAaGtnnBUoDb+1D3JC+tu+kJQZSOAi6JFJw4QbhP97IaCQO6nyFkOPc1sxJmqPOm;25:l0MUrcNHCFNP1hrx5htgUzvilCoOVISnpbfeMswlj0BBTZ1unEGejiAknMydPhXn6lD0/0+RZpkqArNma/ISU+v51BzDt06fR53dhqpSUiHk4BaDzHBggTi/tZCcov0id/s/Yef3Y/4sVzz/clkE/KNjAK/gsWKWsrLggkS1if94pZjFDjEvyFFMHkICZit5GEPvKHsZTEqVb+vqkh0pdOvI43P1GLooCPqp8ShpeKbAuBNWdJzuvANR5G8t5SdcoQw57EUJr5jMyjIiY6WsP29bXP2aXGToBTW/+mrZ+/pDzVC3UPu1sKwf/BeHt7QVaMySQtVDS2nIifwGFxLKyWSmtNqA1N09FdmFXGn6EJwiWEo0e+PVk+0WJTuOJYfFNiIy04to5AlsNRQZ+sjG8P052dEua9BsrTuRRVnHc+A=;31:tuu+1RnFfStug/Vc2dOxBHrrLwiEGrmB8Md7bAO81uEf3JlN/koNS60PBi6JcLzfme6/9gdNiRFUmmEU5jPy1hktEdYCvIS72jGCUjkyYppfHd/QCS4Hq9O4mD7E9VA1h3alf55ZZOwDHs2UCXZE+c8v67LPdQawOzIe7E9ZDTrTJ6NTQdSm9BXv0HX8j2N0M7f4oTO60193HY3TX4YJYA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:TU4PR84MB0238; X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0238;20:jwRhg03EZsCy/yUgPJimv4crhabbrUYqOMjFDE+gjn9Nco4tpZaw6j+AMHdJrdGLpBjIHnuy7JXLLBgNxAAWQDiVBfqrsn+QC2MLTd+lOlY44+rrh14nByyMwcbxsTZAVQNmYfvtorMA/4DmoCH1DJIiiU2f8HTTKGId1OzlIxAC6bXLYby50cBF6O3uEBo6V+pboYOJOXaqToytU8U1/mHkK1gztBr74jJmnK+XxnSRvuh1iiRjJgSoA0YAJkBps0fmu0GTiMHW729ehQdGWVoMxIui8vxRBTP8gQo1cX37dPkHKwGyZdFkYeZ2IWGkjUEVp3H2Ub+LrdOZVn6sN+hnQyKOFr9F9aYWzUKGqFOX1VmDrfUAOBKiKI1PkK4Eas3UaUwaSiKIs1zyFC5UMwskibge+05NYaftCsHMJ2szXZAJ7AkOgdGnL78gC/rIU+rLTCF9WvUpWoaOGID5EjMF3Ezbj3bekxM0Ivm5J6hX8KEljmBzy9HKDj7dgE8I X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(162533806227266)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:TU4PR84MB0238;BCL:0;PCL:0;RULEID:;SRVR:TU4PR84MB0238; X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0238;4:h48qmxTgnfAojYDv2W0NYXuceWTI1NBULc08RWS9p3ARL8ih9GKV8GXLmNuzNEXd7ydWJXBHx0QyRpREllDTMxzL8WwxEc518FbGnW/9T58tSX65k9uUGvOttYCmMmnZKWiMZ+CU5SpbBzGE2iuydP+rhoZZBxGp4iYvL8Kg6aMOTKXnE51NujhmNRj76r+R2n/kp1gvirYXFReJy5MZY0uyboqAND8fvZziVAo97bA/cWlbOtrlqc551AoepEzwRlJBsykUIiLasUEmdT9hvOWdXl5spKz0vcBywOPjyuunlL5mNdamh1BvWE+04oJF6pqbqsZTQ5AP8SXNHEf14YUhuNdjATpsRdrEFpqlwRr3sxfgtDiah2dLg3x7g4R1Y+g95o0xF+tdceeDWVL20ltrTDkSsqGf6eSjA7Ewe8wBQ3BOrerw0L/X97LaUuxQi2ZV7wt5nIlYQOba9aTH34CpSRbtNSubdvtFh/WbW4xZRZhK50UGaxeyrQ90yjwS X-Forefront-PRVS: 0010D93EFE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(7916002)(24454002)(377454003)(189002)(199003)(189998001)(6116002)(42186005)(4001350100001)(64126003)(3846002)(68736007)(77096005)(23746002)(105586002)(2950100001)(97736004)(99136001)(36756003)(5001770100001)(230700001)(50466002)(117156001)(59896002)(7736002)(101416001)(305945005)(81156014)(8676002)(81166006)(106356001)(4326007)(122286003)(86362001)(76176999)(586003)(2906002)(87266999)(54356999)(19580395003)(50986999)(19580405001)(117636001)(65806001)(66066001)(65956001)(65816999)(7846002)(47776003)(83506001)(92566002)(62816006);DIR:OUT;SFP:1102;SCL:1;SRVR:TU4PR84MB0238;H:[192.168.1.12];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;TU4PR84MB0238;23:+jI+TpVcaOVL3MvymTGcQ7508XjgR3e5bY58I?= =?Windows-1252?Q?tL3UPZVFPjOn2sAFflkHVBoWQkLn0o2JXrbY+WybC5Wa/fse0C1X2i1E?= =?Windows-1252?Q?En/yBTgPk33ChJ68d/rcbZ9WpC8WNkFu4cwlt3jQ87jlp74QcHOjKA/4?= =?Windows-1252?Q?I8eP/PiS7+iTjXHFwFlTqVV4CFyxzDabSdEYeKq0lsjw0ejMBps9vFm+?= =?Windows-1252?Q?aL41oGpWriNksCaXNsmW9Hspv33ibJ/2rESec1wQ2pEg2WjIQT/5Z9Cd?= =?Windows-1252?Q?SKI23oxJyc4PCXGDO0WLzKVMFvAsmhaQrjIL12IKk8BkSnHQ6F89Cr1o?= =?Windows-1252?Q?oxejog4aFatKJV2n+ORnwi43TZi6tT9U3defs+ZJNxBLBsSBrDPQ25Ns?= =?Windows-1252?Q?rf3IHjsmZ4jBOLw3xaab06YlMcwkw0ZljZiq5MXCa/dTJWpj3PgyWsCG?= =?Windows-1252?Q?2VfGZcEBVYr565dQaV075iOIW/+y0Tnm3wbFhwQ/UU40iNIVXKsDkGCM?= =?Windows-1252?Q?yFGpuWIt8J0YRj/7Kuswp1JsgJO0MHLtH7E3rDkasMhPJW8/FpqTJDcP?= =?Windows-1252?Q?CwRbBvNIJQGMHWgQ49IfsQme1tOzXOVwquMA7LVm57uUS6g5TlUFlAJr?= =?Windows-1252?Q?hy2kAVK3Z0xp3i8nT6X/sTr+n11k7fB3gLG3zOgR2SkIKK9IGP4FjGMu?= =?Windows-1252?Q?cZTVYjH0IsFS9+yWQ5XEjIcR/ooDDlTYftUVlePM7O6QXZKafiP1jftr?= =?Windows-1252?Q?3PrKfaU45F6F7QOB57epl5ScgRj3HTpuC/ZQrxoFPCsYicjp6GUmKKhZ?= =?Windows-1252?Q?hpRCq+1iRZTlLX/mxvLC+3XtFrrxf33mmKAMf1eON5sZrr3ihVzW/xtr?= =?Windows-1252?Q?tjY+YEjmX/S/V6zFQgnTn/GBXz9cXGjWaNUwN9gfUp3pL2Z9l6/apcSH?= =?Windows-1252?Q?sv2mo2WJCbVUsZDlwKyTJAAV4TuQVmyDYCDBX0d95rXytPO+7TlxyK9q?= =?Windows-1252?Q?ILEm3YggM+IuHNGKq8/IXwHC76U0XOQaQc8zgnhyKTuzpJ+wx0282SgU?= =?Windows-1252?Q?xeEhKyHLq8g4aK/dQwKR3ATeumvhc+GpAjQmg8zb8BULFARfmY5mhRGb?= =?Windows-1252?Q?2fTRhy9X8gkGuzsHFQVbbUFUkvgcJbMAMFGbF2K5Wc97cWiDTPWgBaze?= =?Windows-1252?Q?5Ch7SzLiqwzsglVNFtDqCOepOlFWbj23DLprY2sJTEtE45St5e7At1tF?= =?Windows-1252?Q?jntTc4/69Cv/kAAA0WSDIWNcW+C4IeQ73ZcvlPOt3Z9NnSeItycZsAAR?= =?Windows-1252?Q?d4dwHwXe0+G39n7jBH54j4Vx0v77rXO+ec3ogvTIT8Vg0yoJETnREbpz?= =?Windows-1252?Q?MwWLywJEX+tlvHUWXdx/YjNuI2xlbozP909w85utJz6ltHJeCPJRXp7g?= =?Windows-1252?Q?FTR86kduDaCa63E0H8Xhk2a9i4X6OMV7SvXSTgPkw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0238;6:MCKlY8wYv3Um4GDgzI12FD2ViDft7MFIVZMvtt2zlR3pT0Wza7XQIPhsTTTje8ZrGZ8nOI20h1hzEcavavHnMcoyOl7+TpaxG7fNxVJdS+GU/GIumjtSnsWbeNWghLkR+mwONOddBJLTBiMzAKEqjCtDKuh7Iz+St0XWzafpkSL1h6CtPQ5UizrPMPlONafsk4lbFsCfj07lMpXlLo/063SD1BmYDFw7/iqIQZTCGT/sNIuN45A2u1t/QTPFaydLlubV7SMWSHLLoVxh705Pg7EHe6NNoPjry9jPj377yuMGYeYJKnmsAAyC6UR8I2n3sovDiC9NlBvYBndMVQXiaA==;5:h+SmEiV15wuUZvWezBqi8MMd3CcHlnIxlhCswpyWeHT0IJdQHvdpoqB5WAsvfEVz7VSmU/KicUYBb9+C2848JngKcHEa+AfY5LQCmxICpFmM3wr3bXf4fx7yrwMIoMOCKjAEv5Sbs+29mqg8s+k8MQ==;24:d9EsnS9b2Lo+E71mHz2HawdPTUNcO2VYWLG+UvweE6UIZpi25cpkTLGvfmX4oW1LZliQQfihcU/PZIf8hNPa5L5NudO2yjO8+ZDyFxXseOU=;7:+Rq1pu+kqqjvGqNjj3MpXjv+O3LVpRPtqwWsiMB2tFnTp1Hf+BP9r1gw8Es1JruI+7T/Tqux+GogPiUlpJ8UFA8up5o9cOXO1WLZVbMcNBCYoNWIzRO9NUU83c2b30thkOhZZ+Mwexx8gxqzSdLoSkdwDomHi21BNyV9/a1ZkNcOhh1/1QDC2JQwaCbtQ+a32k3OmKF8bNWYPCIyPE7ymCjbBHYWuH1Y00BcikgqglUEaDqI2UNtWebMf4cKj+0Y SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2016 19:40:33.2076 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: TU4PR84MB0238 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/20/2016 09:50 PM, Vishal Verma wrote: > Normally, an ARS (Address Range Scrub) only happens at > boot/initialization time. There can however arise situations where a > bus-wide rescan is needed - notably, in the case of discovering a latent > media error, we should do a full rescan to figure out what other sectors > are bad, and thus potentially avoid triggering an mce on them in the > future. Also provide a sysfs trigger to start a bus-wide scrub. I don't see anything in here that checks to see if the platform actually supports ARS before setting all this stuff up. Setting up an MCE handler and exposing a sysfs trigger for something that is optional and perhaps not implemented doesn't seem helpful. Or is there a check that I missed? -- ljk > > Cc: Dan Williams > Cc: Rafael J. Wysocki > Cc: > Cc: > Signed-off-by: Vishal Verma > --- > drivers/acpi/nfit.c | 123 +++++++++++++++++++++++++++++++++------ > drivers/acpi/nfit.h | 4 +- > drivers/nvdimm/core.c | 7 +++ > include/linux/libnvdimm.h | 1 + > tools/testing/nvdimm/test/nfit.c | 16 +++++ > 5 files changed, 131 insertions(+), 20 deletions(-) > > diff --git a/drivers/acpi/nfit.c b/drivers/acpi/nfit.c > index ac6ddcc0..4e65255 100644 > --- a/drivers/acpi/nfit.c > +++ b/drivers/acpi/nfit.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -806,8 +807,41 @@ static ssize_t revision_show(struct device *dev, > } > static DEVICE_ATTR_RO(revision); > > +/* > + * This shows the number of full Address Range Scrubs that have been > + * completed since driver load time. Userspace can wait on this using > + * select/poll etc. > + */ > +static ssize_t scrub_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + > + return sprintf(buf, "%d\n", acpi_desc->scrub_count); > +} > + > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc); > + > +static ssize_t scrub_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t size) > +{ > + struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); > + struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); > + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > + int rc; > + > + rc = acpi_nfit_ars_rescan(acpi_desc); > + if (rc) > + return rc; > + return size; > +} > +static DEVICE_ATTR_RW(scrub); > + > static struct attribute *acpi_nfit_attributes[] = { > &dev_attr_revision.attr, > + &dev_attr_scrub.attr, > NULL, > }; > > @@ -2138,7 +2172,7 @@ static void acpi_nfit_async_scrub(struct acpi_nfit_desc *acpi_desc, > unsigned int tmo = scrub_timeout; > int rc; > > - if (nfit_spa->ars_done || !nfit_spa->nd_region) > + if (!(nfit_spa->ars_required && nfit_spa->nd_region)) > return; > > rc = ars_start(acpi_desc, nfit_spa); > @@ -2227,7 +2261,9 @@ static void acpi_nfit_scrub(struct work_struct *work) > * firmware initiated scrubs to complete and then we go search for the > * affected spa regions to mark them scanned. In the second phase we > * initiate a directed scrub for every range that was not scrubbed in > - * phase 1. > + * phase 1. If we're called for a 'rescan', we harmlessly pass through > + * the first phase, but really only care about running phase 2, where > + * regions can be notified of new poison. > */ > > /* process platform firmware initiated scrubs */ > @@ -2330,14 +2366,17 @@ static void acpi_nfit_scrub(struct work_struct *work) > * Flag all the ranges that still need scrubbing, but > * register them now to make data available. > */ > - if (nfit_spa->nd_region) > - nfit_spa->ars_done = 1; > - else > + if (!nfit_spa->nd_region) { > + nfit_spa->ars_required = 1; > acpi_nfit_register_region(acpi_desc, nfit_spa); > + } > } > > list_for_each_entry(nfit_spa, &acpi_desc->spas, list) > acpi_nfit_async_scrub(acpi_desc, nfit_spa); > + acpi_desc->scrub_count++; > + if (acpi_desc->scrub_count_state) > + sysfs_notify_dirent(acpi_desc->scrub_count_state); > mutex_unlock(&acpi_desc->init_mutex); > } > > @@ -2495,6 +2534,27 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc, > return 0; > } > > +static int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc) > +{ > + struct device *dev = acpi_desc->dev; > + struct nfit_spa *nfit_spa; > + > + if (work_busy(&acpi_desc->work)) > + return -EBUSY; > + > + list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { > + struct acpi_nfit_system_address *spa = nfit_spa->spa; > + > + if (nfit_spa_type(spa) != NFIT_SPA_PM) > + continue; > + > + nfit_spa->ars_required = 1; > + } > + queue_work(nfit_wq, &acpi_desc->work); > + dev_info(dev, "%s: ars_scan triggered\n", __func__); > + return 0; > +} > + > void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > { > struct nvdimm_bus_descriptor *nd_desc; > @@ -2523,6 +2583,37 @@ void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) > } > EXPORT_SYMBOL_GPL(acpi_nfit_desc_init); > > +static struct acpi_nfit_desc *acpi_nfit_desc_alloc_register(struct device *dev) > +{ > + struct acpi_nfit_desc *acpi_desc; > + struct kernfs_node *nfit; > + struct device *bus_dev; > + > + acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > + if (!acpi_desc) > + return ERR_PTR(-ENOMEM); > + > + acpi_nfit_desc_init(acpi_desc, dev); > + > + acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > + if (!acpi_desc->nvdimm_bus) > + return ERR_PTR(-ENOMEM); > + > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return ERR_PTR(-ENODEV); > + } > + > + return acpi_desc; > +} > + > static int acpi_nfit_add(struct acpi_device *adev) > { > struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; > @@ -2540,13 +2631,9 @@ static int acpi_nfit_add(struct acpi_device *adev) > return 0; > } > > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - return -ENOMEM; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - return -ENOMEM; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + return PTR_ERR(acpi_desc); > > /* > * Save the acpi header for later and then skip it, > @@ -2587,6 +2674,7 @@ static int acpi_nfit_remove(struct acpi_device *adev) > > acpi_desc->cancel = 1; > flush_workqueue(nfit_wq); > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > return 0; > } > @@ -2611,13 +2699,10 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event) > } > > if (!acpi_desc) { > - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > - if (!acpi_desc) > - goto out_unlock; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > - acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc); > - if (!acpi_desc->nvdimm_bus) > - goto out_unlock; > + acpi_desc = acpi_nfit_desc_alloc_register(dev); > + if (IS_ERR(acpi_desc)) > + dev_err(dev, "%s: failed to alloc acpi_desc (%ld)\n", > + __func__, PTR_ERR(acpi_desc)); > } else { > /* > * Finish previous registration before considering new > diff --git a/drivers/acpi/nfit.h b/drivers/acpi/nfit.h > index 02b9ea1..954d2aa 100644 > --- a/drivers/acpi/nfit.h > +++ b/drivers/acpi/nfit.h > @@ -77,7 +77,7 @@ struct nfit_spa { > struct acpi_nfit_system_address *spa; > struct list_head list; > struct nd_region *nd_region; > - unsigned int ars_done:1; > + unsigned int ars_required:1; > u32 clear_err_unit; > u32 max_ars; > }; > @@ -146,6 +146,8 @@ struct acpi_nfit_desc { > struct nd_cmd_ars_status *ars_status; > size_t ars_status_size; > struct work_struct work; > + struct kernfs_node *scrub_count_state; > + unsigned int scrub_count; > unsigned int cancel:1; > unsigned long dimm_cmd_force_en; > unsigned long bus_cmd_force_en; > diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c > index be89764..d81db3ac 100644 > --- a/drivers/nvdimm/core.c > +++ b/drivers/nvdimm/core.c > @@ -99,6 +99,13 @@ struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus) > } > EXPORT_SYMBOL_GPL(to_nd_desc); > > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus) > +{ > + /* struct nvdimm_bus definition is private to libnvdimm */ > + return &nvdimm_bus->dev; > +} > +EXPORT_SYMBOL_GPL(to_nvdimm_bus_dev); > + > struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev) > { > struct device *dev; > diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h > index 0c3c30c..27cecc2 100644 > --- a/include/linux/libnvdimm.h > +++ b/include/linux/libnvdimm.h > @@ -129,6 +129,7 @@ struct nvdimm *to_nvdimm(struct device *dev); > struct nd_region *to_nd_region(struct device *dev); > struct nd_blk_region *to_nd_blk_region(struct device *dev); > struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus); > +struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus); > const char *nvdimm_name(struct nvdimm *nvdimm); > unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm); > void *nvdimm_provider_data(struct nvdimm *nvdimm); > diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c > index c919866..74231de 100644 > --- a/tools/testing/nvdimm/test/nfit.c > +++ b/tools/testing/nvdimm/test/nfit.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1409,6 +1410,8 @@ static int nfit_test_probe(struct platform_device *pdev) > struct acpi_nfit_desc *acpi_desc; > struct device *dev = &pdev->dev; > struct nfit_test *nfit_test; > + struct kernfs_node *nfit; > + struct device *bus_dev; > int rc; > > nfit_test = to_nfit_test(&pdev->dev); > @@ -1471,6 +1474,18 @@ static int nfit_test_probe(struct platform_device *pdev) > if (!acpi_desc->nvdimm_bus) > return -ENXIO; > > + bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); > + nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); > + if (!nfit) { > + dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); > + return -ENODEV; > + } > + acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); > + if (!acpi_desc->scrub_count_state) { > + dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); > + return -ENODEV; > + } > + > rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); > if (rc) { > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > @@ -1497,6 +1512,7 @@ static int nfit_test_remove(struct platform_device *pdev) > struct nfit_test *nfit_test = to_nfit_test(&pdev->dev); > struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc; > > + sysfs_put(acpi_desc->scrub_count_state); > nvdimm_bus_unregister(acpi_desc->nvdimm_bus); > > return 0; >