Skip to contentSkip to conversation

PMEM device emulation without nfit depenency

RFC Superseded Santosh Sivaraj 2 participants 10 messages Nov 8, 2020 – Dec 9, 2020 libnvdimm: non-volatile memory device

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover PMEM device emulation without nfit depenency

The current test module cannot be used for testing platforms (make check) that do not have support for NFIT. In order to get the ndctl tests working, we need a module which can emulate NVDIMM devices without relying on ACPI/NFIT.

The emulated PMEM device is made part of the PAPR family.

Corresponding changes for ndctl is also required, to add attributes needed for the test, which will be sent as a reply to this patch.

The following is the test result, run on a x86 guest:

PASS: libndctl
PASS: dsm-fail
PASS: dpa-alloc
PASS: parent-uuid
PASS: multi-pmem
PASS: create.sh
FAIL: clear.sh
FAIL: pmem-errors.sh
FAIL: daxdev-errors.sh
PASS: multi-dax.sh
PASS: btt-check.sh
FAIL: label-compat.sh
PASS: blk-exhaust.sh
PASS: sector-mode.sh
FAIL: inject-error.sh
SKIP: btt-errors.sh
PASS: hugetlb
PASS: btt-pad-compat.sh
SKIP: firmware-update.sh
FAIL: ack-shutdown-count-set
PASS: rescan-partitions.sh
FAIL: inject-smart.sh
FAIL: monitor.sh
PASS: max_available_extent_ns.sh
FAIL: pfn-meta-errors.sh
PASS: track-uuid.sh
============================================================================
Testsuite summary for ndctl 70.6.ge117f22
============================================================================
# TOTAL: 26
# PASS: 15
# SKIP: 2
# XFAIL: 0
# FAIL: 9
# XPASS: 0
# ERROR: 0

The following is the test result from a PowerPC 64 guest.

PASS: libndctl
PASS: dsm-fail
PASS: dpa-alloc
PASS: parent-uuid
PASS: multi-pmem
PASS: create.sh
FAIL: clear.sh
FAIL: pmem-errors.sh
FAIL: daxdev-errors.sh
PASS: multi-dax.sh
PASS: btt-check.sh
FAIL: label-compat.sh
PASS: blk-exhaust.sh
PASS: sector-mode.sh
FAIL: inject-error.sh
SKIP: btt-errors.sh
SKIP: hugetlb
PASS: btt-pad-compat.sh
SKIP: firmware-update.sh
FAIL: ack-shutdown-count-set
PASS: rescan-partitions.sh
FAIL: inject-smart.sh
FAIL: monitor.sh
PASS: max_available_extent_ns.sh
FAIL: pfn-meta-errors.sh
PASS: track-uuid.sh
============================================================================
Testsuite summary for ndctl 70.gite29f6c57
============================================================================
# TOTAL: 26
# PASS: 14
# SKIP: 3
# XFAIL: 0
# FAIL: 9
# XPASS: 0
# ERROR: 0

Error injection tests and SMART are not yet implemented. To run the tests disable CONFIG_ACPI_NFIT, the kernel will pick the new driver.

Santosh Sivaraj (1):
testing/nvdimm: Add test module for non-nfit platforms

 drivers/nvdimm/region_devs.c        |    5 +
 tools/testing/nvdimm/config_check.c |    3 +-
 tools/testing/nvdimm/test/Kbuild    |    6 +-
 tools/testing/nvdimm/test/ndtest.c  | 1174 +++++++++++++++++++++++++++
 tools/testing/nvdimm/test/ndtest.h  |   84 ++
 5 files changed, 1270 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw

RFC v4 1/1 testing/nvdimm: Add test module for non-nfit platforms

The current test module cannot be used for testing platforms (make check) that do not have support for NFIT. In order to get the ndctl tests working, we need a module which can emulate NVDIMM devices without relying on ACPI/NFIT.

The aim of this proposed module is to implement a similar functionality to the existing module but without the ACPI dependencies.

---
 drivers/nvdimm/bus.c                |    1 +
 drivers/nvdimm/region_devs.c        |    5 +
 tools/testing/nvdimm/config_check.c |    3 +-
 tools/testing/nvdimm/test/Kbuild    |    6 +-
 tools/testing/nvdimm/test/ndtest.c  | 1168 +++++++++++++++++++++++++++
 tools/testing/nvdimm/test/ndtest.h  |   84 ++
 6 files changed, 1265 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h
drivers/nvdimm/bus.c +1 -0
index 09087c38fabd..c8f4bb708ead 100644
@@ -382,6 +382,7 @@ void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus)
 {
 	if (!nvdimm_bus)
 		return;
+
 	device_unregister(&nvdimm_bus->dev);
 }
 EXPORT_SYMBOL_GPL(nvdimm_bus_unregister);
drivers/nvdimm/region_devs.c +5 -0
index c3237c2b03a6..ba7dcc0fc25c 100644
@@ -1128,6 +1128,11 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
 	dev->type = dev_type;
 	dev->groups = ndr_desc->attr_groups;
 	dev->of_node = ndr_desc->of_node;
+	if (!ndr_desc->res) {
+		pr_err("region%d: Resource is NULL\n", nd_region->id);
+		dump_stack();
+		return NULL;
+	}
 	nd_region->ndr_size = resource_size(ndr_desc->res);
 	nd_region->ndr_start = ndr_desc->res->start;
 	nd_region->align = default_align(nd_region);
tools/testing/nvdimm/config_check.c +2 -1
index cac891028cd1..3e3a5f518864 100644
@@ -12,7 +12,8 @@ void check(void)
 	BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_BTT));
 	BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_PFN));
 	BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_BLK));
-	BUILD_BUG_ON(!IS_MODULE(CONFIG_ACPI_NFIT));
+	if (IS_ENABLED(CONFIG_ACPI_NFIT))
+		BUILD_BUG_ON(!IS_MODULE(CONFIG_ACPI_NFIT));
 	BUILD_BUG_ON(!IS_MODULE(CONFIG_DEV_DAX));
 	BUILD_BUG_ON(!IS_MODULE(CONFIG_DEV_DAX_PMEM));
 }
tools/testing/nvdimm/test/Kbuild +5 -1
index 75baebf8f4ba..197bcb2b7f35 100644
@@ -5,5 +5,9 @@ ccflags-y += -I$(srctree)/drivers/acpi/nfit/
 obj-m += nfit_test.o
 obj-m += nfit_test_iomap.o
 
-nfit_test-y := nfit.o
+ifeq  ($(CONFIG_ACPI_NFIT),m)
+	nfit_test-y := nfit.o
+else
+	nfit_test-y := ndtest.o
+endif
 nfit_test_iomap-y := iomap.o
tools/testing/nvdimm/test/ndtest.c new file +1168 -0

1,168 lines not on this page · raw message

tools/testing/nvdimm/test/ndtest.h new file +84 -0

84 lines not on this page · raw message

Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#2 lore raw

RFC v4 1/3 libndctl: test enablement for non-nfit devices

In reply to Santosh Sivaraj

Don't fail is nfit module is missing, this will happen in platforms that don't have ACPI support. Add attributes to PAPR dimm family that are independent of platforms like the test dimms.

---
 ndctl/lib/libndctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
 test/core.c          |  6 +++++
 2 files changed, 58 insertions(+)
ndctl/lib/libndctl.c +52 -0
index ad521d3..d1f8e4e 100644
@@ -1655,6 +1655,54 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
 static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
 static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias);
 
+static void populate_dimm_attributes(struct ndctl_dimm *dimm,
+				     const char *dimm_base)
+{
+	char buf[SYSFS_ATTR_SIZE];
+	struct ndctl_ctx *ctx = dimm->bus->ctx;
+	char *path = calloc(1, strlen(dimm_base) + 100);
+
+	sprintf(path, "%s/phys_id", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		goto err_read;
+	dimm->phys_id = strtoul(buf, NULL, 0);
+
+	sprintf(path, "%s/handle", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		goto err_read;
+	dimm->handle = strtoul(buf, NULL, 0);
+
+	sprintf(path, "%s/vendor", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0)
+		dimm->vendor_id = strtoul(buf, NULL, 0);
+
+	sprintf(path, "%s/id", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0) {
+		unsigned int b[9];
+
+		dimm->unique_id = strdup(buf);
+		if (!dimm->unique_id)
+			goto err_read;
+		if (sscanf(dimm->unique_id, "%02x%02x-%02x-%02x%02x-%02x%02x%02x%02x",
+					&b[0], &b[1], &b[2], &b[3], &b[4],
+					&b[5], &b[6], &b[7], &b[8]) == 9) {
+			dimm->manufacturing_date = b[3] << 8 | b[4];
+			dimm->manufacturing_location = b[2];
+		}
+	}
+	sprintf(path, "%s/subsystem_vendor", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0)
+		dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
+
+
+	sprintf(path, "%s/dirty_shutdown", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0)
+		dimm->dirty_shutdown = strtoll(buf, NULL, 0);
+
+err_read:
+	free(path);
+}
+
 static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
 {
 	int rc = -ENODEV;
@@ -1685,6 +1733,10 @@ static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
 		rc = 0;
 	}
 
+	/* add the available dimm attributes, the platform can override or add
+	 * additional attributes later */
+	populate_dimm_attributes(dimm, dimm_base);
+
 	free(path);
 	return rc;
 }
test/core.c +6 -0
index 5118d86..0fd1011 100644
@@ -195,6 +195,12 @@ retry:
 
 		path = kmod_module_get_path(*mod);
 		if (!path) {
+			/* For non-nfit platforms it's ok if nfit module is
+			 * missing */
+			if (strcmp(name, "nfit") == 0 ||
+			    strcmp(name, "nd_e820") == 0)
+				continue;
+
 			log_err(&log_ctx, "%s.ko: failed to get path\n", name);
 			break;
 		}
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#3 lore raw

RFC v4 2/3 Skip smart tests when non nfit devices present

---
 ndctl/lib/libndctl.c | 34 ++++++++++++++++++++++++++--------
 test/libndctl.c      |  3 ++-
 2 files changed, 28 insertions(+), 9 deletions(-)
ndctl/lib/libndctl.c +26 -8
index d1f8e4e..26fc14c 100644
@@ -815,8 +815,11 @@ static void parse_papr_flags(struct ndctl_dimm *dimm, char *flags)
 			dimm->flags.f_restore = 1;
 		else if (strcmp(start, "smart_notify") == 0)
 			dimm->flags.f_smart = 1;
+		else if (strcmp(start, "save_fail") == 0)
+			dimm->flags.f_save = 1;
 		start = end + 1;
 	}
+
 	if (end != start)
 		dbg(ctx, "%s: Flags:%s\n", ndctl_dimm_get_devname(dimm), flags);
 }
@@ -1044,7 +1047,8 @@ NDCTL_EXPORT int ndctl_bus_is_papr_scm(struct ndctl_bus *bus)
 	if (sysfs_read_attr(bus->ctx, bus->bus_buf, buf) < 0)
 		return 0;
 
-	return (strcmp(buf, "ibm,pmemory") == 0);
+	return (strcmp(buf, "ibm,pmemory") == 0 ||
+		strcmp(buf, "nvdimm_test") == 0);
 }
 
 /**
@@ -1661,6 +1665,7 @@ static void populate_dimm_attributes(struct ndctl_dimm *dimm,
 	char buf[SYSFS_ATTR_SIZE];
 	struct ndctl_ctx *ctx = dimm->bus->ctx;
 	char *path = calloc(1, strlen(dimm_base) + 100);
+	int i;
 
 	sprintf(path, "%s/phys_id", dimm_base);
 	if (sysfs_read_attr(ctx, path, buf) < 0)
@@ -1690,6 +1695,16 @@ static void populate_dimm_attributes(struct ndctl_dimm *dimm,
 			dimm->manufacturing_location = b[2];
 		}
 	}
+
+	sprintf(path, "%s/format", dimm_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0)
+		dimm->format[0] = strtoul(buf, NULL, 0);
+	for (i = 1; i < dimm->formats; i++) {
+		sprintf(path, "%s/format%d", dimm_base, i);
+		if (sysfs_read_attr(ctx, path, buf) == 0)
+			dimm->format[i] = strtoul(buf, NULL, 0);
+	}
+
 	sprintf(path, "%s/subsystem_vendor", dimm_base);
 	if (sysfs_read_attr(ctx, path, buf) == 0)
 		dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
@@ -1853,7 +1868,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
 	if (!path)
 		return NULL;
 
-	sprintf(path, "%s/nfit/formats", dimm_base);
+	sprintf(path, "%s%s/formats", dimm_base,
+		ndctl_bus_has_nfit(bus) ? "/nfit" : "");
 	if (sysfs_read_attr(ctx, path, buf) < 0)
 		formats = 1;
 	else
@@ -1927,9 +1943,9 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
 	else
 		dimm->fwa_result = fwa_result_to_result(buf);
 
+	dimm->formats = formats;
 	/* Check if the given dimm supports nfit */
 	if (ndctl_bus_has_nfit(bus)) {
-		dimm->formats = formats;
 		rc = add_nfit_dimm(dimm, dimm_base);
 	} else if (ndctl_bus_has_of_node(bus)) {
 		rc = add_papr_dimm(dimm, dimm_base);
@@ -2592,13 +2608,15 @@ static void *add_region(void *parent, int id, const char *region_base)
 		goto err_read;
 	region->num_mappings = strtoul(buf, NULL, 0);
 
-	sprintf(path, "%s/nfit/range_index", region_base);
-	if (ndctl_bus_has_nfit(bus)) {
-		if (sysfs_read_attr(ctx, path, buf) < 0)
+	sprintf(path, "%s%s/range_index", region_base,
+		ndctl_bus_has_nfit(bus) ? "/nfit" : "");
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
+		if (ndctl_bus_has_nfit(bus))
 			goto err_read;
-		region->range_index = strtoul(buf, NULL, 0);
+		else
+			region->range_index = -1;
 	} else
-		region->range_index = -1;
+		region->range_index = strtoul(buf, NULL, 0);
 
 	sprintf(path, "%s/read_only", region_base);
 	if (sysfs_read_attr(ctx, path, buf) < 0)
test/libndctl.c +2 -1
index 994e0fa..b7e7b68 100644
@@ -2427,7 +2427,8 @@ static int check_commands(struct ndctl_bus *bus, struct ndctl_dimm *dimm,
 	 * The kernel did not start emulating v1.2 namespace spec smart data
 	 * until 4.9.
 	 */
-	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0)))
+	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0))
+	    || !ndctl_bus_has_nfit(bus))
 		dimm_commands &= ~((1 << ND_CMD_SMART)
 				| (1 << ND_CMD_SMART_THRESHOLD));
 
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#4 lore raw

Re: [ndctl RFC v4 2/3] Skip smart tests when non nfit devices present

Quoted 1 line · Santosh Sivaraj

-ENOCOMMITMESSAGE

Also this patch is doing more than just skipping SMART tests, which would have been noticed by writing a commit message, and which probably would have prompted those changes to move to their own patch... with their own commit message of course.

Quoted 43 lines
---
 ndctl/lib/libndctl.c | 34 ++++++++++++++++++++++++++--------
 test/libndctl.c      |  3 ++-
 2 files changed, 28 insertions(+), 9 deletions(-)
ndctl/lib/libndctl.c +6 -1
index d1f8e4e..26fc14c 100644
@@ -815,8 +815,11 @@ static void parse_papr_flags(struct ndctl_dimm *dimm, char *flags)
                        dimm->flags.f_restore = 1;
                else if (strcmp(start, "smart_notify") == 0)
                        dimm->flags.f_smart = 1;
+               else if (strcmp(start, "save_fail") == 0)
+                       dimm->flags.f_save = 1;
                start = end + 1;
        }
+
        if (end != start)
                dbg(ctx, "%s: Flags:%s\n", ndctl_dimm_get_devname(dimm), flags);
 }
@@ -1044,7 +1047,8 @@ NDCTL_EXPORT int ndctl_bus_is_papr_scm(struct ndctl_bus *bus)
        if (sysfs_read_attr(bus->ctx, bus->bus_buf, buf) < 0)
                return 0;
 
-       return (strcmp(buf, "ibm,pmemory") == 0);
+       return (strcmp(buf, "ibm,pmemory") == 0 ||
+               strcmp(buf, "nvdimm_test") == 0);
 }
 
 /**
@@ -1661,6 +1665,7 @@ static void populate_dimm_attributes(struct ndctl_dimm *dimm,
        char buf[SYSFS_ATTR_SIZE];
        struct ndctl_ctx *ctx = dimm->bus->ctx;
        char *path = calloc(1, strlen(dimm_base) + 100);
+       int i;
 
        sprintf(path, "%s/phys_id", dimm_base);
        if (sysfs_read_attr(ctx, path, buf) < 0)
@@ -1690,6 +1695,16 @@ static void populate_dimm_attributes(struct ndctl_dimm *dimm,
                        dimm->manufacturing_location = b[2];
                }

ndctl/lib/libndctl.c static void populate_dimm_attributes(struct ndctl_dimm *dimm, · line 1706

Quoted 10 lines
ndctl/lib/libndctl.c +9 -0
        }
+
+       sprintf(path, "%s/format", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->format[0] = strtoul(buf, NULL, 0);
+       for (i = 1; i < dimm->formats; i++) {
+               sprintf(path, "%s/format%d", dimm_base, i);
+               if (sysfs_read_attr(ctx, path, buf) == 0)
+                       dimm->format[i] = strtoul(buf, NULL, 0);
+       }

The "format" attribute is this strange artifact of the ACPI NFIT definition. You've already done the work to emulate it, but I wish I could have saved you from that diversion because I don't see the point for papr, especially just to make a unit test happy.

The "format" was related to a JEDEC designation IIRC, but it has no practical implication on the kernel or ndctl. It was only 3rd party management software that thought they needed this, but even then I think the justification was dubious.

Quoted 51 lines
ndctl/lib/libndctl.c +11 -7
+
        sprintf(path, "%s/subsystem_vendor", dimm_base);
        if (sysfs_read_attr(ctx, path, buf) == 0)
                dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
@@ -1853,7 +1868,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
        if (!path)
                return NULL;
 
-       sprintf(path, "%s/nfit/formats", dimm_base);
+       sprintf(path, "%s%s/formats", dimm_base,
+               ndctl_bus_has_nfit(bus) ? "/nfit" : "");
        if (sysfs_read_attr(ctx, path, buf) < 0)
                formats = 1;
        else
@@ -1927,9 +1943,9 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
        else
                dimm->fwa_result = fwa_result_to_result(buf);
 
+       dimm->formats = formats;
        /* Check if the given dimm supports nfit */
        if (ndctl_bus_has_nfit(bus)) {
-               dimm->formats = formats;
                rc = add_nfit_dimm(dimm, dimm_base);
        } else if (ndctl_bus_has_of_node(bus)) {
                rc = add_papr_dimm(dimm, dimm_base);
@@ -2592,13 +2608,15 @@ static void *add_region(void *parent, int id, const char *region_base)
                goto err_read;
        region->num_mappings = strtoul(buf, NULL, 0);
 
-       sprintf(path, "%s/nfit/range_index", region_base);
-       if (ndctl_bus_has_nfit(bus)) {
-               if (sysfs_read_attr(ctx, path, buf) < 0)
+       sprintf(path, "%s%s/range_index", region_base,
+               ndctl_bus_has_nfit(bus) ? "/nfit" : "");
+       if (sysfs_read_attr(ctx, path, buf) < 0) {
+               if (ndctl_bus_has_nfit(bus))
                        goto err_read;
-               region->range_index = strtoul(buf, NULL, 0);
+               else
+                       region->range_index = -1;
        } else
-               region->range_index = -1;
+               region->range_index = strtoul(buf, NULL, 0);
 
        sprintf(path, "%s/read_only", region_base);
        if (sysfs_read_attr(ctx, path, buf) < 0)
test/libndctl.c +0 -0
index 994e0fa..b7e7b68 100644

test/libndctl.c static int check_commands(struct ndctl_bus *bus, struct ndctl_dimm *dimm, · line 2433

Quoted 8 lines
test/libndctl.c +2 -1
@@ -2427,7 +2427,8 @@ static int check_commands(struct ndctl_bus *bus, struct ndctl_dimm *dimm,
         * The kernel did not start emulating v1.2 namespace spec smart data
         * until 4.9.
         */
-       if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0)))
+       if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0))
+           || !ndctl_bus_has_nfit(bus))
                dimm_commands &= ~((1 << ND_CMD_SMART)
                                | (1 << ND_CMD_SMART_THRESHOLD));

I was going to say split test/libndctl.c into a generic test and and nfit-specific test/libndctl-nfit.c, but if the vast majority of the tests runs with just small tweaks like this I think I can do that refactoring later.
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]

#5 lore raw

RFC v4 3/3 Use page size as alignment value

In reply to Santosh Sivaraj
---
 test/dpa-alloc.c    | 23 ++++++++++++++---------
 test/multi-dax.sh   |  6 ++++--
 test/sector-mode.sh |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)
test/dpa-alloc.c +14 -9
index b757b9a..dff9b62 100644
@@ -48,12 +48,13 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	struct ndctl_region *region, *blk_region = NULL;
 	struct ndctl_namespace *ndns;
 	struct ndctl_dimm *dimm;
-	unsigned long size;
+	unsigned long size, page_size;
 	struct ndctl_bus *bus;
 	char uuid_str[40];
 	int round;
 	int rc;
 
+	page_size = sysconf(_SC_PAGESIZE);
 	/* disable nfit_test.1, not used in this test */
 	bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
 	if (!bus)
@@ -134,11 +135,11 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 			return rc;
 		}
 		ndctl_namespace_disable_invalidate(ndns);
-		rc = ndctl_namespace_set_size(ndns, SZ_4K);
+		rc = ndctl_namespace_set_size(ndns, page_size);
 		if (rc) {
-			fprintf(stderr, "failed to init %s to size: %d\n",
+			fprintf(stderr, "failed to init %s to size: %lu\n",
 					ndctl_namespace_get_devname(ndns),
-					SZ_4K);
+					page_size);
 			return rc;
 		}
 		namespaces[i].ndns = ndns;
@@ -160,7 +161,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
 		if (i % ARRAY_SIZE(namespaces) == 0)
 			round++;
-		size = SZ_4K * round;
+		size = page_size * round;
 		rc = ndctl_namespace_set_size(ndns, size);
 		if (rc) {
 			fprintf(stderr, "%s: set_size: %lx failed: %d\n",
@@ -176,7 +177,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	i--;
 	round++;
 	ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
-	size = SZ_4K * round;
+	size = page_size * round;
 	rc = ndctl_namespace_set_size(ndns, size);
 	if (rc) {
 		fprintf(stderr, "%s failed to update while labels full\n",
@@ -185,7 +186,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	}
 
 	round--;
-	size = SZ_4K * round;
+	size = page_size * round;
 	rc = ndctl_namespace_set_size(ndns, size);
 	if (rc) {
 		fprintf(stderr, "%s failed to reduce size while labels full\n",
@@ -279,8 +280,12 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 
 	available_slots = ndctl_dimm_get_available_labels(dimm);
 	if (available_slots != default_available_slots - 1) {
-		fprintf(stderr, "mishandled slot count\n");
-		return -ENXIO;
+		fprintf(stderr, "mishandled slot count (%u, %u)\n",
+			available_slots, default_available_slots - 1);
+
+		/* TODO: fix it on non-acpi platforms */
+		if (ndctl_bus_has_nfit(bus))
+			return -ENXIO;
 	}
 
 	ndctl_region_foreach(bus, region)
test/multi-dax.sh +4 -2
index 110ba3d..8250128 100755
@@ -21,6 +21,8 @@ check_min_kver "4.13" || do_skip "may lack multi-dax support"
 
 trap 'err $LINENO' ERR
 
+ALIGN_SIZE=`getconf PAGESIZE`
+
 # setup (reset nfit_test dimms)
 modprobe nfit_test
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
@@ -31,9 +33,9 @@ rc=1
 query=". | sort_by(.available_size) | reverse | .[0].dev"
 region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query")
 
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
 chardev1=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
 chardev2=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
 
 _cleanup
test/sector-mode.sh +3 -1
index eef8dc6..cee0313 100755
@@ -18,6 +18,8 @@ rc=77
 set -e
 trap 'err $LINENO' ERR
 
+ALIGN_SIZE=`getconf PAGESIZE`
+
 # setup (reset nfit_test dimms)
 modprobe nfit_test
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
@@ -34,7 +36,7 @@ NAMESPACE=$($NDCTL list -b $NFIT_TEST_BUS1 -N | jq -r "$query")
 REGION=$($NDCTL list -R --namespace=$NAMESPACE | jq -r "(.[]) | .dev")
 echo 0 > /sys/bus/nd/devices/$REGION/read_only
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
-$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a 4K
+$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a $ALIGN_SIZE
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
 
 _cleanup
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#6 lore raw

Re: [ndctl RFC v4 3/3] Use page size as alignment value

Quoted 1 line · Santosh Sivaraj

-ENOCOMMITMESSAGE

...I can guess why this is needed, but I'd rather not guess.

Otherwise, looks ok to me.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#7 lore raw

Re: [ndctl RFC v4 1/3] libndctl: test enablement for non-nfit devices

In reply to Santosh Sivaraj
Quoted 53 lines · Santosh Sivaraj

Don't fail is nfit module is missing, this will happen in platforms that don't have ACPI support. Add attributes to PAPR dimm family that are independent of platforms like the test dimms.

---
 ndctl/lib/libndctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
 test/core.c          |  6 +++++
 2 files changed, 58 insertions(+)
ndctl/lib/libndctl.c +33 -0
index ad521d3..d1f8e4e 100644
@@ -1655,6 +1655,54 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
 static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
 static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias);
 
+static void populate_dimm_attributes(struct ndctl_dimm *dimm,
+                                    const char *dimm_base)
+{
+       char buf[SYSFS_ATTR_SIZE];
+       struct ndctl_ctx *ctx = dimm->bus->ctx;
+       char *path = calloc(1, strlen(dimm_base) + 100);
+
+       sprintf(path, "%s/phys_id", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) < 0)
+               goto err_read;
+       dimm->phys_id = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/handle", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) < 0)
+               goto err_read;
+       dimm->handle = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/vendor", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->vendor_id = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/id", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0) {
+               unsigned int b[9];
+
+               dimm->unique_id = strdup(buf);
+               if (!dimm->unique_id)
+                       goto err_read;
+               if (sscanf(dimm->unique_id, "%02x%02x-%02x-%02x%02x-%02x%02x%02x%02x",
+                                       &b[0], &b[1], &b[2], &b[3], &b[4],
+                                       &b[5], &b[6], &b[7], &b[8]) == 9) {
+                       dimm->manufacturing_date = b[3] << 8 | b[4];
+                       dimm->manufacturing_location = b[2];

ndctl/lib/libndctl.c static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module, · line 1700

Quoted 10 lines
ndctl/lib/libndctl.c +10 -0
+               }
+       }
+       sprintf(path, "%s/subsystem_vendor", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
+
+
+       sprintf(path, "%s/dirty_shutdown", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->dirty_shutdown = strtoll(buf, NULL, 0);

These are fairly similar to the nfit ones... how about refactoring this into a routine that takes a bus prefix and shares it between "nfit" and "papr"...

We might also consider unifying them into a standard set of attributes that both the nfit-bus-provider and the papr-bus-provider export. I.e. that nfit was wrong to place them under nfit/ and they should have went somewhere generic from the beginning. The nfit compatibility can be done with symlinks to the new common location.

Quoted 24 lines
ndctl/lib/libndctl.c +9 -0
+
+err_read:
+       free(path);
+}
+
 static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
 {
        int rc = -ENODEV;
@@ -1685,6 +1733,10 @@ static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
                rc = 0;
        }
 
+       /* add the available dimm attributes, the platform can override or add
+        * additional attributes later */
+       populate_dimm_attributes(dimm, dimm_base);
+
        free(path);
        return rc;
 }
test/core.c +0 -0
index 5118d86..0fd1011 100644

test/core.c retry: · line 202

Quoted 8 lines
test/core.c +5 -0
@@ -195,6 +195,12 @@ retry:
 
                path = kmod_module_get_path(*mod);
                if (!path) {
+                       /* For non-nfit platforms it's ok if nfit module is
+                        * missing */
+                       if (strcmp(name, "nfit") == 0 ||
+                           strcmp(name, "nd_e820") == 0)
+                               continue;

This breaks the safety it afforded on nfit platforms. Instead I think this needs a couple changes:

- rename nfit_test_init to ndctl_test_init
- add a parameter for whether the test is initializing for nfit_test.ko or ndtest.ko.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#8 lore raw

Re: [ndctl RFC v4 1/3] libndctl: test enablement for non-nfit devices

Quoted 111 lines · Dan Williams
Quoted 53 lines · Santosh Sivaraj

Don't fail is nfit module is missing, this will happen in platforms that don't have ACPI support. Add attributes to PAPR dimm family that are independent of platforms like the test dimms.

---
 ndctl/lib/libndctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
 test/core.c          |  6 +++++
 2 files changed, 58 insertions(+)
ndctl/lib/libndctl.c +33 -0
index ad521d3..d1f8e4e 100644
@@ -1655,6 +1655,54 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
 static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
 static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias);
 
+static void populate_dimm_attributes(struct ndctl_dimm *dimm,
+                                    const char *dimm_base)
+{
+       char buf[SYSFS_ATTR_SIZE];
+       struct ndctl_ctx *ctx = dimm->bus->ctx;
+       char *path = calloc(1, strlen(dimm_base) + 100);
+
+       sprintf(path, "%s/phys_id", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) < 0)
+               goto err_read;
+       dimm->phys_id = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/handle", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) < 0)
+               goto err_read;
+       dimm->handle = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/vendor", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->vendor_id = strtoul(buf, NULL, 0);
+
+       sprintf(path, "%s/id", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0) {
+               unsigned int b[9];
+
+               dimm->unique_id = strdup(buf);
+               if (!dimm->unique_id)
+                       goto err_read;
+               if (sscanf(dimm->unique_id, "%02x%02x-%02x-%02x%02x-%02x%02x%02x%02x",
+                                       &b[0], &b[1], &b[2], &b[3], &b[4],
+                                       &b[5], &b[6], &b[7], &b[8]) == 9) {
+                       dimm->manufacturing_date = b[3] << 8 | b[4];
+                       dimm->manufacturing_location = b[2];

ndctl/lib/libndctl.c static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module, · line 1700

Quoted 10 lines
ndctl/lib/libndctl.c +10 -0
+               }
+       }
+       sprintf(path, "%s/subsystem_vendor", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
+
+
+       sprintf(path, "%s/dirty_shutdown", dimm_base);
+       if (sysfs_read_attr(ctx, path, buf) == 0)
+               dimm->dirty_shutdown = strtoll(buf, NULL, 0);

These are fairly similar to the nfit ones... how about refactoring this into a routine that takes a bus prefix and shares it between "nfit" and "papr"...

We might also consider unifying them into a standard set of attributes that both the nfit-bus-provider and the papr-bus-provider export. I.e. that nfit was wrong to place them under nfit/ and they should have went somewhere generic from the beginning. The nfit compatibility can be done with symlinks to the new common location.

Quoted 24 lines
ndctl/lib/libndctl.c +9 -0
+
+err_read:
+       free(path);
+}
+
 static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
 {
        int rc = -ENODEV;
@@ -1685,6 +1733,10 @@ static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
                rc = 0;
        }
 
+       /* add the available dimm attributes, the platform can override or add
+        * additional attributes later */
+       populate_dimm_attributes(dimm, dimm_base);
+
        free(path);
        return rc;
 }
test/core.c +0 -0
index 5118d86..0fd1011 100644

test/core.c retry: · line 202

Quoted 8 lines
test/core.c +5 -0
@@ -195,6 +195,12 @@ retry:
 
                path = kmod_module_get_path(*mod);
                if (!path) {
+                       /* For non-nfit platforms it's ok if nfit module is
+                        * missing */
+                       if (strcmp(name, "nfit") == 0 ||
+                           strcmp(name, "nd_e820") == 0)
+                               continue;

This breaks the safety it afforded on nfit platforms. Instead I think this needs a couple changes:

Quoted 3 lines

- rename nfit_test_init to ndctl_test_init
- add a parameter for whether the test is initializing for nfit_test.ko or ndtest.ko.

Thanks for review Dan. I will make changes accordingly and send newer version without -ENOCOMMITMESSAGE error.

Since I posted this only for the comments on the approach I took, I think I got how to proceed in terms on ndctl changes atleast. I will send a v5 soon enough.

Thanks,
Santosh
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#9 lore raw
In reply to Santosh Sivaraj
Quoted 6 lines · Santosh Sivaraj

The current test module cannot be used for testing platforms (make check) that do not have support for NFIT. In order to get the ndctl tests working, we need a module which can emulate NVDIMM devices without relying on ACPI/NFIT.

Quoted 6 lines

The emulated PMEM device is made part of the PAPR family.

Corresponding changes for ndctl is also required, to add attributes needed for the test, which will be sent as a reply to this patch.

The following is the test result, run on a x86 guest:

Just wanted to let you know I have not forgotten about this and will be circling back to review it soon. Apologies for the delay.
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]