linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Allow EINJ to inject memory error to NVDIMM
@ 2015-10-22 23:20 Toshi Kani
  2015-10-22 23:20 ` [PATCH 1/3] resource: Add @flags to region_intersects() Toshi Kani
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Toshi Kani @ 2015-10-22 23:20 UTC (permalink / raw)
  To: akpm, dan.j.williams, rjw
  Cc: linux-mm, linux-nvdimm, linux-acpi, linux-kernel

This patch-set extends the EINJ driver to allow injecting a memory
error to NVDIMM.  It first extends iomem resource interface to support
checking a NVDIMM region.

Patch 1/3 changes region_intersects() to accept non-RAM regions, and
adds region_intersects_ram().

Patch 2/3 adds region_intersects_pmem() to check a NVDIMM region.

Patch 3/3 changes the EINJ driver to allow injecting a memory error
to NVDIMM.

---
Toshi Kani (3):
 1/3 resource: Add @flags to region_intersects()
 2/3 resource: Add region_intersects_pmem()
 3/3 ACPI/APEI/EINJ: Allow memory error injection to NVDIMM

---
 drivers/acpi/apei/einj.c | 12 ++++++++----
 include/linux/mm.h       |  5 ++++-
 kernel/memremap.c        |  5 ++---
 kernel/resource.c        | 34 +++++++++++++++++++++++++++-------
 4 files changed, 41 insertions(+), 15 deletions(-)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 1/3] resource: Add @flags to region_intersects()
  2015-10-22 23:20 [PATCH 0/3] Allow EINJ to inject memory error to NVDIMM Toshi Kani
@ 2015-10-22 23:20 ` Toshi Kani
  2015-10-22 23:20 ` [PATCH 2/3] resource: Add region_intersects_pmem() Toshi Kani
  2015-10-22 23:20 ` [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM Toshi Kani
  2 siblings, 0 replies; 6+ messages in thread
From: Toshi Kani @ 2015-10-22 23:20 UTC (permalink / raw)
  To: akpm, dan.j.williams, rjw
  Cc: linux-mm, linux-nvdimm, linux-acpi, linux-kernel, Toshi Kani

region_intersects() checks if a specified region partially overlaps
or fully eclipses a resource identified by @name.  It currently sets
resource flags statically, which prevents the caller from specifying
a non-RAM region, such as persistent memory.  Add @flags so that
any region can be specified to the function.

A helper function, region_intersects_ram(), is added so that the
callers that check a RAM region do not have to specify its iomem
resource name and flags.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
---
 include/linux/mm.h |    4 +++-
 kernel/memremap.c  |    5 ++---
 kernel/resource.c  |   22 +++++++++++++++-------
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 80001de..699224e 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -358,7 +358,9 @@ enum {
 	REGION_MIXED,
 };
 
-int region_intersects(resource_size_t offset, size_t size, const char *type);
+int region_intersects(resource_size_t offset, size_t size, const char *type,
+			unsigned long flags);
+int region_intersects_ram(resource_size_t offset, size_t size);
 
 /* Support for virtually mapped pages */
 struct page *vmalloc_to_page(const void *addr);
diff --git a/kernel/memremap.c b/kernel/memremap.c
index 72b0c66..2157ea5 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -47,7 +47,7 @@ __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)
  */
 void *memremap(resource_size_t offset, size_t size, unsigned long flags)
 {
-	int is_ram = region_intersects(offset, size, "System RAM");
+	int is_ram = region_intersects_ram(offset, size);
 	void *addr = NULL;
 
 	if (is_ram == REGION_MIXED) {
@@ -152,8 +152,7 @@ static void devm_memremap_pages_release(struct device *dev, void *res)
 
 void *devm_memremap_pages(struct device *dev, struct resource *res)
 {
-	int is_ram = region_intersects(res->start, resource_size(res),
-			"System RAM");
+	int is_ram = region_intersects_ram(res->start, resource_size(res));
 	struct page_map *page_map;
 	int error, nid;
 
diff --git a/kernel/resource.c b/kernel/resource.c
index f150dbb..8a77ed8 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -497,6 +497,7 @@ EXPORT_SYMBOL_GPL(page_is_ram);
  * @start: region start address
  * @size: size of region
  * @name: name of resource (in iomem_resource)
+ * @flags: flags of resource (in iomem_resource)
  *
  * Check if the specified region partially overlaps or fully eclipses a
  * resource identified by @name.  Return REGION_DISJOINT if the region
@@ -504,15 +505,11 @@ EXPORT_SYMBOL_GPL(page_is_ram);
  * @type and another resource, and return REGION_INTERSECTS if the
  * region overlaps @type and no other defined resource. Note, that
  * REGION_INTERSECTS is also returned in the case when the specified
- * region overlaps RAM and undefined memory holes.
- *
- * region_intersect() is used by memory remapping functions to ensure
- * the user is not remapping RAM and is a vast speed up over walking
- * through the resource table page by page.
+ * region overlaps with undefined memory holes.
  */
-int region_intersects(resource_size_t start, size_t size, const char *name)
+int region_intersects(resource_size_t start, size_t size, const char *name,
+			unsigned long flags)
 {
-	unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	resource_size_t end = start + size - 1;
 	int type = 0; int other = 0;
 	struct resource *p;
@@ -539,6 +536,17 @@ int region_intersects(resource_size_t start, size_t size, const char *name)
 	return REGION_DISJOINT;
 }
 
+/*
+ * region_intersect_ram() is used by memory remapping functions to ensure
+ * the user is not remapping RAM and is a vast speed up over walking
+ * through the resource table page by page.
+ */
+int region_intersects_ram(resource_size_t start, size_t size)
+{
+	return region_intersects(start, size, "System RAM",
+				 IORESOURCE_MEM | IORESOURCE_BUSY);
+}
+
 void __weak arch_remove_reservations(struct resource *avail)
 {
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 2/3] resource: Add region_intersects_pmem()
  2015-10-22 23:20 [PATCH 0/3] Allow EINJ to inject memory error to NVDIMM Toshi Kani
  2015-10-22 23:20 ` [PATCH 1/3] resource: Add @flags to region_intersects() Toshi Kani
@ 2015-10-22 23:20 ` Toshi Kani
  2015-10-22 23:20 ` [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM Toshi Kani
  2 siblings, 0 replies; 6+ messages in thread
From: Toshi Kani @ 2015-10-22 23:20 UTC (permalink / raw)
  To: akpm, dan.j.williams, rjw
  Cc: linux-mm, linux-nvdimm, linux-acpi, linux-kernel, Toshi Kani

Add region_intersects_pmem(), which checks if a specified address
range is persistent memory registered as "Persistent Memory" in
the iomem_resource list.

Note, it does not support legacy persistent memory registered as
"Persistent Memory (legacy)".  It can be supported by extending
this function or a separate function, if necessary.

This interface is exported so that it can be called from modules,
such as the EINJ driver.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
---
 include/linux/mm.h |    1 +
 kernel/resource.c  |   12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 699224e..ae1790f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -361,6 +361,7 @@ enum {
 int region_intersects(resource_size_t offset, size_t size, const char *type,
 			unsigned long flags);
 int region_intersects_ram(resource_size_t offset, size_t size);
+int region_intersects_pmem(resource_size_t offset, size_t size);
 
 /* Support for virtually mapped pages */
 struct page *vmalloc_to_page(const void *addr);
diff --git a/kernel/resource.c b/kernel/resource.c
index 8a77ed8..b6b61a1 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -547,6 +547,18 @@ int region_intersects_ram(resource_size_t start, size_t size)
 				 IORESOURCE_MEM | IORESOURCE_BUSY);
 }
 
+/*
+ * region_intersects_pmem() checks if a specified address range is
+ * persistent memory, registered as "Persistent Memory", in the
+ * iomem_resource list.
+ */
+int region_intersects_pmem(resource_size_t start, size_t size)
+{
+	return region_intersects(start, size, "Persistent Memory",
+				 IORESOURCE_MEM);
+}
+EXPORT_SYMBOL_GPL(region_intersects_pmem);
+
 void __weak arch_remove_reservations(struct resource *avail)
 {
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM
  2015-10-22 23:20 [PATCH 0/3] Allow EINJ to inject memory error to NVDIMM Toshi Kani
  2015-10-22 23:20 ` [PATCH 1/3] resource: Add @flags to region_intersects() Toshi Kani
  2015-10-22 23:20 ` [PATCH 2/3] resource: Add region_intersects_pmem() Toshi Kani
@ 2015-10-22 23:20 ` Toshi Kani
  2015-10-23  0:14   ` Dan Williams
  2 siblings, 1 reply; 6+ messages in thread
From: Toshi Kani @ 2015-10-22 23:20 UTC (permalink / raw)
  To: akpm, dan.j.williams, rjw
  Cc: linux-mm, linux-nvdimm, linux-acpi, linux-kernel, Toshi Kani

In the case of memory error injection, einj_error_inject() checks
if a target address is regular RAM.  Change this check to allow
injecting a memory error to both RAM and NVDIMM so that memory
errors can be tested on NVDIMM as well.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
---
 drivers/acpi/apei/einj.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index 0431883..696f45a 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -519,7 +519,7 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			     u64 param3, u64 param4)
 {
 	int rc;
-	unsigned long pfn;
+	u64 base_addr, size;
 
 	/* If user manually set "flags", make sure it is legal */
 	if (flags && (flags &
@@ -545,10 +545,14 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 	/*
 	 * Disallow crazy address masks that give BIOS leeway to pick
 	 * injection address almost anywhere. Insist on page or
-	 * better granularity and that target address is normal RAM.
+	 * better granularity and that target address is normal RAM or
+	 * NVDIMM.
 	 */
-	pfn = PFN_DOWN(param1 & param2);
-	if (!page_is_ram(pfn) || ((param2 & PAGE_MASK) != PAGE_MASK))
+	base_addr = param1 & param2;
+	size = (~param2) + 1;
+	if (((!page_is_ram(PFN_DOWN(base_addr))) &&
+	     (region_intersects_pmem(base_addr, size) != REGION_INTERSECTS)) ||
+	    ((param2 & PAGE_MASK) != PAGE_MASK))
 		return -EINVAL;
 
 inject:

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM
  2015-10-22 23:20 ` [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM Toshi Kani
@ 2015-10-23  0:14   ` Dan Williams
  2015-10-23 14:03     ` Toshi Kani
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Williams @ 2015-10-23  0:14 UTC (permalink / raw)
  To: Toshi Kani
  Cc: Andrew Morton, Rafael J. Wysocki, Linux MM,
	linux-nvdimm@lists.01.org, Linux ACPI,
	linux-kernel@vger.kernel.org

On Thu, Oct 22, 2015 at 4:20 PM, Toshi Kani <toshi.kani@hpe.com> wrote:
> In the case of memory error injection, einj_error_inject() checks
> if a target address is regular RAM.  Change this check to allow
> injecting a memory error to both RAM and NVDIMM so that memory
> errors can be tested on NVDIMM as well.
>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> ---
>  drivers/acpi/apei/einj.c |   12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
> index 0431883..696f45a 100644
> --- a/drivers/acpi/apei/einj.c
> +++ b/drivers/acpi/apei/einj.c
> @@ -519,7 +519,7 @@ static int
(u32 type, u32 flags, u64 param1, u64 param2,
>                              u64 param3, u64 param4)
>  {
>         int rc;
> -       unsigned long pfn;
> +       u64 base_addr, size;
>
>         /* If user manually set "flags", make sure it is legal */
>         if (flags && (flags &
> @@ -545,10 +545,14 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
>         /*
>          * Disallow crazy address masks that give BIOS leeway to pick
>          * injection address almost anywhere. Insist on page or
> -        * better granularity and that target address is normal RAM.
> +        * better granularity and that target address is normal RAM or
> +        * NVDIMM.
>          */
> -       pfn = PFN_DOWN(param1 & param2);
> -       if (!page_is_ram(pfn) || ((param2 & PAGE_MASK) != PAGE_MASK))
> +       base_addr = param1 & param2;
> +       size = (~param2) + 1;
> +       if (((!page_is_ram(PFN_DOWN(base_addr))) &&
> +            (region_intersects_pmem(base_addr, size) != REGION_INTERSECTS)) ||
> +           ((param2 & PAGE_MASK) != PAGE_MASK))

Hmm, should we also convert the page_is_ram() call to
region_intersects_ram() so that we check the entire range from
base_addr to base_addr + size?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM
  2015-10-23  0:14   ` Dan Williams
@ 2015-10-23 14:03     ` Toshi Kani
  0 siblings, 0 replies; 6+ messages in thread
From: Toshi Kani @ 2015-10-23 14:03 UTC (permalink / raw)
  To: Dan Williams
  Cc: Andrew Morton, Rafael J. Wysocki, Linux MM,
	linux-nvdimm@lists.01.org, Linux ACPI,
	linux-kernel@vger.kernel.org

On Thu, 2015-10-22 at 17:14 -0700, Dan Williams wrote:
> On Thu, Oct 22, 2015 at 4:20 PM, Toshi Kani <toshi.kani@hpe.com> wrote:
> > In the case of memory error injection, einj_error_inject() checks
> > if a target address is regular RAM.  Change this check to allow
> > injecting a memory error to both RAM and NVDIMM so that memory
> > errors can be tested on NVDIMM as well.
> > 
> > Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> > ---
> >  drivers/acpi/apei/einj.c |   12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
> > index 0431883..696f45a 100644
> > --- a/drivers/acpi/apei/einj.c
> > +++ b/drivers/acpi/apei/einj.c
> > @@ -519,7 +519,7 @@ static int
> (u32 type, u32 flags, u64 param1, u64 param2,
> >                              u64 param3, u64 param4)
> >  {
> >         int rc;
> > -       unsigned long pfn;
> > +       u64 base_addr, size;
> > 
> >         /* If user manually set "flags", make sure it is legal */
> >         if (flags && (flags &
> > @@ -545,10 +545,14 @@ static int einj_error_inject(u32 type, u32 flags, u64
> > param1, u64 param2,
> >         /*
> >          * Disallow crazy address masks that give BIOS leeway to pick
> >          * injection address almost anywhere. Insist on page or
> > -        * better granularity and that target address is normal RAM.
> > +        * better granularity and that target address is normal RAM or
> > +        * NVDIMM.
> >          */
> > -       pfn = PFN_DOWN(param1 & param2);
> > -       if (!page_is_ram(pfn) || ((param2 & PAGE_MASK) != PAGE_MASK))
> > +       base_addr = param1 & param2;
> > +       size = (~param2) + 1;
> > +       if (((!page_is_ram(PFN_DOWN(base_addr))) &&
> > +            (region_intersects_pmem(base_addr, size) != REGION_INTERSECTS))
> > ||
> > +           ((param2 & PAGE_MASK) != PAGE_MASK))
> 
> Hmm, should we also convert the page_is_ram() call to
> region_intersects_ram() so that we check the entire range from
> base_addr to base_addr + size?

Agreed.  I will update to use region_intersects_ram().

Thanks,
-Toshi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2015-10-23 14:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-22 23:20 [PATCH 0/3] Allow EINJ to inject memory error to NVDIMM Toshi Kani
2015-10-22 23:20 ` [PATCH 1/3] resource: Add @flags to region_intersects() Toshi Kani
2015-10-22 23:20 ` [PATCH 2/3] resource: Add region_intersects_pmem() Toshi Kani
2015-10-22 23:20 ` [PATCH 3/3] ACPI/APEI/EINJ: Allow memory error injection to NVDIMM Toshi Kani
2015-10-23  0:14   ` Dan Williams
2015-10-23 14:03     ` Toshi Kani

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).