From: Santosh Sivaraj <santosh@fossix.org>
To: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Oliver O'Halloran <oohall@gmail.com>,
Chandan Rajendra <chandan@linux.ibm.com>,
Reza Arbab <arbab@linux.ibm.com>,
Mahesh Salgaonkar <mahesh@linux.ibm.com>
Subject: [PATCH 2/3] of_pmem: Add memory ranges which took a mce to bad range
Date: Wed, 14 Aug 2019 13:54:51 +0530 [thread overview]
Message-ID: <20190814082452.28013-3-santosh@fossix.org> (raw)
In-Reply-To: <20190814082452.28013-1-santosh@fossix.org>
Subscribe to the MCE notification and add the physical address which
generated a memory error to nvdimm bad range.
Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
drivers/nvdimm/of_pmem.c | 122 +++++++++++++++++++++++++++++++++------
1 file changed, 103 insertions(+), 19 deletions(-)
diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index a0c8dcfa0bf9..828dbfe44ca6 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -8,6 +8,9 @@
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/nd.h>
+#include <asm/mce.h>
static const struct attribute_group *region_attr_groups[] = {
&nd_region_attribute_group,
@@ -25,11 +28,77 @@ struct of_pmem_private {
struct nvdimm_bus *bus;
};
+struct of_pmem_region {
+ struct of_pmem_private *priv;
+ struct nd_region_desc *region_desc;
+ struct nd_region *region;
+ struct list_head list;
+};
+
+LIST_HEAD(pmem_regions);
+DEFINE_MUTEX(pmem_region_lock);
+
+static int handle_mce_ue(struct notifier_block *nb, unsigned long val,
+ void *data)
+{
+ struct machine_check_event *evt = data;
+ struct of_pmem_region *pmem_region;
+ u64 phys_addr;
+
+ if (evt->error_type != MCE_ERROR_TYPE_UE)
+ return NOTIFY_DONE;
+
+ if (list_empty(&pmem_regions))
+ return NOTIFY_DONE;
+
+ 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;
+
+ mutex_lock(&pmem_region_lock);
+ list_for_each_entry(pmem_region, &pmem_regions, list) {
+ struct resource *res = pmem_region->region_desc->res;
+ u64 aligned_addr;
+
+ if (res->start > phys_addr)
+ continue;
+
+ if (res->end < phys_addr)
+ continue;
+
+ aligned_addr = ALIGN_DOWN(phys_addr, L1_CACHE_BYTES);
+ pr_debug("Add memory range (0x%llx -- 0x%llx) as bad range\n",
+ aligned_addr, aligned_addr + L1_CACHE_BYTES);
+
+ if (nvdimm_bus_add_badrange(pmem_region->priv->bus,
+ aligned_addr, L1_CACHE_BYTES))
+ pr_warn("Failed to add bad range (0x%llx -- 0x%llx)\n",
+ aligned_addr, aligned_addr + L1_CACHE_BYTES);
+
+ nvdimm_region_notify(pmem_region->region,
+ NVDIMM_REVALIDATE_POISON);
+
+ break;
+ }
+ mutex_unlock(&pmem_region_lock);
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block mce_ue_nb = {
+ .notifier_call = handle_mce_ue
+};
+
static int of_pmem_region_probe(struct platform_device *pdev)
{
struct of_pmem_private *priv;
struct device_node *np;
struct nvdimm_bus *bus;
+ struct of_pmem_region *pmem_region;
+ struct nd_region_desc *ndr_desc;
bool is_volatile;
int i;
@@ -58,34 +127,49 @@ static int of_pmem_region_probe(struct platform_device *pdev)
is_volatile ? "volatile" : "non-volatile", np);
for (i = 0; i < pdev->num_resources; i++) {
- struct nd_region_desc ndr_desc;
struct nd_region *region;
- /*
- * NB: libnvdimm copies the data from ndr_desc into it's own
- * structures so passing a stack pointer is fine.
- */
- memset(&ndr_desc, 0, sizeof(ndr_desc));
- ndr_desc.attr_groups = region_attr_groups;
- ndr_desc.numa_node = dev_to_node(&pdev->dev);
- ndr_desc.target_node = ndr_desc.numa_node;
- ndr_desc.res = &pdev->resource[i];
- ndr_desc.of_node = np;
- set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
+ ndr_desc = kzalloc(sizeof(struct nd_region_desc), GFP_KERNEL);
+ if (!ndr_desc) {
+ nvdimm_bus_unregister(priv->bus);
+ kfree(priv);
+ return -ENOMEM;
+ }
+
+ ndr_desc->attr_groups = region_attr_groups;
+ ndr_desc->numa_node = dev_to_node(&pdev->dev);
+ ndr_desc->target_node = ndr_desc->numa_node;
+ ndr_desc->res = &pdev->resource[i];
+ ndr_desc->of_node = np;
+ set_bit(ND_REGION_PAGEMAP, &ndr_desc->flags);
if (is_volatile)
- region = nvdimm_volatile_region_create(bus, &ndr_desc);
+ region = nvdimm_volatile_region_create(bus, ndr_desc);
else
- region = nvdimm_pmem_region_create(bus, &ndr_desc);
+ region = nvdimm_pmem_region_create(bus, ndr_desc);
if (!region)
- dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
- ndr_desc.res, np);
- else
- dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
- ndr_desc.res, np);
+ continue;
+
+ dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
+ ndr_desc->res, np);
+
+ pmem_region = kzalloc(sizeof(struct of_pmem_region),
+ GFP_KERNEL);
+ if (!pmem_region)
+ continue;
+
+ pmem_region->region_desc = ndr_desc;
+ pmem_region->region = region;
+ pmem_region->priv = priv;
+
+ /* Save regions registered for use by the notification code */
+ mutex_lock(&pmem_region_lock);
+ list_add_tail(&pmem_region->list, &pmem_regions);
+ mutex_unlock(&pmem_region_lock);
}
+ mce_register_notifier(&mce_ue_nb);
return 0;
}
--
2.21.0
next prev parent reply other threads:[~2019-08-14 8:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-14 8:24 [PATCH 0/3] Add bad pmem bad blocks to bad range Santosh Sivaraj
2019-08-14 8:24 ` [PATCH 1/3] powerpc/mce: Add MCE notification chain Santosh Sivaraj
2019-08-14 8:24 ` Santosh Sivaraj [this message]
2019-08-14 8:24 ` [PATCH 3/3] papr/scm: Add bad memory ranges to nvdimm bad ranges Santosh Sivaraj
2019-08-15 13:11 ` Oliver O'Halloran
2019-08-15 14:00 ` Santosh Sivaraj
2019-08-20 2:30 [PATCH 0/3] Add bad pmem bad blocks to bad range Santosh Sivaraj
2019-08-20 2:30 ` [PATCH 2/3] of_pmem: Add memory ranges which took a mce " Santosh Sivaraj
2019-08-20 8:41 ` Oliver O'Halloran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190814082452.28013-3-santosh@fossix.org \
--to=santosh@fossix.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=arbab@linux.ibm.com \
--cc=chandan@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mahesh@linux.ibm.com \
--cc=oohall@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).