Skip to contentSkip to conversation

Mark the namespace disabled on pfn superblock mismatch

PATCH Superseded Aneesh Kumar K.V 2 participants 15 messages Aug 9, 2019 – Aug 19, 2019

Subsystems (6)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Mark the namespace disabled on pfn superblock mismatch

We add new members to pfn superblock (PAGE_SIZE and struct page size) in this series. This is now checked while initializing the namespace. If we find a mismatch we mark the namespace disabled.

This series also handle configs where hugepage support is not enabled by default. This can result in different align restrictions for dax namespace. We mark the dax namespace disabled if we find the alignment not supported.

Aneesh Kumar K.V (4):
nvdimm: Consider probe return -EOPNOTSUPP as success mm/nvdimm: Add page size and struct page size to pfn superblock mm/nvdimm: Use correct #defines instead of open coding mm/nvdimm: Pick the right alignment default when creating dax devices

 arch/powerpc/include/asm/libnvdimm.h |  9 ++++
 arch/powerpc/mm/Makefile             |  1 +
 arch/powerpc/mm/nvdimm.c             | 34 +++++++++++++++
 arch/x86/include/asm/libnvdimm.h     | 19 +++++++++
 drivers/nvdimm/bus.c                 |  2 +-
 drivers/nvdimm/label.c               |  2 +-
 drivers/nvdimm/namespace_devs.c      |  6 +--
 drivers/nvdimm/nd.h                  |  6 ---
 drivers/nvdimm/pfn.h                 |  5 ++-
 drivers/nvdimm/pfn_devs.c            | 62 ++++++++++++++++++++++++++--
 drivers/nvdimm/pmem.c                | 26 ++++++++++--
 drivers/nvdimm/region_devs.c         |  8 ++--
 include/linux/huge_mm.h              |  7 +++-
 13 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 arch/powerpc/include/asm/libnvdimm.h
 create mode 100644 arch/powerpc/mm/nvdimm.c
 create mode 100644 arch/x86/include/asm/libnvdimm.h
Signature · 1 line
2.21.0
#1 lore raw

PATCH v5 1/4 nvdimm: Consider probe return -EOPNOTSUPP as success

This patch add -EOPNOTSUPP as return from probe callback to indicate we were not able to initialize a namespace due to pfn superblock feature/version mismatch. We want to consider this a probe success so that we can create new namesapce seed and there by avoid marking the failed namespace as the seed namespace.

---
 drivers/nvdimm/bus.c  |  2 +-
 drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/nvdimm/bus.c +1 -1
index 798c5c4aea9c..16c35e6446a7 100644
@@ -95,7 +95,7 @@ static int nvdimm_bus_probe(struct device *dev)
 	rc = nd_drv->probe(dev);
 	debug_nvdimm_unlock(dev);
 
-	if (rc == 0)
+	if (rc == 0 || rc == -EOPNOTSUPP)
 		nd_region_probe_success(nvdimm_bus, dev);
 	else
 		nd_region_disable(nvdimm_bus, dev);
drivers/nvdimm/pmem.c +22 -4
index 4c121dd03dd9..3f498881dd28 100644
@@ -490,6 +490,7 @@ static int pmem_attach_disk(struct device *dev,
 
 static int nd_pmem_probe(struct device *dev)
 {
+	int ret;
 	struct nd_namespace_common *ndns;
 
 	ndns = nvdimm_namespace_common_probe(dev);
@@ -505,12 +506,29 @@ static int nd_pmem_probe(struct device *dev)
 	if (is_nd_pfn(dev))
 		return pmem_attach_disk(dev, ndns);
 
-	/* if we find a valid info-block we'll come back as that personality */
-	if (nd_btt_probe(dev, ndns) == 0 || nd_pfn_probe(dev, ndns) == 0
-			|| nd_dax_probe(dev, ndns) == 0)
+	ret = nd_btt_probe(dev, ndns);
+	if (ret == 0)
 		return -ENXIO;
+	else if (ret == -EOPNOTSUPP)
+		return ret;
 
-	/* ...otherwise we're just a raw pmem device */
+	ret = nd_pfn_probe(dev, ndns);
+	if (ret == 0)
+		return -ENXIO;
+	else if (ret == -EOPNOTSUPP)
+		return ret;
+
+	ret = nd_dax_probe(dev, ndns);
+	if (ret == 0)
+		return -ENXIO;
+	else if (ret == -EOPNOTSUPP)
+		return ret;
+	/*
+	 * We have two failure conditions here, there is no
+	 * info reserver block or we found a valid info reserve block
+	 * but failed to initialize the pfn superblock.
+	 * Don't create a raw pmem disk for the second case.
+	 */
 	return pmem_attach_disk(dev, ndns);
 }
 
Signature · 1 line
2.21.0
#6 lore raw

PATCH v5 2/4 mm/nvdimm: Add page size and struct page size to pfn superblock

In reply to Aneesh Kumar K.V

This is needed so that we don't wrongly initialize a namespace which doesn't have enough space reserved for holding struct pages with the current kernel.

---
 drivers/nvdimm/pfn.h      |  5 ++++-
 drivers/nvdimm/pfn_devs.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)
drivers/nvdimm/pfn.h +4 -1
index 7381673b7b70..acb19517f678 100644
@@ -29,7 +29,10 @@ struct nd_pfn_sb {
 	/* minor-version-2 record the base alignment of the mapping */
 	__le32 align;
 	/* minor-version-3 guarantee the padding and flags are zero */
-	u8 padding[4000];
+	/* minor-version-4 record the page size and struct page size */
+	__le32 page_size;
+	__le16 page_struct_size;
+	u8 padding[3994];
 	__le64 checksum;
 };
 
drivers/nvdimm/pfn_devs.c +26 -1
index 3e7b11cf1aae..37e96811c2fc 100644
@@ -460,6 +460,15 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 	if (__le16_to_cpu(pfn_sb->version_minor) < 2)
 		pfn_sb->align = 0;
 
+	if (__le16_to_cpu(pfn_sb->version_minor) < 4) {
+		/*
+		 * For a large part we use PAGE_SIZE. But we
+		 * do have some accounting code using SZ_4K.
+		 */
+		pfn_sb->page_struct_size = cpu_to_le16(64);
+		pfn_sb->page_size = cpu_to_le32(PAGE_SIZE);
+	}
+
 	switch (le32_to_cpu(pfn_sb->mode)) {
 	case PFN_MODE_RAM:
 	case PFN_MODE_PMEM:
@@ -475,6 +484,20 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 		align = 1UL << ilog2(offset);
 	mode = le32_to_cpu(pfn_sb->mode);
 
+	if (le32_to_cpu(pfn_sb->page_size) != PAGE_SIZE) {
+		dev_err(&nd_pfn->dev,
+			"init failed, page size mismatch %d\n",
+			le32_to_cpu(pfn_sb->page_size));
+		return -EOPNOTSUPP;
+	}
+
+	if (le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) {
+		dev_err(&nd_pfn->dev,
+			"init failed, struct page size mismatch %d\n",
+			le16_to_cpu(pfn_sb->page_struct_size));
+		return -EOPNOTSUPP;
+	}
+
 	if (!nd_pfn->uuid) {
 		/*
 		 * When probing a namepace via nd_pfn_probe() the uuid
@@ -722,8 +745,10 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
 	memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
 	memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
 	pfn_sb->version_major = cpu_to_le16(1);
-	pfn_sb->version_minor = cpu_to_le16(3);
+	pfn_sb->version_minor = cpu_to_le16(4);
 	pfn_sb->align = cpu_to_le32(nd_pfn->align);
+	pfn_sb->page_struct_size = cpu_to_le16(sizeof(struct page));
+	pfn_sb->page_size = cpu_to_le32(PAGE_SIZE);
 	checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
 	pfn_sb->checksum = cpu_to_le64(checksum);
 
Signature · 1 line
2.21.0
#9 lore raw

PATCH v5 3/4 mm/nvdimm: Use correct #defines instead of open coding

In reply to Aneesh Kumar K.V

Use PAGE_SIZE instead of SZ_4K and sizeof(struct page) instead of 64. If we have a kernel built with different struct page size the previous patch should handle marking the namespace disabled.

---
 drivers/nvdimm/label.c          | 2 +-
 drivers/nvdimm/namespace_devs.c | 6 +++---
 drivers/nvdimm/pfn_devs.c       | 3 ++-
 drivers/nvdimm/region_devs.c    | 8 ++++----
 4 files changed, 10 insertions(+), 9 deletions(-)
drivers/nvdimm/label.c +1 -1
index 73e197babc2f..7ee037063be7 100644
@@ -355,7 +355,7 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
 
 	/* check that DPA allocations are page aligned */
 	if ((__le64_to_cpu(nd_label->dpa)
-				| __le64_to_cpu(nd_label->rawsize)) % SZ_4K)
+				| __le64_to_cpu(nd_label->rawsize)) % PAGE_SIZE)
 		return false;
 
 	/* check checksum */
drivers/nvdimm/namespace_devs.c +3 -3
index a16e52251a30..a9c76df12cb9 100644
@@ -1006,10 +1006,10 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
 		return -ENXIO;
 	}
 
-	div_u64_rem(val, SZ_4K * nd_region->ndr_mappings, &remainder);
+	div_u64_rem(val, PAGE_SIZE * nd_region->ndr_mappings, &remainder);
 	if (remainder) {
-		dev_dbg(dev, "%llu is not %dK aligned\n", val,
-				(SZ_4K * nd_region->ndr_mappings) / SZ_1K);
+		dev_dbg(dev, "%llu is not %ldK aligned\n", val,
+				(PAGE_SIZE * nd_region->ndr_mappings) / SZ_1K);
 		return -EINVAL;
 	}
 
drivers/nvdimm/pfn_devs.c +2 -1
index 37e96811c2fc..c1d9be609322 100644
@@ -725,7 +725,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
 		 * when populating the vmemmap. This *should* be equal to
 		 * PMD_SIZE for most architectures.
 		 */
-		offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
+		offset = ALIGN(start + SZ_8K + sizeof(struct page) * npfns,
+			       align) - start;
 	} else if (nd_pfn->mode == PFN_MODE_RAM)
 		offset = ALIGN(start + SZ_8K, align) - start;
 	else
drivers/nvdimm/region_devs.c +4 -4
index af30cbe7a8ea..20e265a534f8 100644
@@ -992,10 +992,10 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
 		struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
 		struct nvdimm *nvdimm = mapping->nvdimm;
 
-		if ((mapping->start | mapping->size) % SZ_4K) {
-			dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
-					caller, dev_name(&nvdimm->dev), i);
-
+		if ((mapping->start | mapping->size) % PAGE_SIZE) {
+			dev_err(&nvdimm_bus->dev,
+				"%s: %s mapping%d is not %ld aligned\n",
+				caller, dev_name(&nvdimm->dev), i, PAGE_SIZE);
 			return NULL;
 		}
 
Signature · 1 line
2.21.0
#14 lore raw

PATCH v5 4/4 mm/nvdimm: Pick the right alignment default when creating dax devices

In reply to Aneesh Kumar K.V

Allow arch to provide the supported alignments and use hugepage alignment only if we support hugepage. Right now we depend on compile time configs whereas this patch switch this to runtime discovery.

Architectures like ppc64 can have THP enabled in code, but then can have hugepage size disabled by the hypervisor. This allows us to create dax devices with PAGE_SIZE alignment in this case.

Existing dax namespace with alignment larger than PAGE_SIZE will fail to initialize in this specific case. We still allow fsdax namespace initialization.

With respect to identifying whether to enable hugepage fault for a dax device, if THP is enabled during compile, we default to taking hugepage fault and in dax fault handler if we find the fault size > alignment we retry with PAGE_SIZE fault size.

This also addresses the below failure scenario on ppc64

ndctl create-namespace --mode=devdax | grep align
"align":16777216,
"align":16777216

cat /sys/devices/ndbus0/region0/dax0.0/supported_alignments
65536 16777216

daxio.static-debug -z -o /dev/dax0.0
Bus error (core dumped)

  $ dmesg | tail
   lpar: Failed hash pte insert with error -4
   hash-mmu: mm: Hashing failure ! EA=0x7fff17000000 access=0x8000000000000006 current=daxio
   hash-mmu:     trap=0x300 vsid=0x22cb7a3 ssize=1 base psize=2 psize 10 pte=0xc000000501002b86
   daxio[3860]: bus error (7) at 7fff17000000 nip 7fff973c007c lr 7fff973bff34 code 2 in libpmem.so.1.0.0[7fff973b0000+20000]
   daxio[3860]: code: 792945e4 7d494b78 e95f0098 7d494b78 f93f00a0 4800012c e93f0088 f93f0120
   daxio[3860]: code: e93f00a0 f93f0128 e93f0120 e95f0128 <f9490000> e93f0088 39290008 f93f0110

The failure was due to guest kernel using wrong page size.

The namespaces created with 16M alignment will appear as below on a config with 16M page size disabled.

$ ndctl list -Ni
[
  {
    "dev":"namespace0.1",
    "mode":"fsdax",
    "map":"dev",
    "size":5351931904,
    "uuid":"fc6e9667-461a-4718-82b4-69b24570bddb",
    "align":16777216,
    "blockdev":"pmem0.1",
    "supported_alignments":[
      65536
    ]
  },
  {
    "dev":"namespace0.0",
    "mode":"fsdax",    <==== devdax 16M alignment marked disabled.
    "map":"mem",
    "size":5368709120,
    "uuid":"a4bdf81a-f2ee-4bc6-91db-7b87eddd0484",
    "state":"disabled"
  }
]
---
 arch/powerpc/include/asm/libnvdimm.h |  9 ++++++++
 arch/powerpc/mm/Makefile             |  1 +
 arch/powerpc/mm/nvdimm.c             | 34 ++++++++++++++++++++++++++++
 arch/x86/include/asm/libnvdimm.h     | 19 ++++++++++++++++
 drivers/nvdimm/nd.h                  |  6 -----
 drivers/nvdimm/pfn_devs.c            | 32 +++++++++++++++++++++++++-
 include/linux/huge_mm.h              |  7 +++++-
 7 files changed, 100 insertions(+), 8 deletions(-)
 create mode 100644 arch/powerpc/include/asm/libnvdimm.h
 create mode 100644 arch/powerpc/mm/nvdimm.c
 create mode 100644 arch/x86/include/asm/libnvdimm.h
arch/powerpc/include/asm/libnvdimm.h new file +9 -0
new file mode 100644
index 000000000000..d35fd7f48603
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_POWERPC_LIBNVDIMM_H
+#define _ASM_POWERPC_LIBNVDIMM_H
+
+#define nd_pfn_supported_alignments nd_pfn_supported_alignments
+extern unsigned long *nd_pfn_supported_alignments(void);
+extern unsigned long nd_pfn_default_alignment(void);
+
+#endif
arch/powerpc/mm/Makefile +1 -0
index 0f499db315d6..42e4a399ba5d 100644
@@ -20,3 +20,4 @@ obj-$(CONFIG_HIGHMEM)		+= highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)	+= copro_fault.o
 obj-$(CONFIG_PPC_PTDUMP)	+= ptdump/
 obj-$(CONFIG_KASAN)		+= kasan/
+obj-$(CONFIG_NVDIMM_PFN)		+= nvdimm.o
arch/powerpc/mm/nvdimm.c new file +34 -0
new file mode 100644
index 000000000000..a29a4510715e
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <asm/pgtable.h>
+#include <asm/page.h>
+
+#include <linux/mm.h>
+/*
+ * We support only pte and pmd mappings for now.
+ */
+const unsigned long *nd_pfn_supported_alignments(void)
+{
+	static unsigned long supported_alignments[3];
+
+	supported_alignments[0] = PAGE_SIZE;
+
+	if (has_transparent_hugepage())
+		supported_alignments[1] = HPAGE_PMD_SIZE;
+	else
+		supported_alignments[1] = 0;
+
+	supported_alignments[2] = 0;
+	return supported_alignments;
+}
+
+/*
+ * Use pmd mapping if supported as default alignment
+ */
+unsigned long nd_pfn_default_alignment(void)
+{
+
+	if (has_transparent_hugepage())
+		return HPAGE_PMD_SIZE;
+	return PAGE_SIZE;
+}
arch/x86/include/asm/libnvdimm.h new file +19 -0
new file mode 100644
index 000000000000..3d5361db9164
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_LIBNVDIMM_H
+#define _ASM_X86_LIBNVDIMM_H
+
+static inline unsigned long nd_pfn_default_alignment(void)
+{
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	return HPAGE_PMD_SIZE;
+#else
+	return PAGE_SIZE;
+#endif
+}
+
+static inline unsigned long nd_altmap_align_size(unsigned long nd_align)
+{
+	return PMD_SIZE;
+}
+
+#endif
drivers/nvdimm/nd.h +0 -6
index 1b9955651379..5d095a19ff2c 100644
@@ -289,12 +289,6 @@ static inline struct device *nd_btt_create(struct nd_region *nd_region)
 struct nd_pfn *to_nd_pfn(struct device *dev);
 #if IS_ENABLED(CONFIG_NVDIMM_PFN)
 
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-#define PFN_DEFAULT_ALIGNMENT HPAGE_PMD_SIZE
-#else
-#define PFN_DEFAULT_ALIGNMENT PAGE_SIZE
-#endif
-
 int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns);
 bool is_nd_pfn(struct device *dev);
 struct device *nd_pfn_create(struct nd_region *nd_region);
drivers/nvdimm/pfn_devs.c +31 -1
index c1d9be609322..f43d1baa6f33 100644
@@ -10,6 +10,7 @@
 #include <linux/slab.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
+#include <asm/libnvdimm.h>
 #include "nd-core.h"
 #include "pfn.h"
 #include "nd.h"
@@ -103,6 +104,8 @@ static ssize_t align_show(struct device *dev,
 	return sprintf(buf, "%ld\n", nd_pfn->align);
 }
 
+#ifndef nd_pfn_supported_alignments
+#define nd_pfn_supported_alignments nd_pfn_supported_alignments
 static const unsigned long *nd_pfn_supported_alignments(void)
 {
 	/*
@@ -125,6 +128,7 @@ static const unsigned long *nd_pfn_supported_alignments(void)
 
 	return data;
 }
+#endif
 
 static ssize_t align_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
@@ -302,7 +306,7 @@ struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
 		return NULL;
 
 	nd_pfn->mode = PFN_MODE_NONE;
-	nd_pfn->align = PFN_DEFAULT_ALIGNMENT;
+	nd_pfn->align = nd_pfn_default_alignment();
 	dev = &nd_pfn->dev;
 	device_initialize(&nd_pfn->dev);
 	if (ndns && !__nd_attach_ndns(&nd_pfn->dev, ndns, &nd_pfn->ndns)) {
@@ -412,6 +416,20 @@ static int nd_pfn_clear_memmap_errors(struct nd_pfn *nd_pfn)
 	return 0;
 }
 
+static bool nd_supported_alignment(unsigned long align)
+{
+	int i;
+	const unsigned long *supported = nd_pfn_supported_alignments();
+
+	if (align == 0)
+		return false;
+
+	for (i = 0; supported[i]; i++)
+		if (align == supported[i])
+			return true;
+	return false;
+}
+
 /**
  * nd_pfn_validate - read and validate info-block
  * @nd_pfn: fsdax namespace runtime state / properties
@@ -498,6 +516,18 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 		return -EOPNOTSUPP;
 	}
 
+	/*
+	 * Check whether the we support the alignment. For Dax if the
+	 * superblock alignment is not matching, we won't initialize
+	 * the device.
+	 */
+	if (!nd_supported_alignment(align) &&
+	    !memcmp(pfn_sb->signature, DAX_SIG, PFN_SIG_LEN)) {
+		dev_err(&nd_pfn->dev, "init failed, alignment mismatch: "
+			"%ld:%ld\n", nd_pfn->align, align);
+		return -EOPNOTSUPP;
+	}
+
 	if (!nd_pfn->uuid) {
 		/*
 		 * When probing a namepace via nd_pfn_probe() the uuid
include/linux/huge_mm.h +6 -1
index 45ede62aa85b..4fa91f9bd0da 100644
@@ -108,7 +108,12 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
 
 	if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_FLAG))
 		return true;
-
+	/*
+	 * For dax let's try to do hugepage fault always. If we don't support
+	 * hugepages we will not have enabled namespaces with hugepage alignment.
+	 * This also means we try to handle hugepage fault on device with
+	 * smaller alignment. But for then we will return with VM_FAULT_FALLBACK
+	 */
 	if (vma_is_dax(vma))
 		return true;
 
Signature · 1 line
2.21.0
#7 lore raw

Re: [PATCH v5 2/4] mm/nvdimm: Add page size and struct page size to pfn superblock

In reply to Aneesh Kumar K.V

"Aneesh Kumar K.V" <[email protected]> writes:

case PFN_MODE_PMEM:

Quoted 8 lines
(quoted diff) +4 -0
@@ -475,6 +484,20 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 		align = 1UL << ilog2(offset);
 	mode = le32_to_cpu(pfn_sb->mode);
 
+	if (le32_to_cpu(pfn_sb->page_size) != PAGE_SIZE) {
+		dev_err(&nd_pfn->dev,
+			"init failed, page size mismatch %d\n",
+			le32_to_cpu(pfn_sb->page_size));

Review int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) · line 500

Quoted 10 lines
(quoted diff) +10 -0
+		return -EOPNOTSUPP;
+	}
+
+	if (le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) {
+		dev_err(&nd_pfn->dev,
+			"init failed, struct page size mismatch %d\n",
+			le16_to_cpu(pfn_sb->page_struct_size));
+		return -EOPNOTSUPP;
+	}
+

We need this here?

Quoted 1 line

From 9885b2f9ed81a2438fc81507cfcdbdb1aeab756c Mon Sep 17 00:00:00 2001

From: "Aneesh Kumar K.V" <[email protected]>
Date: Fri, 9 Aug 2019 22:10:08 +0530
Subject: [PATCH] nvdimm: check struct page size only if pfn node is PMEM

We should do the check only with PFN_MODE_PMEM. If we use memory for backing vmemmap, we should be able to enable the namespace even if struct page size change.

---
 drivers/nvdimm/pfn_devs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +2 -1
index f43d1baa6f33..f3e9a4b826da 100644
@@ -509,7 +509,8 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 		return -EOPNOTSUPP;
 	}
 
-	if (le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) {
+	if ((le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) &&
+	     (mode == PFN_MODE_PMEM)) {
 		dev_err(&nd_pfn->dev,
 			"init failed, struct page size mismatch %d\n",
 			le16_to_cpu(pfn_sb->page_struct_size));
Signature · 6 lines
2.21.0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#2 lore raw

Re: [PATCH v5 1/4] nvdimm: Consider probe return -EOPNOTSUPP as success

In reply to Aneesh Kumar K.V

Hi Aneesh, logic looks correct but there are some cleanups I'd like to see and a lead-in patch that I attached.

I've started prefixing nvdimm patches with:

libnvdimm/$component:

...since this patch mostly impacts the pmem driver lets prefix it "libnvdimm/pmem: "

Quoted 2 lines · Aneesh Kumar K.V

This patch add -EOPNOTSUPP as return from probe callback to

s/This patch add/Add/

No need to say "this patch" it's obviously a patch.

Quoted 4 lines

indicate we were not able to initialize a namespace due to pfn superblock feature/version mismatch. We want to consider this a probe success so that we can create new namesapce seed and there by avoid marking the failed namespace as the seed namespace.

Please replace usage of "we" with the exact agent involved as which "we" is being referred to gets confusing for the reader.

i.e. "indicate that the pmem driver was not..." "The nvdimm core wants to consider this...".

Quoted 12 lines
---
 drivers/nvdimm/bus.c  |  2 +-
 drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/nvdimm/bus.c +0 -0
index 798c5c4aea9c..16c35e6446a7 100644

drivers/nvdimm/bus.c static int nvdimm_bus_probe(struct device *dev) · line 99

Quoted 6 lines
drivers/nvdimm/bus.c +1 -1
@@ -95,7 +95,7 @@ static int nvdimm_bus_probe(struct device *dev)
        rc = nd_drv->probe(dev);
        debug_nvdimm_unlock(dev);
 
-       if (rc == 0)
+       if (rc == 0 || rc == -EOPNOTSUPP)
                nd_region_probe_success(nvdimm_bus, dev);

This now makes the nd_region_probe_success() helper obviously misnamed since it now wants to take actions on non-probe success. I attached a lead-in cleanup that you can pull into your series that renames that routine to nd_region_advance_seeds().

When you rebase this needs a comment about why EOPNOTSUPP has special handling.

Quoted 15 lines
drivers/nvdimm/bus.c +0 -0
        else
                nd_region_disable(nvdimm_bus, dev);
drivers/nvdimm/pmem.c +1 -0
index 4c121dd03dd9..3f498881dd28 100644
@@ -490,6 +490,7 @@ static int pmem_attach_disk(struct device *dev,
 
 static int nd_pmem_probe(struct device *dev)
 {
+       int ret;
        struct nd_namespace_common *ndns;
 
        ndns = nvdimm_namespace_common_probe(dev);

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 510

Quoted 6 lines
drivers/nvdimm/pmem.c +0 -3
@@ -505,12 +506,29 @@ static int nd_pmem_probe(struct device *dev)
        if (is_nd_pfn(dev))
                return pmem_attach_disk(dev, ndns);
 
-       /* if we find a valid info-block we'll come back as that personality */
-       if (nd_btt_probe(dev, ndns) == 0 || nd_pfn_probe(dev, ndns) == 0
-                       || nd_dax_probe(dev, ndns) == 0)

Similar need for an updated comment here to explain the special translation of error codes.

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 512

Quoted 4 lines
drivers/nvdimm/pmem.c +3 -0
+       ret = nd_btt_probe(dev, ndns);
+       if (ret == 0)
                return -ENXIO;
+       else if (ret == -EOPNOTSUPP)

Are there cases where the btt driver needs to return EOPNOTSUPP? I'd otherwise like to keep this special casing constrained to the pfn / dax info block cases.

From 9ec13a8672e87e0b1c5b9427ab926168e53d55bc Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 13 Aug 2019 13:09:27 -0700
Subject: [PATCH] libnvdimm/region: Rewrite _probe_success() to
_advance_seeds()

The nd_region_probe_success() helper collides seed management with nvdimm->busy tracking. Given the 'busy' increment is handled internal to the nd_region driver 'probe' path move the decrement to the 'remove' path. With that cleanup the routine can be renamed to the more descriptive nd_region_advance_seeds().

The change is prompted by an incoming need to optionally advance the seeds on other events besides 'probe' success.

Cc "Aneesh Kumar K.V" <[email protected]>
---
 drivers/nvdimm/bus.c            |  7 +---
 drivers/nvdimm/namespace_devs.c | 34 ++++++++++++++---
 drivers/nvdimm/nd-core.h        |  3 +-
 drivers/nvdimm/region_devs.c    | 68 +++++----------------------------
 4 files changed, 41 insertions(+), 71 deletions(-)
drivers/nvdimm/bus.c +2 -5
index 29479d3b01b0..ee6de34ae525 100644
@@ -95,10 +95,8 @@ static int nvdimm_bus_probe(struct device *dev)
 	rc = nd_drv->probe(dev);
 	debug_nvdimm_unlock(dev);
 
-	if (rc == 0)
-		nd_region_probe_success(nvdimm_bus, dev);
-	else
-		nd_region_disable(nvdimm_bus, dev);
+	if (rc == 0 && dev->parent && is_nd_region(dev->parent))
+		nd_region_advance_seeds(to_nd_region(dev->parent), dev);
 	nvdimm_bus_probe_end(nvdimm_bus);
 
 	dev_dbg(&nvdimm_bus->dev, "END: %s.probe(%s) = %d\n", dev->driver->name,
@@ -121,7 +119,6 @@ static int nvdimm_bus_remove(struct device *dev)
 		rc = nd_drv->remove(dev);
 		debug_nvdimm_unlock(dev);
 	}
-	nd_region_disable(nvdimm_bus, dev);
 
 	dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name,
 			dev_name(dev), rc);
drivers/nvdimm/namespace_devs.c +28 -6
index a16e52251a30..3be81f7b9ed3 100644
@@ -2462,6 +2462,27 @@ static struct device **create_namespaces(struct nd_region *nd_region)
 	return devs;
 }
 
+static void deactivate_labels(void *region)
+{
+	struct nd_region *nd_region = region;
+	int i;
+
+	for (i = 0; i < nd_region->ndr_mappings; i++) {
+		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
+		struct nvdimm_drvdata *ndd = nd_mapping->ndd;
+		struct nvdimm *nvdimm = nd_mapping->nvdimm;
+
+		mutex_lock(&nd_mapping->lock);
+		nd_mapping_free_labels(nd_mapping);
+		mutex_unlock(&nd_mapping->lock);
+
+		put_ndd(ndd);
+		nd_mapping->ndd = NULL;
+		if (ndd)
+			atomic_dec(&nvdimm->busy);
+	}
+}
+
 static int init_active_labels(struct nd_region *nd_region)
 {
 	int i;
@@ -2519,16 +2540,17 @@ static int init_active_labels(struct nd_region *nd_region)
 			mutex_unlock(&nd_mapping->lock);
 		}
 
-		if (j >= count)
-			continue;
+		if (j < count)
+			break;
+	}
 
-		mutex_lock(&nd_mapping->lock);
-		nd_mapping_free_labels(nd_mapping);
-		mutex_unlock(&nd_mapping->lock);
+	if (i < nd_region->ndr_mappings) {
+		deactivate_labels(nd_region);
 		return -ENOMEM;
 	}
 
-	return 0;
+	return devm_add_action_or_reset(&nd_region->dev, deactivate_labels,
+			nd_region);
 }
 
 int nd_region_register_namespaces(struct nd_region *nd_region, int *err)
drivers/nvdimm/nd-core.h +1 -2
index 454454ba1738..25fa121104d0 100644
@@ -115,13 +115,12 @@ int __init nvdimm_bus_init(void);
 void nvdimm_bus_exit(void);
 void nvdimm_devs_exit(void);
 void nd_region_devs_exit(void);
-void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev);
 struct nd_region;
+void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
 void nd_region_create_ns_seed(struct nd_region *nd_region);
 void nd_region_create_btt_seed(struct nd_region *nd_region);
 void nd_region_create_pfn_seed(struct nd_region *nd_region);
 void nd_region_create_dax_seed(struct nd_region *nd_region);
-void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev);
 int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
 void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
 void nd_synchronize(void);
drivers/nvdimm/region_devs.c +10 -58

95 lines not on this page · raw message

Signature · 1 line
2.20.1
#8 lore raw

Re: [PATCH v5 2/4] mm/nvdimm: Add page size and struct page size to pfn superblock

In reply to Aneesh Kumar K.V
Quoted 9 lines · Aneesh Kumar K.V

"Aneesh Kumar K.V" <[email protected]> writes:

case PFN_MODE_PMEM:

Review int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) · line 487

Quoted 5 lines
(quoted diff) +1 -0
@@ -475,6 +484,20 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
              align = 1UL << ilog2(offset);
      mode = le32_to_cpu(pfn_sb->mode);
 
+     if (le32_to_cpu(pfn_sb->page_size) != PAGE_SIZE) {

I think this is too strict. It's only a potential problem in the "pfn_sb->page_size > PAGE_SIZE" case, because only then might the existing reservation for the memmap be too small. Otherwise, unless I'm missing something, there should be no ill effects for under-utilizing the reservation.

Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+             dev_err(&nd_pfn->dev,
+                     "init failed, page size mismatch %d\n",
+                     le32_to_cpu(pfn_sb->page_size));
+             return -EOPNOTSUPP;
+     }
+
+     if (le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) {
Quoted 8 lines

Review int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) · line 500

Quoted 6 lines
(quoted diff) +6 -0
+             dev_err(&nd_pfn->dev,
+                     "init failed, struct page size mismatch %d\n",
+                     le16_to_cpu(pfn_sb->page_struct_size));
+             return -EOPNOTSUPP;
+     }
+

We need this here?

Yes, both ->page_struct_size and ->page_size are only relevant in the PFN_MODE_PMEM case because PFN_MODE_RAM assumes all pages are allocated dynamically and the size does not matter.

Quoted 9 lines

From 9885b2f9ed81a2438fc81507cfcdbdb1aeab756c Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Fri, 9 Aug 2019 22:10:08 +0530
Subject: [PATCH] nvdimm: check struct page size only if pfn node is PMEM

We should do the check only with PFN_MODE_PMEM. If we use memory for backing vmemmap, we should be able to enable the namespace even if struct page size change.

Same as the other patches please drop the usage of "we" in the changelog.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

Re: [PATCH v5 1/4] nvdimm: Consider probe return -EOPNOTSUPP as success

In reply to Dan Williams
Quoted 82 lines · Dan Williams

Hi Aneesh, logic looks correct but there are some cleanups I'd like to see and a lead-in patch that I attached.

I've started prefixing nvdimm patches with:

libnvdimm/$component:

...since this patch mostly impacts the pmem driver lets prefix it "libnvdimm/pmem: "

Quoted 2 lines · Aneesh Kumar K.V

This patch add -EOPNOTSUPP as return from probe callback to

s/This patch add/Add/

No need to say "this patch" it's obviously a patch.

Quoted 4 lines

indicate we were not able to initialize a namespace due to pfn superblock feature/version mismatch. We want to consider this a probe success so that we can create new namesapce seed and there by avoid marking the failed namespace as the seed namespace.

Please replace usage of "we" with the exact agent involved as which "we" is being referred to gets confusing for the reader.

i.e. "indicate that the pmem driver was not..." "The nvdimm core wants to consider this...".

Quoted 12 lines
---
 drivers/nvdimm/bus.c  |  2 +-
 drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/nvdimm/bus.c +0 -0
index 798c5c4aea9c..16c35e6446a7 100644

drivers/nvdimm/bus.c static int nvdimm_bus_probe(struct device *dev) · line 99

Quoted 6 lines
drivers/nvdimm/bus.c +1 -1
@@ -95,7 +95,7 @@ static int nvdimm_bus_probe(struct device *dev)
        rc = nd_drv->probe(dev);
        debug_nvdimm_unlock(dev);
 
-       if (rc == 0)
+       if (rc == 0 || rc == -EOPNOTSUPP)
                nd_region_probe_success(nvdimm_bus, dev);

This now makes the nd_region_probe_success() helper obviously misnamed since it now wants to take actions on non-probe success. I attached a lead-in cleanup that you can pull into your series that renames that routine to nd_region_advance_seeds().

When you rebase this needs a comment about why EOPNOTSUPP has special handling.

Quoted 15 lines
drivers/nvdimm/bus.c +0 -0
        else
                nd_region_disable(nvdimm_bus, dev);
drivers/nvdimm/pmem.c +1 -0
index 4c121dd03dd9..3f498881dd28 100644
@@ -490,6 +490,7 @@ static int pmem_attach_disk(struct device *dev,
 
 static int nd_pmem_probe(struct device *dev)
 {
+       int ret;
        struct nd_namespace_common *ndns;
 
        ndns = nvdimm_namespace_common_probe(dev);

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 510

Quoted 6 lines
drivers/nvdimm/pmem.c +0 -3
@@ -505,12 +506,29 @@ static int nd_pmem_probe(struct device *dev)
        if (is_nd_pfn(dev))
                return pmem_attach_disk(dev, ndns);
 
-       /* if we find a valid info-block we'll come back as that personality */
-       if (nd_btt_probe(dev, ndns) == 0 || nd_pfn_probe(dev, ndns) == 0
-                       || nd_dax_probe(dev, ndns) == 0)

Similar need for an updated comment here to explain the special translation of error codes.

Quoted 8 lines

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 512

Quoted 4 lines
drivers/nvdimm/pmem.c +3 -0
+       ret = nd_btt_probe(dev, ndns);
+       if (ret == 0)
                return -ENXIO;
+       else if (ret == -EOPNOTSUPP)

Are there cases where the btt driver needs to return EOPNOTSUPP? I'd otherwise like to keep this special casing constrained to the pfn / dax info block cases.

In fact I think EOPNOTSUPP is only something that the device-dax case would be concerned with because that's the only interface that attempts to guarantee a given mapping granularity.

#10 lore raw

Re: [PATCH v5 3/4] mm/nvdimm: Use correct #defines instead of open coding

In reply to Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

Use PAGE_SIZE instead of SZ_4K and sizeof(struct page) instead of 64. If we have a kernel built with different struct page size the previous patch should handle marking the namespace disabled.

Each of these changes carry independent non-overlapping regression risk, so lets split them into separate patches. Others might

Quoted 13 lines
---
 drivers/nvdimm/label.c          | 2 +-
 drivers/nvdimm/namespace_devs.c | 6 +++---
 drivers/nvdimm/pfn_devs.c       | 3 ++-
 drivers/nvdimm/region_devs.c    | 8 ++++----
 4 files changed, 10 insertions(+), 9 deletions(-)
drivers/nvdimm/label.c +0 -0
index 73e197babc2f..7ee037063be7 100644

drivers/nvdimm/label.c static bool slot_valid(struct nvdimm_drvdata *ndd, · line 358

Quoted 5 lines
drivers/nvdimm/label.c +1 -1
@@ -355,7 +355,7 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
 
        /* check that DPA allocations are page aligned */
        if ((__le64_to_cpu(nd_label->dpa)
-                               | __le64_to_cpu(nd_label->rawsize)) % SZ_4K)
+                               | __le64_to_cpu(nd_label->rawsize)) % PAGE_SIZE)

The UEFI label specification has no concept of PAGE_SIZE, so this check is a pure Linux-ism. There's no strict requirement why slot_valid() needs to check for page alignment and it would seem to actively hurt cross-page-size compatibility, so let's delete the check and rely on checksum validation.

Quoted 9 lines
drivers/nvdimm/label.c +0 -0
                return false;
 
        /* check checksum */
drivers/nvdimm/namespace_devs.c +0 -0
index a16e52251a30..a9c76df12cb9 100644
@@ -1006,10 +1006,10 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
                return -ENXIO;

drivers/nvdimm/namespace_devs.c static ssize_t __size_store(struct device *dev, unsigned long long val) · line 1013

Quoted 10 lines
drivers/nvdimm/namespace_devs.c +3 -3
        }
 
-       div_u64_rem(val, SZ_4K * nd_region->ndr_mappings, &remainder);
+       div_u64_rem(val, PAGE_SIZE * nd_region->ndr_mappings, &remainder);
        if (remainder) {
-               dev_dbg(dev, "%llu is not %dK aligned\n", val,
-                               (SZ_4K * nd_region->ndr_mappings) / SZ_1K);
+               dev_dbg(dev, "%llu is not %ldK aligned\n", val,
+                               (PAGE_SIZE * nd_region->ndr_mappings) / SZ_1K);
                return -EINVAL;

Yes, looks good, but this deserves its own independent patch.

drivers/nvdimm/pfn_devs.c static int nd_pfn_init(struct nd_pfn *nd_pfn) · line 728

Quoted 12 lines
drivers/nvdimm/namespace_devs.c +0 -0
        }
 
drivers/nvdimm/pfn_devs.c +1 -1
index 37e96811c2fc..c1d9be609322 100644
@@ -725,7 +725,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
                 * when populating the vmemmap. This *should* be equal to
                 * PMD_SIZE for most architectures.
                 */
-               offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
+               offset = ALIGN(start + SZ_8K + sizeof(struct page) * npfns,

I'd prefer if this was not dynamic and was instead set to the maximum size of 'struct page' across all archs just to enhance cross-arch compatibility. I think that answer is '64'.

Quoted 26 lines
drivers/nvdimm/pfn_devs.c +1 -0
+                              align) - start;
        } else if (nd_pfn->mode == PFN_MODE_RAM)
                offset = ALIGN(start + SZ_8K, align) - start;
        else
drivers/nvdimm/region_devs.c +4 -5
index af30cbe7a8ea..20e265a534f8 100644
@@ -992,10 +992,10 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
                struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
                struct nvdimm *nvdimm = mapping->nvdimm;
 
-               if ((mapping->start | mapping->size) % SZ_4K) {
-                       dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
-                                       caller, dev_name(&nvdimm->dev), i);
-
+               if ((mapping->start | mapping->size) % PAGE_SIZE) {
+                       dev_err(&nvdimm_bus->dev,
+                               "%s: %s mapping%d is not %ld aligned\n",
+                               caller, dev_name(&nvdimm->dev), i, PAGE_SIZE);
                        return NULL;
                }
 
--

2.21.0

#4 lore raw

Re: [PATCH v5 1/4] nvdimm: Consider probe return -EOPNOTSUPP as success

In reply to Dan Williams
Quoted 88 lines · Dan Williams
Quoted 87 lines · Dan Williams

Hi Aneesh, logic looks correct but there are some cleanups I'd like to see and a lead-in patch that I attached.

I've started prefixing nvdimm patches with:

libnvdimm/$component:

...since this patch mostly impacts the pmem driver lets prefix it "libnvdimm/pmem: "

Quoted 2 lines · Aneesh Kumar K.V

This patch add -EOPNOTSUPP as return from probe callback to

s/This patch add/Add/

No need to say "this patch" it's obviously a patch.

Quoted 4 lines

indicate we were not able to initialize a namespace due to pfn superblock feature/version mismatch. We want to consider this a probe success so that we can create new namesapce seed and there by avoid marking the failed namespace as the seed namespace.

Please replace usage of "we" with the exact agent involved as which "we" is being referred to gets confusing for the reader.

i.e. "indicate that the pmem driver was not..." "The nvdimm core wants to consider this...".

Quoted 12 lines
---
 drivers/nvdimm/bus.c  |  2 +-
 drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/nvdimm/bus.c +0 -0
index 798c5c4aea9c..16c35e6446a7 100644

drivers/nvdimm/bus.c static int nvdimm_bus_probe(struct device *dev) · line 99

Quoted 6 lines
drivers/nvdimm/bus.c +1 -1
@@ -95,7 +95,7 @@ static int nvdimm_bus_probe(struct device *dev)
        rc = nd_drv->probe(dev);
        debug_nvdimm_unlock(dev);
 
-       if (rc == 0)
+       if (rc == 0 || rc == -EOPNOTSUPP)
                nd_region_probe_success(nvdimm_bus, dev);

This now makes the nd_region_probe_success() helper obviously misnamed since it now wants to take actions on non-probe success. I attached a lead-in cleanup that you can pull into your series that renames that routine to nd_region_advance_seeds().

When you rebase this needs a comment about why EOPNOTSUPP has special handling.

Quoted 15 lines
drivers/nvdimm/bus.c +0 -0
        else
                nd_region_disable(nvdimm_bus, dev);
drivers/nvdimm/pmem.c +1 -0
index 4c121dd03dd9..3f498881dd28 100644
@@ -490,6 +490,7 @@ static int pmem_attach_disk(struct device *dev,
 
 static int nd_pmem_probe(struct device *dev)
 {
+       int ret;
        struct nd_namespace_common *ndns;
 
        ndns = nvdimm_namespace_common_probe(dev);

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 510

Quoted 6 lines
drivers/nvdimm/pmem.c +0 -3
@@ -505,12 +506,29 @@ static int nd_pmem_probe(struct device *dev)
        if (is_nd_pfn(dev))
                return pmem_attach_disk(dev, ndns);
 
-       /* if we find a valid info-block we'll come back as that personality */
-       if (nd_btt_probe(dev, ndns) == 0 || nd_pfn_probe(dev, ndns) == 0
-                       || nd_dax_probe(dev, ndns) == 0)

Similar need for an updated comment here to explain the special translation of error codes.

Quoted 4 lines
drivers/nvdimm/pmem.c +3 -0
+       ret = nd_btt_probe(dev, ndns);
+       if (ret == 0)
                return -ENXIO;
+       else if (ret == -EOPNOTSUPP)
Quoted 7 lines
Quoted 3 lines

Are there cases where the btt driver needs to return EOPNOTSUPP? I'd otherwise like to keep this special casing constrained to the pfn / dax info block cases.

In fact I think EOPNOTSUPP is only something that the device-dax case would be concerned with because that's the only interface that attempts to guarantee a given mapping granularity.

We need to do similar error handling w.r.t fsdax when the pfn superblock indicates different PAGE_SIZE and struct page size? I don't think btt needs to support EOPNOTSUPP. But we can keep it for consistency?

-aneesh

#11 lore raw

Re: [PATCH v5 3/4] mm/nvdimm: Use correct #defines instead of open coding

In reply to Dan Williams
Quoted 24 lines · Dan Williams
Quoted 4 lines · Aneesh Kumar K.V

Use PAGE_SIZE instead of SZ_4K and sizeof(struct page) instead of 64. If we have a kernel built with different struct page size the previous patch should handle marking the namespace disabled.

Each of these changes carry independent non-overlapping regression risk, so lets split them into separate patches. Others might

Quoted 14 lines
---
 drivers/nvdimm/label.c          | 2 +-
 drivers/nvdimm/namespace_devs.c | 6 +++---
 drivers/nvdimm/pfn_devs.c       | 3 ++-
 drivers/nvdimm/region_devs.c    | 8 ++++----
 4 files changed, 10 insertions(+), 9 deletions(-)
drivers/nvdimm/label.c +0 -0
index 73e197babc2f..7ee037063be7 100644
@@ -355,7 +355,7 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
 
Quoted 10 lines

drivers/nvdimm/label.c static bool slot_valid(struct nvdimm_drvdata *ndd, · line 358

Quoted 4 lines
drivers/nvdimm/label.c +1 -1
        /* check that DPA allocations are page aligned */
        if ((__le64_to_cpu(nd_label->dpa)
-                               | __le64_to_cpu(nd_label->rawsize)) % SZ_4K)
+                               | __le64_to_cpu(nd_label->rawsize)) % PAGE_SIZE)

The UEFI label specification has no concept of PAGE_SIZE, so this check is a pure Linux-ism. There's no strict requirement why slot_valid() needs to check for page alignment and it would seem to actively hurt cross-page-size compatibility, so let's delete the check and rely on checksum validation.

Will do a separate patch to drop that check.

Quoted 25 lines
Quoted 10 lines
drivers/nvdimm/label.c +0 -0
                return false;
 
        /* check checksum */
drivers/nvdimm/namespace_devs.c +0 -0
index a16e52251a30..a9c76df12cb9 100644
@@ -1006,10 +1006,10 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
                return -ENXIO;

drivers/nvdimm/namespace_devs.c static ssize_t __size_store(struct device *dev, unsigned long long val) · line 1013

Quoted 10 lines
drivers/nvdimm/namespace_devs.c +3 -3
        }
 
-       div_u64_rem(val, SZ_4K * nd_region->ndr_mappings, &remainder);
+       div_u64_rem(val, PAGE_SIZE * nd_region->ndr_mappings, &remainder);
        if (remainder) {
-               dev_dbg(dev, "%llu is not %dK aligned\n", val,
-                               (SZ_4K * nd_region->ndr_mappings) / SZ_1K);
+               dev_dbg(dev, "%llu is not %ldK aligned\n", val,
+                               (PAGE_SIZE * nd_region->ndr_mappings) / SZ_1K);
                return -EINVAL;

Yes, looks good, but this deserves its own independent patch.

Quoted 2 lines
drivers/nvdimm/namespace_devs.c +0 -0
        }
 
Quoted 14 lines

drivers/nvdimm/pfn_devs.c static int nd_pfn_init(struct nd_pfn *nd_pfn) · line 728

Quoted 10 lines
drivers/nvdimm/pfn_devs.c +1 -1
index 37e96811c2fc..c1d9be609322 100644
@@ -725,7 +725,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
                 * when populating the vmemmap. This *should* be equal to
                 * PMD_SIZE for most architectures.
                 */
-               offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
+               offset = ALIGN(start + SZ_8K + sizeof(struct page) * npfns,

I'd prefer if this was not dynamic and was instead set to the maximum size of 'struct page' across all archs just to enhance cross-arch compatibility. I think that answer is '64'.

That still doesn't take care of the case where we add new elements to struct page later. If we have struct page size changing across architectures, we should still be ok as long as new size is less than what is stored in pfn superblock? I understand the desire to keep it non-dynamic. But we also need to make sure we don't reserve less space when creating a new namespace on a config that got struct page size > 64?

Quoted 26 lines
Quoted 26 lines
drivers/nvdimm/pfn_devs.c +1 -0
+                              align) - start;
        } else if (nd_pfn->mode == PFN_MODE_RAM)
                offset = ALIGN(start + SZ_8K, align) - start;
        else
drivers/nvdimm/region_devs.c +4 -5
index af30cbe7a8ea..20e265a534f8 100644
@@ -992,10 +992,10 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
                struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
                struct nvdimm *nvdimm = mapping->nvdimm;
 
-               if ((mapping->start | mapping->size) % SZ_4K) {
-                       dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
-                                       caller, dev_name(&nvdimm->dev), i);
-
+               if ((mapping->start | mapping->size) % PAGE_SIZE) {
+                       dev_err(&nvdimm_bus->dev,
+                               "%s: %s mapping%d is not %ld aligned\n",
+                               caller, dev_name(&nvdimm->dev), i, PAGE_SIZE);
                        return NULL;
                }
 
--

2.21.0

#12 lore raw

Re: [PATCH v5 3/4] mm/nvdimm: Use correct #defines instead of open coding

Quoted 6 lines · Aneesh Kumar K.V
Quoted 4 lines · Dan Williams
Quoted 1 line · Aneesh Kumar K.V

...

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
drivers/nvdimm/pfn_devs.c +0 -0
index 37e96811c2fc..c1d9be609322 100644
@@ -725,7 +725,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
                 * when populating the vmemmap. This *should* be equal to
Quoted 8 lines

drivers/nvdimm/pfn_devs.c static int nd_pfn_init(struct nd_pfn *nd_pfn) · line 728

Quoted 4 lines
drivers/nvdimm/pfn_devs.c +1 -1
                 * PMD_SIZE for most architectures.
                 */
-               offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
+               offset = ALIGN(start + SZ_8K + sizeof(struct page) * npfns,

I'd prefer if this was not dynamic and was instead set to the maximum size of 'struct page' across all archs just to enhance cross-arch compatibility. I think that answer is '64'.

Quoted 7 lines

That still doesn't take care of the case where we add new elements to struct page later. If we have struct page size changing across architectures, we should still be ok as long as new size is less than what is stored in pfn superblock? I understand the desire to keep it non-dynamic. But we also need to make sure we don't reserve less space when creating a new namespace on a config that got struct page size > 64?

How about

libnvdimm/pfn_dev: Add a build check to make sure we notice when struct page size change

When namespace is created with map device as pmem device, struct page is stored in the reserve block area. We need to make sure we account for the right struct page size while doing this. Instead of directly depending on sizeof(struct page) which can change based on different kernel config option, use the max struct page size (64) while calculating the reserve block area. This makes sure pmem device can be used across kernels built with different configs.

If the above assumption of max struct page size change, we need to update the reserve block allocation space for new namespaces created.

1 file changed, 7 insertions(+)

drivers/nvdimm/pfn_devs.c | 7 +++++++

modified drivers/nvdimm/pfn_devs.c
@@ -722,7 +722,14 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
* The altmap should be padded out to the block size used
* when populating the vmemmap. This *should* be equal to
* PMD_SIZE for most architectures.
+ *
+ * Also make sure size of struct page is less than 64. We
+ * want to make sure we use large enough size here so that
+ * we don't have a dynamic reserve space depending on
+ * struct page size. But we also want to make sure we notice
+ * if we end up adding new elements to struct page.
*/
+ BUILD_BUG_ON(64 < sizeof(struct page));
offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
} else if (nd_pfn->mode == PFN_MODE_RAM)
offset = ALIGN(start + SZ_8K, align) - start;

-aneesh

#5 lore raw

Re: [PATCH v5 1/4] nvdimm: Consider probe return -EOPNOTSUPP as success

In reply to Aneesh Kumar K.V
Quoted 95 lines · Aneesh Kumar K.V
Quoted 92 lines · Dan Williams
Quoted 90 lines · Dan Williams

Hi Aneesh, logic looks correct but there are some cleanups I'd like to see and a lead-in patch that I attached.

I've started prefixing nvdimm patches with:

libnvdimm/$component:

...since this patch mostly impacts the pmem driver lets prefix it "libnvdimm/pmem: "

Quoted 2 lines · Aneesh Kumar K.V

This patch add -EOPNOTSUPP as return from probe callback to

s/This patch add/Add/

No need to say "this patch" it's obviously a patch.

Quoted 4 lines

indicate we were not able to initialize a namespace due to pfn superblock feature/version mismatch. We want to consider this a probe success so that we can create new namesapce seed and there by avoid marking the failed namespace as the seed namespace.

Please replace usage of "we" with the exact agent involved as which "we" is being referred to gets confusing for the reader.

i.e. "indicate that the pmem driver was not..." "The nvdimm core wants to consider this...".

Quoted 12 lines
---
 drivers/nvdimm/bus.c  |  2 +-
 drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/nvdimm/bus.c +0 -0
index 798c5c4aea9c..16c35e6446a7 100644

drivers/nvdimm/bus.c static int nvdimm_bus_probe(struct device *dev) · line 99

Quoted 6 lines
drivers/nvdimm/bus.c +1 -1
@@ -95,7 +95,7 @@ static int nvdimm_bus_probe(struct device *dev)
        rc = nd_drv->probe(dev);
        debug_nvdimm_unlock(dev);
 
-       if (rc == 0)
+       if (rc == 0 || rc == -EOPNOTSUPP)
                nd_region_probe_success(nvdimm_bus, dev);

This now makes the nd_region_probe_success() helper obviously misnamed since it now wants to take actions on non-probe success. I attached a lead-in cleanup that you can pull into your series that renames that routine to nd_region_advance_seeds().

When you rebase this needs a comment about why EOPNOTSUPP has special handling.

Quoted 15 lines
drivers/nvdimm/bus.c +0 -0
        else
                nd_region_disable(nvdimm_bus, dev);
drivers/nvdimm/pmem.c +1 -0
index 4c121dd03dd9..3f498881dd28 100644
@@ -490,6 +490,7 @@ static int pmem_attach_disk(struct device *dev,
 
 static int nd_pmem_probe(struct device *dev)
 {
+       int ret;
        struct nd_namespace_common *ndns;
 
        ndns = nvdimm_namespace_common_probe(dev);

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 510

Quoted 6 lines
drivers/nvdimm/pmem.c +0 -3
@@ -505,12 +506,29 @@ static int nd_pmem_probe(struct device *dev)
        if (is_nd_pfn(dev))
                return pmem_attach_disk(dev, ndns);
 
-       /* if we find a valid info-block we'll come back as that personality */
-       if (nd_btt_probe(dev, ndns) == 0 || nd_pfn_probe(dev, ndns) == 0
-                       || nd_dax_probe(dev, ndns) == 0)

Similar need for an updated comment here to explain the special translation of error codes.

drivers/nvdimm/pmem.c static int nd_pmem_probe(struct device *dev) · line 512

Quoted 4 lines
drivers/nvdimm/pmem.c +3 -0
+       ret = nd_btt_probe(dev, ndns);
+       if (ret == 0)
                return -ENXIO;
+       else if (ret == -EOPNOTSUPP)

Are there cases where the btt driver needs to return EOPNOTSUPP? I'd otherwise like to keep this special casing constrained to the pfn / dax info block cases.

Quoted 6 lines
Quoted 3 lines

In fact I think EOPNOTSUPP is only something that the device-dax case would be concerned with because that's the only interface that attempts to guarantee a given mapping granularity.

We need to do similar error handling w.r.t fsdax when the pfn superblock indicates different PAGE_SIZE and struct page size?

Only in the case where PAGE_SIZE is less than the pfn superblock page size, the memmap is stored on pmem, and the reservation is too small. Otherwise the PAGE_SIZE difference does not matter in practice for the fsdax case... unless I'm overlooking another failure case?

Quoted 2 lines

I don't think btt
needs to support EOPNOTSUPP. But we can keep it for consistency?

That's not a sufficient argument in my mind. The comment about why EOPNOTSUPP is treated specially should have a note about the known usages, and since there is no BTT case for it lets leave it out.

#13 lore raw

Re: [PATCH v5 3/4] mm/nvdimm: Use correct #defines instead of open coding

In reply to Aneesh Kumar K.V
Quoted 59 lines · Aneesh Kumar K.V
Quoted 6 lines · Aneesh Kumar K.V
Quoted 4 lines · Dan Williams
Quoted 1 line · Aneesh Kumar K.V

...

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
drivers/nvdimm/pfn_devs.c +0 -0
index 37e96811c2fc..c1d9be609322 100644
@@ -725,7 +725,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
                 * when populating the vmemmap. This *should* be equal to
Quoted 8 lines

drivers/nvdimm/pfn_devs.c static int nd_pfn_init(struct nd_pfn *nd_pfn) · line 728

Quoted 4 lines
drivers/nvdimm/pfn_devs.c +1 -1
                 * PMD_SIZE for most architectures.
                 */
-               offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
+               offset = ALIGN(start + SZ_8K + sizeof(struct page) * npfns,

I'd prefer if this was not dynamic and was instead set to the maximum size of 'struct page' across all archs just to enhance cross-arch compatibility. I think that answer is '64'.

Quoted 7 lines

That still doesn't take care of the case where we add new elements to struct page later. If we have struct page size changing across architectures, we should still be ok as long as new size is less than what is stored in pfn superblock? I understand the desire to keep it non-dynamic. But we also need to make sure we don't reserve less space when creating a new namespace on a config that got struct page size > 64?

How about

libnvdimm/pfn_dev: Add a build check to make sure we notice when struct page size change

When namespace is created with map device as pmem device, struct page is stored in the reserve block area. We need to make sure we account for the right struct page size while doing this. Instead of directly depending on sizeof(struct page) which can change based on different kernel config option, use the max struct page size (64) while calculating the reserve block area. This makes sure pmem device can be used across kernels built with different configs.

If the above assumption of max struct page size change, we need to update the reserve block allocation space for new namespaces created.

1 file changed, 7 insertions(+)

drivers/nvdimm/pfn_devs.c | 7 +++++++

modified drivers/nvdimm/pfn_devs.c

(quoted diff) +0 -0
@@ -722,7 +722,14 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
                 * The altmap should be padded out to the block size used

Review static int nd_pfn_init(struct nd_pfn *nd_pfn) · line 732

Quoted 10 lines
(quoted diff) +7 -0
                 * when populating the vmemmap. This *should* be equal to
                 * PMD_SIZE for most architectures.
+                *
+                * Also make sure size of struct page is less than 64. We
+                * want to make sure we use large enough size here so that
+                * we don't have a dynamic reserve space depending on
+                * struct page size. But we also want to make sure we notice
+                * if we end up adding new elements to struct page.
                 */
+               BUILD_BUG_ON(64 < sizeof(struct page));

Looks ok to me. There are ongoing heroic efforts to make sure 'struct page' does not grown beyond the size of cacheline. The fact that 'struct page_ext' is allocated out of line makes it safe to assume that 'struct page' will not be growing larger in the foreseeable future.