All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/6] libnvdimm/namespace: Make namespace size validation arch dependent
@ 2020-01-08  6:52 Aneesh Kumar K.V
  2020-01-08  6:52 ` [PATCH v3 2/6] libnvdimm/namespace: Validate namespace start addr and size Aneesh Kumar K.V
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Aneesh Kumar K.V @ 2020-01-08  6:52 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm, Aneesh Kumar K.V

The page size used to map the namespace is arch dependent. For example
architectures like ppc64 use 16MB page size for direct-mapping. If the namespace
size is not aligned to the mapping page size, we can observe kernel crash
during namespace init and destroy.

This is due to kernel doing partial map/unmap of the resource range

BUG: Unable to handle kernel data access at 0xc001000406000000
Faulting instruction address: 0xc000000000090790
NIP [c000000000090790] arch_add_memory+0xc0/0x130
LR [c000000000090744] arch_add_memory+0x74/0x130
Call Trace:
 arch_add_memory+0x74/0x130 (unreliable)
 memremap_pages+0x74c/0xa30
 devm_memremap_pages+0x3c/0xa0
 pmem_attach_disk+0x188/0x770
 nvdimm_bus_probe+0xd8/0x470
 really_probe+0x148/0x570
 driver_probe_device+0x19c/0x1d0
 device_driver_attach+0xcc/0x100
 bind_store+0x134/0x1c0
 drv_attr_store+0x44/0x60
 sysfs_kf_write+0x74/0xc0
 kernfs_fop_write+0x1b4/0x290
 __vfs_write+0x3c/0x70
 vfs_write+0xd0/0x260
 ksys_write+0xdc/0x130
 system_call+0x5c/0x68

Kernel should also ensure that namespace size is also mulitple of subsection size.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
Changes from v2:
* Use SUBSECTION_SIZE instead of PAGE_SIZE. Namespace size should be multiple
of SUBSECTION size.

 arch/arm64/mm/flush.c     |  6 ++++++
 arch/powerpc/lib/pmem.c   | 11 +++++++++++
 arch/x86/mm/pageattr.c    |  7 +++++++
 include/linux/libnvdimm.h |  1 +
 4 files changed, 25 insertions(+)

diff --git a/arch/arm64/mm/flush.c b/arch/arm64/mm/flush.c
index ac485163a4a7..5d82484ac8ca 100644
--- a/arch/arm64/mm/flush.c
+++ b/arch/arm64/mm/flush.c
@@ -91,4 +91,10 @@ void arch_invalidate_pmem(void *addr, size_t size)
 	__inval_dcache_area(addr, size);
 }
 EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
+
+unsigned long arch_namespace_align_size(void)
+{
+	return (1UL << SUBSECTION_SHIFT);
+}
+EXPORT_SYMBOL_GPL(arch_namespace_align_size);
 #endif
diff --git a/arch/powerpc/lib/pmem.c b/arch/powerpc/lib/pmem.c
index 0666a8d29596..b94e7d4876d1 100644
--- a/arch/powerpc/lib/pmem.c
+++ b/arch/powerpc/lib/pmem.c
@@ -26,6 +26,17 @@ void arch_invalidate_pmem(void *addr, size_t size)
 }
 EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
 
+unsigned long arch_namespace_align_size(void)
+{
+	unsigned long sub_section_size = (1UL << SUBSECTION_SHIFT);
+
+	if (radix_enabled())
+		return sub_section_size;
+	return max(sub_section_size, (1UL << mmu_psize_defs[mmu_linear_psize].shift));
+
+}
+EXPORT_SYMBOL_GPL(arch_namespace_align_size);
+
 /*
  * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
  */
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 1b99ad05b117..0bcd22e11dd0 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -310,6 +310,13 @@ void arch_invalidate_pmem(void *addr, size_t size)
 }
 EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
 
+unsigned long arch_namespace_align_size(void)
+{
+	return (1UL << SUBSECTION_SHIFT);
+}
+EXPORT_SYMBOL_GPL(arch_namespace_align_size);
+
+
 static void __cpa_flush_all(void *arg)
 {
 	unsigned long cache = (unsigned long)arg;
diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h
index 9df091bd30ba..f2a33f2e3ba8 100644
--- a/include/linux/libnvdimm.h
+++ b/include/linux/libnvdimm.h
@@ -284,4 +284,5 @@ static inline void arch_invalidate_pmem(void *addr, size_t size)
 }
 #endif
 
+unsigned long arch_namespace_align_size(void);
 #endif /* __LIBNVDIMM_H__ */
-- 
2.24.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

end of thread, other threads:[~2020-01-13 15:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08  6:52 [PATCH v3 1/6] libnvdimm/namespace: Make namespace size validation arch dependent Aneesh Kumar K.V
2020-01-08  6:52 ` [PATCH v3 2/6] libnvdimm/namespace: Validate namespace start addr and size Aneesh Kumar K.V
2020-01-08  6:52 ` [PATCH v3 3/6] libnvdimm/namespace: Validate namespace size when creating new namespace Aneesh Kumar K.V
2020-01-08  6:52 ` [PATCH v3 4/6] libnvdimm/namespace: Add debug check while initializing namespace resource size Aneesh Kumar K.V
2020-01-08  6:52 ` [PATCH v3 5/6] libnvdimm/namespace: Align DPA based on arch restrictions Aneesh Kumar K.V
2020-01-08  6:52 ` [PATCH v3 6/6] libnvdimm/namespace: Expose arch specific supported size align value Aneesh Kumar K.V
2020-01-10 20:38 ` [PATCH v3 1/6] libnvdimm/namespace: Make namespace size validation arch dependent Jeff Moyer
2020-01-10 21:03   ` Dan Williams
2020-01-11  4:29     ` Aneesh Kumar K.V
2020-01-11  4:33   ` Aneesh Kumar K.V
2020-01-11  4:55     ` Dan Williams
2020-01-13 15:08       ` Aneesh Kumar K.V

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.