* [PATCH 0/2] devm_memremap_pages vs section-misaligned pmem
@ 2016-03-01 2:56 Dan Williams
2016-03-01 2:56 ` [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces Dan Williams
2016-03-01 2:56 ` [PATCH 2/2] mm: fix mixed zone detection in devm_memremap_pages Dan Williams
0 siblings, 2 replies; 4+ messages in thread
From: Dan Williams @ 2016-03-01 2:56 UTC (permalink / raw)
To: linux-nvdimm; +Cc: linux-mm, akpm, linux-kernel
Recent testing uncovered two bugs around the handling of section-misaligned
pmem regions:
1/ If the pmem section overlaps "System RAM" we need to fail the
devm_memremap_pages() request. Previously we would mis-detect a
memory map like the following:
100000000-37bffffff : System RAM
37c000000-837ffffff : Persistent Memory
2/ If the pmem section is misaligned, but otherwise does not overlap
memory from another zone, the altmap needs to be fixed up to add the
alignment padding to the 'reserved ' pfns of the altmap.
---
Dan Williams (2):
libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces
mm: fix mixed zone detection in devm_memremap_pages
drivers/nvdimm/pmem.c | 29 +++++++++++++++++++++++++++--
kernel/memremap.c | 9 ++++-----
2 files changed, 31 insertions(+), 7 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] 4+ messages in thread
* [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces
2016-03-01 2:56 [PATCH 0/2] devm_memremap_pages vs section-misaligned pmem Dan Williams
@ 2016-03-01 2:56 ` Dan Williams
2016-03-01 3:16 ` kbuild test robot
2016-03-01 2:56 ` [PATCH 2/2] mm: fix mixed zone detection in devm_memremap_pages Dan Williams
1 sibling, 1 reply; 4+ messages in thread
From: Dan Williams @ 2016-03-01 2:56 UTC (permalink / raw)
To: linux-nvdimm; +Cc: linux-mm, akpm, linux-kernel
The altmap for a section-misaligned namespace needs to arrange for the
base_pfn to be section-aligned. As a result the 'reserve' region (pfns
from base that do not have a struct page) must be increased. Otherwise
we trip the altmap validation check in __add_pages:
if (altmap->base_pfn != phys_start_pfn
|| vmem_altmap_offset(altmap) > nr_pages) {
pr_warn_once("memory add fail, invalid altmap\n");
return -EINVAL;
}
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
drivers/nvdimm/pmem.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index efc2a5e671c6..6a6283ab974c 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -356,6 +356,31 @@ static int nvdimm_namespace_detach_pfn(struct nd_namespace_common *ndns)
return 0;
}
+/*
+ * We hotplug memory at section granularity, pad the reserved area from
+ * the previous section base to the namespace base address.
+ */
+static unsigned long init_altmap_base(resource_size_t base)
+{
+ unsigned long base_pfn = __phys_to_pfn(base);
+
+#ifdef CONFIG_SPARSEMEM
+ base_pfn = SECTION_ALIGN_DOWN(base_pfn);
+#endif
+ return base_pfn;
+}
+
+static unsigned long init_altmap_reserve(resource_size_t base)
+{
+ unsigned long base_pfn = __phys_to_pfn(base);
+ unsigned long reserve = __phys_to_pfn(SZ_8K);
+
+#ifdef CONFIG_SPARSEMEM
+ reserve += base_pfn - SECTION_ALIGN_DOWN(base_pfn);
+#endif
+ return reserve;
+}
+
static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns)
{
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
@@ -369,8 +394,8 @@ static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns)
phys_addr_t offset;
int rc;
struct vmem_altmap __altmap = {
- .base_pfn = __phys_to_pfn(nsio->res.start),
- .reserve = __phys_to_pfn(SZ_8K),
+ .base_pfn = init_altmap_base(nsio->res.start),
+ .reserve = init_altmap_reserve(nsio->res.start),
};
if (!nd_pfn->uuid || !nd_pfn->ndns)
--
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] 4+ messages in thread
* [PATCH 2/2] mm: fix mixed zone detection in devm_memremap_pages
2016-03-01 2:56 [PATCH 0/2] devm_memremap_pages vs section-misaligned pmem Dan Williams
2016-03-01 2:56 ` [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces Dan Williams
@ 2016-03-01 2:56 ` Dan Williams
1 sibling, 0 replies; 4+ messages in thread
From: Dan Williams @ 2016-03-01 2:56 UTC (permalink / raw)
To: linux-nvdimm; +Cc: linux-mm, akpm, linux-kernel
The check for whether we overlap "System RAM" needs to be done at
section granularity. For example a system with the following mapping:
100000000-37bffffff : System RAM
37c000000-837ffffff : Persistent Memory
...is unable to use devm_memremap_pages() as it would result in two
zones colliding within a given section.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
kernel/memremap.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/kernel/memremap.c b/kernel/memremap.c
index b981a7b023f0..4c7d08339f62 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -270,9 +270,10 @@ struct dev_pagemap *find_dev_pagemap(resource_size_t phys)
void *devm_memremap_pages(struct device *dev, struct resource *res,
struct percpu_ref *ref, struct vmem_altmap *altmap)
{
- int is_ram = region_intersects(res->start, resource_size(res),
- "System RAM");
- resource_size_t key, align_start, align_size, align_end;
+ resource_size_t align_start = res->start & ~(SECTION_SIZE - 1);
+ resource_size_t align_size = ALIGN(resource_size(res), SECTION_SIZE);
+ int is_ram = region_intersects(align_start, align_size, "System RAM");
+ resource_size_t key, align_end;
struct dev_pagemap *pgmap;
struct page_map *page_map;
unsigned long pfn;
@@ -314,8 +315,6 @@ void *devm_memremap_pages(struct device *dev, struct resource *res,
mutex_lock(&pgmap_lock);
error = 0;
- align_start = res->start & ~(SECTION_SIZE - 1);
- align_size = ALIGN(resource_size(res), SECTION_SIZE);
align_end = align_start + align_size - 1;
for (key = align_start; key <= align_end; key += SECTION_SIZE) {
struct dev_pagemap *dup;
--
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] 4+ messages in thread
* Re: [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces
2016-03-01 2:56 ` [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces Dan Williams
@ 2016-03-01 3:16 ` kbuild test robot
0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2016-03-01 3:16 UTC (permalink / raw)
To: Dan Williams; +Cc: kbuild-all, linux-nvdimm, linux-mm, akpm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1767 bytes --]
Hi Dan,
[auto build test WARNING on v4.5-rc6]
[also build test WARNING on next-20160229]
[cannot apply to linux-nvdimm/libnvdimm-for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Dan-Williams/devm_memremap_pages-vs-section-misaligned-pmem/20160301-105936
config: i386-randconfig-x007-201609 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
drivers/nvdimm/pmem.c: In function 'init_altmap_reserve':
>> drivers/nvdimm/pmem.c:375:16: warning: unused variable 'base_pfn' [-Wunused-variable]
unsigned long base_pfn = __phys_to_pfn(base);
^
vim +/base_pfn +375 drivers/nvdimm/pmem.c
359 /*
360 * We hotplug memory at section granularity, pad the reserved area from
361 * the previous section base to the namespace base address.
362 */
363 static unsigned long init_altmap_base(resource_size_t base)
364 {
365 unsigned long base_pfn = __phys_to_pfn(base);
366
367 #ifdef CONFIG_SPARSEMEM
368 base_pfn = SECTION_ALIGN_DOWN(base_pfn);
369 #endif
370 return base_pfn;
371 }
372
373 static unsigned long init_altmap_reserve(resource_size_t base)
374 {
> 375 unsigned long base_pfn = __phys_to_pfn(base);
376 unsigned long reserve = __phys_to_pfn(SZ_8K);
377
378 #ifdef CONFIG_SPARSEMEM
379 reserve += base_pfn - SECTION_ALIGN_DOWN(base_pfn);
380 #endif
381 return reserve;
382 }
383
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 24045 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-01 3:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 2:56 [PATCH 0/2] devm_memremap_pages vs section-misaligned pmem Dan Williams
2016-03-01 2:56 ` [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces Dan Williams
2016-03-01 3:16 ` kbuild test robot
2016-03-01 2:56 ` [PATCH 2/2] mm: fix mixed zone detection in devm_memremap_pages Dan Williams
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).