[ndctl v2 3/4] inject-error: Remove assumptions on error injection support

2021-05-17 Thread Santosh Sivaraj
Currently the code assumes that only nfit supports error injection,
remove those assumptions before error injection support for PAPR is
added. Add bus operations similar to that of DIMM operations with
injection operations in it.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/inject.c   | 96 
 ndctl/lib/libndctl.c | 11 +++--
 ndctl/lib/nfit.c | 20 +
 ndctl/lib/private.h  | 14 +++
 4 files changed, 85 insertions(+), 56 deletions(-)

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index d61c02c..35fd11e 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -6,19 +6,15 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "private.h"
 
 NDCTL_EXPORT int ndctl_bus_has_error_injection(struct ndctl_bus *bus)
 {
-   /* Currently, only nfit buses have error injection */
-   if (!bus || !ndctl_bus_has_nfit(bus))
+   if (!bus)
return 0;
 
-   if (ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_SET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_GET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_CLEAR))
+   if (bus->ops->err_inj_supported(bus))
return 1;
 
return 0;
@@ -151,7 +147,7 @@ static int ndctl_namespace_inject_one_error(struct 
ndctl_namespace *ndns,
length = clear_unit;
}
 
-   cmd = ndctl_bus_cmd_new_err_inj(bus);
+   cmd = bus->ops->new_err_inj(bus);
if (!cmd)
return -ENOMEM;
 
@@ -185,8 +181,6 @@ NDCTL_EXPORT int ndctl_namespace_inject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_inject_one_error(ndns, block + i, flags);
@@ -231,7 +225,7 @@ static int ndctl_namespace_uninject_one_error(struct 
ndctl_namespace *ndns,
length = clear_unit;
}
 
-   cmd = ndctl_bus_cmd_new_err_inj_clr(bus);
+   cmd = bus->ops->new_err_inj_clr(bus);
if (!cmd)
return -ENOMEM;
 
@@ -263,8 +257,6 @@ NDCTL_EXPORT int ndctl_namespace_uninject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_uninject_one_error(ndns, block + i,
@@ -445,51 +437,49 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct 
ndctl_namespace *ndns)
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
 
-   if (ndctl_bus_has_nfit(bus)) {
-   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
-   _size);
-   if (rc)
-   return rc;
+   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
+ _size);
+   if (rc)
+   return rc;
 
-   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
-   if (!cmd) {
-   err(ctx, "%s: failed to create cmd\n",
-   ndctl_namespace_get_devname(ndns));
-   return -ENOTTY;
-   }
-   rc = ndctl_cmd_submit(cmd);
-   if (rc < 0) {
-   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
-   goto out;
-   }
-   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
-   if (buf_size == 0) {
-   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
-   rc = -EINVAL;
-   goto out;
-   }
-   ndctl_cmd_unref(cmd);
+   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
+   if (!cmd) {
+   err(ctx, "%s: failed to create cmd\n",
+   ndctl_namespace_get_devname(ndns));
+   return -ENOTTY;
+   }
+   rc = ndctl_cmd_submit(cmd);
+   if (rc < 0) {
+   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
+   goto out;
+   }
+   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
+   if (buf_size == 0) {
+   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
+   rc = -EINVAL;
+   goto out;
+   }
+   ndctl_cmd_unref(cmd);
 
-   cmd = ndctl_bus_cmd_new_err_inj_stat(bus, buf_size);
-   if (!cmd)
-   return -ENOMEM;
+   cmd = bus->ops->new_err_inj_stat(bus, buf_size);
+   if (!cmd)
+   return -ENOMEM

[ndctl v2 4/4] Error injection support for PAPR

2021-05-17 Thread Santosh Sivaraj
Add support for error injection on PAPR family of devices. This is
particularly useful in running 'make check' on non-nfit platforms.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c  |   1 +
 ndctl/lib/papr.c  | 134 ++
 ndctl/lib/private.h   |   1 +
 ndctl/libndctl-papr.h |   7 +++
 4 files changed, 143 insertions(+)
 create mode 100644 ndctl/libndctl-papr.h

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 232c531..95cdc14 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -904,6 +904,7 @@ static void *add_bus(void *parent, int id, const char 
*ctl_base)
else {
bus->has_of_node = 1;
bus_name = "papr";
+   bus->ops = papr_bus_ops;
}
 
sprintf(path, "%s/device/%s/dsm_mask", ctl_base, bus_name);
diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c
index f94f8aa..6ac3d3e 100644
--- a/ndctl/lib/papr.c
+++ b/ndctl/lib/papr.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "papr.h"
 
@@ -38,6 +39,33 @@
 /* return the pdsm command */
 #define to_pdsm_cmd(C) ((enum papr_pdsm)to_ndcmd(C)->nd_command)
 
+/**
+ * ndctl_bus_is_papr_cmd_supported - check if command is supported on @bus.
+ * @bus: ndctl_bus instance
+ * @cmd: papr command number (defined as PAPR_PDSM_XXX in papr-pdsm.h)
+ *
+ * Return 1: command is supported. Return 0: command is not supported.
+ *
+ */
+NDCTL_EXPORT int ndctl_bus_is_papr_cmd_supported(struct ndctl_bus *bus,
+int cmd)
+{
+   return !!(bus->nfit_dsm_mask & (1ULL << cmd));
+}
+
+static int papr_is_errinj_supported(struct ndctl_bus *bus)
+{
+   if (!ndctl_bus_is_papr_scm(bus))
+   return 0;
+
+   if (ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_SET) &&
+   ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_CLEAR) &&
+   ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_GET))
+   return 1;
+
+   return 0;
+}
+
 static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd)
 {
/* Handle this separately to support monitor mode */
@@ -559,3 +587,109 @@ struct ndctl_dimm_ops * const papr_dimm_ops = &(struct 
ndctl_dimm_ops) {
= papr_cmd_smart_threshold_set_ctrl_temperature,
.smart_threshold_set_spares = papr_cmd_smart_threshold_set_spares,
 };
+
+static u32 bus_get_firmware_status(struct ndctl_cmd *cmd)
+{
+   struct nd_cmd_bus *cmd_bus = cmd->cmd_bus;
+
+   switch (cmd_bus->gen.nd_command) {
+   case PAPR_PDSM_INJECT_SET:
+   return cmd_bus->err_inj.status;
+   case PAPR_PDSM_INJECT_CLEAR:
+   return cmd_bus->err_inj_clr.status;
+   case PAPR_PDSM_INJECT_GET:
+   return cmd_bus->err_inj_stat.status;
+   }
+
+   return -1U;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj(struct ndctl_bus *bus)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+   struct ndctl_cmd *cmd;
+
+   cmd_length = sizeof(struct nd_cmd_ars_err_inj);
+   size = sizeof(*cmd) + sizeof(*pkg) + cmd_length;
+   cmd = calloc(1, size);
+   if (!cmd)
+   return NULL;
+
+   cmd->bus = bus;
+   ndctl_cmd_ref(cmd);
+   cmd->type = ND_CMD_CALL;
+   cmd->get_firmware_status = bus_get_firmware_status;
+   cmd->size = size;
+   cmd->status = 1;
+   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
+   pkg->nd_command = PAPR_PDSM_INJECT_SET;
+   pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj, status);
+   pkg->nd_size_out = cmd_length - pkg->nd_size_in;
+   pkg->nd_fw_size = pkg->nd_size_out;
+
+   return cmd;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj_clr(struct ndctl_bus *bus)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+   struct ndctl_cmd *cmd;
+
+   cmd_length = sizeof(struct nd_cmd_ars_err_inj_clr);
+   size = sizeof(*cmd) + sizeof(*pkg) + cmd_length;
+   cmd = calloc(1, size);
+   if (!cmd)
+   return NULL;
+
+   cmd->bus = bus;
+   ndctl_cmd_ref(cmd);
+   cmd->type = ND_CMD_CALL;
+   cmd->get_firmware_status = bus_get_firmware_status;
+   cmd->size = size;
+   cmd->status = 1;
+   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
+   pkg->nd_command = PAPR_PDSM_INJECT_CLEAR;
+   pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj_clr, status);
+   pkg->nd_size_out = cmd_length - pkg->nd_size_in;
+   pkg->nd_fw_size = pkg->nd_size_out;
+
+   return cmd;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj_stat(struct ndctl_bus *bus,
+   u32 buf_size)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+  

[ndctl v2 2/4] papr: ndtest: Enable smart test cases

2021-05-17 Thread Santosh Sivaraj
From: Shivaprasad G Bhat 

The patch implements all necessary smart APIs for the
ndtest kernel driver.

Both inject-smart.sh and monitor.sh tests pass with the patch.

Signed-off-by: Shivaprasad G Bhat 
---
 ndctl/lib/papr.c  | 313 ++
 ndctl/lib/papr.h  |   9 ++
 ndctl/lib/papr_pdsm.h |  50 ++-
 3 files changed, 371 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c
index 9c6f2f0..f94f8aa 100644
--- a/ndctl/lib/papr.c
+++ b/ndctl/lib/papr.c
@@ -165,6 +165,18 @@ static unsigned int papr_smart_get_flags(struct ndctl_cmd 
*cmd)
if (health.extension_flags & PDSM_DIMM_HEALTH_RUN_GAUGE_VALID)
flags |= ND_SMART_USED_VALID;
 
+   if (health.extension_flags & 
PDSM_DIMM_HEALTH_MEDIA_TEMPERATURE_VALID)
+   flags |= ND_SMART_MTEMP_VALID;
+
+   if (health.extension_flags & 
PDSM_DIMM_HEALTH_CTRL_TEMPERATURE_VALID)
+   flags |= ND_SMART_CTEMP_VALID;
+
+   if (health.extension_flags & PDSM_DIMM_HEALTH_SPARES_VALID)
+   flags |= ND_SMART_SPARES_VALID;
+
+   if (health.extension_flags & PDSM_DIMM_HEALTH_ALARM_VALID)
+   flags |= ND_SMART_ALARM_VALID;
+
return flags;
}
 
@@ -201,6 +213,26 @@ static unsigned int papr_smart_get_health(struct ndctl_cmd 
*cmd)
return  !health.dimm_health ? 0 : 1 << (health.dimm_health - 1);
 }
 
+static int papr_pdsm_health_set_threshold_valid(struct ndctl_cmd *cmd)
+{
+   if (!cmd_is_valid(cmd) ||
+   to_pdsm(cmd)->cmd_status != 0 ||
+   to_pdsm_cmd(cmd) != PAPR_PDSM_HEALTH_THRESHOLD_SET) {
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static unsigned int papr_cmd_smart_threshold_get_supported_alarms(
+   struct ndctl_cmd *cmd)
+{
+   if (papr_pdsm_health_set_threshold_valid(cmd) < 0)
+   return 0;
+   return ND_SMART_SPARE_TRIP | ND_SMART_MTEMP_TRIP
+   | ND_SMART_CTEMP_TRIP;
+}
+
 static unsigned int papr_smart_get_shutdown_state(struct ndctl_cmd *cmd)
 {
struct nd_papr_pdsm_health health;
@@ -218,6 +250,126 @@ static unsigned int papr_smart_get_shutdown_state(struct 
ndctl_cmd *cmd)
return health.dimm_bad_shutdown;
 }
 
+static int papr_smart_inject_supported(struct ndctl_dimm *dimm)
+{
+   struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm);
+
+   if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_CALL)) {
+   dbg(ctx, "unsupported cmd: %d\n", ND_CMD_CALL);
+   return -EOPNOTSUPP;
+   }
+
+   if (!test_dimm_dsm(dimm, PAPR_PDSM_HEALTH_INJECT)) {
+   dbg(ctx, "smart injection functions unsupported\n");
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int papr_smart_inject_valid(struct ndctl_cmd *cmd)
+{
+   if (cmd->type != ND_CMD_CALL ||
+   to_pdsm(cmd)->cmd_status != 0 ||
+   to_pdsm_cmd(cmd) != PAPR_PDSM_HEALTH_INJECT)
+   return -EINVAL;
+
+   return 0;
+}
+
+static int papr_cmd_smart_inject_media_temperature(struct ndctl_cmd *cmd,
+   bool enable, unsigned int mtemp)
+{
+   if (papr_smart_inject_valid(cmd) < 0)
+   return -EINVAL;
+
+   to_payload(cmd)->inject.flags |= ND_PAPR_SMART_INJECT_MTEMP;
+   to_payload(cmd)->inject.mtemp_enable = enable == true;
+   to_payload(cmd)->inject.media_temperature = mtemp;
+
+   return 0;
+}
+
+static int papr_cmd_smart_inject_ctrl_temperature(struct ndctl_cmd *cmd,
+   bool enable, unsigned int mtemp)
+{
+   if (papr_smart_inject_valid(cmd) < 0)
+   return -EINVAL;
+
+   to_payload(cmd)->inject.flags |= ND_PAPR_SMART_INJECT_MTEMP;
+   to_payload(cmd)->inject.ctemp_enable = enable == true;
+   to_payload(cmd)->inject.ctrl_temperature = mtemp;
+
+   return 0;
+}
+
+static int papr_cmd_smart_inject_spares(struct ndctl_cmd *cmd,
+   bool enable, unsigned int spares)
+{
+   if (papr_smart_inject_valid(cmd) < 0)
+   return -EINVAL;
+
+   to_payload(cmd)->inject.flags |= ND_PAPR_SMART_INJECT_SPARES;
+   to_payload(cmd)->inject.spares_enable = enable == true;
+   to_payload(cmd)->inject.spares = spares;
+
+   return 0;
+}
+
+static struct ndctl_cmd *papr_new_smart_inject(struct ndctl_dimm *dimm)
+{
+   struct ndctl_cmd *cmd;
+
+   cmd = allocate_cmd(dimm, PAPR_PDSM_HEALTH_INJECT,
+   sizeof(struct nd_papr_pdsm_health_inject));
+   if (!cmd)
+   return NULL;
+
+   return cmd;
+}
+
+static struct ndctl_cmd *papr_dimm_cmd_new_smart_set_threshold(
+   struct ndctl_cmd *threshold_cmd)
+{
+   struct ndctl_cmd *set_cmd;
+   struct nd_papr_pdsm_health_threshold thresh;
+
+   if (!cmd_is_valid(threshold_cmd) ||
+   to_pdsm(threshold_cmd)->cmd_status != 0 ||

[ndctl v2 1/4] libndctl: Rename dimm property nfit_dsm_mask for generic use

2021-05-17 Thread Santosh Sivaraj
From: Shivaprasad G Bhat 

The dimm specific dsm masks can be used by different platforms.
Rename it to dsm_mask to avoid confusion.

Signed-off-by: Shivaprasad G Bhat 
---
 ndctl/lib/libndctl.c | 4 ++--
 ndctl/lib/private.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

Resending both the SMART test and error injection patches as one series. Will be
easier for review and testing.

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index bf0968c..a148438 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1728,7 +1728,7 @@ static int populate_dimm_attributes(struct ndctl_dimm 
*dimm,
 
sprintf(path, "%s/%s/dsm_mask", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
-   dimm->nfit_dsm_mask = strtoul(buf, NULL, 0);
+   dimm->dsm_mask = strtoul(buf, NULL, 0);
 
sprintf(path, "%s/%s/format", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
@@ -1821,7 +1821,7 @@ static void *add_dimm(void *parent, int id, const char 
*dimm_base)
dimm->manufacturing_date = -1;
dimm->manufacturing_location = -1;
dimm->cmd_family = -1;
-   dimm->nfit_dsm_mask = ULONG_MAX;
+   dimm->dsm_mask = ULONG_MAX;
for (i = 0; i < formats; i++)
dimm->format[i] = -1;
 
diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h
index 8f4510e..53fae0f 100644
--- a/ndctl/lib/private.h
+++ b/ndctl/lib/private.h
@@ -68,7 +68,7 @@ struct ndctl_dimm {
unsigned char manufacturing_location;
unsigned long cmd_family;
unsigned long cmd_mask;
-   unsigned long nfit_dsm_mask;
+   unsigned long dsm_mask;
long long dirty_shutdown;
enum ndctl_fwa_state fwa_state;
enum ndctl_fwa_result fwa_result;
@@ -105,9 +105,9 @@ enum dsm_support {
 
 static inline enum dsm_support test_dimm_dsm(struct ndctl_dimm *dimm, int fn)
 {
-   if (dimm->nfit_dsm_mask == ULONG_MAX) {
+   if (dimm->dsm_mask == ULONG_MAX) {
return DIMM_DSM_UNKNOWN;
-   } else if (dimm->nfit_dsm_mask & (1 << fn))
+   } else if (dimm->dsm_mask & (1 << fn))
return DIMM_DSM_SUPPORTED;
return DIMM_DSM_UNSUPPORTED;
 }
-- 
2.31.1
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[v2 2/2] nvdimm/ndtest: Add support for error injection tests

2021-05-17 Thread Santosh Sivaraj
Add necessary support for error injection family of tests on non-acpi
platforms.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 455 -
 tools/testing/nvdimm/test/ndtest.h |  25 ++
 2 files changed, 477 insertions(+), 3 deletions(-)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index bb47b145466d..09d98317bf4e 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#define pr_fmt(fmt) "ndtest :" fmt
 
 #include 
 #include 
@@ -42,6 +42,7 @@ static DEFINE_SPINLOCK(ndtest_lock);
 static struct ndtest_priv *instances[NUM_INSTANCES];
 static struct class *ndtest_dimm_class;
 static struct gen_pool *ndtest_pool;
+static struct workqueue_struct *ndtest_wq;
 
 static const struct nd_papr_pdsm_health health_defaults = {
.dimm_unarmed = 0,
@@ -496,6 +497,139 @@ static int ndtest_pdsm_health_set_threshold(struct 
ndtest_dimm *dimm,
return 0;
 }
 
+static void ars_complete_all(struct ndtest_priv *p)
+{
+   int i;
+
+   for (i = 0; i < p->config->num_regions; i++) {
+   struct ndtest_region *region = >config->regions[i];
+
+   if (region->region)
+   nvdimm_region_notify(region->region,
+NVDIMM_REVALIDATE_POISON);
+   }
+}
+
+static void ndtest_scrub(struct work_struct *work)
+{
+   struct ndtest_priv *p = container_of(work, typeof(struct ndtest_priv),
+dwork.work);
+   struct badrange_entry *be;
+   int rc, i = 0;
+
+   spin_lock(>badrange.lock);
+   list_for_each_entry(be, >badrange.list, list) {
+   rc = nvdimm_bus_add_badrange(p->bus, be->start, be->length);
+   if (rc)
+   dev_err(>pdev.dev, "Failed to process ARS 
records\n");
+   else
+   i++;
+   }
+   spin_unlock(>badrange.lock);
+
+   if (i == 0) {
+   queue_delayed_work(ndtest_wq, >dwork, HZ);
+   return;
+   }
+
+   ars_complete_all(p);
+   p->scrub_count++;
+
+   mutex_lock(>ars_lock);
+   sysfs_notify_dirent(p->scrub_state);
+   clear_bit(ARS_BUSY, >scrub_flags);
+   clear_bit(ARS_POLL, >scrub_flags);
+   set_bit(ARS_VALID, >scrub_flags);
+   mutex_unlock(>ars_lock);
+
+}
+
+static int ndtest_scrub_notify(struct ndtest_priv *p)
+{
+   if (!test_and_set_bit(ARS_BUSY, >scrub_flags))
+   queue_delayed_work(ndtest_wq, >dwork, HZ);
+
+   return 0;
+}
+
+static int ndtest_ars_inject(struct ndtest_priv *p,
+struct nd_cmd_ars_err_inj *inj,
+unsigned int buf_len)
+{
+   int rc;
+
+   if (buf_len != sizeof(*inj)) {
+   dev_dbg(>bus->dev, "buflen: %u, inj size: %lu\n",
+   buf_len, sizeof(*inj));
+   rc = -EINVAL;
+   goto err;
+   }
+
+   rc =  badrange_add(>badrange, inj->err_inj_spa_range_base,
+  inj->err_inj_spa_range_length);
+
+   if (inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY))
+   ndtest_scrub_notify(p);
+
+   inj->status = 0;
+
+   return 0;
+
+err:
+   inj->status = NFIT_ARS_INJECT_INVALID;
+   return rc;
+}
+
+static int ndtest_ars_inject_clear(struct ndtest_priv *p,
+  struct nd_cmd_ars_err_inj_clr *inj,
+  unsigned int buf_len)
+{
+   int rc;
+
+   if (buf_len != sizeof(*inj)) {
+   rc = -EINVAL;
+   goto err;
+   }
+
+   if (inj->err_inj_clr_spa_range_length <= 0) {
+   rc = -EINVAL;
+   goto err;
+   }
+
+   badrange_forget(>badrange, inj->err_inj_clr_spa_range_base,
+   inj->err_inj_clr_spa_range_length);
+
+   inj->status = 0;
+   return 0;
+
+err:
+   inj->status = NFIT_ARS_INJECT_INVALID;
+   return rc;
+}
+
+static int ndtest_ars_inject_status(struct ndtest_priv *p,
+   struct nd_cmd_ars_err_inj_stat *stat,
+   unsigned int buf_len)
+{
+   struct badrange_entry *be;
+   int max = SZ_4K / sizeof(struct nd_error_stat_query_record);
+   int i = 0;
+
+   stat->status = 0;
+   spin_lock(>badrange.lock);
+   list_for_each_entry(be, >badrange.list, list) {
+   stat->record[i].err_inj_stat_spa_range_base = be->start;
+   stat->record[i].err_inj_stat_spa_range_length = be->length;
+   i++;
+   if (

[v2 1/2] tests/nvdimm/ndtest: Enable smart tests

2021-05-17 Thread Santosh Sivaraj
From: Shivaprasad G Bhat 

The patch adds necessary health related dsm command implementations for
the ndctl inject-smart and monitor tests to pass.

Signed-off-by: Shivaprasad G Bhat 
---
 tools/testing/nvdimm/test/ndtest.c | 258 +
 tools/testing/nvdimm/test/ndtest.h | 129 +++
 2 files changed, 387 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 6862915f1fb0..bb47b145466d 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -30,6 +30,8 @@ enum {
((1ul << ND_CMD_GET_CONFIG_SIZE) | \
 (1ul << ND_CMD_GET_CONFIG_DATA) | \
 (1ul << ND_CMD_SET_CONFIG_DATA) | \
+(1ul << ND_CMD_SMART_THRESHOLD) | \
+(1uL << ND_CMD_SMART)   | \
 (1ul << ND_CMD_CALL))
 
 #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm)
\
@@ -41,6 +43,21 @@ static struct ndtest_priv *instances[NUM_INSTANCES];
 static struct class *ndtest_dimm_class;
 static struct gen_pool *ndtest_pool;
 
+static const struct nd_papr_pdsm_health health_defaults = {
+   .dimm_unarmed = 0,
+   .dimm_bad_shutdown = 0,
+   .dimm_health = PAPR_PDSM_DIMM_UNHEALTHY,
+   .extension_flags = PDSM_DIMM_HEALTH_MEDIA_TEMPERATURE_VALID | 
PDSM_DIMM_HEALTH_ALARM_VALID |
+  PDSM_DIMM_HEALTH_CTRL_TEMPERATURE_VALID | 
PDSM_DIMM_HEALTH_SPARES_VALID |
+  PDSM_DIMM_HEALTH_RUN_GAUGE_VALID,
+   .dimm_fuel_gauge = 95,
+   .media_temperature = 23 * 16,
+   .ctrl_temperature = 25 * 16,
+   .spares = 75,
+   .alarm_flags = ND_PAPR_HEALTH_SPARE_TRIP |
+   ND_PAPR_HEALTH_TEMP_TRIP,
+};
+
 static struct ndtest_dimm dimm_group1[] = {
{
.size = DIMM_SIZE,
@@ -48,6 +65,16 @@ static struct ndtest_dimm dimm_group1[] = {
.uuid_str = "1e5c75d2-b618-11ea-9aa3-507b9ddc0f72",
.physical_id = 0,
.num_formats = 2,
+   .flags = PAPR_PMEM_HEALTH_NON_CRITICAL,
+   .extension_flags = health_defaults.extension_flags,
+   .dimm_fuel_gauge = health_defaults.dimm_fuel_gauge,
+   .media_temperature = health_defaults.media_temperature,
+   .ctrl_temperature = health_defaults.ctrl_temperature,
+   .spares = health_defaults.spares,
+   .alarm_flags = health_defaults.alarm_flags,
+   .media_temperature_threshold = 40 * 16,
+   .ctrl_temperature_threshold = 30 * 16,
+   .spares_threshold = 5,
},
{
.size = DIMM_SIZE,
@@ -55,6 +82,16 @@ static struct ndtest_dimm dimm_group1[] = {
.uuid_str = "1c4d43ac-b618-11ea-be80-507b9ddc0f72",
.physical_id = 1,
.num_formats = 2,
+   .flags = PAPR_PMEM_HEALTH_NON_CRITICAL,
+   .extension_flags = health_defaults.extension_flags,
+   .dimm_fuel_gauge = health_defaults.dimm_fuel_gauge,
+   .media_temperature = health_defaults.media_temperature,
+   .ctrl_temperature = health_defaults.ctrl_temperature,
+   .spares = health_defaults.spares,
+   .alarm_flags = health_defaults.alarm_flags,
+   .media_temperature_threshold = 40 * 16,
+   .ctrl_temperature_threshold = 30 * 16,
+   .spares_threshold = 5,
},
{
.size = DIMM_SIZE,
@@ -62,6 +99,16 @@ static struct ndtest_dimm dimm_group1[] = {
.uuid_str = "a9f17ffc-b618-11ea-b36d-507b9ddc0f72",
.physical_id = 2,
.num_formats = 2,
+   .flags = PAPR_PMEM_HEALTH_NON_CRITICAL,
+   .extension_flags = health_defaults.extension_flags,
+   .dimm_fuel_gauge = health_defaults.dimm_fuel_gauge,
+   .media_temperature = health_defaults.media_temperature,
+   .ctrl_temperature = health_defaults.ctrl_temperature,
+   .spares = health_defaults.spares,
+   .alarm_flags = health_defaults.alarm_flags,
+   .media_temperature_threshold = 40 * 16,
+   .ctrl_temperature_threshold = 30 * 16,
+   .spares_threshold = 5,
},
{
.size = DIMM_SIZE,
@@ -69,6 +116,16 @@ static struct ndtest_dimm dimm_group1[] = {
.uuid_str = "b6b83b22-b618-11ea-8aae-507b9ddc0f72",
.physical_id = 3,
.num_formats = 2,
+   .flags = PAPR_PMEM_HEALTH_NON_CRITICAL,
+   .extension_flags = health_defaults.extension_flags,
+   .dimm_fuel_gauge = health_defaults.dimm_fuel_gauge,
+   .media_temperature = health_defaults.media_temperature,
+   .ctrl_temperature = health_defaults.ctrl_temperature,
+   .spares = health_defaults.spares,
+   

[ndctl V5 4/4] Use page size as alignment value

2021-05-13 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 15 ---
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 0b3bb7a..59185cf 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -38,12 +38,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)
@@ -124,11 +125,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;
@@ -150,7 +151,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",
@@ -166,7 +167,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",
@@ -175,7 +176,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",
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index e932569..9451ed0 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -12,6 +12,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
@@ -22,9 +24,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
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index dd7013e..d03c0ca 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -9,6 +9,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
@@ -25,7 +27,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 $NAMES

[ndctl V5 3/4] papr: Add support to parse save_fail flag for dimm

2021-05-13 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 26b9317..dd1a5fc 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -805,6 +805,8 @@ 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)
@@ -1035,7 +1037,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);
 }
 
 /**
-- 
2.31.1
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl V5 2/4] test: Don't skip tests if nfit modules are missing

2021-05-13 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 28 ++--
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/test.h b/test.h
index cba8d41..7de13fe 100644
--- a/test.h
+++ b/test.h
@@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index fb1d82b..c561ff3 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index d7f00cb..f076e85 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index cc7d8d9..2b03aa9 100644
--- a/test/core.c
+++ b/test/core.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = -1;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -127,10 +128,28 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_e820",
"nd_pmem",
};
+   char *test_env;
 
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
 
+   /*
+* The following two checks determine the platform family. For
+* Intel/platforms which support ACPI, check sysfs; for other platforms
+* determine from the environment variable NVDIMM_TEST_FAMILY
+*/
+   if (access("/sys/bus/acpi", F_OK) == 0)
+   family = NVDIMM_FAMILY_INTEL;
+
+   test_env = getenv("NDCTL_TEST_FAMILY");
+   if (test_env && strcmp(test_env, "PAPR") == 0)
+   family = NVDIMM_FAMILY_PAPR;
+
+   if (family == -1) {
+   log_err(_ctx, "Cannot determine NVDIMM family\n");
+   return -ENOTSUP;
+   }
+
*ctx = kmod_new(NULL, NULL);
if (!*ctx)
return -ENXIO;
@@ -185,6 +204,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family != NVDIMM_FAMILY_INTEL &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index e922009..0b3bb7a 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -289,7 +289,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
  

[ndctl V5 1/4] libndctl: Unify adding dimms for papr and nfit families

2021-05-13 Thread Santosh Sivaraj
In preparation for enabling tests on non-nfit devices, unify both, already very
similar, functions into one. This will help in adding all attributes needed for
the unit tests. Since the function doesn't fail if some of the dimm attributes
are missing, this will work fine on PAPR platforms though only part of the DIMM
attributes are provided (This doesn't mean that all of the DIMM attributes can
be missing).

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 103 ---
 1 file changed, 38 insertions(+), 65 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 36fb6fe..26b9317 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1646,41 +1646,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
-{
-   int rc = -ENODEV;
-   char buf[SYSFS_ATTR_SIZE];
-   struct ndctl_ctx *ctx = dimm->bus->ctx;
-   char *path = calloc(1, strlen(dimm_base) + 100);
-   const char * const devname = ndctl_dimm_get_devname(dimm);
-
-   dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
-
-   if (!path)
-   return -ENOMEM;
-
-   /* construct path to the papr compatible dimm flags file */
-   sprintf(path, "%s/papr/flags", dimm_base);
-
-   if (ndctl_bus_is_papr_scm(dimm->bus) &&
-   sysfs_read_attr(ctx, path, buf) == 0) {
-
-   dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
buf);
-   dimm->cmd_family = NVDIMM_FAMILY_PAPR;
-
-   /* Parse dimm flags */
-   parse_papr_flags(dimm, buf);
-
-   /* Allocate monitor mode fd */
-   dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
-   rc = 0;
-   }
-
-   free(path);
-   return rc;
-}
-
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
+   const char *dimm_base,
+   const char *bus_prefix)
 {
int i, rc = -1;
char buf[SYSFS_ATTR_SIZE];
@@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
 * 'unique_id' may not be available on older kernels, so don't
 * fail if the read fails.
 */
-   sprintf(path, "%s/nfit/id", dimm_base);
+   sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0) {
unsigned int b[9];
 
@@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
}
}
 
-   sprintf(path, "%s/nfit/handle", dimm_base);
+   sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->handle = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/phys_id", dimm_base);
+   sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->phys_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/serial", dimm_base);
+   sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->serial = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/vendor", dimm_base);
+   sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/device", dimm_base);
+   sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->device_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/rev_id", dimm_base);
+   sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->revision_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
+   sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->dirty_shutdown = strtoll(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_vendor", dimm_base);
+   sprintf(path, "%s/%s/subsystem_vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
   

Re: [PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-05-12 Thread Santosh Sivaraj
Santosh Sivaraj  writes:

> "Verma, Vishal L"  writes:
>
> Hi Vishal,
>
>> On Sat, 2021-05-01 at 11:57 +0530, Santosh Sivaraj wrote:
>>> "Verma, Vishal L"  writes:
>>> 
>>> Hi Vishal,
>>> 
>>> > On Sun, 2021-03-28 at 07:39 +0530, Santosh Sivaraj wrote:
>>> > > For NFIT to be available ACPI is a must, so don't fail when nfit modules
>>> > > are missing on a platform that doesn't support ACPI.
>>> > > 
>>> > > Signed-off-by: Santosh Sivaraj 
>>> > > ---
>>> > >  test.h|  2 +-
>>> > >  test/ack-shutdown-count-set.c |  2 +-
>>> > >  test/blk_namespaces.c |  2 +-
>>> > >  test/core.c   | 30 --
>>> > >  test/dpa-alloc.c  |  2 +-
>>> > >  test/dsm-fail.c   |  2 +-
>>> > >  test/libndctl.c   |  2 +-
>>> > >  test/multi-pmem.c |  2 +-
>>> > >  test/parent-uuid.c|  2 +-
>>> > >  test/pmem_namespaces.c|  2 +-
>>> > >  10 files changed, 37 insertions(+), 11 deletions(-)
>>> > > 
>>> > 
>>> > I haven't looked deeper, but this seems to fail the blk-ns test with:
>>> > 
>>> >   ACPI.NFIT unavailable falling back to nfit_test
>>> >   test/init: ndctl_test_init: Cannot determine NVDIMM family
>>> >   __ndctl_test_skip: explicit skip test_blk_namespaces:235
>>> >   nfit_test unavailable skipping tests
>>> 
>>> The first message will be emitted even without the changes if the bus is not
>>> found. The second error will be emitted when check "/sys/bus/acpi" is not
>>> found. We fail for all other buses by default except for NFIT as before and 
>>> PAPR
>>> tests are enabled only when NVDIMM_TEST_FAMILY is set to "PAPR".
>>
>> See below on this.
>>
>>> 
>>> All tests pass in my setup (x86_64 qemu guest) with the recent upstream 
>>> kernel,
>>> except for the the below warning from drivers/acpi/nfit/core.c:
>>
>> Hm I've not seen this with 5.11 or 5.12. What's the qemu command line
>> and is it just triggered from a unit test tun?
>
> This was on a 5.12 kernel, which I have mentioned earlier, but I am not able 
> to
> reproduce now, I had rebased the kernel now. But anyway it doesn't seem to be
> reproducible now. Will come back if I see something again.

I could reproduce this with

make check TESTS=create.sh

and it reproduces with all the tests when the module is being removed.

kernel: 5.13-rc1 (6efb943b8616ec53a5e444193dccf1af9ad627b5)
ndctl: ea014c0c9ec8d0ef945d072dcc52b306c7a686f9

qemu --version: QEMU emulator version 5.0.1 (v5.0.1)

$QEMU_X86 -smp 4 -enable-kvm -hda $DISK -boot c \
  -m 4G,slots=4,maxmem=8G \
  -M pc,accel=kvm,nvdimm \
  -name guest=santosh-x86,debug-threads=on \
  -netdev user,id=ethernet.0,hostfwd=tcp::12121-:22 -device 
e1000,netdev=ethernet.0 \
  -serial mon:stdio -display none -vga none -nographic \
  -kernel $1 -append "console=ttyS0 root=$ROOT" \
  -hdb $DISK2

Thanks,
Santosh

>
>>
>>> 
>>> [ 2426.727584] [ cut here ]
>>> [ 2426.728405] WARNING: CPU: 2 PID: 47504 at 
>>> tools/testing/nvdimm/../../../drivers/acpi/nfit/core.c:3879 nfit_exit+0x]
>>> [ 2426.730264] Modules linked in: dax_pmem(O) nd_pmem(O) nfit(O-) kmem 
>>> dax_pmem_compat(O) nd_blk(O) dax_pmem_core(O) ]
>>> [ 2426.733209] CPU: 2 PID: 47504 Comm: modprobe Tainted: GW  O  
>>> 5.12.0+ #3
>>> [ 2426.734472] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
>>> rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.o4
>>> [ 2426.736305] RIP: 0010:nfit_exit+0x2c/0x703 [nfit]
>>> [ 2426.737099] Code: fd ff ff 48 c7 c7 00 f0 39 c0 e8 52 a1 38 da 48 8b 3d 
>>> 6b 46 00 00 e8 e6 88 ee d9 48 8b 05 5f 3c 0
>>> [ 2426.740046] RSP: 0018:a8e800b77ed8 EFLAGS: 00010287
>>> [ 2426.740990] RAX: 95b7e51935b0 RBX: 0800 RCX: 
>>> 9b4a36a8
>>> [ 2426.742236] RDX:  RSI: 0083 RDI: 
>>> 95b7c03e1554
>>> [ 2426.743404] RBP: c039f740 R08: 0400 R09: 
>>> 95b7c03e0e50
>>> [ 2426.744617] R10: 95b7fbd296f0 R11: 00895440 R12: 
>>> a8e800b77f58
>>> [ 2426.745792] R13:  R14:  R15: 
>>

Re: [PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-05-12 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

Hi Vishal,

> On Sat, 2021-05-01 at 11:57 +0530, Santosh Sivaraj wrote:
>> "Verma, Vishal L"  writes:
>> 
>> Hi Vishal,
>> 
>> > On Sun, 2021-03-28 at 07:39 +0530, Santosh Sivaraj wrote:
>> > > For NFIT to be available ACPI is a must, so don't fail when nfit modules
>> > > are missing on a platform that doesn't support ACPI.
>> > > 
>> > > Signed-off-by: Santosh Sivaraj 
>> > > ---
>> > >  test.h|  2 +-
>> > >  test/ack-shutdown-count-set.c |  2 +-
>> > >  test/blk_namespaces.c |  2 +-
>> > >  test/core.c   | 30 --
>> > >  test/dpa-alloc.c  |  2 +-
>> > >  test/dsm-fail.c   |  2 +-
>> > >  test/libndctl.c   |  2 +-
>> > >  test/multi-pmem.c |  2 +-
>> > >  test/parent-uuid.c|  2 +-
>> > >  test/pmem_namespaces.c|  2 +-
>> > >  10 files changed, 37 insertions(+), 11 deletions(-)
>> > > 
>> > 
>> > I haven't looked deeper, but this seems to fail the blk-ns test with:
>> > 
>> >   ACPI.NFIT unavailable falling back to nfit_test
>> >   test/init: ndctl_test_init: Cannot determine NVDIMM family
>> >   __ndctl_test_skip: explicit skip test_blk_namespaces:235
>> >   nfit_test unavailable skipping tests
>> 
>> The first message will be emitted even without the changes if the bus is not
>> found. The second error will be emitted when check "/sys/bus/acpi" is not
>> found. We fail for all other buses by default except for NFIT as before and 
>> PAPR
>> tests are enabled only when NVDIMM_TEST_FAMILY is set to "PAPR".
>
> See below on this.
>
>> 
>> All tests pass in my setup (x86_64 qemu guest) with the recent upstream 
>> kernel,
>> except for the the below warning from drivers/acpi/nfit/core.c:
>
> Hm I've not seen this with 5.11 or 5.12. What's the qemu command line
> and is it just triggered from a unit test tun?

This was on a 5.12 kernel, which I have mentioned earlier, but I am not able to
reproduce now, I had rebased the kernel now. But anyway it doesn't seem to be
reproducible now. Will come back if I see something again.

>
>> 
>> [ 2426.727584] [ cut here ]
>> [ 2426.728405] WARNING: CPU: 2 PID: 47504 at 
>> tools/testing/nvdimm/../../../drivers/acpi/nfit/core.c:3879 nfit_exit+0x]
>> [ 2426.730264] Modules linked in: dax_pmem(O) nd_pmem(O) nfit(O-) kmem 
>> dax_pmem_compat(O) nd_blk(O) dax_pmem_core(O) ]
>> [ 2426.733209] CPU: 2 PID: 47504 Comm: modprobe Tainted: GW  O  
>> 5.12.0+ #3
>> [ 2426.734472] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
>> rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.o4
>> [ 2426.736305] RIP: 0010:nfit_exit+0x2c/0x703 [nfit]
>> [ 2426.737099] Code: fd ff ff 48 c7 c7 00 f0 39 c0 e8 52 a1 38 da 48 8b 3d 
>> 6b 46 00 00 e8 e6 88 ee d9 48 8b 05 5f 3c 0
>> [ 2426.740046] RSP: 0018:a8e800b77ed8 EFLAGS: 00010287
>> [ 2426.740990] RAX: 95b7e51935b0 RBX: 0800 RCX: 
>> 9b4a36a8
>> [ 2426.742236] RDX:  RSI: 0083 RDI: 
>> 95b7c03e1554
>> [ 2426.743404] RBP: c039f740 R08: 0400 R09: 
>> 95b7c03e0e50
>> [ 2426.744617] R10: 95b7fbd296f0 R11: 00895440 R12: 
>> a8e800b77f58
>> [ 2426.745792] R13:  R14:  R15: 
>> 
>> [ 2426.746946] FS:  7f48297e3740() GS:95b7fbd0() 
>> knlGS:
>> [ 2426.748250] CS:  0010 DS:  ES:  CR0: 80050033
>> [ 2426.749198] CR2: 56072aadc9f8 CR3: 000118b08000 CR4: 
>> 06e0
>> [ 2426.750349] Call Trace:
>> [ 2426.750754]  __do_sys_delete_module+0x19d/0x240
>> [ 2426.751472]  ? task_work_run+0x5c/0x90
>> [ 2426.751964]  ? exit_to_user_mode_prepare+0x2a/0x130
>> [ 2426.752637]  do_syscall_64+0x40/0x80
>> [ 2426.753121]  entry_SYSCALL_64_after_hwframe+0x44/0xae
>> [ 2426.753810] RIP: 0033:0x7f482991361b
>> [ 2426.754274] Code: 73 01 c3 48 8b 0d 5d 18 0c 00 f7 d8 64 89 01 48 83 c8 
>> ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 8
>> [ 2426.756668] RSP: 002b:7ffd46c89b98 EFLAGS: 0206 ORIG_RAX: 
>> 00b0
>> [ 2426.757676] RAX: ffda RBX: 56072aad8f90 RCX: 
>> 7f482991361b
>> [ 2426.758618] RDX:  RSI: 0800 RDI: 

Re: [PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-05-01 Thread Santosh Sivaraj
Santosh Sivaraj  writes:

> "Verma, Vishal L"  writes:
>
> Hi Vishal,
>
>> On Sun, 2021-03-28 at 07:39 +0530, Santosh Sivaraj wrote:
>>> For NFIT to be available ACPI is a must, so don't fail when nfit modules
>>> are missing on a platform that doesn't support ACPI.
>>> 
>>> Signed-off-by: Santosh Sivaraj 
>>> ---
>>>  test.h|  2 +-
>>>  test/ack-shutdown-count-set.c |  2 +-
>>>  test/blk_namespaces.c |  2 +-
>>>  test/core.c   | 30 --
>>>  test/dpa-alloc.c  |  2 +-
>>>  test/dsm-fail.c   |  2 +-
>>>  test/libndctl.c   |  2 +-
>>>  test/multi-pmem.c |  2 +-
>>>  test/parent-uuid.c|  2 +-
>>>  test/pmem_namespaces.c|  2 +-
>>>  10 files changed, 37 insertions(+), 11 deletions(-)
>>> 
>>
>> I haven't looked deeper, but this seems to fail the blk-ns test with:
>>
>>   ACPI.NFIT unavailable falling back to nfit_test
>>   test/init: ndctl_test_init: Cannot determine NVDIMM family
>>   __ndctl_test_skip: explicit skip test_blk_namespaces:235
>>   nfit_test unavailable skipping tests
>
> The first message will be emitted even without the changes if the bus is not
> found. The second error will be emitted when /sys/bus/acpi is not found. We 
> fail
> for all other buses by default as before. PAPR tests are enabled only when
> NVDIMM_TEST_FAMILY is set to "PAPR".
>
> All tests pass in my setup with the recent upstream kernel, except for the the
> below warning from drivers/acpi/nfit/core.c:
>
> [ 2426.727584] [ cut here ]
> [ 2426.728405] WARNING: CPU: 2 PID: 47504 at 
> tools/testing/nvdimm/../../../drivers/acpi/nfit/core.c:3879 nfit_exit+0x]
> [ 2426.730264] Modules linked in: dax_pmem(O) nd_pmem(O) nfit(O-) kmem 
> dax_pmem_compat(O) nd_blk(O) dax_pmem_core(O) ]
> [ 2426.733209] CPU: 2 PID: 47504 Comm: modprobe Tainted: GW  O  
> 5.12.0+ #3
> [ 2426.734472] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.o4
> [ 2426.736305] RIP: 0010:nfit_exit+0x2c/0x703 [nfit]
> [ 2426.737099] Code: fd ff ff 48 c7 c7 00 f0 39 c0 e8 52 a1 38 da 48 8b 3d 6b 
> 46 00 00 e8 e6 88 ee d9 48 8b 05 5f 3c 0
> [ 2426.740046] RSP: 0018:a8e800b77ed8 EFLAGS: 00010287
> [ 2426.740990] RAX: 95b7e51935b0 RBX: 0800 RCX: 
> 9b4a36a8
> [ 2426.742236] RDX:  RSI: 0083 RDI: 
> 95b7c03e1554
> [ 2426.743404] RBP: c039f740 R08: 0400 R09: 
> 95b7c03e0e50
> [ 2426.744617] R10: 95b7fbd296f0 R11: 00895440 R12: 
> a8e800b77f58
> [ 2426.745792] R13:  R14:  R15: 
> 
> [ 2426.746946] FS:  7f48297e3740() GS:95b7fbd0() 
> knlGS:
> [ 2426.748250] CS:  0010 DS:  ES:  CR0: 80050033
> [ 2426.749198] CR2: 56072aadc9f8 CR3: 000118b08000 CR4: 
> 06e0
> [ 2426.750349] Call Trace:
> [ 2426.750754]  __do_sys_delete_module+0x19d/0x240
> [ 2426.751472]  ? task_work_run+0x5c/0x90
> [ 2426.751964]  ? exit_to_user_mode_prepare+0x2a/0x130
> [ 2426.752637]  do_syscall_64+0x40/0x80
> [ 2426.753121]  entry_SYSCALL_64_after_hwframe+0x44/0xae
> [ 2426.753810] RIP: 0033:0x7f482991361b
> [ 2426.754274] Code: 73 01 c3 48 8b 0d 5d 18 0c 00 f7 d8 64 89 01 48 83 c8 ff 
> c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 8
> [ 2426.756668] RSP: 002b:7ffd46c89b98 EFLAGS: 0206 ORIG_RAX: 
> 00b0
> [ 2426.757676] RAX: ffda RBX: 56072aad8f90 RCX: 
> 7f482991361b
> [ 2426.758618] RDX:  RSI: 0800 RDI: 
> 56072aad8ff8
> [ 2426.759563] RBP: 56072aad8f90 R08:  R09: 
> 
> [ 2426.760513] R10: 7f4829987ac0 R11: 0206 R12: 
> 56072aad8ff8
> [ 2426.761463] R13:  R14: 56072aadb4e8 R15: 
> 7ffd46c89d18
> [ 2426.762405] ---[ end trace 14a8748cda8b4777 ]---
>
> This was not seen with the 5.11 kernel.
>

Reverting cf16b05c607b ("ACPICA: ACPI 6.4: NFIT: add Location Cookie field")
doesn't produce the warning.

Thanks,
Santosh

>>
>>> diff --git a/test.h b/test.h
>>> index cba8d41..7de13fe 100644
>>> --- a/test.h
>>> +++ b/test.h
>>> @@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
>>>  
>>> 
>>>  struct kmod_ctx;
>>>  struct kmod_module;
>>> -int nfit_test_init(struct kmod_ctx **ctx

Re: [PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-05-01 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

Hi Vishal,

> On Sun, 2021-03-28 at 07:39 +0530, Santosh Sivaraj wrote:
>> For NFIT to be available ACPI is a must, so don't fail when nfit modules
>> are missing on a platform that doesn't support ACPI.
>> 
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  test.h|  2 +-
>>  test/ack-shutdown-count-set.c |  2 +-
>>  test/blk_namespaces.c |  2 +-
>>  test/core.c   | 30 --
>>  test/dpa-alloc.c  |  2 +-
>>  test/dsm-fail.c   |  2 +-
>>  test/libndctl.c   |  2 +-
>>  test/multi-pmem.c |  2 +-
>>  test/parent-uuid.c|  2 +-
>>  test/pmem_namespaces.c|  2 +-
>>  10 files changed, 37 insertions(+), 11 deletions(-)
>> 
>
> I haven't looked deeper, but this seems to fail the blk-ns test with:
>
>   ACPI.NFIT unavailable falling back to nfit_test
>   test/init: ndctl_test_init: Cannot determine NVDIMM family
>   __ndctl_test_skip: explicit skip test_blk_namespaces:235
>   nfit_test unavailable skipping tests

The first message will be emitted even without the changes if the bus is not
found. The second error will be emitted when check "/sys/bus/acpi" is not
found. We fail for all other buses by default except for NFIT as before and PAPR
tests are enabled only when NVDIMM_TEST_FAMILY is set to "PAPR".

All tests pass in my setup (x86_64 qemu guest) with the recent upstream kernel,
except for the the below warning from drivers/acpi/nfit/core.c:

[ 2426.727584] [ cut here ]
[ 2426.728405] WARNING: CPU: 2 PID: 47504 at 
tools/testing/nvdimm/../../../drivers/acpi/nfit/core.c:3879 nfit_exit+0x]
[ 2426.730264] Modules linked in: dax_pmem(O) nd_pmem(O) nfit(O-) kmem 
dax_pmem_compat(O) nd_blk(O) dax_pmem_core(O) ]
[ 2426.733209] CPU: 2 PID: 47504 Comm: modprobe Tainted: GW  O  
5.12.0+ #3
[ 2426.734472] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.o4
[ 2426.736305] RIP: 0010:nfit_exit+0x2c/0x703 [nfit]
[ 2426.737099] Code: fd ff ff 48 c7 c7 00 f0 39 c0 e8 52 a1 38 da 48 8b 3d 6b 
46 00 00 e8 e6 88 ee d9 48 8b 05 5f 3c 0
[ 2426.740046] RSP: 0018:a8e800b77ed8 EFLAGS: 00010287
[ 2426.740990] RAX: 95b7e51935b0 RBX: 0800 RCX: 9b4a36a8
[ 2426.742236] RDX:  RSI: 0083 RDI: 95b7c03e1554
[ 2426.743404] RBP: c039f740 R08: 0400 R09: 95b7c03e0e50
[ 2426.744617] R10: 95b7fbd296f0 R11: 00895440 R12: a8e800b77f58
[ 2426.745792] R13:  R14:  R15: 
[ 2426.746946] FS:  7f48297e3740() GS:95b7fbd0() 
knlGS:
[ 2426.748250] CS:  0010 DS:  ES:  CR0: 80050033
[ 2426.749198] CR2: 56072aadc9f8 CR3: 000118b08000 CR4: 06e0
[ 2426.750349] Call Trace:
[ 2426.750754]  __do_sys_delete_module+0x19d/0x240
[ 2426.751472]  ? task_work_run+0x5c/0x90
[ 2426.751964]  ? exit_to_user_mode_prepare+0x2a/0x130
[ 2426.752637]  do_syscall_64+0x40/0x80
[ 2426.753121]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[ 2426.753810] RIP: 0033:0x7f482991361b
[ 2426.754274] Code: 73 01 c3 48 8b 0d 5d 18 0c 00 f7 d8 64 89 01 48 83 c8 ff 
c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 8
[ 2426.756668] RSP: 002b:7ffd46c89b98 EFLAGS: 0206 ORIG_RAX: 
00b0
[ 2426.757676] RAX: ffda RBX: 56072aad8f90 RCX: 7f482991361b
[ 2426.758618] RDX:  RSI: 0800 RDI: 56072aad8ff8
[ 2426.759563] RBP: 56072aad8f90 R08:  R09: 
[ 2426.760513] R10: 7f4829987ac0 R11: 0206 R12: 56072aad8ff8
[ 2426.761463] R13:  R14: 56072aadb4e8 R15: 7ffd46c89d18
[ 2426.762405] ---[ end trace 14a8748cda8b4777 ]---

This was not seen with the 5.11 kernel.

Thanks,
Santosh
>
>> diff --git a/test.h b/test.h
>> index cba8d41..7de13fe 100644
>> --- a/test.h
>> +++ b/test.h
>> @@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
>>  
>> 
>>  struct kmod_ctx;
>>  struct kmod_module;
>> -int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>> +int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>>  struct ndctl_ctx *nd_ctx, int log_level,
>>  struct ndctl_test *test);
>>  
>> 
>> diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
>> index fb1d82b..c561ff3 100644
>> --- a/test/ack-shutdown-count-set.c
>> +++ b/test/ack-shutdown-count-set.c
>> @@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, 
>> struct ndctl_test *test,
>>  i

Re: [PATCH] libnvdimm.h: Remove duplicate struct declaration

2021-04-20 Thread Santosh Sivaraj
Hi Ira,

Ira Weiny  writes:

> On Mon, Apr 19, 2021 at 07:27:25PM +0800, Wan Jiabing wrote:
>> struct device is declared at 133rd line.
>> The declaration here is unnecessary. Remove it.
>> 
>> Signed-off-by: Wan Jiabing 
>> ---
>>  include/linux/libnvdimm.h | 1 -
>>  1 file changed, 1 deletion(-)
>> 
>> diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h
>> index 01f251b6e36c..89b69e645ac7 100644
>> --- a/include/linux/libnvdimm.h
>> +++ b/include/linux/libnvdimm.h
>> @@ -141,7 +141,6 @@ static inline void __iomem *devm_nvdimm_ioremap(struct 
>> device *dev,
>>  
>>  struct nvdimm_bus;
>>  struct module;
>> -struct device;
>>  struct nd_blk_region;
>
> What is the coding style preference for pre-declarations like this?  Should
> they be placed at the top of the file?
>
> The patch is reasonable but if the intent is to declare right before use for
> clarity, both devm_nvdimm_memremap() and nd_blk_region_desc() use struct
> device.  So perhaps this duplicate is on purpose?

There are other struct device usage much later in the file, which doesn't have
any pre-declarations for struct device. So I assume this might not be on
purpose :-)

On a side note, types.h can also be removed, since it's already included in
kernel.h.

Santosh

>
> Ira
>
>>  struct nd_blk_region_desc {
>>  int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
>> -- 
>> 2.25.1
>> 
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [PATCH -next] tools/testing/nvdimm: Make symbol '__nfit_test_ioremap' static

2021-04-20 Thread Santosh Sivaraj


Hi Zou,

Zou Wei  writes:

> The sparse tool complains as follows:
>
> tools/testing/nvdimm/test/iomap.c:65:14: warning:
>  symbol '__nfit_test_ioremap' was not declared. Should it be static?
>
> This symbol is not used outside of security.c, so this

s/security.c/iomap.c/

Thanks,
Santosh

> commit marks it static.
>
> Reported-by: Hulk Robot 
> Signed-off-by: Zou Wei 
> ---
>  tools/testing/nvdimm/test/iomap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/nvdimm/test/iomap.c 
> b/tools/testing/nvdimm/test/iomap.c
> index c62d372..ed563bd 100644
> --- a/tools/testing/nvdimm/test/iomap.c
> +++ b/tools/testing/nvdimm/test/iomap.c
> @@ -62,7 +62,7 @@ struct nfit_test_resource *get_nfit_res(resource_size_t 
> resource)
>  }
>  EXPORT_SYMBOL(get_nfit_res);
>  
> -void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
> +static void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned 
> long size,
>   void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
>  {
>   struct nfit_test_resource *nfit_res = get_nfit_res(offset);
> -- 
> 2.6.2
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl PATCH 2/2] Error injection support for PAPR

2021-04-19 Thread Santosh Sivaraj
Add support for error injection on PAPR family of devices. This is
particularly useful in running 'make check' on non-nfit platforms.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c  |   1 +
 ndctl/lib/papr.c  | 134 ++
 ndctl/lib/private.h   |   1 +
 ndctl/libndctl-papr.h |   7 +++
 4 files changed, 143 insertions(+)
 create mode 100644 ndctl/libndctl-papr.h

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 2364578..2c2f485 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -904,6 +904,7 @@ static void *add_bus(void *parent, int id, const char 
*ctl_base)
else {
bus->has_of_node = 1;
bus_name = "papr";
+   bus->ops = papr_bus_ops;
}
 
sprintf(path, "%s/device/%s/dsm_mask", ctl_base, bus_name);
diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c
index f94f8aa..6ac3d3e 100644
--- a/ndctl/lib/papr.c
+++ b/ndctl/lib/papr.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "papr.h"
 
@@ -38,6 +39,33 @@
 /* return the pdsm command */
 #define to_pdsm_cmd(C) ((enum papr_pdsm)to_ndcmd(C)->nd_command)
 
+/**
+ * ndctl_bus_is_papr_cmd_supported - check if command is supported on @bus.
+ * @bus: ndctl_bus instance
+ * @cmd: papr command number (defined as PAPR_PDSM_XXX in papr-pdsm.h)
+ *
+ * Return 1: command is supported. Return 0: command is not supported.
+ *
+ */
+NDCTL_EXPORT int ndctl_bus_is_papr_cmd_supported(struct ndctl_bus *bus,
+int cmd)
+{
+   return !!(bus->nfit_dsm_mask & (1ULL << cmd));
+}
+
+static int papr_is_errinj_supported(struct ndctl_bus *bus)
+{
+   if (!ndctl_bus_is_papr_scm(bus))
+   return 0;
+
+   if (ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_SET) &&
+   ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_CLEAR) &&
+   ndctl_bus_is_papr_cmd_supported(bus, PAPR_PDSM_INJECT_GET))
+   return 1;
+
+   return 0;
+}
+
 static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd)
 {
/* Handle this separately to support monitor mode */
@@ -559,3 +587,109 @@ struct ndctl_dimm_ops * const papr_dimm_ops = &(struct 
ndctl_dimm_ops) {
= papr_cmd_smart_threshold_set_ctrl_temperature,
.smart_threshold_set_spares = papr_cmd_smart_threshold_set_spares,
 };
+
+static u32 bus_get_firmware_status(struct ndctl_cmd *cmd)
+{
+   struct nd_cmd_bus *cmd_bus = cmd->cmd_bus;
+
+   switch (cmd_bus->gen.nd_command) {
+   case PAPR_PDSM_INJECT_SET:
+   return cmd_bus->err_inj.status;
+   case PAPR_PDSM_INJECT_CLEAR:
+   return cmd_bus->err_inj_clr.status;
+   case PAPR_PDSM_INJECT_GET:
+   return cmd_bus->err_inj_stat.status;
+   }
+
+   return -1U;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj(struct ndctl_bus *bus)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+   struct ndctl_cmd *cmd;
+
+   cmd_length = sizeof(struct nd_cmd_ars_err_inj);
+   size = sizeof(*cmd) + sizeof(*pkg) + cmd_length;
+   cmd = calloc(1, size);
+   if (!cmd)
+   return NULL;
+
+   cmd->bus = bus;
+   ndctl_cmd_ref(cmd);
+   cmd->type = ND_CMD_CALL;
+   cmd->get_firmware_status = bus_get_firmware_status;
+   cmd->size = size;
+   cmd->status = 1;
+   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
+   pkg->nd_command = PAPR_PDSM_INJECT_SET;
+   pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj, status);
+   pkg->nd_size_out = cmd_length - pkg->nd_size_in;
+   pkg->nd_fw_size = pkg->nd_size_out;
+
+   return cmd;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj_clr(struct ndctl_bus *bus)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+   struct ndctl_cmd *cmd;
+
+   cmd_length = sizeof(struct nd_cmd_ars_err_inj_clr);
+   size = sizeof(*cmd) + sizeof(*pkg) + cmd_length;
+   cmd = calloc(1, size);
+   if (!cmd)
+   return NULL;
+
+   cmd->bus = bus;
+   ndctl_cmd_ref(cmd);
+   cmd->type = ND_CMD_CALL;
+   cmd->get_firmware_status = bus_get_firmware_status;
+   cmd->size = size;
+   cmd->status = 1;
+   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
+   pkg->nd_command = PAPR_PDSM_INJECT_CLEAR;
+   pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj_clr, status);
+   pkg->nd_size_out = cmd_length - pkg->nd_size_in;
+   pkg->nd_fw_size = pkg->nd_size_out;
+
+   return cmd;
+}
+
+static struct ndctl_cmd *papr_bus_cmd_new_err_inj_stat(struct ndctl_bus *bus,
+   u32 buf_size)
+{
+   size_t size, cmd_length;
+   struct nd_cmd_pkg *pkg;
+  

[ndctl PATCH 1/2] inject-error: Remove assumptions on error injection support

2021-04-19 Thread Santosh Sivaraj
Currently the code assumes that only nfit supports error injection,
remove those assumptions before error injection support for PAPR is
added. Add bus operations similar to that of DIMM operations with
injection operations in it.

Signed-off-by: Santosh Sivaraj 
---
This patch series is on top of Shiva's SMART test patches for PAPR[1].

[1]: 
https://lkml.kernel.org/r/161711738576.593.320964839920955692.stgit@9add658da52e

 ndctl/lib/inject.c   | 96 
 ndctl/lib/libndctl.c | 11 +++--
 ndctl/lib/nfit.c | 20 +
 ndctl/lib/private.h  | 12 ++
 4 files changed, 83 insertions(+), 56 deletions(-)

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index d61c02c..35fd11e 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -6,19 +6,15 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "private.h"
 
 NDCTL_EXPORT int ndctl_bus_has_error_injection(struct ndctl_bus *bus)
 {
-   /* Currently, only nfit buses have error injection */
-   if (!bus || !ndctl_bus_has_nfit(bus))
+   if (!bus)
return 0;
 
-   if (ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_SET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_GET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_CLEAR))
+   if (bus->ops->err_inj_supported(bus))
return 1;
 
return 0;
@@ -151,7 +147,7 @@ static int ndctl_namespace_inject_one_error(struct 
ndctl_namespace *ndns,
length = clear_unit;
}
 
-   cmd = ndctl_bus_cmd_new_err_inj(bus);
+   cmd = bus->ops->new_err_inj(bus);
if (!cmd)
return -ENOMEM;
 
@@ -185,8 +181,6 @@ NDCTL_EXPORT int ndctl_namespace_inject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_inject_one_error(ndns, block + i, flags);
@@ -231,7 +225,7 @@ static int ndctl_namespace_uninject_one_error(struct 
ndctl_namespace *ndns,
length = clear_unit;
}
 
-   cmd = ndctl_bus_cmd_new_err_inj_clr(bus);
+   cmd = bus->ops->new_err_inj_clr(bus);
if (!cmd)
return -ENOMEM;
 
@@ -263,8 +257,6 @@ NDCTL_EXPORT int ndctl_namespace_uninject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_uninject_one_error(ndns, block + i,
@@ -445,51 +437,49 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct 
ndctl_namespace *ndns)
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
 
-   if (ndctl_bus_has_nfit(bus)) {
-   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
-   _size);
-   if (rc)
-   return rc;
+   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
+ _size);
+   if (rc)
+   return rc;
 
-   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
-   if (!cmd) {
-   err(ctx, "%s: failed to create cmd\n",
-   ndctl_namespace_get_devname(ndns));
-   return -ENOTTY;
-   }
-   rc = ndctl_cmd_submit(cmd);
-   if (rc < 0) {
-   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
-   goto out;
-   }
-   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
-   if (buf_size == 0) {
-   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
-   rc = -EINVAL;
-   goto out;
-   }
-   ndctl_cmd_unref(cmd);
+   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
+   if (!cmd) {
+   err(ctx, "%s: failed to create cmd\n",
+   ndctl_namespace_get_devname(ndns));
+   return -ENOTTY;
+   }
+   rc = ndctl_cmd_submit(cmd);
+   if (rc < 0) {
+   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
+   goto out;
+   }
+   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
+   if (buf_size == 0) {
+   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
+   rc = -EINVAL;
+   goto out;
+   }
+   ndctl_cmd_unref(cmd);
 
-   cmd = ndctl_bus_cmd_new_err_inj_stat(bus, buf_size);
-   

[PATCH] nvdimm/ndtest: Add support for error injection tests

2021-04-18 Thread Santosh Sivaraj
Add necessary support for error injection family of tests on non-acpi
platforms.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 455 -
 tools/testing/nvdimm/test/ndtest.h |  25 ++
 2 files changed, 477 insertions(+), 3 deletions(-)

This patch is based on top of Shiva's "Enable SMART test" patch[1].

[1]: 
https://lkml.kernel.org/r/161711723989.556.4220555988871072543.stgit@9add658da52e

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index bb47b145466d..09d98317bf4e 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#define pr_fmt(fmt) "ndtest :" fmt
 
 #include 
 #include 
@@ -42,6 +42,7 @@ static DEFINE_SPINLOCK(ndtest_lock);
 static struct ndtest_priv *instances[NUM_INSTANCES];
 static struct class *ndtest_dimm_class;
 static struct gen_pool *ndtest_pool;
+static struct workqueue_struct *ndtest_wq;
 
 static const struct nd_papr_pdsm_health health_defaults = {
.dimm_unarmed = 0,
@@ -496,6 +497,139 @@ static int ndtest_pdsm_health_set_threshold(struct 
ndtest_dimm *dimm,
return 0;
 }
 
+static void ars_complete_all(struct ndtest_priv *p)
+{
+   int i;
+
+   for (i = 0; i < p->config->num_regions; i++) {
+   struct ndtest_region *region = >config->regions[i];
+
+   if (region->region)
+   nvdimm_region_notify(region->region,
+NVDIMM_REVALIDATE_POISON);
+   }
+}
+
+static void ndtest_scrub(struct work_struct *work)
+{
+   struct ndtest_priv *p = container_of(work, typeof(struct ndtest_priv),
+dwork.work);
+   struct badrange_entry *be;
+   int rc, i = 0;
+
+   spin_lock(>badrange.lock);
+   list_for_each_entry(be, >badrange.list, list) {
+   rc = nvdimm_bus_add_badrange(p->bus, be->start, be->length);
+   if (rc)
+   dev_err(>pdev.dev, "Failed to process ARS 
records\n");
+   else
+   i++;
+   }
+   spin_unlock(>badrange.lock);
+
+   if (i == 0) {
+   queue_delayed_work(ndtest_wq, >dwork, HZ);
+   return;
+   }
+
+   ars_complete_all(p);
+   p->scrub_count++;
+
+   mutex_lock(>ars_lock);
+   sysfs_notify_dirent(p->scrub_state);
+   clear_bit(ARS_BUSY, >scrub_flags);
+   clear_bit(ARS_POLL, >scrub_flags);
+   set_bit(ARS_VALID, >scrub_flags);
+   mutex_unlock(>ars_lock);
+
+}
+
+static int ndtest_scrub_notify(struct ndtest_priv *p)
+{
+   if (!test_and_set_bit(ARS_BUSY, >scrub_flags))
+   queue_delayed_work(ndtest_wq, >dwork, HZ);
+
+   return 0;
+}
+
+static int ndtest_ars_inject(struct ndtest_priv *p,
+struct nd_cmd_ars_err_inj *inj,
+unsigned int buf_len)
+{
+   int rc;
+
+   if (buf_len != sizeof(*inj)) {
+   dev_dbg(>bus->dev, "buflen: %u, inj size: %lu\n",
+   buf_len, sizeof(*inj));
+   rc = -EINVAL;
+   goto err;
+   }
+
+   rc =  badrange_add(>badrange, inj->err_inj_spa_range_base,
+  inj->err_inj_spa_range_length);
+
+   if (inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY))
+   ndtest_scrub_notify(p);
+
+   inj->status = 0;
+
+   return 0;
+
+err:
+   inj->status = NFIT_ARS_INJECT_INVALID;
+   return rc;
+}
+
+static int ndtest_ars_inject_clear(struct ndtest_priv *p,
+  struct nd_cmd_ars_err_inj_clr *inj,
+  unsigned int buf_len)
+{
+   int rc;
+
+   if (buf_len != sizeof(*inj)) {
+   rc = -EINVAL;
+   goto err;
+   }
+
+   if (inj->err_inj_clr_spa_range_length <= 0) {
+   rc = -EINVAL;
+   goto err;
+   }
+
+   badrange_forget(>badrange, inj->err_inj_clr_spa_range_base,
+   inj->err_inj_clr_spa_range_length);
+
+   inj->status = 0;
+   return 0;
+
+err:
+   inj->status = NFIT_ARS_INJECT_INVALID;
+   return rc;
+}
+
+static int ndtest_ars_inject_status(struct ndtest_priv *p,
+   struct nd_cmd_ars_err_inj_stat *stat,
+   unsigned int buf_len)
+{
+   struct badrange_entry *be;
+   int max = SZ_4K / sizeof(struct nd_error_stat_query_record);
+   int i = 0;
+
+   stat->status = 0;
+   spin_lock(>badrange.lock);
+   list_for_each_entry(be, >badrange.list, list) {
+  

Re: [PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-04-06 Thread Santosh Sivaraj
"Aneesh Kumar K.V"  writes:

> Santosh Sivaraj  writes:
>
>> For NFIT to be available ACPI is a must, so don't fail when nfit modules
>> are missing on a platform that doesn't support ACPI.
>>
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  test.h|  2 +-
>>  test/ack-shutdown-count-set.c |  2 +-
>>  test/blk_namespaces.c |  2 +-
>>  test/core.c   | 30 --
>>  test/dpa-alloc.c  |  2 +-
>>  test/dsm-fail.c   |  2 +-
>>  test/libndctl.c   |  2 +-
>>  test/multi-pmem.c |  2 +-
>>  test/parent-uuid.c|  2 +-
>>  test/pmem_namespaces.c|  2 +-
>>  10 files changed, 37 insertions(+), 11 deletions(-)
>>
>> diff --git a/test.h b/test.h
>> index cba8d41..7de13fe 100644
>> --- a/test.h
>> +++ b/test.h
>> @@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
>>  
>>  struct kmod_ctx;
>>  struct kmod_module;
>> -int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>> +int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>>  struct ndctl_ctx *nd_ctx, int log_level,
>>  struct ndctl_test *test);
>>  
>> diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
>> index fb1d82b..c561ff3 100644
>> --- a/test/ack-shutdown-count-set.c
>> +++ b/test/ack-shutdown-count-set.c
>> @@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, 
>> struct ndctl_test *test,
>>  int result = EXIT_FAILURE, err;
>>  
>>  ndctl_set_log_priority(ctx, loglevel);
>> -err = nfit_test_init(_ctx, , NULL, loglevel, test);
>> +err = ndctl_test_init(_ctx, , NULL, loglevel, test);
>>  if (err < 0) {
>>  result = 77;
>>  ndctl_test_skip(test);
>> diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
>> index d7f00cb..f076e85 100644
>> --- a/test/blk_namespaces.c
>> +++ b/test/blk_namespaces.c
>> @@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
>> *test,
>>  
>>  if (!bus) {
>>  fprintf(stderr, "ACPI.NFIT unavailable falling back to 
>> nfit_test\n");
>> -rc = nfit_test_init(_ctx, , NULL, log_level, test);
>> +rc = ndctl_test_init(_ctx, , NULL, log_level, test);
>>  ndctl_invalidate(ctx);
>>  bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
>>  if (rc < 0 || !bus) {
>> diff --git a/test/core.c b/test/core.c
>> index cc7d8d9..44cb277 100644
>> --- a/test/core.c
>> +++ b/test/core.c
>> @@ -11,6 +11,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  
>>  #define KVER_STRLEN 20
>> @@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
>>  return test->skip;
>>  }
>>  
>> -int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>> +int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>>  struct ndctl_ctx *nd_ctx, int log_level,
>>  struct ndctl_test *test)
>>  {
>> -int rc;
>> +int rc, family = -1;
>>  unsigned int i;
>>  const char *name;
>>  struct ndctl_bus *bus;
>> @@ -127,10 +128,30 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
>> kmod_module **mod,
>>  "nd_e820",
>>  "nd_pmem",
>>  };
>> +char *test_env;
>>  
>>  log_init(_ctx, "test/init", "NDCTL_TEST");
>>  log_ctx.log_priority = log_level;
>>  
>> +/*
>> + * The following two checks determine the platform family. For
>> + * Intel/platforms which support ACPI, check sysfs; for other platforms
>> + * determine from the environment variable NVDIMM_TEST_FAMILY
>> + */
>> +if (access("/sys/bus/acpi", F_OK) == 0) {
>> +if (errno == ENOENT)
>> +family = NVDIMM_FAMILY_INTEL;
>> +}
>> +
>> +test_env = getenv("NDCTL_TEST_FAMILY");
>> +if (test_env && strcmp(test_env, "PAPR") == 0)
>> +family = NVDIMM_FAMILY_PAPR;
>
> I am wondering whether it is confusing to call this as
> NVDIMM_FAMILY_PAPR. If you are looking at a platform agnoistic family we
> should probably name it accordingly. Maybe NVDIMM_FAMILY

Re: [PATCH 1/4] libndctl: Unify adding dimms for papr and nfit families

2021-03-27 Thread Santosh Sivaraj


Sorry, I missed to provide the version in the subject, this is v4 of the series.

Santosh Sivaraj  writes:

> In preparation for enabling tests on non-nfit devices, unify both, already 
> very
> similar, functions into one. This will help in adding all attributes needed 
> for
> the unit tests. Since the function doesn't fail if some of the dimm attributes
> are missing, this will work fine on PAPR platforms though only part of the 
> DIMM
> attributes are provided (This doesn't mean that all of the DIMM attributes can
> be missing).
>
> Signed-off-by: Santosh Sivaraj 
> ---
>  ndctl/lib/libndctl.c | 103 ---
>  1 file changed, 38 insertions(+), 65 deletions(-)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 36fb6fe..26b9317 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -1646,41 +1646,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
> -{
> - int rc = -ENODEV;
> - char buf[SYSFS_ATTR_SIZE];
> - struct ndctl_ctx *ctx = dimm->bus->ctx;
> - char *path = calloc(1, strlen(dimm_base) + 100);
> - const char * const devname = ndctl_dimm_get_devname(dimm);
> -
> - dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
> -
> - if (!path)
> - return -ENOMEM;
> -
> - /* construct path to the papr compatible dimm flags file */
> - sprintf(path, "%s/papr/flags", dimm_base);
> -
> - if (ndctl_bus_is_papr_scm(dimm->bus) &&
> - sysfs_read_attr(ctx, path, buf) == 0) {
> -
> - dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
> buf);
> - dimm->cmd_family = NVDIMM_FAMILY_PAPR;
> -
> - /* Parse dimm flags */
> - parse_papr_flags(dimm, buf);
> -
> - /* Allocate monitor mode fd */
> - dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
> - rc = 0;
> - }
> -
> - free(path);
> - return rc;
> -}
> -
> -static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
> +static int populate_dimm_attributes(struct ndctl_dimm *dimm,
> + const char *dimm_base,
> + const char *bus_prefix)
>  {
>   int i, rc = -1;
>   char buf[SYSFS_ATTR_SIZE];
> @@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
> char *dimm_base)
>* 'unique_id' may not be available on older kernels, so don't
>* fail if the read fails.
>*/
> - sprintf(path, "%s/nfit/id", dimm_base);
> + sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0) {
>   unsigned int b[9];
>  
> @@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
> const char *dimm_base)
>   }
>   }
>  
> - sprintf(path, "%s/nfit/handle", dimm_base);
> + sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) < 0)
>   goto err_read;
>   dimm->handle = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/phys_id", dimm_base);
> + sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) < 0)
>   goto err_read;
>   dimm->phys_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/serial", dimm_base);
> + sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->serial = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/vendor", dimm_base);
> + sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->vendor_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/device", dimm_base);
> + sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->device_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/rev_id", dimm_base);
> + sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 

[PATCH 2/4] test: Don't skip tests if nfit modules are missing

2021-03-27 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 30 --
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/test.h b/test.h
index cba8d41..7de13fe 100644
--- a/test.h
+++ b/test.h
@@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index fb1d82b..c561ff3 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index d7f00cb..f076e85 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index cc7d8d9..44cb277 100644
--- a/test/core.c
+++ b/test/core.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = -1;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -127,10 +128,30 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_e820",
"nd_pmem",
};
+   char *test_env;
 
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
 
+   /*
+* The following two checks determine the platform family. For
+* Intel/platforms which support ACPI, check sysfs; for other platforms
+* determine from the environment variable NVDIMM_TEST_FAMILY
+*/
+   if (access("/sys/bus/acpi", F_OK) == 0) {
+   if (errno == ENOENT)
+   family = NVDIMM_FAMILY_INTEL;
+   }
+
+   test_env = getenv("NDCTL_TEST_FAMILY");
+   if (test_env && strcmp(test_env, "PAPR") == 0)
+   family = NVDIMM_FAMILY_PAPR;
+
+   if (family == -1) {
+   log_err(_ctx, "Cannot determine NVDIMM family\n");
+   return -ENOTSUP;
+   }
+
*ctx = kmod_new(NULL, NULL);
if (!*ctx)
return -ENXIO;
@@ -185,6 +206,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family != NVDIMM_FAMILY_INTEL &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index e922009..0b3bb7a 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -289,7 +289,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_

[PATCH 4/4] Use page size as alignment value

2021-03-27 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 15 ---
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 0b3bb7a..59185cf 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -38,12 +38,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)
@@ -124,11 +125,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;
@@ -150,7 +151,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",
@@ -166,7 +167,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",
@@ -175,7 +176,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",
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index e932569..9451ed0 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -12,6 +12,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
@@ -22,9 +24,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
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index dd7013e..d03c0ca 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -9,6 +9,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
@@ -25,7 +27,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 $NAMES

[PATCH 3/4] papr: Add support to parse save_fail flag for dimm

2021-03-27 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 26b9317..dd1a5fc 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -805,6 +805,8 @@ 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)
@@ -1035,7 +1037,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);
 }
 
 /**
-- 
2.30.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH 1/4] libndctl: Unify adding dimms for papr and nfit families

2021-03-27 Thread Santosh Sivaraj
In preparation for enabling tests on non-nfit devices, unify both, already very
similar, functions into one. This will help in adding all attributes needed for
the unit tests. Since the function doesn't fail if some of the dimm attributes
are missing, this will work fine on PAPR platforms though only part of the DIMM
attributes are provided (This doesn't mean that all of the DIMM attributes can
be missing).

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 103 ---
 1 file changed, 38 insertions(+), 65 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 36fb6fe..26b9317 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1646,41 +1646,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
-{
-   int rc = -ENODEV;
-   char buf[SYSFS_ATTR_SIZE];
-   struct ndctl_ctx *ctx = dimm->bus->ctx;
-   char *path = calloc(1, strlen(dimm_base) + 100);
-   const char * const devname = ndctl_dimm_get_devname(dimm);
-
-   dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
-
-   if (!path)
-   return -ENOMEM;
-
-   /* construct path to the papr compatible dimm flags file */
-   sprintf(path, "%s/papr/flags", dimm_base);
-
-   if (ndctl_bus_is_papr_scm(dimm->bus) &&
-   sysfs_read_attr(ctx, path, buf) == 0) {
-
-   dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
buf);
-   dimm->cmd_family = NVDIMM_FAMILY_PAPR;
-
-   /* Parse dimm flags */
-   parse_papr_flags(dimm, buf);
-
-   /* Allocate monitor mode fd */
-   dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
-   rc = 0;
-   }
-
-   free(path);
-   return rc;
-}
-
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
+   const char *dimm_base,
+   const char *bus_prefix)
 {
int i, rc = -1;
char buf[SYSFS_ATTR_SIZE];
@@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
 * 'unique_id' may not be available on older kernels, so don't
 * fail if the read fails.
 */
-   sprintf(path, "%s/nfit/id", dimm_base);
+   sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0) {
unsigned int b[9];
 
@@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
}
}
 
-   sprintf(path, "%s/nfit/handle", dimm_base);
+   sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->handle = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/phys_id", dimm_base);
+   sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->phys_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/serial", dimm_base);
+   sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->serial = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/vendor", dimm_base);
+   sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/device", dimm_base);
+   sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->device_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/rev_id", dimm_base);
+   sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->revision_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
+   sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->dirty_shutdown = strtoll(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_vendor", dimm_base);
+   sprintf(path, "%s/%s/subsystem_vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
   

[PATCH] libndctl: Remove redundant checks and assignments

2021-03-27 Thread Santosh Sivaraj
check_udev already checks for udev allocation failure, remove the redundant
check.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 36fb6fe..262d758 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -323,12 +323,9 @@ NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx)
dbg(c, "timeout = %ld\n", tmo);
}
 
-   if (udev) {
-   c->udev = udev;
-   c->udev_queue = udev_queue_new(udev);
-   if (!c->udev_queue)
-   err(c, "failed to retrieve udev queue\n");
-   }
+   c->udev_queue = udev_queue_new(udev);
+   if (!c->udev_queue)
+   err(c, "failed to retrieve udev queue\n");
 
c->kmod_ctx = kmod_ctx;
c->daxctl_ctx = daxctl_ctx;
-- 
2.30.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl PATCH v3 2/4] test: Don't skip tests if nfit modules are missing

2021-03-25 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

> On Fri, 2021-03-19 at 11:20 +0530, Santosh Sivaraj wrote:
>> "Verma, Vishal L"  writes:
>
> [..]
>
>> > 
>> > fix multi line comment to the right formatting:
>> > /*
>> >  * line 1, etc
>> >  */
>> > 
>> 
>> Will fix that.
>> 
>> > > +if (access("/sys/bus/acpi", F_OK) == -1) {
>> > > +if (errno == ENOENT)
>> > > +family = NVDIMM_FAMILY_PAPR;
>> > > +}
>> > 
>> > Instead of a blind default, can we perform a similar check for presence of
>> > PAPR too?
>> > 
>> 
>> Yes, I wanted to do that, but there is no reliable way of check that; there 
>> is
>> no ofnode before module load, and there won't be any PAPR specific DT 
>> entries if
>> the platform is not Power.
>> 
>> I also test the 'ndtest' module on x86 with NDCTL_TEST_FAMILY environment
>> variable. I can let the default be nfit_test (NVDIMM_FAMILY_INTEL) and only 
>> load
>> PAPR module when the environment variable is set. Thoughts?
>> 
> The env variable seems reasonable to me. If there is ever a third
> 'family' adding tests, having an arbitrary default might be awkward.
> I may suggest - if acpi is detected, use NFIT. If env has something that
> is known, e.g. PAPR, use that. If env is unset or doesn't match anything
> we know about, then bail with an error message. Does that sound
> reasonable?

Yes, that sounds too to me. I will send in the next version soon.
Thanks for the review!

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [PATCH] ndtest: Remove redundant NULL check

2021-03-22 Thread Santosh Sivaraj


Hi Ira,

Ira Weiny  writes:

> On Mon, Mar 22, 2021 at 06:00:40PM +0800, Jiapeng Chong wrote:
>> Fix the following coccicheck warnings:
>> 
>> ./tools/testing/nvdimm/test/ndtest.c:491:2-7: WARNING: NULL check before
>> some freeing functions is not needed.
>
> I don't think there is anything wrong with this patch specifically but why is
> buf not checked for null after the vmalloc?
>
> It seems to me that if size >= DIMM_SIZE and the vmalloc fails the gen pool
> allocation is going to be leaked.
>

If vmalloc fails, gen_pool_free will get called through ndtest_release_resource,
registered with devm_action. But we will still need to check for vmalloc fail.

I will fix that when I send my inject-error support for the driver.

Thanks,
Santosh

> Ira
>
>> 
>> Reported-by: Abaci Robot 
>> Signed-off-by: Jiapeng Chong 
>> ---
>>  tools/testing/nvdimm/test/ndtest.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>> 
>> diff --git a/tools/testing/nvdimm/test/ndtest.c 
>> b/tools/testing/nvdimm/test/ndtest.c
>> index 6862915..98b4a43 100644
>> --- a/tools/testing/nvdimm/test/ndtest.c
>> +++ b/tools/testing/nvdimm/test/ndtest.c
>> @@ -487,8 +487,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv 
>> *p, size_t size,
>>  buf_err:
>>  if (__dma && size >= DIMM_SIZE)
>>  gen_pool_free(ndtest_pool, __dma, size);
>> -if (buf)
>> -vfree(buf);
>> +vfree(buf);
>>  kfree(res);
>>  
>>  return NULL;
>> -- 
>> 1.8.3.1
>> 
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl PATCH v3 1/4] libndctl: test enablement for non-nfit devices

2021-03-18 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

Hi Vishal,

> On Thu, 2021-03-11 at 13:16 +0530, Santosh Sivaraj wrote:
>> Unify adding dimms for papr and nfit families, this will help in adding
>
> Minor nit, but it seems like the subject line and the first sentence in
> the body should be swapped. The one-line description of what's happening
> in this patch is "Unify adding dimms for papr and nfit families", and
> the body can go into more detail about why - i.e. in preparation for
> enabling tests on non-nfit devices.
>

Agree.

>> all attributes needed for the unit tests too. We don't fail adding a dimm
>> if some of the dimm attributes are missing, so this will work fine on PAPR
>> platforms where most dimm attributes are provided.
>
> Does this mean 'most - but not all'? Might be a good clarification to
> make here.

Yes, that's right. I will fix that up in the next version.

Thanks,
Santosh
>
>> 
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  ndctl/lib/libndctl.c | 103 ---
>>  1 file changed, 38 insertions(+), 65 deletions(-)
>> 
>> v3:
>> * Drop patch which skips SMART tests, smart test enablement will be posted
>>   soon.
>> 
>> v2:
>> * Patch 2: Fix a bug, I skip erroring out if PAPR family, but condition had
>>   INTEL family instead. That change was there to test the same code on x86, 
>> but
>>   accidently committed. Now have a environment variable to force test PAPR
>>   family on x86.
>> 
>> * Patch 4: Remove stray code, artifact of refactoring in patch 1.
>> 
>> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
>> index 36fb6fe..26b9317 100644
>> --- a/ndctl/lib/libndctl.c
>> +++ b/ndctl/lib/libndctl.c
>> @@ -1646,41 +1646,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
>> -{
>> -int rc = -ENODEV;
>> -char buf[SYSFS_ATTR_SIZE];
>> -struct ndctl_ctx *ctx = dimm->bus->ctx;
>> -char *path = calloc(1, strlen(dimm_base) + 100);
>> -const char * const devname = ndctl_dimm_get_devname(dimm);
>> -
>> -dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
>> -
>> -if (!path)
>> -return -ENOMEM;
>> -
>> -/* construct path to the papr compatible dimm flags file */
>> -sprintf(path, "%s/papr/flags", dimm_base);
>> -
>> -if (ndctl_bus_is_papr_scm(dimm->bus) &&
>> -sysfs_read_attr(ctx, path, buf) == 0) {
>> -
>> -dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
>> buf);
>> -dimm->cmd_family = NVDIMM_FAMILY_PAPR;
>> -
>> -/* Parse dimm flags */
>> -parse_papr_flags(dimm, buf);
>> -
>> -/* Allocate monitor mode fd */
>> -dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
>> -rc = 0;
>> -}
>> -
>> -free(path);
>> -return rc;
>> -}
>> -
>> -static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
>> +static int populate_dimm_attributes(struct ndctl_dimm *dimm,
>> +const char *dimm_base,
>> +const char *bus_prefix)
>>  {
>>  int i, rc = -1;
>>  char buf[SYSFS_ATTR_SIZE];
>> @@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
>> const char *dimm_base)
>>   * 'unique_id' may not be available on older kernels, so don't
>>   * fail if the read fails.
>>   */
>> -sprintf(path, "%s/nfit/id", dimm_base);
>> +sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) == 0) {
>>  unsigned int b[9];
>> 
>> @@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
>> const char *dimm_base)
>>  }
>>  }
>> 
>> -sprintf(path, "%s/nfit/handle", dimm_base);
>> +sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) < 0)
>>  goto err_read;
>>  dimm->handle = strtoul(buf, NULL, 0);
>>  
>> -sprintf(path, "%s/nfit/phys_id"

Re: [ndctl PATCH v3 2/4] test: Don't skip tests if nfit modules are missing

2021-03-18 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

> On Thu, 2021-03-11 at 13:16 +0530, Santosh Sivaraj wrote:
>> For NFIT to be available ACPI is a must, so don't fail when nfit modules
>> are missing on a platform that doesn't support ACPI.
>> 
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  test.h|  2 +-
>>  test/ack-shutdown-count-set.c |  2 +-
>>  test/blk_namespaces.c |  2 +-
>>  test/core.c   | 23 +--
>>  test/dpa-alloc.c  |  2 +-
>>  test/dsm-fail.c   |  2 +-
>>  test/libndctl.c   |  2 +-
>>  test/multi-pmem.c |  2 +-
>>  test/parent-uuid.c|  2 +-
>>  test/pmem_namespaces.c|  2 +-
>>  10 files changed, 30 insertions(+), 11 deletions(-)
>> 
>> diff --git a/test.h b/test.h
>> index cba8d41..7de13fe 100644
>> --- a/test.h
>> +++ b/test.h
>> @@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
>>  
>> 
>>  struct kmod_ctx;
>>  struct kmod_module;
>> -int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>> +int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>>  struct ndctl_ctx *nd_ctx, int log_level,
>>  struct ndctl_test *test);
>>  
>> 
>> diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
>> index fb1d82b..c561ff3 100644
>> --- a/test/ack-shutdown-count-set.c
>> +++ b/test/ack-shutdown-count-set.c
>> @@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, 
>> struct ndctl_test *test,
>>  int result = EXIT_FAILURE, err;
>>  
>> 
>>  ndctl_set_log_priority(ctx, loglevel);
>> -err = nfit_test_init(_ctx, , NULL, loglevel, test);
>> +err = ndctl_test_init(_ctx, , NULL, loglevel, test);
>>  if (err < 0) {
>>  result = 77;
>>  ndctl_test_skip(test);
>> diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
>> index d7f00cb..f076e85 100644
>> --- a/test/blk_namespaces.c
>> +++ b/test/blk_namespaces.c
>> @@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
>> *test,
>>  
>> 
>>  if (!bus) {
>>  fprintf(stderr, "ACPI.NFIT unavailable falling back to 
>> nfit_test\n");
>> -rc = nfit_test_init(_ctx, , NULL, log_level, test);
>> +rc = ndctl_test_init(_ctx, , NULL, log_level, test);
>>  ndctl_invalidate(ctx);
>>  bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
>>  if (rc < 0 || !bus) {
>> diff --git a/test/core.c b/test/core.c
>> index cc7d8d9..903034a 100644
>> --- a/test/core.c
>> +++ b/test/core.c
>> @@ -11,6 +11,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  
>> 
>>  #define KVER_STRLEN 20
>> @@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
>>  return test->skip;
>>  }
>>  
>> 
>> -int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>> +int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
>>  struct ndctl_ctx *nd_ctx, int log_level,
>>  struct ndctl_test *test)
>>  {
>> -int rc;
>> +int rc, family = NVDIMM_FAMILY_INTEL;
>>  unsigned int i;
>>  const char *name;
>>  struct ndctl_bus *bus;
>> @@ -127,6 +128,19 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
>> kmod_module **mod,
>>  "nd_e820",
>>  "nd_pmem",
>>  };
>> +char *test_env;
>> +
>> +/* Do we want to force test PAPR? */
>> +test_env = getenv("NDCTL_TEST_FAMILY");
>> +if (test_env && strcmp(test_env, "PAPR") == 0)
>> +family = NVDIMM_FAMILY_PAPR;
>> +
>> +/* ACPI is a must for nfit, so if ACPI is not available let's default to
>> + * PAPR */
>
> fix multi line comment to the right formatting:
> /*
>  * line 1, etc
>  */
>

Will fix that.

>> +if (access("/sys/bus/acpi", F_OK) == -1) {
>> +if (errno == ENOENT)
>> +family = NVDIMM_FAMILY_PAPR;
>> +}
>
> Instead of a blind default, can we perform a similar check for presence of
> PAPR too?
>

Yes, I wanted to do that, but there is no reliable way of check that; there is
no ofnode before module load, and there won't be any PAPR

[ndctl PATCH v3 4/4] Use page size as alignment value

2021-03-10 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 15 ---
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 0b3bb7a..59185cf 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -38,12 +38,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)
@@ -124,11 +125,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;
@@ -150,7 +151,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",
@@ -166,7 +167,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",
@@ -175,7 +176,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",
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index e932569..9451ed0 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -12,6 +12,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
@@ -22,9 +24,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
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index dd7013e..d03c0ca 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -9,6 +9,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
@@ -25,7 +27,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 $NAMES

[ndctl PATCH v3 3/4] papr: Add support to parse save_fail flag for dimm

2021-03-10 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 26b9317..dd1a5fc 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -805,6 +805,8 @@ 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)
@@ -1035,7 +1037,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);
 }
 
 /**
-- 
2.29.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl PATCH v3 2/4] test: Don't skip tests if nfit modules are missing

2021-03-10 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 23 +--
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/test.h b/test.h
index cba8d41..7de13fe 100644
--- a/test.h
+++ b/test.h
@@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index fb1d82b..c561ff3 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index d7f00cb..f076e85 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index cc7d8d9..903034a 100644
--- a/test/core.c
+++ b/test/core.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = NVDIMM_FAMILY_INTEL;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -127,6 +128,19 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_e820",
"nd_pmem",
};
+   char *test_env;
+
+   /* Do we want to force test PAPR? */
+   test_env = getenv("NDCTL_TEST_FAMILY");
+   if (test_env && strcmp(test_env, "PAPR") == 0)
+   family = NVDIMM_FAMILY_PAPR;
+
+   /* ACPI is a must for nfit, so if ACPI is not available let's default to
+* PAPR */
+   if (access("/sys/bus/acpi", F_OK) == -1) {
+   if (errno == ENOENT)
+   family = NVDIMM_FAMILY_PAPR;
+   }
 
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
@@ -185,6 +199,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family == NVDIMM_FAMILY_PAPR &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index e922009..0b3bb7a 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -289,7 +289,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
ndctl_test_skip(test);
fprintf(stderr, "nfit_test unavailable skipping tests\n");
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index 9dfd8b0..0a6383d 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -346,7 +346,7 @@ int test_

[ndctl PATCH v3 1/4] libndctl: test enablement for non-nfit devices

2021-03-10 Thread Santosh Sivaraj
Unify adding dimms for papr and nfit families, this will help in adding
all attributes needed for the unit tests too. We don't fail adding a dimm
if some of the dimm attributes are missing, so this will work fine on PAPR
platforms where most dimm attributes are provided.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 103 ---
 1 file changed, 38 insertions(+), 65 deletions(-)

v3:
* Drop patch which skips SMART tests, smart test enablement will be posted
  soon.

v2:
* Patch 2: Fix a bug, I skip erroring out if PAPR family, but condition had
  INTEL family instead. That change was there to test the same code on x86, but
  accidently committed. Now have a environment variable to force test PAPR
  family on x86.

* Patch 4: Remove stray code, artifact of refactoring in patch 1.

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 36fb6fe..26b9317 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1646,41 +1646,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
-{
-   int rc = -ENODEV;
-   char buf[SYSFS_ATTR_SIZE];
-   struct ndctl_ctx *ctx = dimm->bus->ctx;
-   char *path = calloc(1, strlen(dimm_base) + 100);
-   const char * const devname = ndctl_dimm_get_devname(dimm);
-
-   dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
-
-   if (!path)
-   return -ENOMEM;
-
-   /* construct path to the papr compatible dimm flags file */
-   sprintf(path, "%s/papr/flags", dimm_base);
-
-   if (ndctl_bus_is_papr_scm(dimm->bus) &&
-   sysfs_read_attr(ctx, path, buf) == 0) {
-
-   dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
buf);
-   dimm->cmd_family = NVDIMM_FAMILY_PAPR;
-
-   /* Parse dimm flags */
-   parse_papr_flags(dimm, buf);
-
-   /* Allocate monitor mode fd */
-   dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
-   rc = 0;
-   }
-
-   free(path);
-   return rc;
-}
-
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
+   const char *dimm_base,
+   const char *bus_prefix)
 {
int i, rc = -1;
char buf[SYSFS_ATTR_SIZE];
@@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
 * 'unique_id' may not be available on older kernels, so don't
 * fail if the read fails.
 */
-   sprintf(path, "%s/nfit/id", dimm_base);
+   sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0) {
unsigned int b[9];
 
@@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
}
}
 
-   sprintf(path, "%s/nfit/handle", dimm_base);
+   sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->handle = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/phys_id", dimm_base);
+   sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->phys_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/serial", dimm_base);
+   sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->serial = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/vendor", dimm_base);
+   sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/device", dimm_base);
+   sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->device_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/rev_id", dimm_base);
+   sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->revision_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
+   sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)

Re: [ndctl PATCH 2/2] ndctl/test: add checking the presence of jq command ahead

2021-03-01 Thread Santosh Sivaraj
QI Fuli  writes:

> Due to the lack of jq command, the result of the test will be 'fail'.
> This patch adds checking the presence of jq commmand ahead.
> If there is no jq command in the system, the test will be marked as 'skip'.
>
> Signed-off-by: QI Fuli 
> Link: https://github.com/pmem/ndctl/issues/141

Though it looks slightly redundant after having the check in configure.ac, not
against having additional checks.

Reviewed-by: Santosh Sivaraj 

Thanks,
Santosh

> ---
>  test/daxdev-errors.sh   | 1 +
>  test/inject-error.sh| 2 ++
>  test/inject-smart.sh| 1 +
>  test/label-compat.sh| 1 +
>  test/max_available_extent_ns.sh | 1 +
>  test/monitor.sh | 2 ++
>  test/multi-dax.sh   | 1 +
>  test/sector-mode.sh | 2 ++
>  8 files changed, 11 insertions(+)
>
> diff --git a/test/daxdev-errors.sh b/test/daxdev-errors.sh
> index 6281f32..9547d78 100755
> --- a/test/daxdev-errors.sh
> +++ b/test/daxdev-errors.sh
> @@ -9,6 +9,7 @@ rc=77
>  . $(dirname $0)/common
>
>  check_min_kver "4.12" || do_skip "lacks dax dev error handling"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/inject-error.sh b/test/inject-error.sh
> index c636033..7d0b826 100755
> --- a/test/inject-error.sh
> +++ b/test/inject-error.sh
> @@ -11,6 +11,8 @@ err_count=8
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  trap 'err $LINENO' ERR
>
>  # sample json:
> diff --git a/test/inject-smart.sh b/test/inject-smart.sh
> index 94705df..4ca83b8 100755
> --- a/test/inject-smart.sh
> +++ b/test/inject-smart.sh
> @@ -166,6 +166,7 @@ do_tests()
>  }
>
>  check_min_kver "4.19" || do_skip "kernel $KVER may not support smart 
> (un)injection"
> +check_prereq "jq"
>  modprobe nfit_test
>  rc=1
>
> diff --git a/test/label-compat.sh b/test/label-compat.sh
> index 340b93d..8ab2858 100755
> --- a/test/label-compat.sh
> +++ b/test/label-compat.sh
> @@ -10,6 +10,7 @@ BASE=$(dirname $0)
>  . $BASE/common
>
>  check_min_kver "4.11" || do_skip "may not provide reliable isetcookie values"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/max_available_extent_ns.sh b/test/max_available_extent_ns.sh
> index 14d741d..343f3c9 100755
> --- a/test/max_available_extent_ns.sh
> +++ b/test/max_available_extent_ns.sh
> @@ -9,6 +9,7 @@ rc=77
>  trap 'err $LINENO' ERR
>
>  check_min_kver "4.19" || do_skip "kernel $KVER may not support 
> max_available_size"
> +check_prereq "jq"
>
>  init()
>  {
> diff --git a/test/monitor.sh b/test/monitor.sh
> index cdab5e1..28c5541 100755
> --- a/test/monitor.sh
> +++ b/test/monitor.sh
> @@ -13,6 +13,8 @@ smart_supported_bus=""
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  trap 'err $LINENO' ERR
>
>  check_min_kver "4.15" || do_skip "kernel $KVER may not support monitor 
> service"
> diff --git a/test/multi-dax.sh b/test/multi-dax.sh
> index e932569..8496619 100755
> --- a/test/multi-dax.sh
> +++ b/test/multi-dax.sh
> @@ -9,6 +9,7 @@ rc=77
>  . $(dirname $0)/common
>
>  check_min_kver "4.13" || do_skip "may lack multi-dax support"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/sector-mode.sh b/test/sector-mode.sh
> index dd7013e..54fa806 100755
> --- a/test/sector-mode.sh
> +++ b/test/sector-mode.sh
> @@ -6,6 +6,8 @@ rc=77
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  set -e
>  trap 'err $LINENO' ERR
>
> --
> 2.29.2
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl PATCH 1/2] configure: add checking jq command

2021-03-01 Thread Santosh Sivaraj


Hi Qi,

QI Fuli  writes:

> Add checking jq command since it is needed to validate tests
>
> Cc: Santosh Sivaraj 
> Signed-off-by: QI Fuli 
> Link: https://github.com/pmem/ndctl/issues/141
> ---
>  configure.ac | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index 5ec8d2f..839836b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -65,6 +65,12 @@ fi
>  AC_SUBST([XMLTO])
>  fi
>
> +AC_CHECK_PROG(JQ, [jq], [$(which jq)], [missing])
> +if test "x$JQ" = xmissing; then
> + AC_MSG_ERROR([jq command needed to validate tests])
> +fi
> +AC_SUBST([JQ])
> +
>  AC_C_TYPEOF
>  AC_DEFINE([HAVE_STATEMENT_EXPR], 1, [Define to 1 if you have statement 
> expressions.])
>
> --
> 2.29.2

Acked-by: Santosh Sivaraj 

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl PATCH] ndctl/test: add checking the presence of jq command ahead

2021-02-25 Thread Santosh Sivaraj


Hi QI,

QI Fuli  writes:

> Due to the lack of jq command, the result of the test will be 'fail'.
> This patch adds checking the presence of jq commmand ahead.
> If there is no jq command in the system, the test will be marked as 'skip'.
>
> Signed-off-by: QI Fuli 
> Link: https://github.com/pmem/ndctl/issues/141

Could this dependency be made part of configure.ac? Something like

diff --git a/configure.ac b/configure.ac
index 5ec8d2f..0f2c6c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,13 @@ fi
 AC_SUBST([XMLTO])
 fi
 
+AC_CHECK_PROG(JQ, [jq], [$(which jq)], [missing])
+if test "x$JQ" = xmissing; then
+   AC_MSG_ERROR([jq needed to validate tests])
+fi
+AC_SUBST([JQ])
+
+
 AC_C_TYPEOF
 AC_DEFINE([HAVE_STATEMENT_EXPR], 1, [Define to 1 if you have statement 
expressions.])

Thanks,
Santosh

> ---
>  test/daxdev-errors.sh   | 1 +
>  test/inject-error.sh| 2 ++
>  test/inject-smart.sh| 1 +
>  test/label-compat.sh| 1 +
>  test/max_available_extent_ns.sh | 1 +
>  test/monitor.sh | 2 ++
>  test/multi-dax.sh   | 1 +
>  test/sector-mode.sh | 2 ++
>  8 files changed, 11 insertions(+)
>
> diff --git a/test/daxdev-errors.sh b/test/daxdev-errors.sh
> index 6281f32..9547d78 100755
> --- a/test/daxdev-errors.sh
> +++ b/test/daxdev-errors.sh
> @@ -9,6 +9,7 @@ rc=77
>  . $(dirname $0)/common
>
>  check_min_kver "4.12" || do_skip "lacks dax dev error handling"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/inject-error.sh b/test/inject-error.sh
> index c636033..7d0b826 100755
> --- a/test/inject-error.sh
> +++ b/test/inject-error.sh
> @@ -11,6 +11,8 @@ err_count=8
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  trap 'err $LINENO' ERR
>
>  # sample json:
> diff --git a/test/inject-smart.sh b/test/inject-smart.sh
> index 94705df..4ca83b8 100755
> --- a/test/inject-smart.sh
> +++ b/test/inject-smart.sh
> @@ -166,6 +166,7 @@ do_tests()
>  }
>
>  check_min_kver "4.19" || do_skip "kernel $KVER may not support smart 
> (un)injection"
> +check_prereq "jq"
>  modprobe nfit_test
>  rc=1
>
> diff --git a/test/label-compat.sh b/test/label-compat.sh
> index 340b93d..8ab2858 100755
> --- a/test/label-compat.sh
> +++ b/test/label-compat.sh
> @@ -10,6 +10,7 @@ BASE=$(dirname $0)
>  . $BASE/common
>
>  check_min_kver "4.11" || do_skip "may not provide reliable isetcookie values"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/max_available_extent_ns.sh b/test/max_available_extent_ns.sh
> index 14d741d..343f3c9 100755
> --- a/test/max_available_extent_ns.sh
> +++ b/test/max_available_extent_ns.sh
> @@ -9,6 +9,7 @@ rc=77
>  trap 'err $LINENO' ERR
>
>  check_min_kver "4.19" || do_skip "kernel $KVER may not support 
> max_available_size"
> +check_prereq "jq"
>
>  init()
>  {
> diff --git a/test/monitor.sh b/test/monitor.sh
> index cdab5e1..28c5541 100755
> --- a/test/monitor.sh
> +++ b/test/monitor.sh
> @@ -13,6 +13,8 @@ smart_supported_bus=""
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  trap 'err $LINENO' ERR
>
>  check_min_kver "4.15" || do_skip "kernel $KVER may not support monitor 
> service"
> diff --git a/test/multi-dax.sh b/test/multi-dax.sh
> index e932569..8496619 100755
> --- a/test/multi-dax.sh
> +++ b/test/multi-dax.sh
> @@ -9,6 +9,7 @@ rc=77
>  . $(dirname $0)/common
>
>  check_min_kver "4.13" || do_skip "may lack multi-dax support"
> +check_prereq "jq"
>
>  trap 'err $LINENO' ERR
>
> diff --git a/test/sector-mode.sh b/test/sector-mode.sh
> index dd7013e..54fa806 100755
> --- a/test/sector-mode.sh
> +++ b/test/sector-mode.sh
> @@ -6,6 +6,8 @@ rc=77
>
>  . $(dirname $0)/common
>
> +check_prereq "jq"
> +
>  set -e
>  trap 'err $LINENO' ERR
>
> --
> 2.29.2
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH v2 4/4] Use page size as alignment value

2021-02-24 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 15 ---
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 10af189..ef3a1a9 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -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",
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index 110ba3d..8250128 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -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
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index eef8dc6..cee0313 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -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-autolabe

[PATCH v2 3/4] test/libndctl: skip SMART tests on non-nfit devices

2021-02-24 Thread Santosh Sivaraj
This is just a temporary check till the new module has SMART capabilities
emulated.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 5043ae0..001f78a 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -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));
 
-- 
2.29.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH v2 2/4] papr: Add support to parse save_fail flag for dimm

2021-02-24 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 5f09628..3fb3aed 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -815,6 +815,8 @@ 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)
@@ -1044,7 +1046,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);
 }
 
 /**
-- 
2.29.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH v2 1/4] test: Don't skip tests if nfit modules are missing

2021-02-24 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 23 +--
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 30 insertions(+), 11 deletions(-)

Changelog:
v2:
  * Patch 2: Fix a bug, I skip erroring out if PAPR family, but condition had 
INTEL family instead.
That change was there to test the same code on x86, but accidently 
committed. Now have
a environment variable to force test PAPR family on x86.

  * Patch 4: Remove stray code, artifact of refactoring in patch 1.
  
diff --git a/test.h b/test.h
index 3f6212e..94d8936 100644
--- a/test.h
+++ b/test.h
@@ -30,7 +30,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index 742e976..6315a94 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index 437fcad..dfb0332 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -240,7 +240,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index 5118d86..8e48fd6 100644
--- a/test/core.c
+++ b/test/core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -116,11 +117,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = NVDIMM_FAMILY_INTEL;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -137,6 +138,19 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_e820",
"nd_pmem",
};
+   char *test_env;
+
+   /* Do we want to force test PAPR? */
+   test_env = getenv("NDCTL_TEST_FAMILY");
+   if (test_env && strcmp(test_env, "PAPR") == 0)
+   family = NVDIMM_FAMILY_PAPR;
+
+   /* ACPI is a must for nfit, so if ACPI is not available let's default to
+* PAPR */
+   if (access("/sys/bus/acpi", F_OK) == -1) {
+   if (errno == ENOENT)
+   family = NVDIMM_FAMILY_PAPR;
+   }
 
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
@@ -195,6 +209,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family == NVDIMM_FAMILY_PAPR &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index b757b9a..10af189 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -299,7 +299,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_

Re: [ndctl 5/5] Use page size as alignment value

2021-02-24 Thread Santosh Sivaraj
Dan Williams  writes:

> On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj  wrote:
>>
>> The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
>> the default page size on x86. Change those to the default page size on that
>> architecture (sysconf/getconf). No functional changes otherwise.
>>
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  test/dpa-alloc.c| 23 ++-
>>  test/multi-dax.sh   |  6 --
>>  test/sector-mode.sh |  4 +++-
>>  3 files changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
>> index 10af189..ff6143e 100644
>> --- a/test/dpa-alloc.c
>> +++ b/test/dpa-alloc.c
>> @@ -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;
>
> This change seems unrelated to page size fixups. Care to break it out?

This change is not required, I have already fixed this up. Refactoring residue.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl 3/5] papr: Add support to parse save_fail flag for dimm

2021-02-24 Thread Santosh Sivaraj
Dan Williams  writes:

> On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj  wrote:
>>
>> This will help in getting the dimm fail tests to run on papr family too.
>> Also add nvdimm_test compatibility string for recognizing the test module.
>>
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  ndctl/lib/libndctl.c | 5 -
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
>> index 5f09628..3fb3aed 100644
>> --- a/ndctl/lib/libndctl.c
>> +++ b/ndctl/lib/libndctl.c
>> @@ -815,6 +815,8 @@ 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)
>> @@ -1044,7 +1046,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);
>
> A bit unfortunate to leak test details into the production path,
> especially when nvdimm_test is meant to be generic. It seems what you
> really want is a generic way to determine if dimm supports the common
> error state flags, right? I'd add an api for that and say yes for nfit
> and papr.

Sorry to get to this late.

Though I would like it to be generic, there is some advantage of code reuse if
it's part of the PAPR_FAMILY.

So the idea in the above code is to determine which flag parsing code to call,
either parse_nfit_mem_flags or parse_papr_flags. Or I could write a new function
if the bus is of neither type. But that would again want me to duplicate error
inject related code, and may be other paths too.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl 5/5] Use page size as alignment value

2021-01-28 Thread Santosh Sivaraj
Dan Williams  writes:

> On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj  wrote:
>>
>> The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
>> the default page size on x86. Change those to the default page size on that
>> architecture (sysconf/getconf). No functional changes otherwise.
>>
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  test/dpa-alloc.c| 23 ++-
>>  test/multi-dax.sh   |  6 --
>>  test/sector-mode.sh |  4 +++-
>>  3 files changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
>> index 10af189..ff6143e 100644
>> --- a/test/dpa-alloc.c
>> +++ b/test/dpa-alloc.c
>> @@ -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;
>
> This change seems unrelated to page size fixups. Care to break it out?

Sure Dan, I will add the API to check for DIMM error state flags too. Thanks for
the review, I will send a v2 soon.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl 5/5] Use page size as alignment value

2020-12-21 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 23 ++-
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 10af189..ff6143e 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -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)
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index 110ba3d..8250128 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -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
d

[ndctl 4/5] test/libndctl: skip SMART tests on non-nfit devices

2020-12-21 Thread Santosh Sivaraj
This is just a temporary check till the new module has SMART capabilities
emulated.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 5043ae0..001f78a 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -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));
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl 3/5] papr: Add support to parse save_fail flag for dimm

2020-12-21 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 5f09628..3fb3aed 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -815,6 +815,8 @@ 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)
@@ -1044,7 +1046,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);
 }
 
 /**
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl 2/5] test: Don't skip tests if nfit modules are missing

2020-12-21 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 15 +--
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/test.h b/test.h
index 3f6212e..94d8936 100644
--- a/test.h
+++ b/test.h
@@ -30,7 +30,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index 742e976..6315a94 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index 437fcad..dfb0332 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -240,7 +240,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index 5118d86..974bbc4 100644
--- a/test/core.c
+++ b/test/core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -116,11 +117,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = NVDIMM_FAMILY_INTEL;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -138,6 +139,11 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_pmem",
};
 
+   if (access("/sys/bus/acpi", F_OK) == 0) {
+   if (errno == ENOENT)
+   family = NVDIMM_FAMILY_PAPR;
+   }
+
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
 
@@ -195,6 +201,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family == NVDIMM_FAMILY_INTEL &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index b757b9a..10af189 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -299,7 +299,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
ndctl_test_skip(test);
fprintf(stderr, "nfit_test unavailable skipping tests\n");
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index b2c51db..1d03470 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -356,7 +356,7 @@ int test_dsm_fail(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/tes

[ndctl 1/5] libndctl: test enablement for non-nfit devices

2020-12-21 Thread Santosh Sivaraj
Unify adding dimms for papr and nfit families, this will help in adding
all attributes needed for the unit tests too. We don't fail adding a dimm
if some of the dimm attributes are missing, so this will work fine on PAPR
platforms where most dimm attributes are provided.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 103 ---
 1 file changed, 38 insertions(+), 65 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ad521d3..5f09628 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1655,41 +1655,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
-{
-   int rc = -ENODEV;
-   char buf[SYSFS_ATTR_SIZE];
-   struct ndctl_ctx *ctx = dimm->bus->ctx;
-   char *path = calloc(1, strlen(dimm_base) + 100);
-   const char * const devname = ndctl_dimm_get_devname(dimm);
-
-   dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
-
-   if (!path)
-   return -ENOMEM;
-
-   /* construct path to the papr compatible dimm flags file */
-   sprintf(path, "%s/papr/flags", dimm_base);
-
-   if (ndctl_bus_is_papr_scm(dimm->bus) &&
-   sysfs_read_attr(ctx, path, buf) == 0) {
-
-   dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
buf);
-   dimm->cmd_family = NVDIMM_FAMILY_PAPR;
-
-   /* Parse dimm flags */
-   parse_papr_flags(dimm, buf);
-
-   /* Allocate monitor mode fd */
-   dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
-   rc = 0;
-   }
-
-   free(path);
-   return rc;
-}
-
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
+   const char *dimm_base,
+   const char *bus_prefix)
 {
int i, rc = -1;
char buf[SYSFS_ATTR_SIZE];
@@ -1703,7 +1671,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
 * 'unique_id' may not be available on older kernels, so don't
 * fail if the read fails.
 */
-   sprintf(path, "%s/nfit/id", dimm_base);
+   sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0) {
unsigned int b[9];
 
@@ -1718,68 +1686,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
}
}
 
-   sprintf(path, "%s/nfit/handle", dimm_base);
+   sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->handle = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/phys_id", dimm_base);
+   sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->phys_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/serial", dimm_base);
+   sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->serial = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/vendor", dimm_base);
+   sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/device", dimm_base);
+   sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->device_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/rev_id", dimm_base);
+   sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->revision_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
+   sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->dirty_shutdown = strtoll(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_vendor", dimm_base);
+   sprintf(path, "%s/%s/subsystem_vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_device", dimm_base)

[PATCH 7/7] ndtest: Add papr health related flags

2020-12-21 Thread Santosh Sivaraj
sysfs attibutes to show health related flags are added.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 41 ++
 tools/testing/nvdimm/test/ndtest.h | 31 ++
 2 files changed, 72 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index dc1e3636616a..6862915f1fb0 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -86,6 +86,9 @@ static struct ndtest_dimm dimm_group2[] = {
.uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
.physical_id = 0,
.num_formats = 1,
+   .flags = PAPR_PMEM_UNARMED | PAPR_PMEM_EMPTY |
+PAPR_PMEM_SAVE_FAILED | PAPR_PMEM_SHUTDOWN_DIRTY |
+PAPR_PMEM_HEALTH_FATAL,
},
 };
 
@@ -789,6 +792,40 @@ static umode_t ndtest_nvdimm_attr_visible(struct kobject 
*kobj,
return a->mode;
 }
 
+static ssize_t flags_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+   struct seq_buf s;
+   u64 flags;
+
+   flags = dimm->flags;
+
+   seq_buf_init(, buf, PAGE_SIZE);
+   if (flags & PAPR_PMEM_UNARMED_MASK)
+   seq_buf_printf(, "not_armed ");
+
+   if (flags & PAPR_PMEM_BAD_SHUTDOWN_MASK)
+   seq_buf_printf(, "flush_fail ");
+
+   if (flags & PAPR_PMEM_BAD_RESTORE_MASK)
+   seq_buf_printf(, "restore_fail ");
+
+   if (flags & PAPR_PMEM_SAVE_MASK)
+   seq_buf_printf(, "save_fail ");
+
+   if (flags & PAPR_PMEM_SMART_EVENT_MASK)
+   seq_buf_printf(, "smart_notify ");
+
+
+   if (seq_buf_used())
+   seq_buf_printf(, "\n");
+
+   return seq_buf_used();
+}
+static DEVICE_ATTR_RO(flags);
+
 static struct attribute *ndtest_nvdimm_attributes[] = {
_attr_nvdimm_show_handle.attr,
_attr_vendor.attr,
@@ -799,6 +836,7 @@ static struct attribute *ndtest_nvdimm_attributes[] = {
_attr_formats.attr,
_attr_format.attr,
_attr_format1.attr,
+   _attr_flags.attr,
NULL,
 };
 
@@ -824,6 +862,9 @@ static int ndtest_dimm_register(struct ndtest_priv *priv,
set_bit(NDD_LABELING, _flags);
}
 
+   if (dimm->flags & PAPR_PMEM_UNARMED_MASK)
+   set_bit(NDD_UNARMED, _flags);
+
dimm->nvdimm = nvdimm_create(priv->bus, dimm,
ndtest_nvdimm_attribute_groups, dimm_flags,
NDTEST_SCM_DIMM_CMD_MASK, 0, NULL);
diff --git a/tools/testing/nvdimm/test/ndtest.h 
b/tools/testing/nvdimm/test/ndtest.h
index 8f27ad6f7319..2c54c9cbb90c 100644
--- a/tools/testing/nvdimm/test/ndtest.h
+++ b/tools/testing/nvdimm/test/ndtest.h
@@ -5,6 +5,37 @@
 #include 
 #include 
 
+/* SCM device is unable to persist memory contents */
+#define PAPR_PMEM_UNARMED   (1ULL << (63 - 0))
+/* SCM device failed to persist memory contents */
+#define PAPR_PMEM_SHUTDOWN_DIRTY(1ULL << (63 - 1))
+/* SCM device contents are not persisted from previous IPL */
+#define PAPR_PMEM_EMPTY (1ULL << (63 - 3))
+#define PAPR_PMEM_HEALTH_CRITICAL   (1ULL << (63 - 4))
+/* SCM device will be garded off next IPL due to failure */
+#define PAPR_PMEM_HEALTH_FATAL  (1ULL << (63 - 5))
+/* SCM contents cannot persist due to current platform health status */
+#define PAPR_PMEM_HEALTH_UNHEALTHY  (1ULL << (63 - 6))
+
+/* Bits status indicators for health bitmap indicating unarmed dimm */
+#define PAPR_PMEM_UNARMED_MASK (PAPR_PMEM_UNARMED |\
+   PAPR_PMEM_HEALTH_UNHEALTHY)
+
+#define PAPR_PMEM_SAVE_FAILED(1ULL << (63 - 10))
+
+/* Bits status indicators for health bitmap indicating unflushed dimm */
+#define PAPR_PMEM_BAD_SHUTDOWN_MASK (PAPR_PMEM_SHUTDOWN_DIRTY)
+
+/* Bits status indicators for health bitmap indicating unrestored dimm */
+#define PAPR_PMEM_BAD_RESTORE_MASK  (PAPR_PMEM_EMPTY)
+
+/* Bit status indicators for smart event notification */
+#define PAPR_PMEM_SMART_EVENT_MASK (PAPR_PMEM_HEALTH_CRITICAL | \
+   PAPR_PMEM_HEALTH_FATAL |\
+   PAPR_PMEM_HEALTH_UNHEALTHY)
+
+#define PAPR_PMEM_SAVE_MASK(PAPR_PMEM_SAVE_FAILED)
+
 struct ndtest_config;
 
 struct ndtest_priv {
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH 6/7] ndtest: Add nvdimm control functions

2020-12-21 Thread Santosh Sivaraj
Add functions to support ND_CMD_GET_CONFIG_SIZE, ND_CMD_SET_CONFIG_DATA and
ND_CMD_GET_CONFIG_DATA.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 821296b59bdc..dc1e3636616a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -254,6 +254,45 @@ static inline struct ndtest_priv *to_ndtest_priv(struct 
device *dev)
return container_of(pdev, struct ndtest_priv, pdev);
 }
 
+static int ndtest_config_get(struct ndtest_dimm *p, unsigned int buf_len,
+struct nd_cmd_get_config_data_hdr *hdr)
+{
+   unsigned int len;
+
+   if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+   return -EINVAL;
+
+   hdr->status = 0;
+   len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+   memcpy(hdr->out_buf, p->label_area + hdr->in_offset, len);
+
+   return buf_len - len;
+}
+
+static int ndtest_config_set(struct ndtest_dimm *p, unsigned int buf_len,
+struct nd_cmd_set_config_hdr *hdr)
+{
+   unsigned int len;
+
+   if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+   return -EINVAL;
+
+   len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+   memcpy(p->label_area + hdr->in_offset, hdr->in_buf, len);
+
+   return buf_len - len;
+}
+
+static int ndtest_get_config_size(struct ndtest_dimm *dimm, unsigned int 
buf_len,
+ struct nd_cmd_get_config_size *size)
+{
+   size->status = 0;
+   size->max_xfer = 8;
+   size->config_size = dimm->config_size;
+
+   return 0;
+}
+
 static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
  struct nvdimm *nvdimm, unsigned int cmd, void *buf,
  unsigned int buf_len, int *cmd_rc)
@@ -275,12 +314,24 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor 
*nd_desc,
 
switch (cmd) {
case ND_CMD_GET_CONFIG_SIZE:
+   *cmd_rc = ndtest_get_config_size(dimm, buf_len, buf);
+   break;
case ND_CMD_GET_CONFIG_DATA:
+   *cmd_rc = ndtest_config_get(dimm, buf_len, buf);
+   break;
case ND_CMD_SET_CONFIG_DATA:
+   *cmd_rc = ndtest_config_set(dimm, buf_len, buf);
+   break;
default:
return -EINVAL;
}
 
+   /* Failures for a DIMM can be injected using fail_cmd and
+* fail_cmd_code, see the device attributes below
+*/
+   if ((1 << cmd) & dimm->fail_cmd)
+   return dimm->fail_cmd_code ? dimm->fail_cmd_code : -EIO;
+
return 0;
 }
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH 5/7] ndtest: Add regions and mappings to the test buses

2020-12-21 Thread Santosh Sivaraj
The bus config array is used to hold the regions and the respective
mappings. This config based interface enables to change the
dimm/region/namespace layouts easily.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 352 +
 tools/testing/nvdimm/test/ndtest.h |  26 +++
 2 files changed, 378 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index f7682e1d3efe..821296b59bdc 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -23,6 +23,7 @@ enum {
LABEL_SIZE = SZ_128K,
NUM_INSTANCES = 2,
NUM_DCR = 4,
+   NDTEST_MAX_MAPPING = 6,
 };
 
 #define NDTEST_SCM_DIMM_CMD_MASK  \
@@ -88,18 +89,161 @@ static struct ndtest_dimm dimm_group2[] = {
},
 };
 
+static struct ndtest_mapping region0_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 1,
+   .position = 1,
+   .start = 0,
+   .size = SZ_16M,
+   }
+};
+
+static struct ndtest_mapping region1_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 1,
+   .position = 1,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 2,
+   .position = 2,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 3,
+   .position = 3,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+};
+
+static struct ndtest_mapping region2_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = DIMM_SIZE,
+   },
+};
+
+static struct ndtest_mapping region3_mapping[] = {
+   {
+   .dimm = 1,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_mapping region4_mapping[] = {
+   {
+   .dimm = 2,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_mapping region5_mapping[] = {
+   {
+   .dimm = 3,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_region bus0_regions[] = {
+   {
+   .type = ND_DEVICE_NAMESPACE_PMEM,
+   .num_mappings = ARRAY_SIZE(region0_mapping),
+   .mapping = region0_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 1,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_PMEM,
+   .num_mappings = ARRAY_SIZE(region1_mapping),
+   .mapping = region1_mapping,
+   .size = DIMM_SIZE * 2,
+   .range_index = 2,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region2_mapping),
+   .mapping = region2_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 3,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region3_mapping),
+   .mapping = region3_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 4,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region4_mapping),
+   .mapping = region4_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 5,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region5_mapping),
+   .mapping = region5_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 6,
+   },
+};
+
+static struct ndtest_mapping region6_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = DIMM_SIZE,
+   },
+};
+
+static struct ndtest_region bus1_regions[] = {
+   {
+   .type = ND_DEVICE_NAMESPACE_IO,
+   .num_mappings = ARRAY_SIZE(region6_mapping),
+   .mapping = region6_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 1,
+   },
+};
+
 static struct ndtest_config bus_configs[NUM_INSTANCES] = {
/* bus 1 */
{
.dimm_start = 0,
.dimm_count = ARRAY_SIZE(dimm_group1),
.dimms = dimm_group1,
+   .regions = bus0_regions,
+   .num_regions = ARRAY_SIZE(bus0_regions),
},
/* bus 2 */
{
.dimm_start = ARRAY_SIZE(dimm_group1),
.dimm_count = ARRAY_SIZE(dimm_group2

[PATCH 4/7] ndtest: Add dimm attributes

2020-12-21 Thread Santosh Sivaraj
This patch adds sysfs attributes for nvdimm and the dimm device.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 202 -
 1 file changed, 200 insertions(+), 2 deletions(-)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index a82790013f8a..f7682e1d3efe 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -219,6 +219,203 @@ static void put_dimms(void *data)
}
 }
 
+static ssize_t handle_show(struct device *dev, struct device_attribute *attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%#x\n", dimm->handle);
+}
+static DEVICE_ATTR_RO(handle);
+
+static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%#x\n", dimm->fail_cmd);
+}
+
+static ssize_t fail_cmd_store(struct device *dev, struct device_attribute 
*attr,
+   const char *buf, size_t size)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+   unsigned long val;
+   ssize_t rc;
+
+   rc = kstrtol(buf, 0, );
+   if (rc)
+   return rc;
+
+   dimm->fail_cmd = val;
+
+   return size;
+}
+static DEVICE_ATTR_RW(fail_cmd);
+
+static ssize_t fail_cmd_code_show(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%d\n", dimm->fail_cmd_code);
+}
+
+static ssize_t fail_cmd_code_store(struct device *dev, struct device_attribute 
*attr,
+   const char *buf, size_t size)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+   unsigned long val;
+   ssize_t rc;
+
+   rc = kstrtol(buf, 0, );
+   if (rc)
+   return rc;
+
+   dimm->fail_cmd_code = val;
+   return size;
+}
+static DEVICE_ATTR_RW(fail_cmd_code);
+
+static struct attribute *dimm_attributes[] = {
+   _attr_handle.attr,
+   _attr_fail_cmd.attr,
+   _attr_fail_cmd_code.attr,
+   NULL,
+};
+
+static struct attribute_group dimm_attribute_group = {
+   .attrs = dimm_attributes,
+};
+
+static const struct attribute_group *dimm_attribute_groups[] = {
+   _attribute_group,
+   NULL,
+};
+
+static ssize_t phys_id_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%#x\n", dimm->physical_id);
+}
+static DEVICE_ATTR_RO(phys_id);
+
+static ssize_t vendor_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "0x1234567\n");
+}
+static DEVICE_ATTR_RO(vendor);
+
+static ssize_t id_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%04x-%02x-%04x-%08x", 0xabcd,
+  0xa, 2016, ~(dimm->handle));
+}
+static DEVICE_ATTR_RO(id);
+
+static ssize_t nvdimm_handle_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%#x\n", dimm->handle);
+}
+
+static struct device_attribute dev_attr_nvdimm_show_handle =  {
+   .attr   = { .name = "handle", .mode = 0444 },
+   .show   = nvdimm_handle_show,
+};
+
+static ssize_t subsystem_vendor_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "0x%04x\n", 0);
+}
+static DEVICE_ATTR_RO(subsystem_vendor);
+
+static ssize_t dirty_shutdown_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "%d\n", 42);
+}
+static DEVICE_ATTR_RO(dirty_shutdown);
+
+static ssize_t formats_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%d\n", dimm->num_formats);
+}
+static DEVICE_ATTR_RO(formats);
+
+static ssize_t format_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   if (dimm->num_formats > 1)
+   return sprintf(buf, "0x201\n");
+
+ 

[PATCH 3/7] ndtest: Add dimms to the two buses

2020-12-21 Thread Santosh Sivaraj
A config array is used to hold the dimms for each bus. These dimms are
registered with nvdimm, and new nvdimms are created on the buses.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 258 +
 tools/testing/nvdimm/test/ndtest.h |  36 
 2 files changed, 294 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 001527b37a23..a82790013f8a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -25,8 +25,83 @@ enum {
NUM_DCR = 4,
 };
 
+#define NDTEST_SCM_DIMM_CMD_MASK  \
+   ((1ul << ND_CMD_GET_CONFIG_SIZE) | \
+(1ul << ND_CMD_GET_CONFIG_DATA) | \
+(1ul << ND_CMD_SET_CONFIG_DATA) | \
+(1ul << ND_CMD_CALL))
+
+#define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm)
\
+   (((node & 0xfff) << 16) | ((socket & 0xf) << 12)\
+| ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
+
+static DEFINE_SPINLOCK(ndtest_lock);
 static struct ndtest_priv *instances[NUM_INSTANCES];
 static struct class *ndtest_dimm_class;
+static struct gen_pool *ndtest_pool;
+
+static struct ndtest_dimm dimm_group1[] = {
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
+   .uuid_str = "1e5c75d2-b618-11ea-9aa3-507b9ddc0f72",
+   .physical_id = 0,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
+   .uuid_str = "1c4d43ac-b618-11ea-be80-507b9ddc0f72",
+   .physical_id = 1,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
+   .uuid_str = "a9f17ffc-b618-11ea-b36d-507b9ddc0f72",
+   .physical_id = 2,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
+   .uuid_str = "b6b83b22-b618-11ea-8aae-507b9ddc0f72",
+   .physical_id = 3,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
+   .uuid_str = "bf9baaee-b618-11ea-b181-507b9ddc0f72",
+   .physical_id = 4,
+   .num_formats = 2,
+   },
+};
+
+static struct ndtest_dimm dimm_group2[] = {
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0),
+   .uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
+   .physical_id = 0,
+   .num_formats = 1,
+   },
+};
+
+static struct ndtest_config bus_configs[NUM_INSTANCES] = {
+   /* bus 1 */
+   {
+   .dimm_start = 0,
+   .dimm_count = ARRAY_SIZE(dimm_group1),
+   .dimms = dimm_group1,
+   },
+   /* bus 2 */
+   {
+   .dimm_start = ARRAY_SIZE(dimm_group1),
+   .dimm_count = ARRAY_SIZE(dimm_group2),
+   .dimms = dimm_group2,
+   },
+};
 
 static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
 {
@@ -65,6 +140,152 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor 
*nd_desc,
return 0;
 }
 
+static void ndtest_release_resource(void *data)
+{
+   struct nfit_test_resource *res  = data;
+
+   spin_lock(_lock);
+   list_del(>list);
+   spin_unlock(_lock);
+
+   if (resource_size(>res) >= DIMM_SIZE)
+   gen_pool_free(ndtest_pool, res->res.start,
+   resource_size(>res));
+   vfree(res->buf);
+   kfree(res);
+}
+
+static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
+  dma_addr_t *dma)
+{
+   dma_addr_t __dma;
+   void *buf;
+   struct nfit_test_resource *res;
+   struct genpool_data_align data = {
+   .align = SZ_128M,
+   };
+
+   res = kzalloc(sizeof(*res), GFP_KERNEL);
+   if (!res)
+   return NULL;
+
+   buf = vmalloc(size);
+   if (size >= DIMM_SIZE)
+   __dma = gen_pool_alloc_algo(ndtest_pool, size,
+   gen_pool_first_fit_align, );
+   else
+   __dma = (unsigned long) buf;
+
+   if (!__dma)
+   goto buf_err;
+
+   INIT_LIST_HEAD(>list);
+   res->dev = >pdev.dev;
+   res->buf = buf;
+   res->res.start = __dma;
+   res->res.end = __dma + size - 1;
+   res->res.name = "NFIT";
+   spin_lock_init(>lock);
+   INIT_LIST_HEAD(>requests);
+   spin_lock(_lock)

[PATCH 2/7] ndtest: Add compatability string to treat it as PAPR family

2020-12-21 Thread Santosh Sivaraj
Since this module is written to be platform agnostic, the module is made
part of the PAPR_FAMILY. ndctl identifies the family using the compatible
string inside of_node dir-entry.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index f89d74fdcdee..001527b37a23 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -65,11 +65,34 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
return 0;
 }
 
+static ssize_t compatible_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "nvdimm_test");
+}
+static DEVICE_ATTR_RO(compatible);
+
+static struct attribute *of_node_attributes[] = {
+   _attr_compatible.attr,
+   NULL
+};
+
+static const struct attribute_group of_node_attribute_group = {
+   .name = "of_node",
+   .attrs = of_node_attributes,
+};
+
+static const struct attribute_group *ndtest_attribute_groups[] = {
+   _node_attribute_group,
+   NULL,
+};
+
 static int ndtest_bus_register(struct ndtest_priv *p)
 {
p->bus_desc.ndctl = ndtest_ctl;
p->bus_desc.module = THIS_MODULE;
p->bus_desc.provider_name = NULL;
+   p->bus_desc.attr_groups = ndtest_attribute_groups;
 
p->bus = nvdimm_bus_register(>pdev.dev, >bus_desc);
if (!p->bus) {
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH 1/7] testing/nvdimm: Add test module for non-nfit platforms

2020-12-21 Thread 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.

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

This RFC series is split into reviewable and compilable chunks.

This patch adds a new driver and registers two nvdimm bus needed for ndctl
make check.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/config_check.c |   3 +-
 tools/testing/nvdimm/test/Kbuild|   6 +-
 tools/testing/nvdimm/test/ndtest.c  | 206 
 tools/testing/nvdimm/test/ndtest.h  |  16 +++
 4 files changed, 229 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

diff --git a/tools/testing/nvdimm/config_check.c 
b/tools/testing/nvdimm/config_check.c
index cac891028cd1..3e3a5f518864 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -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));
 }
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index 75baebf8f4ba..197bcb2b7f35 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -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
diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
new file mode 100644
index ..f89d74fdcdee
--- /dev/null
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../watermark.h"
+#include "nfit_test.h"
+#include "ndtest.h"
+
+enum {
+   DIMM_SIZE = SZ_32M,
+   LABEL_SIZE = SZ_128K,
+   NUM_INSTANCES = 2,
+   NUM_DCR = 4,
+};
+
+static struct ndtest_priv *instances[NUM_INSTANCES];
+static struct class *ndtest_dimm_class;
+
+static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+
+   return container_of(pdev, struct ndtest_priv, pdev);
+}
+
+static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
+ struct nvdimm *nvdimm, unsigned int cmd, void *buf,
+ unsigned int buf_len, int *cmd_rc)
+{
+   struct ndtest_dimm *dimm;
+   int _cmd_rc;
+
+   if (!cmd_rc)
+   cmd_rc = &_cmd_rc;
+
+   *cmd_rc = 0;
+
+   if (!nvdimm)
+   return -EINVAL;
+
+   dimm = nvdimm_provider_data(nvdimm);
+   if (!dimm)
+   return -EINVAL;
+
+   switch (cmd) {
+   case ND_CMD_GET_CONFIG_SIZE:
+   case ND_CMD_GET_CONFIG_DATA:
+   case ND_CMD_SET_CONFIG_DATA:
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int ndtest_bus_register(struct ndtest_priv *p)
+{
+   p->bus_desc.ndctl = ndtest_ctl;
+   p->bus_desc.module = THIS_MODULE;
+   p->bus_desc.provider_name = NULL;
+
+   p->bus = nvdimm_bus_register(>pdev.dev, >bus_desc);
+   if (!p->bus) {
+   dev_err(>pdev.dev, "Error creating nvdimm bus %pOF\n", 
p->dn);
+   return -ENOMEM;
+   }
+
+   return 0;
+}
+
+static int ndtest_remove(struct platform_device *pdev)
+{
+   struct ndtest_priv *p = to_ndtest_priv(>dev);
+
+   nvdimm_bus_unregister(p->bus);
+   return 0;
+}
+
+static int ndtest_probe(struct platform_device *pdev)
+{
+   struct ndtest_priv *p;
+
+   p = to_ndtest_priv(>dev);
+   if (ndtest_bus_register(p))
+   return -ENOMEM;
+
+   platform_set_drvdata(pdev, p);
+
+   return 0;
+}
+
+static const struct platform_device_id ndtest_id[] = {
+   { KBUILD_MODNAME },
+   { },
+};
+
+static struct platform_driver ndtest_driver = {
+   .probe = ndtest_probe,
+   .remove = ndtest_remove,
+   .driver = {
+   .name = KBUILD_MODNAME,
+   },
+   .id_table = ndtest_id,
+};
+
+static void ndtest_release(str

[0/7] PMEM device emulation without nfit depenency

2020-12-21 Thread 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.

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.

None of tests passed on PAPR before, now there are 16 test that pass. Error
injection tests and SMART are not yet implemented.

Santosh Sivaraj (7):
  testing/nvdimm: Add test module for non-nfit platforms
  ndtest: Add compatability string to treat it as PAPR family
  ndtest: Add dimms to the two buses
  ndtest: Add dimm attributes
  ndtest: Add regions and mappings to the test buses
  ndtest: Add nvdimm control functions
  ndtest: Add papr health related flags

 tools/testing/nvdimm/config_check.c |3 +-
 tools/testing/nvdimm/test/Kbuild|6 +-
 tools/testing/nvdimm/test/ndtest.c  | 1138 +++
 tools/testing/nvdimm/test/ndtest.h  |  109 +++
 4 files changed, 1254 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [RFC v5 0/7] PMEM device emulation without nfit depenency

2020-12-16 Thread Santosh Sivaraj
Dan Williams  writes:

> Typically RFC means "not ready to apply, still seeking fundamental
> approach feedback". Should I be looking to consider this for
> v5.11-rc1, or is this still RFC / should wait for v5.12?

I would like this to go in, after your comments to the previously RFC, I guess
this has moved beyond the RFC tag. I will re-send the series without the RFC
tag. Meanwhile I will continue to work on getting both modules to co-exist and
be exercised in the same build apart from getting SMART and error injection
tests.

>
> On Mon, Dec 14, 2020 at 2:39 AM Santosh Sivaraj  wrote:
>>
>> 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.10.g7ecd11c
>> 
>> # 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.git94a00679
>> 
>> # TOTAL: 26
>> # PASS:  14
>> # SKIP:  3
>> # XFAIL: 0
>> # FAIL:  9
>> # XPASS: 0
>> # ERROR: 0
>
> With these run reports are you trying to demonstrate the improvement,
> or the future work?

This shows what work still needs to be done. As of now there is SMART and error
injection which I am working on right now.
>
> I think it's sufficient to say that no tests ran with nfit_test
> previously, but now 26 pass. Extra interesting would be to determine
> if any current papr regression fixes in the tree would have been
> caught by an ndtest run.

So far there is are no regressions caught.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [RFC v5 1/7] testing/nvdimm: Add test module for non-nfit platforms

2020-12-16 Thread Santosh Sivaraj
Dan Williams  writes:

> On Mon, Dec 14, 2020 at 2:39 AM Santosh Sivaraj  wrote:
>>
>> 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.
>>
>> This RFC series is split into reviewable and compilable chunks.
>>
>> This patch adds a new driver and registers two nvdimm bus needed for ndctl
>> make check.
>
> I'd like to be able to test either nfit_test or nd_test by environment
> variable from the same build. See the attached patch. Otherwise, if
> the ndctl release process is not constantly testing nd_test it *will*
> regress / bitrot.
>
> So, "make check" should try nfit_test.ko, fallback to nd_test.ko, or
> otherwise be forced to one or the other via an environment variable.
> For example I'd like the release process on x86 to be:
>
> make check
> NVDIMM_TEST_MOD=nd_test make check
>
> ...where the first invocation assumes to test nfit_test.ko.
>
> It needs some fixups to either prevent nfit_test and nd_test from
> being loaded at the same time, or fixups to allow them to coexist.
>
> This rework implies v5.11 is too aggressive a merge target.

Yes I agree. If you feel good about this series, I would like you to take this
and I can send the corresponding ndctl changes incrementally to work with the
patch you sent.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl RFC v5 5/5] Use page size as alignment value

2020-12-14 Thread Santosh Sivaraj
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 23 ++-
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 10af189..ff6143e 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -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)
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index 110ba3d..8250128 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -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
d

[ndctl RFC v5 4/5] test/libndctl: skip SMART tests on non-nfit devices

2020-12-14 Thread Santosh Sivaraj
This is just a temporary check till the new module has SMART capabilities
emulated.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 5043ae0..001f78a 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -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));
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl RFC v5 3/5] papr: Add support to parse save_fail flag for dimm

2020-12-14 Thread Santosh Sivaraj
This will help in getting the dimm fail tests to run on papr family too.
Also add nvdimm_test compatibility string for recognizing the test module.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 5f09628..3fb3aed 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -815,6 +815,8 @@ 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)
@@ -1044,7 +1046,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);
 }
 
 /**
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl RFC v5 2/5] test: Don't skip tests if nfit modules are missing

2020-12-14 Thread Santosh Sivaraj
For NFIT to be available ACPI is a must, so don't fail when nfit modules
are missing on a platform that doesn't support ACPI.

Signed-off-by: Santosh Sivaraj 
---
 test.h|  2 +-
 test/ack-shutdown-count-set.c |  2 +-
 test/blk_namespaces.c |  2 +-
 test/core.c   | 15 +--
 test/dpa-alloc.c  |  2 +-
 test/dsm-fail.c   |  2 +-
 test/libndctl.c   |  2 +-
 test/multi-pmem.c |  2 +-
 test/parent-uuid.c|  2 +-
 test/pmem_namespaces.c|  2 +-
 10 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/test.h b/test.h
index 3f6212e..94d8936 100644
--- a/test.h
+++ b/test.h
@@ -30,7 +30,7 @@ void builtin_xaction_namespace_reset(void);
 
 struct kmod_ctx;
 struct kmod_module;
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test);
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index 742e976..6315a94 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct 
ndctl_test *test,
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index 437fcad..dfb0332 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -240,7 +240,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test 
*test,
 
if (!bus) {
fprintf(stderr, "ACPI.NFIT unavailable falling back to 
nfit_test\n");
-   rc = nfit_test_init(_ctx, , NULL, log_level, test);
+   rc = ndctl_test_init(_ctx, , NULL, log_level, test);
ndctl_invalidate(ctx);
bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
if (rc < 0 || !bus) {
diff --git a/test/core.c b/test/core.c
index 5118d86..974bbc4 100644
--- a/test/core.c
+++ b/test/core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define KVER_STRLEN 20
@@ -116,11 +117,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
return test->skip;
 }
 
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
struct ndctl_ctx *nd_ctx, int log_level,
struct ndctl_test *test)
 {
-   int rc;
+   int rc, family = NVDIMM_FAMILY_INTEL;
unsigned int i;
const char *name;
struct ndctl_bus *bus;
@@ -138,6 +139,11 @@ int nfit_test_init(struct kmod_ctx **ctx, struct 
kmod_module **mod,
"nd_pmem",
};
 
+   if (access("/sys/bus/acpi", F_OK) == 0) {
+   if (errno == ENOENT)
+   family = NVDIMM_FAMILY_PAPR;
+   }
+
log_init(_ctx, "test/init", "NDCTL_TEST");
log_ctx.log_priority = log_level;
 
@@ -195,6 +201,11 @@ retry:
 
path = kmod_module_get_path(*mod);
if (!path) {
+   if (family == NVDIMM_FAMILY_INTEL &&
+   (strcmp(name, "nfit") == 0 ||
+strcmp(name, "nd_e820") == 0))
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index b757b9a..10af189 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -299,7 +299,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
return 77;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
ndctl_test_skip(test);
fprintf(stderr, "nfit_test unavailable skipping tests\n");
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index b2c51db..1d03470 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -356,7 +356,7 @@ int test_dsm_fail(int loglevel, struct ndctl_test *test, 
struct ndctl_ctx *ctx)
int result = EXIT_FAILURE, err;
 
ndctl_set_log_priority(ctx, loglevel);
-   err = nfit_test_init(_ctx, , NULL, loglevel, test);
+   err = ndctl_test_init(_ctx, , NULL, loglevel, test);
if (err < 0) {
result = 77;
ndctl_test_skip(test);
diff --git a/tes

[ndctl RFC v5 1/5] libndctl: test enablement for non-nfit devices

2020-12-14 Thread Santosh Sivaraj
Unify adding dimms for papr and nfit families, this will help in adding
all attributes needed for the unit tests too. We don't fail adding a dimm
if some of the dimm attributes are missing, so this will work fine on PAPR
platforms where most dimm attributes are provided.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 103 ---
 1 file changed, 38 insertions(+), 65 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ad521d3..5f09628 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1655,41 +1655,9 @@ 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 int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
-{
-   int rc = -ENODEV;
-   char buf[SYSFS_ATTR_SIZE];
-   struct ndctl_ctx *ctx = dimm->bus->ctx;
-   char *path = calloc(1, strlen(dimm_base) + 100);
-   const char * const devname = ndctl_dimm_get_devname(dimm);
-
-   dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
-
-   if (!path)
-   return -ENOMEM;
-
-   /* construct path to the papr compatible dimm flags file */
-   sprintf(path, "%s/papr/flags", dimm_base);
-
-   if (ndctl_bus_is_papr_scm(dimm->bus) &&
-   sysfs_read_attr(ctx, path, buf) == 0) {
-
-   dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
buf);
-   dimm->cmd_family = NVDIMM_FAMILY_PAPR;
-
-   /* Parse dimm flags */
-   parse_papr_flags(dimm, buf);
-
-   /* Allocate monitor mode fd */
-   dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
-   rc = 0;
-   }
-
-   free(path);
-   return rc;
-}
-
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
+   const char *dimm_base,
+   const char *bus_prefix)
 {
int i, rc = -1;
char buf[SYSFS_ATTR_SIZE];
@@ -1703,7 +1671,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
 * 'unique_id' may not be available on older kernels, so don't
 * fail if the read fails.
 */
-   sprintf(path, "%s/nfit/id", dimm_base);
+   sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0) {
unsigned int b[9];
 
@@ -1718,68 +1686,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
}
}
 
-   sprintf(path, "%s/nfit/handle", dimm_base);
+   sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->handle = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/phys_id", dimm_base);
+   sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
dimm->phys_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/serial", dimm_base);
+   sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->serial = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/vendor", dimm_base);
+   sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/device", dimm_base);
+   sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->device_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/rev_id", dimm_base);
+   sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->revision_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
+   sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->dirty_shutdown = strtoll(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_vendor", dimm_base);
+   sprintf(path, "%s/%s/subsystem_vendor", dimm_base, bus_prefix);
if (sysfs_read_attr(ctx, path, buf) == 0)
dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
 
-   sprintf(path, "%s/nfit/subsystem_device", dimm_base)

[RFC v5 7/7] ndtest: Add papr health related flags

2020-12-14 Thread Santosh Sivaraj
sysfs attibutes to show health related flags are added.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 41 ++
 tools/testing/nvdimm/test/ndtest.h | 31 ++
 2 files changed, 72 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index dc1e3636616a..6862915f1fb0 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -86,6 +86,9 @@ static struct ndtest_dimm dimm_group2[] = {
.uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
.physical_id = 0,
.num_formats = 1,
+   .flags = PAPR_PMEM_UNARMED | PAPR_PMEM_EMPTY |
+PAPR_PMEM_SAVE_FAILED | PAPR_PMEM_SHUTDOWN_DIRTY |
+PAPR_PMEM_HEALTH_FATAL,
},
 };
 
@@ -789,6 +792,40 @@ static umode_t ndtest_nvdimm_attr_visible(struct kobject 
*kobj,
return a->mode;
 }
 
+static ssize_t flags_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+   struct seq_buf s;
+   u64 flags;
+
+   flags = dimm->flags;
+
+   seq_buf_init(, buf, PAGE_SIZE);
+   if (flags & PAPR_PMEM_UNARMED_MASK)
+   seq_buf_printf(, "not_armed ");
+
+   if (flags & PAPR_PMEM_BAD_SHUTDOWN_MASK)
+   seq_buf_printf(, "flush_fail ");
+
+   if (flags & PAPR_PMEM_BAD_RESTORE_MASK)
+   seq_buf_printf(, "restore_fail ");
+
+   if (flags & PAPR_PMEM_SAVE_MASK)
+   seq_buf_printf(, "save_fail ");
+
+   if (flags & PAPR_PMEM_SMART_EVENT_MASK)
+   seq_buf_printf(, "smart_notify ");
+
+
+   if (seq_buf_used())
+   seq_buf_printf(, "\n");
+
+   return seq_buf_used();
+}
+static DEVICE_ATTR_RO(flags);
+
 static struct attribute *ndtest_nvdimm_attributes[] = {
_attr_nvdimm_show_handle.attr,
_attr_vendor.attr,
@@ -799,6 +836,7 @@ static struct attribute *ndtest_nvdimm_attributes[] = {
_attr_formats.attr,
_attr_format.attr,
_attr_format1.attr,
+   _attr_flags.attr,
NULL,
 };
 
@@ -824,6 +862,9 @@ static int ndtest_dimm_register(struct ndtest_priv *priv,
set_bit(NDD_LABELING, _flags);
}
 
+   if (dimm->flags & PAPR_PMEM_UNARMED_MASK)
+   set_bit(NDD_UNARMED, _flags);
+
dimm->nvdimm = nvdimm_create(priv->bus, dimm,
ndtest_nvdimm_attribute_groups, dimm_flags,
NDTEST_SCM_DIMM_CMD_MASK, 0, NULL);
diff --git a/tools/testing/nvdimm/test/ndtest.h 
b/tools/testing/nvdimm/test/ndtest.h
index 8f27ad6f7319..2c54c9cbb90c 100644
--- a/tools/testing/nvdimm/test/ndtest.h
+++ b/tools/testing/nvdimm/test/ndtest.h
@@ -5,6 +5,37 @@
 #include 
 #include 
 
+/* SCM device is unable to persist memory contents */
+#define PAPR_PMEM_UNARMED   (1ULL << (63 - 0))
+/* SCM device failed to persist memory contents */
+#define PAPR_PMEM_SHUTDOWN_DIRTY(1ULL << (63 - 1))
+/* SCM device contents are not persisted from previous IPL */
+#define PAPR_PMEM_EMPTY (1ULL << (63 - 3))
+#define PAPR_PMEM_HEALTH_CRITICAL   (1ULL << (63 - 4))
+/* SCM device will be garded off next IPL due to failure */
+#define PAPR_PMEM_HEALTH_FATAL  (1ULL << (63 - 5))
+/* SCM contents cannot persist due to current platform health status */
+#define PAPR_PMEM_HEALTH_UNHEALTHY  (1ULL << (63 - 6))
+
+/* Bits status indicators for health bitmap indicating unarmed dimm */
+#define PAPR_PMEM_UNARMED_MASK (PAPR_PMEM_UNARMED |\
+   PAPR_PMEM_HEALTH_UNHEALTHY)
+
+#define PAPR_PMEM_SAVE_FAILED(1ULL << (63 - 10))
+
+/* Bits status indicators for health bitmap indicating unflushed dimm */
+#define PAPR_PMEM_BAD_SHUTDOWN_MASK (PAPR_PMEM_SHUTDOWN_DIRTY)
+
+/* Bits status indicators for health bitmap indicating unrestored dimm */
+#define PAPR_PMEM_BAD_RESTORE_MASK  (PAPR_PMEM_EMPTY)
+
+/* Bit status indicators for smart event notification */
+#define PAPR_PMEM_SMART_EVENT_MASK (PAPR_PMEM_HEALTH_CRITICAL | \
+   PAPR_PMEM_HEALTH_FATAL |\
+   PAPR_PMEM_HEALTH_UNHEALTHY)
+
+#define PAPR_PMEM_SAVE_MASK(PAPR_PMEM_SAVE_FAILED)
+
 struct ndtest_config;
 
 struct ndtest_priv {
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[RFC v5 6/7] ndtest: Add nvdimm control functions

2020-12-14 Thread Santosh Sivaraj
Add functions to support ND_CMD_GET_CONFIG_SIZE, ND_CMD_SET_CONFIG_DATA and
ND_CMD_GET_CONFIG_DATA.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 821296b59bdc..dc1e3636616a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -254,6 +254,45 @@ static inline struct ndtest_priv *to_ndtest_priv(struct 
device *dev)
return container_of(pdev, struct ndtest_priv, pdev);
 }
 
+static int ndtest_config_get(struct ndtest_dimm *p, unsigned int buf_len,
+struct nd_cmd_get_config_data_hdr *hdr)
+{
+   unsigned int len;
+
+   if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+   return -EINVAL;
+
+   hdr->status = 0;
+   len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+   memcpy(hdr->out_buf, p->label_area + hdr->in_offset, len);
+
+   return buf_len - len;
+}
+
+static int ndtest_config_set(struct ndtest_dimm *p, unsigned int buf_len,
+struct nd_cmd_set_config_hdr *hdr)
+{
+   unsigned int len;
+
+   if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+   return -EINVAL;
+
+   len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+   memcpy(p->label_area + hdr->in_offset, hdr->in_buf, len);
+
+   return buf_len - len;
+}
+
+static int ndtest_get_config_size(struct ndtest_dimm *dimm, unsigned int 
buf_len,
+ struct nd_cmd_get_config_size *size)
+{
+   size->status = 0;
+   size->max_xfer = 8;
+   size->config_size = dimm->config_size;
+
+   return 0;
+}
+
 static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
  struct nvdimm *nvdimm, unsigned int cmd, void *buf,
  unsigned int buf_len, int *cmd_rc)
@@ -275,12 +314,24 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor 
*nd_desc,
 
switch (cmd) {
case ND_CMD_GET_CONFIG_SIZE:
+   *cmd_rc = ndtest_get_config_size(dimm, buf_len, buf);
+   break;
case ND_CMD_GET_CONFIG_DATA:
+   *cmd_rc = ndtest_config_get(dimm, buf_len, buf);
+   break;
case ND_CMD_SET_CONFIG_DATA:
+   *cmd_rc = ndtest_config_set(dimm, buf_len, buf);
+   break;
default:
return -EINVAL;
}
 
+   /* Failures for a DIMM can be injected using fail_cmd and
+* fail_cmd_code, see the device attributes below
+*/
+   if ((1 << cmd) & dimm->fail_cmd)
+   return dimm->fail_cmd_code ? dimm->fail_cmd_code : -EIO;
+
return 0;
 }
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[RFC v5 5/7] ndtest: Add regions and mappings to the test buses

2020-12-14 Thread Santosh Sivaraj
The bus config array is used to hold the regions and the respective
mappings. This config based interface enables to change the
dimm/region/namespace layouts easily.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 352 +
 tools/testing/nvdimm/test/ndtest.h |  26 +++
 2 files changed, 378 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index f7682e1d3efe..821296b59bdc 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -23,6 +23,7 @@ enum {
LABEL_SIZE = SZ_128K,
NUM_INSTANCES = 2,
NUM_DCR = 4,
+   NDTEST_MAX_MAPPING = 6,
 };
 
 #define NDTEST_SCM_DIMM_CMD_MASK  \
@@ -88,18 +89,161 @@ static struct ndtest_dimm dimm_group2[] = {
},
 };
 
+static struct ndtest_mapping region0_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 1,
+   .position = 1,
+   .start = 0,
+   .size = SZ_16M,
+   }
+};
+
+static struct ndtest_mapping region1_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 1,
+   .position = 1,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 2,
+   .position = 2,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+   {
+   .dimm = 3,
+   .position = 3,
+   .start = SZ_16M,
+   .size = SZ_16M,
+   },
+};
+
+static struct ndtest_mapping region2_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = DIMM_SIZE,
+   },
+};
+
+static struct ndtest_mapping region3_mapping[] = {
+   {
+   .dimm = 1,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_mapping region4_mapping[] = {
+   {
+   .dimm = 2,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_mapping region5_mapping[] = {
+   {
+   .dimm = 3,
+   .start = 0,
+   .size = DIMM_SIZE,
+   }
+};
+
+static struct ndtest_region bus0_regions[] = {
+   {
+   .type = ND_DEVICE_NAMESPACE_PMEM,
+   .num_mappings = ARRAY_SIZE(region0_mapping),
+   .mapping = region0_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 1,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_PMEM,
+   .num_mappings = ARRAY_SIZE(region1_mapping),
+   .mapping = region1_mapping,
+   .size = DIMM_SIZE * 2,
+   .range_index = 2,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region2_mapping),
+   .mapping = region2_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 3,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region3_mapping),
+   .mapping = region3_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 4,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region4_mapping),
+   .mapping = region4_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 5,
+   },
+   {
+   .type = ND_DEVICE_NAMESPACE_BLK,
+   .num_mappings = ARRAY_SIZE(region5_mapping),
+   .mapping = region5_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 6,
+   },
+};
+
+static struct ndtest_mapping region6_mapping[] = {
+   {
+   .dimm = 0,
+   .position = 0,
+   .start = 0,
+   .size = DIMM_SIZE,
+   },
+};
+
+static struct ndtest_region bus1_regions[] = {
+   {
+   .type = ND_DEVICE_NAMESPACE_IO,
+   .num_mappings = ARRAY_SIZE(region6_mapping),
+   .mapping = region6_mapping,
+   .size = DIMM_SIZE,
+   .range_index = 1,
+   },
+};
+
 static struct ndtest_config bus_configs[NUM_INSTANCES] = {
/* bus 1 */
{
.dimm_start = 0,
.dimm_count = ARRAY_SIZE(dimm_group1),
.dimms = dimm_group1,
+   .regions = bus0_regions,
+   .num_regions = ARRAY_SIZE(bus0_regions),
},
/* bus 2 */
{
.dimm_start = ARRAY_SIZE(dimm_group1),
.dimm_count = ARRAY_SIZE(dimm_group2

[RFC v5 4/7] ndtest: Add dimm attributes

2020-12-14 Thread Santosh Sivaraj
This patch adds sysfs attributes for nvdimm and the dimm device.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 202 -
 1 file changed, 200 insertions(+), 2 deletions(-)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index a82790013f8a..f7682e1d3efe 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -219,6 +219,203 @@ static void put_dimms(void *data)
}
 }
 
+static ssize_t handle_show(struct device *dev, struct device_attribute *attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%#x\n", dimm->handle);
+}
+static DEVICE_ATTR_RO(handle);
+
+static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%#x\n", dimm->fail_cmd);
+}
+
+static ssize_t fail_cmd_store(struct device *dev, struct device_attribute 
*attr,
+   const char *buf, size_t size)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+   unsigned long val;
+   ssize_t rc;
+
+   rc = kstrtol(buf, 0, );
+   if (rc)
+   return rc;
+
+   dimm->fail_cmd = val;
+
+   return size;
+}
+static DEVICE_ATTR_RW(fail_cmd);
+
+static ssize_t fail_cmd_code_show(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+
+   return sprintf(buf, "%d\n", dimm->fail_cmd_code);
+}
+
+static ssize_t fail_cmd_code_store(struct device *dev, struct device_attribute 
*attr,
+   const char *buf, size_t size)
+{
+   struct ndtest_dimm *dimm = dev_get_drvdata(dev);
+   unsigned long val;
+   ssize_t rc;
+
+   rc = kstrtol(buf, 0, );
+   if (rc)
+   return rc;
+
+   dimm->fail_cmd_code = val;
+   return size;
+}
+static DEVICE_ATTR_RW(fail_cmd_code);
+
+static struct attribute *dimm_attributes[] = {
+   _attr_handle.attr,
+   _attr_fail_cmd.attr,
+   _attr_fail_cmd_code.attr,
+   NULL,
+};
+
+static struct attribute_group dimm_attribute_group = {
+   .attrs = dimm_attributes,
+};
+
+static const struct attribute_group *dimm_attribute_groups[] = {
+   _attribute_group,
+   NULL,
+};
+
+static ssize_t phys_id_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%#x\n", dimm->physical_id);
+}
+static DEVICE_ATTR_RO(phys_id);
+
+static ssize_t vendor_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "0x1234567\n");
+}
+static DEVICE_ATTR_RO(vendor);
+
+static ssize_t id_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%04x-%02x-%04x-%08x", 0xabcd,
+  0xa, 2016, ~(dimm->handle));
+}
+static DEVICE_ATTR_RO(id);
+
+static ssize_t nvdimm_handle_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%#x\n", dimm->handle);
+}
+
+static struct device_attribute dev_attr_nvdimm_show_handle =  {
+   .attr   = { .name = "handle", .mode = 0444 },
+   .show   = nvdimm_handle_show,
+};
+
+static ssize_t subsystem_vendor_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "0x%04x\n", 0);
+}
+static DEVICE_ATTR_RO(subsystem_vendor);
+
+static ssize_t dirty_shutdown_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "%d\n", 42);
+}
+static DEVICE_ATTR_RO(dirty_shutdown);
+
+static ssize_t formats_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   return sprintf(buf, "%d\n", dimm->num_formats);
+}
+static DEVICE_ATTR_RO(formats);
+
+static ssize_t format_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct nvdimm *nvdimm = to_nvdimm(dev);
+   struct ndtest_dimm *dimm = nvdimm_provider_data(nvdimm);
+
+   if (dimm->num_formats > 1)
+   return sprintf(buf, "0x201\n");
+
+ 

[RFC v5 3/7] ndtest: Add dimms to the two buses

2020-12-14 Thread Santosh Sivaraj
A config array is used to hold the dimms for each bus. These dimms are
registered with nvdimm, and new nvdimms are created on the buses.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 258 +
 tools/testing/nvdimm/test/ndtest.h |  36 
 2 files changed, 294 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 001527b37a23..a82790013f8a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -25,8 +25,83 @@ enum {
NUM_DCR = 4,
 };
 
+#define NDTEST_SCM_DIMM_CMD_MASK  \
+   ((1ul << ND_CMD_GET_CONFIG_SIZE) | \
+(1ul << ND_CMD_GET_CONFIG_DATA) | \
+(1ul << ND_CMD_SET_CONFIG_DATA) | \
+(1ul << ND_CMD_CALL))
+
+#define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm)
\
+   (((node & 0xfff) << 16) | ((socket & 0xf) << 12)\
+| ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
+
+static DEFINE_SPINLOCK(ndtest_lock);
 static struct ndtest_priv *instances[NUM_INSTANCES];
 static struct class *ndtest_dimm_class;
+static struct gen_pool *ndtest_pool;
+
+static struct ndtest_dimm dimm_group1[] = {
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
+   .uuid_str = "1e5c75d2-b618-11ea-9aa3-507b9ddc0f72",
+   .physical_id = 0,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
+   .uuid_str = "1c4d43ac-b618-11ea-be80-507b9ddc0f72",
+   .physical_id = 1,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
+   .uuid_str = "a9f17ffc-b618-11ea-b36d-507b9ddc0f72",
+   .physical_id = 2,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
+   .uuid_str = "b6b83b22-b618-11ea-8aae-507b9ddc0f72",
+   .physical_id = 3,
+   .num_formats = 2,
+   },
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
+   .uuid_str = "bf9baaee-b618-11ea-b181-507b9ddc0f72",
+   .physical_id = 4,
+   .num_formats = 2,
+   },
+};
+
+static struct ndtest_dimm dimm_group2[] = {
+   {
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0),
+   .uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
+   .physical_id = 0,
+   .num_formats = 1,
+   },
+};
+
+static struct ndtest_config bus_configs[NUM_INSTANCES] = {
+   /* bus 1 */
+   {
+   .dimm_start = 0,
+   .dimm_count = ARRAY_SIZE(dimm_group1),
+   .dimms = dimm_group1,
+   },
+   /* bus 2 */
+   {
+   .dimm_start = ARRAY_SIZE(dimm_group1),
+   .dimm_count = ARRAY_SIZE(dimm_group2),
+   .dimms = dimm_group2,
+   },
+};
 
 static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
 {
@@ -65,6 +140,152 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor 
*nd_desc,
return 0;
 }
 
+static void ndtest_release_resource(void *data)
+{
+   struct nfit_test_resource *res  = data;
+
+   spin_lock(_lock);
+   list_del(>list);
+   spin_unlock(_lock);
+
+   if (resource_size(>res) >= DIMM_SIZE)
+   gen_pool_free(ndtest_pool, res->res.start,
+   resource_size(>res));
+   vfree(res->buf);
+   kfree(res);
+}
+
+static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
+  dma_addr_t *dma)
+{
+   dma_addr_t __dma;
+   void *buf;
+   struct nfit_test_resource *res;
+   struct genpool_data_align data = {
+   .align = SZ_128M,
+   };
+
+   res = kzalloc(sizeof(*res), GFP_KERNEL);
+   if (!res)
+   return NULL;
+
+   buf = vmalloc(size);
+   if (size >= DIMM_SIZE)
+   __dma = gen_pool_alloc_algo(ndtest_pool, size,
+   gen_pool_first_fit_align, );
+   else
+   __dma = (unsigned long) buf;
+
+   if (!__dma)
+   goto buf_err;
+
+   INIT_LIST_HEAD(>list);
+   res->dev = >pdev.dev;
+   res->buf = buf;
+   res->res.start = __dma;
+   res->res.end = __dma + size - 1;
+   res->res.name = "NFIT";
+   spin_lock_init(>lock);
+   INIT_LIST_HEAD(>requests);
+   spin_lock(_lock)

[RFC v5 2/7] ndtest: Add compatability string to treat it as PAPR family

2020-12-14 Thread Santosh Sivaraj
Since this module is written to be platform agnostic, the module is made
part of the PAPR_FAMILY. ndctl identifies the family using the compatible
string inside of_node dir-entry.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/test/ndtest.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index f89d74fdcdee..001527b37a23 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -65,11 +65,34 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
return 0;
 }
 
+static ssize_t compatible_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   return sprintf(buf, "nvdimm_test");
+}
+static DEVICE_ATTR_RO(compatible);
+
+static struct attribute *of_node_attributes[] = {
+   _attr_compatible.attr,
+   NULL
+};
+
+static const struct attribute_group of_node_attribute_group = {
+   .name = "of_node",
+   .attrs = of_node_attributes,
+};
+
+static const struct attribute_group *ndtest_attribute_groups[] = {
+   _node_attribute_group,
+   NULL,
+};
+
 static int ndtest_bus_register(struct ndtest_priv *p)
 {
p->bus_desc.ndctl = ndtest_ctl;
p->bus_desc.module = THIS_MODULE;
p->bus_desc.provider_name = NULL;
+   p->bus_desc.attr_groups = ndtest_attribute_groups;
 
p->bus = nvdimm_bus_register(>pdev.dev, >bus_desc);
if (!p->bus) {
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[RFC v5 0/7] PMEM device emulation without nfit depenency

2020-12-14 Thread 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.

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.10.g7ecd11c  


# 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.git94a00679

# TOTAL: 26
# PASS:  14
# SKIP:  3
# XFAIL: 0
# FAIL:  9
# XPASS: 0  
# ERROR: 0

Error injection tests and SMART are not yet implemented.

Changes from V4:
- Split the driver patches into smaller chunks for ease of review
- [ndctl] Adding dimm attributes for nfit and papr, make it into one function 
[Dan]
- [ndctl] If nfit modules are missing, check for acpi support before failing, 
slightly
  different approach   than what Dan commented.

Santosh Sivaraj (7):
  testing/nvdimm: Add test module for non-nfit platforms
  ndtest: Add compatability string to treat it as PAPR family
  ndtest: Add dimms to the two buses
  ndtest: Add dimm attributes
  ndtest: Add regions and mappings to the test buses
  ndtest: Add nvdimm control functions
  ndtest: Add papr health related flags

 tools/testing/nvdimm/config_check.c |3 +-
 tools/testing/nvdimm/test/Kbuild|6 +-
 tools/testing/nvdimm/test/ndtest.c  | 1138 +++
 tools/testing/nvdimm/test/ndtest.h  |  109 +++
 4 files changed, 1254 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

-- 
2.26.2
___
Linux-nvdimm

[RFC v5 1/7] testing/nvdimm: Add test module for non-nfit platforms

2020-12-14 Thread 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.

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

This RFC series is split into reviewable and compilable chunks.

This patch adds a new driver and registers two nvdimm bus needed for ndctl
make check.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/config_check.c |   3 +-
 tools/testing/nvdimm/test/Kbuild|   6 +-
 tools/testing/nvdimm/test/ndtest.c  | 206 
 tools/testing/nvdimm/test/ndtest.h  |  16 +++
 4 files changed, 229 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

diff --git a/tools/testing/nvdimm/config_check.c 
b/tools/testing/nvdimm/config_check.c
index cac891028cd1..3e3a5f518864 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -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));
 }
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index 75baebf8f4ba..197bcb2b7f35 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -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
diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
new file mode 100644
index ..f89d74fdcdee
--- /dev/null
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../watermark.h"
+#include "nfit_test.h"
+#include "ndtest.h"
+
+enum {
+   DIMM_SIZE = SZ_32M,
+   LABEL_SIZE = SZ_128K,
+   NUM_INSTANCES = 2,
+   NUM_DCR = 4,
+};
+
+static struct ndtest_priv *instances[NUM_INSTANCES];
+static struct class *ndtest_dimm_class;
+
+static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+
+   return container_of(pdev, struct ndtest_priv, pdev);
+}
+
+static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
+ struct nvdimm *nvdimm, unsigned int cmd, void *buf,
+ unsigned int buf_len, int *cmd_rc)
+{
+   struct ndtest_dimm *dimm;
+   int _cmd_rc;
+
+   if (!cmd_rc)
+   cmd_rc = &_cmd_rc;
+
+   *cmd_rc = 0;
+
+   if (!nvdimm)
+   return -EINVAL;
+
+   dimm = nvdimm_provider_data(nvdimm);
+   if (!dimm)
+   return -EINVAL;
+
+   switch (cmd) {
+   case ND_CMD_GET_CONFIG_SIZE:
+   case ND_CMD_GET_CONFIG_DATA:
+   case ND_CMD_SET_CONFIG_DATA:
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int ndtest_bus_register(struct ndtest_priv *p)
+{
+   p->bus_desc.ndctl = ndtest_ctl;
+   p->bus_desc.module = THIS_MODULE;
+   p->bus_desc.provider_name = NULL;
+
+   p->bus = nvdimm_bus_register(>pdev.dev, >bus_desc);
+   if (!p->bus) {
+   dev_err(>pdev.dev, "Error creating nvdimm bus %pOF\n", 
p->dn);
+   return -ENOMEM;
+   }
+
+   return 0;
+}
+
+static int ndtest_remove(struct platform_device *pdev)
+{
+   struct ndtest_priv *p = to_ndtest_priv(>dev);
+
+   nvdimm_bus_unregister(p->bus);
+   return 0;
+}
+
+static int ndtest_probe(struct platform_device *pdev)
+{
+   struct ndtest_priv *p;
+
+   p = to_ndtest_priv(>dev);
+   if (ndtest_bus_register(p))
+   return -ENOMEM;
+
+   platform_set_drvdata(pdev, p);
+
+   return 0;
+}
+
+static const struct platform_device_id ndtest_id[] = {
+   { KBUILD_MODNAME },
+   { },
+};
+
+static struct platform_driver ndtest_driver = {
+   .probe = ndtest_probe,
+   .remove = ndtest_remove,
+   .driver = {
+   .name = KBUILD_MODNAME,
+   },
+   .id_table = ndtest_id,
+};
+
+static void ndtest_release(str

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

2020-12-08 Thread Santosh Sivaraj
Dan Williams  writes:

> On Sun, Nov 8, 2020 at 4:21 AM Santosh Sivaraj  wrote:
>>
>> 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.
>>
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  ndctl/lib/libndctl.c | 52 
>>  test/core.c  |  6 +
>>  2 files changed, 58 insertions(+)
>>
>> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
>> index ad521d3..d1f8e4e 100644
>> --- a/ndctl/lib/libndctl.c
>> +++ b/ndctl/lib/libndctl.c
>> @@ -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",
>> +   [0], [1], [2], [3], [4],
>> +   [5], [6], [7], [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);
>
> 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.
>
>> +
>> +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;
>>  }
>> diff --git a/test/core.c b/test/core.c
>> index 5118d86..0fd1011 100644
>> --- a/test/core.c
>> +++ b/test/core.c
>> @@ -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 (str

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

2020-11-08 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c| 23 ++-
 test/multi-dax.sh   |  6 --
 test/sector-mode.sh |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index b757b9a..dff9b62 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -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)
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index 110ba3d..8250128 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -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
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index eef8dc6..cee0313 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -18,6 +18,8 @@ rc=77
 set -e
 trap 'err $LINENO' ERR
 
+ALIGN_SIZE=`getco

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

2020-11-08 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 34 ++
 test/libndctl.c  |  3 ++-
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index d1f8e4e..26fc14c 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -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)
diff --git a/test/libndctl.c b/test/libndctl.c
index 994e0fa..b7e7b68 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -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));
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


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

2020-11-08 Thread 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.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 52 
 test/core.c  |  6 +
 2 files changed, 58 insertions(+)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ad521d3..d1f8e4e 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -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",
+   [0], [1], [2], [3], [4],
+   [5], [6], [7], [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;
 }
diff --git a/test/core.c b/test/core.c
index 5118d86..0fd1011 100644
--- a/test/core.c
+++ b/test/core.c
@@ -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(_ctx, "%s.ko: failed to get path\n", name);
break;
}
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[RFC v4 0/1] PMEM device emulation without nfit depenency

2020-11-08 Thread 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.

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

-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


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

2020-11-08 Thread 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.

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

Signed-off-by: Santosh Sivaraj 
---
 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

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 09087c38fabd..c8f4bb708ead 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -382,6 +382,7 @@ void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus)
 {
if (!nvdimm_bus)
return;
+
device_unregister(_bus->dev);
 }
 EXPORT_SYMBOL_GPL(nvdimm_bus_unregister);
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index c3237c2b03a6..ba7dcc0fc25c 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -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);
diff --git a/tools/testing/nvdimm/config_check.c 
b/tools/testing/nvdimm/config_check.c
index cac891028cd1..3e3a5f518864 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -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));
 }
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index 75baebf8f4ba..197bcb2b7f35 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -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
diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
new file mode 100644
index ..e21c5e436cd3
--- /dev/null
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -0,0 +1,1168 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../watermark.h"
+#include "nfit_test.h"
+#include "ndtest.h"
+
+enum {
+   DIMM_SIZE = SZ_32M,
+   LABEL_SIZE = SZ_128K,
+   NUM_INSTANCES = 2,
+   NUM_DCR = 4,
+};
+
+/* SCM device is unable to persist memory contents */
+#define PAPR_PMEM_UNARMED   (1ULL << (63 - 0))
+/* SCM device failed to persist memory contents */
+#define PAPR_PMEM_SHUTDOWN_DIRTY(1ULL << (63 - 1))
+/* SCM device contents are not persisted from previous IPL */
+#define PAPR_PMEM_EMPTY (1ULL << (63 - 3))
+#define PAPR_PMEM_HEALTH_CRITICAL   (1ULL << (63 - 4))
+/* SCM device will be garded off next IPL due to failure */
+#define PAPR_PMEM_HEALTH_FATAL  (1ULL << (63 - 5))
+/* SCM contents cannot persist due to current platform health status */
+#define PAPR_PMEM_HEALTH_UNHEALTHY  (1ULL << (63 - 6))
+
+/* Bits status indicators for health bitmap indicating unarmed dimm */
+#define PAPR_PMEM_UNARMED_MASK (PAPR_PMEM_UNARMED |\
+   PAPR_PMEM_HEALTH_UNHEALTHY)
+
+#define PAPR_PMEM_SAVE_FAILED(1ULL << (63 - 10))
+
+/* Bits status indicators for health bitmap indicating unflushed dimm */
+#define PAPR_PMEM_BAD_SHUTDOWN_MASK (PAPR_PMEM_SHUTDOWN_DIRTY)
+
+/* Bits status indicators for health bitmap indicating unrestored dimm */

Re: [ndctl PATCH] libndctl: Fix probe of non-nfit nvdimms

2020-10-11 Thread Santosh Sivaraj
Vaibhav Jain  writes:

> Hi Dan and Vishal,
>
> Thanks so much for quick turnaround on this.
>
> Dan Williams  writes:
>
>> On Fri, Oct 9, 2020 at 11:36 AM Verma, Vishal L
>>  wrote:
>>>
>>> On Fri, 2020-10-09 at 17:30 +0530, Vaibhav Jain wrote:
>>> > commit 107a24ff429f ("ndctl/list: Add firmware activation
>>> > enumeration") introduced changes in add_dimm() to enumerate the status
>>> > of firmware activation. However a branch added in that commit broke
>>> > the probe for non-nfit nvdimms like one provided by papr-scm. This
>>> > cause an error reported when listing namespaces like below:
>>> >
>>> > $ sudo ndctl list
>>> > libndctl: add_dimm: nmem0: probe failed: No such device
>>> > libndctl: __sysfs_device_parse: nmem0: add_dev() failed
>>> >
>>> > Do a fix for this by removing the offending branch in the add_dimm()
>>> > patch. This continues the flow of add_dimm() probe even if the nfit is
>>> > not detected on the associated bus.
>>> >
>>> > Fixes: 107a24ff429fa("ndctl/list: Add firmware activation enumeration")
>>> > Signed-off-by: Vaibhav Jain 
>>> > ---
>>> >  ndctl/lib/libndctl.c | 3 ---
>>> >  1 file changed, 3 deletions(-)
>>>
>>> Ah apologies - this snuck in when I reflowed Dan's patches on top of the
>>> papr work for v70.
> No worries :-)
>
>>>
>>> I expect you'd like a point release with this fix asap?
> Yes, that will be great. Thanks
>
>>>
>>> Is there a way for me to incorporate some papr unit tests into my
>>> release workflow so I can avoid breaking things like this again?
>>>
>>> I'll also try to do a better job of pushing things out to the pending
>>> branch more frequently so if you're monitoring that branch, hopefully
>>> things like this will get caught before a release happens :)
>
> Fully agree, if that happens we can incorporate it into our CI system to
> ensure that such regressions are caught early on before any release is
> tagged.
>
>>
>> Would be nice to have something like a papr_test next to nfit_test for
>> such regression testing. These kinds of mistakes are really only
>> avoidable with regression tests.
> Yes Agree, fortunatly Santosh  has recently posted an RFC patchset
> implementing such tests at [1]. Once that gets merged, can used to
> perform regression testing.
>
> [1] "testing/nvdimm: Add test module for non-nfit platforms"
> https://lore.kernel.org/linux-nvdimm/20201006010013.848302-1-sant...@fossix.org/
>

Thanks Vaibhav to point that out.

Dan/Vishal/Ira,

If you could provide your comments on the above RFC we could move forward on
this.

Thanks,
Santosh
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 9/9] test: Disable paths which are possibly wrong

2020-10-06 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 test/dpa-alloc.c | 9 -
 test/dsm-fail.c  | 8 +++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index b757b9a..a933b54 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -277,11 +277,18 @@ static int do_test(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
return -ENXIO;
}
 
+   /* FIXME: there should be a delete here, to remove the last namespace,
+* otherwise the comparison should fail below (available vs
+* default). But not sure why it isn't failing with the nfit code. What
+* am I missing? */
+#if 0
available_slots = ndctl_dimm_get_available_labels(dimm);
if (available_slots != default_available_slots - 1) {
-   fprintf(stderr, "mishandled slot count\n");
+   fprintf(stderr, "mishandled slot count (available: %u, default: 
%u)\n",
+   available_slots, default_available_slots - 1);
return -ENXIO;
}
+#endif
 
ndctl_region_foreach(bus, region)
ndctl_region_disable_invalidate(region);
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index b2c51db..f303f09 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -290,6 +290,12 @@ static int do_test(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
goto out;
 
 
+   /* The below test will fail, when -EACCES is set for getting config
+* size, how will the dimm be enabled? With the nfit driver, the dimm
+* is enabled and then failed only with the return code, is that the
+* right way?
+*/
+#if 0
rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_SIZE, -EACCES,
_ctx);
if (rc)
@@ -309,7 +315,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test 
*test)
rc = dimms_disable(bus);
if (rc)
goto out;
-
+#endif
rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_DATA, -EACCES,
_ctx);
if (rc)
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 8/9] test/multi-pmem: fix for no-interleave support

2020-10-06 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 test/multi-pmem.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/test/multi-pmem.c b/test/multi-pmem.c
index 668662c..ef4fec0 100644
--- a/test/multi-pmem.c
+++ b/test/multi-pmem.c
@@ -208,6 +208,14 @@ static int do_multi_pmem(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
break;
}
 
+   /* FIXME: the above expects the a blk region to be available on the
+* previously identified dimm, which won't if we don't have interleaved
+* support
+*/
+
+   if (!region)
+   goto no_interleave;
+
blk_avail_orig = ndctl_region_get_available_size(region);
for (i = 1; i < NUM_NAMESPACES - 1; i++) {
ndns = namespaces[i];
@@ -239,6 +247,7 @@ static int do_multi_pmem(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
if (check_deleted(target, devname, test) != 0)
return -ENXIO;
 
+no_interleave:
ndctl_bus_foreach(ctx, bus) {
if (strncmp(ndctl_bus_get_provider(bus), "nfit_test", 9) != 0)
continue;
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 7/9] test/libndctl: Don't check for error flags on non-nfit dimms

2020-10-06 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 61 +++--
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index aaa72dc..ae87807 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -575,7 +575,8 @@ static int check_regions(struct ndctl_bus *bus, struct 
region *regions, int n,
ndctl_region_get_type_name(region));
return -ENXIO;
}
-   if (ndctl_region_get_interleave_ways(region) != 
regions[i].interleave_ways) {
+   if (ndctl_bus_has_nfit(bus) &&
+   ndctl_region_get_interleave_ways(region) != 
regions[i].interleave_ways) {
fprintf(stderr, "%s: expected interleave_ways: %d got: 
%d\n",
devname, regions[i].interleave_ways,

ndctl_region_get_interleave_ways(region));
@@ -2516,20 +2517,21 @@ static int check_dimms(struct ndctl_bus *bus, struct 
dimm *dimms, int n,
return -ENXIO;
}
 
-   if (ndctl_dimm_has_errors(dimm) != !!dimms[i].flags) {
-   fprintf(stderr, "bus: %s dimm%d %s expected%s errors\n",
+   if (ndctl_bus_has_nfit(bus)) {
+   if (ndctl_dimm_has_errors(dimm) != !!dimms[i].flags) {
+   fprintf(stderr, "bus: %s dimm%d %s expected%s 
errors\n",
ndctl_bus_get_provider(bus), i,
ndctl_dimm_get_devname(dimm),
dimms[i].flags ? "" : " no");
-   return -ENXIO;
-   }
+   return -ENXIO;
+   }
 
-   if (ndctl_dimm_failed_save(dimm) != dimms[i].f_save
-   || ndctl_dimm_failed_arm(dimm) != dimms[i].f_arm
-   || ndctl_dimm_failed_restore(dimm) != 
dimms[i].f_restore
-   || ndctl_dimm_smart_pending(dimm) != 
dimms[i].f_smart
-   || ndctl_dimm_failed_flush(dimm) != 
dimms[i].f_flush) {
-   fprintf(stderr, "expected: %s%s%s%s%sgot: %s%s%s%s%s\n",
+   if (ndctl_dimm_failed_save(dimm) != dimms[i].f_save
+   || ndctl_dimm_failed_arm(dimm) != dimms[i].f_arm
+   || ndctl_dimm_failed_restore(dimm) != 
dimms[i].f_restore
+   || ndctl_dimm_smart_pending(dimm) != 
dimms[i].f_smart
+   || ndctl_dimm_failed_flush(dimm) != 
dimms[i].f_flush) {
+   fprintf(stderr, "expected: %s%s%s%s%sgot: 
%s%s%s%s%s\n",
dimms[i].f_save ? "save_fail " : "",
dimms[i].f_arm ? "not_armed " : "",
dimms[i].f_restore ? "restore_fail " : 
"",
@@ -2540,24 +2542,25 @@ static int check_dimms(struct ndctl_bus *bus, struct 
dimm *dimms, int n,
ndctl_dimm_failed_restore(dimm) ? 
"restore_fail " : "",
ndctl_dimm_smart_pending(dimm) ? 
"smart_event " : "",
ndctl_dimm_failed_flush(dimm) ? 
"flush_fail " : "");
-   return -ENXIO;
-   }
+   return -ENXIO;
+   }
 
-   if (ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0)) &&
-   ndctl_bus_has_nfit(bus)) {
-   if (ndctl_dimm_get_formats(dimm) != dimms[i].formats) {
-   fprintf(stderr, "dimm%d expected formats: %d 
got: %d\n",
+   if (ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0))) {
+   if (ndctl_dimm_get_formats(dimm) != 
dimms[i].formats) {
+   fprintf(stderr, "dimm%d expected 
formats: %d got: %d\n",
i, dimms[i].formats,
ndctl_dimm_get_formats(dimm));
-   return -ENXIO;
-   }
-   for (j = 0; j < dimms[i].formats; j++) {
-   if (ndctl_dimm_get_formatN(dimm, j) != 
dimms[i].format[j]) {
-   fprintf(stderr,
-   "dimm%d expected format[%d]: %d 
got: %d\n",
+   return -ENXIO

[PATCH RFC ndctl 6/9] test/libndctl: Don't check for two formats on a dimm

2020-10-06 Thread Santosh Sivaraj
The number of formats is itself populated only when there is a nfit
bus present. So skip this sub-test for all other platforms.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 93cbc7a..aaa72dc 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2543,7 +2543,8 @@ static int check_dimms(struct ndctl_bus *bus, struct dimm 
*dimms, int n,
return -ENXIO;
}
 
-   if (ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0))) {
+   if (ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0)) &&
+   ndctl_bus_has_nfit(bus)) {
if (ndctl_dimm_get_formats(dimm) != dimms[i].formats) {
fprintf(stderr, "dimm%d expected formats: %d 
got: %d\n",
i, dimms[i].formats,
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 3/9] test/libndctl: Don't compare phys-id if no-interleave support

2020-10-06 Thread Santosh Sivaraj
The tests expect some regions to have the same physical id, but that
will not be the case if there is no interleave support.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 994e0fa..d508948 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2484,7 +2484,8 @@ static int check_dimms(struct ndctl_bus *bus, struct dimm 
*dimms, int n,
return -ENXIO;
}
 
-   if (ndctl_dimm_get_phys_id(dimm) != dimms[i].phys_id) {
+   if (ndctl_bus_has_nfit(bus) &&
+   ndctl_dimm_get_phys_id(dimm) != dimms[i].phys_id) {
fprintf(stderr, "dimm%d expected phys_id: %d got: %d\n",
i, dimms[i].phys_id,
ndctl_dimm_get_phys_id(dimm));
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 5/9] test/libndctl: skip smart tests for non-nfit platforms

2020-10-06 Thread Santosh Sivaraj
Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index 1a5a267..93cbc7a 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2451,7 +2451,7 @@ 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));
 
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 1/9] libndctl: test enablement for non-nfit devices

2020-10-06 Thread Santosh Sivaraj
Add attributes to generic dimms that are independent of platforms like the
test dimms.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c | 51 
 1 file changed, 51 insertions(+)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 952192c..852cb4d 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1619,6 +1619,53 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
char *dimm_base)
free(path);
return rc;
 }
+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",
+   [0], [1], [2], [3], [4],
+   [5], [6], [7], [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 void *add_dimm(void *parent, int id, const char *dimm_base)
 {
@@ -1694,6 +1741,10 @@ static void *add_dimm(void *parent, int id, const char 
*dimm_base)
} else
parse_dimm_flags(dimm, buf);
 
+   /* add the available dimm attributes, the platform can override or add
+* additional attributes later */
+   populate_dimm_attributes(dimm, dimm_base);
+
/* Check if the given dimm supports nfit */
if (ndctl_bus_has_nfit(bus)) {
dimm->formats = formats;
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 4/9] test/libndctl: search by handle instead of range index

2020-10-06 Thread Santosh Sivaraj
When there is no-interleave support, there is no range index.

Signed-off-by: Santosh Sivaraj 
---
 test/libndctl.c | 32 ++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index d508948..1a5a267 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -495,6 +495,26 @@ static struct ndctl_region 
*get_pmem_region_by_range_index(struct ndctl_bus *bus
return NULL;
 }
 
+static struct ndctl_region *get_pmem_region_by_dimm_handle(struct ndctl_bus 
*bus,
+   unsigned int handle)
+{
+   struct ndctl_region *region;
+
+   ndctl_region_foreach(bus, region) {
+   struct ndctl_mapping *map;
+
+   if (ndctl_region_get_type(region) != ND_DEVICE_REGION_PMEM)
+   continue;
+   ndctl_mapping_foreach(region, map) {
+   struct ndctl_dimm *dimm = ndctl_mapping_get_dimm(map);
+
+   if (ndctl_dimm_get_handle(dimm) == handle)
+   return region;
+   }
+   }
+   return NULL;
+}
+
 static struct ndctl_region *get_blk_region_by_dimm_handle(struct ndctl_bus 
*bus,
unsigned int handle)
 {
@@ -532,8 +552,12 @@ static int check_regions(struct ndctl_bus *bus, struct 
region *regions, int n,
struct ndctl_interleave_set *iset;
char devname[50];
 
-   if (strcmp(regions[i].type, "pmem") == 0)
-   region = get_pmem_region_by_range_index(bus, 
regions[i].range_index);
+   if (strcmp(regions[i].type, "pmem") == 0) {
+   if (ndctl_bus_has_nfit(bus))
+   region = get_pmem_region_by_range_index(bus, 
regions[i].range_index);
+   else
+   region = get_pmem_region_by_dimm_handle(bus, 
regions[i].handle);
+   }
else
region = get_blk_region_by_dimm_handle(bus, 
regions[i].handle);
 
@@ -2668,6 +2692,10 @@ static int do_test1(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
if (ndctl_test_attempt(test, KERNEL_VERSION(4, 10, 0)))
dimms1[0].handle = DIMM_HANDLE(1, 0, 0, 0, 0);
 
+   if (!ndctl_bus_has_nfit(bus))
+   regions1[0].handle = DIMM_HANDLE(1, 0, 0, 0, 0);
+
+
rc = check_dimms(bus, dimms1, ARRAY_SIZE(dimms1), 0, 0, test);
if (rc)
return rc;
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC ndctl 2/9] test/core: Don't fail is nfit module is missing

2020-10-06 Thread Santosh Sivaraj
This will happen in platforms that don't have ACPI support.

Signed-off-by: Santosh Sivaraj 
---
 test/core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/test/core.c b/test/core.c
index 5118d86..e3e93ff 100644
--- a/test/core.c
+++ b/test/core.c
@@ -195,6 +195,11 @@ 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)
+   continue;
+
log_err(_ctx, "%s.ko: failed to get path\n", name);
break;
}
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH RFC v3] testing/nvdimm: Add test module for non-nfit platforms

2020-10-05 Thread Santosh Sivaraj
The current test module cannot be used for testing platforms (make check)
that do no 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. Currently interleaving and
error injection are not implemented.

Corresponding changes for ndctl is also required, to skip tests that depend
on nfit attributes, which will be sent as a reply to this.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/config_check.c |   3 +-
 tools/testing/nvdimm/test/Kbuild|   6 +-
 tools/testing/nvdimm/test/ndtest.c  | 819 
 tools/testing/nvdimm/test/ndtest.h  |  65 +++
 4 files changed, 891 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

diff --git a/tools/testing/nvdimm/config_check.c 
b/tools/testing/nvdimm/config_check.c
index cac891028cd1..3e3a5f518864 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -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));
 }
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index 75baebf8f4ba..197bcb2b7f35 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -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
diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
new file mode 100644
index ..415a40345584
--- /dev/null
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -0,0 +1,819 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../watermark.h"
+#include "nfit_test.h"
+#include "ndtest.h"
+
+enum {
+   DIMM_SIZE = SZ_32M,
+   LABEL_SIZE = SZ_128K,
+   NUM_INSTANCES = 2,
+   NUM_DCR = 4,
+};
+
+#define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \
+   (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \
+| ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
+
+static struct ndtest_dimm dimm_group1[] = {
+   {
+   .type = NDTEST_REGION_TYPE_BLK | NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
+   .uuid_str = "1e5c75d2-b618-11ea-9aa3-507b9ddc0f72",
+   .physical_id = 0,
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
+   .uuid_str = "1c4d43ac-b618-11ea-be80-507b9ddc0f72",
+   .physical_id = 1,
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE * 2,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
+   .uuid_str = "a9f17ffc-b618-11ea-b36d-507b9ddc0f72",
+   .physical_id = 2,
+   },
+   {
+   .type = NDTEST_REGION_TYPE_BLK,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
+   .uuid_str = "b6b83b22-b618-11ea-8aae-507b9ddc0f72",
+   .physical_id = 3,
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
+   .uuid_str = "bf9baaee-b618-11ea-b181-507b9ddc0f72",
+   .physical_id = 4,
+   },
+};
+
+static struct ndtest_dimm dimm_group2[] = {
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0),
+   .uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
+   .physical_id = 0,
+   },
+};
+
+static struct ndtest_config bus_configs[NUM_INSTANCES] = {
+   /* bus 1 */
+   {
+   .dimm_start = 0,
+   .dimm_count = ARRAY_SIZE(dimm_group1),
+   .dimm = dimm_group1,
+   },
+   /* bus 2 */
+   {
+  

Re: [PATCH 2/2] ndctl/namespace: Suppress ENODEV when processing all namespaces.

2020-08-28 Thread Santosh Sivaraj
Michal Suchanek  writes:

> When processing all namespaces and no namespaces exist user gets the
> default -ENOENT. Set default rc to 0 when processing all namespaces.
> This avoids confusing error message printed in addition to the message
> saying 0 namespaces were affected.
>
> Before:
>
>  # ndctl check-namespace all
> namespace0.0: namespace_check: namespace0.0: check aborted, namespace online
> error checking namespaces: Device or resource busy
> checked 0 namespaces
>  # ndctl disable-namespace all
> disabled 1 namespace
>  # ndctl check-namespace all
> namespace0.0: namespace_check: Unable to recover any BTT info blocks
> error checking namespaces: No such device or address
> checked 0 namespaces
>  # ndctl destroy-namespace all
> destroyed 1 namespace
>  # ndctl check-namespace all
> error checking namespaces: No such device or address
> checked 0 namespaces
>  # ndctl destroy-namespace all
> error destroying namespaces: No such device or address
> destroyed 0 namespaces
>
> After:
>
>  # ndctl check-namespace all
> namespace0.0: namespace_check: namespace0.0: check aborted, namespace online
> error checking namespaces: Device or resource busy
> checked 0 namespaces
>  # ndctl disable-namespace namespace0.0
> disabled 1 namespace
>  # ndctl check-namespace all
> namespace0.0: namespace_check: Unable to recover any BTT info blocks
> error checking namespaces: No such device or address
> checked 0 namespaces
>  # ndctl destroy-namespace all
> destroyed 1 namespace
>  # ndctl check-namespace all
> checked 0 namespaces
>  # ndctl destroy-namespace all
> destroyed 0 namespaces
>  # ndctl destroy-namespace all
> destroyed 0 namespaces
>
> Note: this does change the return value from -ENOENT to 0 in the cases
> when no namespaces exist and processing all namespaces was requested.
>
> Signed-off-by: Michal Suchanek 

I missed this patch and had a different approach of solving this, fiddling
around with processed and saved_rc in the end of the function. This is
cleaner.

Nit: The default return value is -ENXIO, if that matters in the commit message.

Reviewed-by: Santosh S 

Thanks,
Santosh

> ---
>  ndctl/namespace.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index 3fabe4799d75..835f4076008a 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -2112,6 +2112,9 @@ static int do_xaction_namespace(const char *namespace,
>   if (!namespace && action != ACTION_CREATE)
>   return rc;
>  
> + if (namespace && (strcmp(namespace, "all") == 0))
> + rc = 0;
> +
>   if (verbose)
>   ndctl_set_log_priority(ctx, LOG_DEBUG);
>  
> -- 
> 2.26.2
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[ndctl PATCH v2] namespace-action: Don't act on any seed namespaces

2020-08-26 Thread Santosh Sivaraj
Catch seed namespaces early on. This will prevent checking for sizes in enable,
disable and destroy namespace code path, which in turn prevents the inconsistent
reporting in count of enabled/disabled namespaces.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/libndctl.c |  5 
 ndctl/namespace.c| 57 +---
 2 files changed, 27 insertions(+), 35 deletions(-)

Changes from v2: Updated patch to return the proper error code. In V1, we return
the default -ENXIO even if we had skipped all the namespaces (when there are
only idle namespaces). In cases like that, we need to return zero, except when
creating namespaces, which may fail due to insufficient space.

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ee737cb..d0599f7 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -4130,16 +4130,11 @@ NDCTL_EXPORT int ndctl_namespace_enable(struct 
ndctl_namespace *ndns)
const char *devname = ndctl_namespace_get_devname(ndns);
struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
struct ndctl_region *region = ndns->region;
-   unsigned long long size = ndctl_namespace_get_size(ndns);
int rc;
 
if (ndctl_namespace_is_enabled(ndns))
return 0;
 
-   /* Don't try to enable idle namespace (no capacity allocated) */
-   if (size == 0)
-   return -ENXIO;
-
rc = ndctl_bind(ctx, ndns->module, devname);
 
/*
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 0550580..ea540dd 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1102,7 +1102,6 @@ static int namespace_destroy(struct ndctl_region *region,
struct ndctl_namespace *ndns)
 {
const char *devname = ndctl_namespace_get_devname(ndns);
-   unsigned long long size;
bool did_zero = false;
int rc;
 
@@ -1147,19 +1146,9 @@ static int namespace_destroy(struct ndctl_region *region,
goto out;
}
 
-   size = ndctl_namespace_get_size(ndns);
-
rc = ndctl_namespace_delete(ndns);
if (rc)
debug("%s: failed to reclaim\n", devname);
-
-   /*
-* Don't report a destroyed namespace when no capacity was
-* allocated.
-*/
-   if (size == 0 && rc == 0)
-   rc = 1;
-
 out:
return rc;
 }
@@ -2128,8 +2117,9 @@ static int do_xaction_namespace(const char *namespace,
ndctl_namespace_foreach_safe(region, ndns, _n) {
ndns_name = ndctl_namespace_get_devname(ndns);
 
-   if (strcmp(namespace, "all") != 0
+   if ((strcmp(namespace, "all") != 0
&& strcmp(namespace, ndns_name) 
!= 0)
+   || ndctl_namespace_get_size(ndns) == 0)
continue;
switch (action) {
case ACTION_DISABLE:
@@ -2148,9 +2138,6 @@ static int do_xaction_namespace(const char *namespace,
rc = namespace_destroy(region, ndns);
if (rc == 0)
(*processed)++;
-   /* return success if skipped */
-   if (rc > 0)
-   rc = 0;
break;
case ACTION_CHECK:
rc = namespace_check(ndns, verbose,
@@ -2195,22 +2182,32 @@ static int do_xaction_namespace(const char *namespace,
if (ri_ctx.f_out && ri_ctx.f_out != stdout)
fclose(ri_ctx.f_out);
 
-   if (action == ACTION_CREATE && rc == -EAGAIN) {
-   /*
-* Namespace creation searched through all candidate
-* regions and all of them said "nope, I don't have
-* enough capacity", so report -ENOSPC. Except during
-* greedy namespace creation using --continue as we
-* may have created some namespaces already, and the
-* last one in the region search may preexist.
-*/
-   if (param.greedy && (*processed) > 0)
-   rc = 0;
-   else
-   rc = -ENOSPC;
+   if (action == ACTION_CREATE) {
+   if (rc == -EAGAIN) {
+   /*
+* Namespace creation searched through all candidate
+* regions and all of them said "nope, I don't have
+* enough capacity", so report -ENOSPC. Except during
+* greedy namespa

[PATCH] error-inject: Remove redundant has_nfit check

2020-08-16 Thread Santosh Sivaraj
ndctl_bus_has_error_injection already has the ndctl_bus_has_nfit
check. Remove the redundant checks.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/inject.c | 73 +-
 1 file changed, 33 insertions(+), 40 deletions(-)

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index ab0bee5..509ba27 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -190,8 +190,6 @@ NDCTL_EXPORT int ndctl_namespace_inject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_inject_one_error(ndns, block + i, flags);
@@ -268,8 +266,6 @@ NDCTL_EXPORT int ndctl_namespace_uninject_error2(struct 
ndctl_namespace *ndns,
 
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
-   if (!ndctl_bus_has_nfit(bus))
-   return -EOPNOTSUPP;
 
for (i = 0; i < count; i++) {
rc = ndctl_namespace_uninject_one_error(ndns, block + i,
@@ -450,46 +446,43 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct 
ndctl_namespace *ndns)
if (!ndctl_bus_has_error_injection(bus))
return -EOPNOTSUPP;
 
-   if (ndctl_bus_has_nfit(bus)) {
-   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
-   _size);
-   if (rc)
-   return rc;
+   rc = ndctl_namespace_get_injection_bounds(ndns, _offset,
+ _size);
+   if (rc)
+   return rc;
 
-   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
-   rc = ndctl_cmd_submit(cmd);
-   if (rc < 0) {
-   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
-   goto out;
-   }
-   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
-   if (buf_size == 0) {
-   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
-   rc = -EINVAL;
-   goto out;
-   }
-   ndctl_cmd_unref(cmd);
+   cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
+   rc = ndctl_cmd_submit(cmd);
+   if (rc < 0) {
+   dbg(ctx, "Error submitting ars_cap: %d\n", rc);
+   goto out;
+   }
+   buf_size = ndctl_cmd_ars_cap_get_size(cmd);
+   if (buf_size == 0) {
+   dbg(ctx, "Got an invalid max_ars_out from ars_cap\n");
+   rc = -EINVAL;
+   goto out;
+   }
+   ndctl_cmd_unref(cmd);
 
-   cmd = ndctl_bus_cmd_new_err_inj_stat(bus, buf_size);
-   if (!cmd)
-   return -ENOMEM;
+   cmd = ndctl_bus_cmd_new_err_inj_stat(bus, buf_size);
+   if (!cmd)
+   return -ENOMEM;
 
-   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
-   err_inj_stat =
-   (struct nd_cmd_ars_err_inj_stat *)>nd_payload[0];
+   pkg = (struct nd_cmd_pkg *)>cmd_buf[0];
+   err_inj_stat =
+   (struct nd_cmd_ars_err_inj_stat *)>nd_payload[0];
 
-   rc = ndctl_cmd_submit(cmd);
-   if (rc < 0) {
-   dbg(ctx, "Error submitting command: %d\n", rc);
-   goto out;
-   }
-   rc = injection_status_to_bb(ndns, err_inj_stat,
-   ns_offset, ns_size);
-   if (rc) {
-   dbg(ctx, "Error converting status to badblocks: %d\n",
-   rc);
-   goto out;
-   }
+   rc = ndctl_cmd_submit(cmd);
+   if (rc < 0) {
+   dbg(ctx, "Error submitting command: %d\n", rc);
+   goto out;
+   }
+   rc = injection_status_to_bb(ndns, err_inj_stat,
+   ns_offset, ns_size);
+   if (rc) {
+   dbg(ctx, "Error converting status to badblocks: %d\n", rc);
+   goto out;
}
 
  out:
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


[PATCH] Don't treat DSM commands as NFIT specific

2020-08-16 Thread Santosh Sivaraj
The DSM commands are treated exclusively as NFIT commands, remove NFIT
dependency on using DSM commands.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/lib/inject.c |  6 +++---
 ndctl/lib/libndctl.c   | 29 ++---
 ndctl/lib/libndctl.sym |  4 
 ndctl/lib/nfit.c   | 35 +--
 ndctl/lib/private.h|  2 +-
 ndctl/libndctl-nfit.h  |  8 
 ndctl/libndctl.h   |  9 +
 7 files changed, 48 insertions(+), 45 deletions(-)

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index 815f254..ab0bee5 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -26,9 +26,9 @@ NDCTL_EXPORT int ndctl_bus_has_error_injection(struct 
ndctl_bus *bus)
if (!bus || !ndctl_bus_has_nfit(bus))
return 0;
 
-   if (ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_SET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_GET) &&
-   ndctl_bus_is_nfit_cmd_supported(bus, NFIT_CMD_ARS_INJECT_CLEAR))
+   if (ndctl_bus_is_dsm_supported(bus, DSM_CMD_ARS_INJECT_SET) &&
+   ndctl_bus_is_dsm_supported(bus, DSM_CMD_ARS_INJECT_GET) &&
+   ndctl_bus_is_dsm_supported(bus, DSM_CMD_ARS_INJECT_CLEAR))
return 1;
 
return 0;
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 952192c..410fd16 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -884,12 +884,6 @@ static void *add_bus(void *parent, int id, const char 
*ctl_base)
else
bus->has_of_node = 1;
 
-   sprintf(path, "%s/device/nfit/dsm_mask", ctl_base);
-   if (sysfs_read_attr(ctx, path, buf) < 0)
-   bus->nfit_dsm_mask = 0;
-   else
-   bus->nfit_dsm_mask = strtoul(buf, NULL, 0);
-
sprintf(path, "%s/device/provider", ctl_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
@@ -898,12 +892,20 @@ static void *add_bus(void *parent, int id, const char 
*ctl_base)
if (!bus->provider)
goto err_read;
 
+   sprintf(path, "%s/device/%s/dsm_mask", ctl_base,
+   ndctl_bus_has_nfit(bus) ? "nfit" : bus->provider);
+   if (sysfs_read_attr(ctx, path, buf) < 0)
+   bus->dsm_mask = 0;
+   else
+   bus->dsm_mask = strtoul(buf, NULL, 0);
+
sprintf(path, "%s/device/wait_probe", ctl_base);
bus->wait_probe_path = strdup(path);
if (!bus->wait_probe_path)
goto err_read;
 
-   sprintf(path, "%s/device/nfit/scrub", ctl_base);
+   sprintf(path, "%s/device/%s/scrub", ctl_base,
+   ndctl_bus_has_nfit(bus) ? "nfit" : bus->provider);
bus->scrub_path = strdup(path);
if (!bus->scrub_path)
goto err_read;
@@ -1236,6 +1238,19 @@ NDCTL_EXPORT int ndctl_bus_is_cmd_supported(struct 
ndctl_bus *bus,
return !!(bus->cmd_mask & (1ULL << cmd));
 }
 
+/**
+ * ndctl_bus_is_cmd_supported - ask if command is supported on @bus.
+ * @bus: ndctl_bus instance
+ * @cmd: command number (defined as NFIT_CMD_XXX in libndctl-nfit.h)
+ *
+ * Return 1: command is supported. Return 0: command is not supported.
+ *
+ */
+NDCTL_EXPORT int ndctl_bus_is_dsm_supported(struct ndctl_bus *bus, int cmd)
+{
+   return !!(bus->dsm_mask & (1ULL << cmd));
+}
+
 NDCTL_EXPORT unsigned int ndctl_bus_get_revision(struct ndctl_bus *bus)
 {
return bus->revision;
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index 7ba1dcc..640342c 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -437,3 +437,7 @@ LIBNDCTL_24 {
ndctl_bus_is_papr_scm;
ndctl_region_has_numa;
 } LIBNDCTL_23;
+
+LIBNDCTL_25 {
+   ndctl_bus_is_dsm_supported;
+} LIBNDCTL_24;
diff --git a/ndctl/lib/nfit.c b/ndctl/lib/nfit.c
index f9fbe73..be252e0 100644
--- a/ndctl/lib/nfit.c
+++ b/ndctl/lib/nfit.c
@@ -20,39 +20,22 @@ static u32 bus_get_firmware_status(struct ndctl_cmd *cmd)
struct nd_cmd_bus *cmd_bus = cmd->cmd_bus;
 
switch (cmd_bus->gen.nd_command) {
-   case NFIT_CMD_TRANSLATE_SPA:
+   case DSM_CMD_TRANSLATE_SPA:
return cmd_bus->xlat_spa.status;
-   case NFIT_CMD_ARS_INJECT_SET:
+   case DSM_CMD_ARS_INJECT_SET:
return cmd_bus->err_inj.status;
-   case NFIT_CMD_ARS_INJECT_CLEAR:
+   case DSM_CMD_ARS_INJECT_CLEAR:
return cmd_bus->err_inj_clr.status;
-   case NFIT_CMD_ARS_INJECT_GET:
+   case DSM_CMD_ARS_INJECT_GET:
return cmd_bus->err_inj_stat.status;
}
 
return -1U;
 }
 
-/**
- * ndctl_bus_is_nfit_cmd_supported - ask nfit command is supported on @bus.
- * @bus: ndctl_bus instance
- * @cmd: nfit command number (defined as NFIT_CM

[ndctl PATCH trivial] test: Remove a redundant ndctl_namespace_foreach

2020-08-06 Thread Santosh Sivaraj
I don't think this was intended to be in the code.

Signed-off-by: Santosh Sivaraj 
---
 test/multi-pmem.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/test/multi-pmem.c b/test/multi-pmem.c
index 668662c..cb7cd40 100644
--- a/test/multi-pmem.c
+++ b/test/multi-pmem.c
@@ -162,7 +162,6 @@ static int do_multi_pmem(struct ndctl_ctx *ctx, struct 
ndctl_test *test)
char uuid_str1[40], uuid_str2[40];
uuid_t uuid_check;
 
-   ndctl_namespace_foreach(region, ndns)
sprintf(devname, "namespace%d.%d",
ndctl_region_get_id(region), i);
ndctl_namespace_foreach(region, ndns)
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [PATCH] libnvdimm: call devm_namespace_disable() on error

2020-07-08 Thread Santosh Sivaraj


Hi! Hannes,

Hannes Reinecke  writes:

> Once devm_namespace_enable() has been called the error path in the
> calling function will not call devm_namespace_disable(), leaving the
> namespace enabled on error.
>
> Signed-off-by: Hannes Reinecke 
> ---
>  drivers/dax/pmem/core.c   |  2 +-
>  drivers/nvdimm/btt.c  |  5 -
>  drivers/nvdimm/claim.c|  8 +++-
>  drivers/nvdimm/pfn_devs.c |  1 +
>  drivers/nvdimm/pmem.c | 20 ++--
>  5 files changed, 23 insertions(+), 13 deletions(-)
>

[snip]

> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index d25e66fd942d..4f667fe6ef72 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -401,8 +401,10 @@ static int pmem_attach_disk(struct device *dev,
>   if (is_nd_pfn(dev)) {
>   nd_pfn = to_nd_pfn(dev);
>   rc = nvdimm_setup_pfn(nd_pfn, >pgmap);
> - if (rc)
> + if (rc) {
> + devm_namespace_disable(dev, ndns);
>   return rc;
> + }

As mentioned in the previous mail, when rc != 0, disable is called again
here.

>   }
>  
>   /* we're attaching a block device, disable raw namespace access */
> @@ -549,17 +551,15 @@ static int nd_pmem_probe(struct device *dev)
>   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;
> -
> + else if (ret != EOPNOTSUPP) {
^ -EOPNOTSUPP

Thanks,
Santosh
> + ret = nd_dax_probe(dev, ndns);
> + if (ret == 0)
> + return -ENXIO;
> + }
>   /* probe complete, attach handles namespace enabling */
>   devm_namespace_disable(dev, ndns);
> + if (ret == -EOPNOTSUPP)
> + return ret;
>  
>   return pmem_attach_disk(dev, ndns);
>  }
> -- 
> 2.16.4
> ___
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [PATCH] libnvdimm: call devm_namespace_disable() on error

2020-07-08 Thread Santosh Sivaraj
Hi Hannes,

Hannes Reinecke  writes:

> Once devm_namespace_enable() has been called the error path in the
> calling function will not call devm_namespace_disable(), leaving the
> namespace enabled on error.
>
> Signed-off-by: Hannes Reinecke 
> ---
>  drivers/dax/pmem/core.c   |  2 +-
>  drivers/nvdimm/btt.c  |  5 -
>  drivers/nvdimm/claim.c|  8 +++-
>  drivers/nvdimm/pfn_devs.c |  1 +
>  drivers/nvdimm/pmem.c | 20 ++--
>  5 files changed, 23 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/dax/pmem/core.c b/drivers/dax/pmem/core.c
> index 2bedf8414fff..4b26434f0aca 100644
> --- a/drivers/dax/pmem/core.c
> +++ b/drivers/dax/pmem/core.c
> @@ -31,9 +31,9 @@ struct dev_dax *__dax_pmem_probe(struct device *dev, enum 
> dev_dax_subsys subsys)
>   if (rc)
>   return ERR_PTR(rc);
>   rc = nvdimm_setup_pfn(nd_pfn, );
> + devm_namespace_disable(dev, ndns);
>   if (rc)
>   return ERR_PTR(rc);
> - devm_namespace_disable(dev, ndns);
>  
>   /* reserve the metadata area, device-dax will reserve the data */
>   pfn_sb = nd_pfn->pfn_sb;
> diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
> index 48e9d169b6f9..bd4747f2c99b 100644
> --- a/drivers/nvdimm/btt.c
> +++ b/drivers/nvdimm/btt.c
> @@ -1704,13 +1704,16 @@ int nvdimm_namespace_attach_btt(struct 
> nd_namespace_common *ndns)
>   dev_dbg(_btt->dev, "%s must be at least %ld bytes\n",
>   dev_name(>dev),
>   ARENA_MIN_SIZE + nd_btt->initial_offset);
> + devm_namespace_disable(_btt->dev, ndns);
>   return -ENXIO;
>   }
>   nd_region = to_nd_region(nd_btt->dev.parent);
>   btt = btt_init(nd_btt, rawsize, nd_btt->lbasize, nd_btt->uuid,
>   nd_region);
> - if (!btt)
> + if (!btt) {
> + devm_namespace_disable(_btt->dev, ndns);
>   return -ENOMEM;
> + }
>   nd_btt->btt = btt;
>  
>   return 0;
> diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
> index 45964acba944..15fd1b92d32f 100644
> --- a/drivers/nvdimm/claim.c
> +++ b/drivers/nvdimm/claim.c
> @@ -314,12 +314,18 @@ int devm_nsio_enable(struct device *dev, struct 
> nd_namespace_io *nsio,
>   }
>  
>   ndns->rw_bytes = nsio_rw_bytes;
> - if (devm_init_badblocks(dev, >bb))
> + if (devm_init_badblocks(dev, >bb)) {
> + devm_release_mem_region(dev, res->start, size);
>   return -ENOMEM;
> + }
>   nvdimm_badblocks_populate(to_nd_region(ndns->dev.parent), >bb,
>   >res);
>  
>   nsio->addr = devm_memremap(dev, res->start, size, ARCH_MEMREMAP_PMEM);
> + if (IS_ERR(nsio->addr)) {
> + devm_exit_badblocks(dev, >bb);
> + devm_release_mem_region(dev, res->start, size);
> + }
>  
>   return PTR_ERR_OR_ZERO(nsio->addr);
>  }
> diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
> index 34db557dbad1..9faa92662643 100644
> --- a/drivers/nvdimm/pfn_devs.c
> +++ b/drivers/nvdimm/pfn_devs.c
> @@ -408,6 +408,7 @@ static int nd_pfn_clear_memmap_errors(struct nd_pfn 
> *nd_pfn)
>   nsoff += chunk;
>   }
>   if (rc) {
> + devm_namespace_disable(_pfn->dev, ndns);

The disable here seems to be wrong.

This function called from the pmem_attach_disk path, where its expected the
namespace is enabled after the setup_pfn. Also in case of an error, we do
another disable in pmem_attach_disk.
Thanks,
Santosh

>   dev_err(_pfn->dev,
>   "error clearing %x badblocks at %llx\n",
>   num_bad, first_bad);
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index d25e66fd942d..4f667fe6ef72 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -401,8 +401,10 @@ static int pmem_attach_disk(struct device *dev,
>   if (is_nd_pfn(dev)) {
>   nd_pfn = to_nd_pfn(dev);
>   rc = nvdimm_setup_pfn(nd_pfn, >pgmap);
> - if (rc)
> + if (rc) {
> + devm_namespace_disable(dev, ndns);
>   return rc;
> + }
>   }
>  
>   /* we're attaching a block device, disable raw namespace access */
> @@ -549,17 +551,15 @@ static int nd_pmem_probe(struct device *dev)
>   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;
> -
> + else if (ret != EOPNOTSUPP) {
> + ret = nd_dax_probe(dev, ndns);
> + if (ret == 0)
> + return -ENXIO;
> + }
>   /* probe 

[RFC v2] tools/testing/nvdimm: Add generic test module for non-nfit platforms

2020-07-08 Thread Santosh Sivaraj
We cannot use ndctl test facility (make check) in platforms that don't
support ACPI. In order to get the ndctl tests working, we need a module
which can emulate NVDIMM devices without relying on ACPI/NFIT, which the
current nfit_test module does.

The aim of this proposed module is to implement a similar functionality
to the existing module but without the ACPI dependencies. Currently two
regions are implemented without interleaving or error injection. Using
`make check` with this module passes 11 tests. The rest of tests are
mostly dependent on error injection or on the availability of 'nfit'.

Signed-off-by: Santosh Sivaraj 
---
 tools/testing/nvdimm/config_check.c |   3 +-
 tools/testing/nvdimm/test/Kbuild|   6 +-
 tools/testing/nvdimm/test/ndtest.c  | 768 
 tools/testing/nvdimm/test/ndtest.h  |  63 +++
 4 files changed, 838 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/nvdimm/test/ndtest.c
 create mode 100644 tools/testing/nvdimm/test/ndtest.h

diff --git a/tools/testing/nvdimm/config_check.c 
b/tools/testing/nvdimm/config_check.c
index cac891028cd1b..3e3a5f5188640 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -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));
 }
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index 75baebf8f4ba1..197bcb2b7f351 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -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
diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
new file mode 100644
index 0..f6c585113646d
--- /dev/null
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -0,0 +1,768 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../watermark.h"
+#include "nfit_test.h"
+#include "ndtest.h"
+
+enum {
+   DIMM_SIZE = SZ_32M,
+   LABEL_SIZE = SZ_128K,
+   NUM_INSTANCES = 2,
+   NUM_DCR = 4,
+};
+
+#define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \
+   (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \
+| ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
+
+struct ndtest_dimm dimm_group1[] = {
+   {
+   .type = NDTEST_REGION_TYPE_BLK,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
+   .uuid_str = "1e5c75d2-b618-11ea-9aa3-507b9ddc0f72",
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE * 2,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
+   .uuid_str = "1c4d43ac-b618-11ea-be80-507b9ddc0f72",
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
+   .uuid_str = "a9f17ffc-b618-11ea-b36d-507b9ddc0f72",
+   },
+   {
+   .type = NDTEST_REGION_TYPE_BLK,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
+   .uuid_str = "b6b83b22-b618-11ea-8aae-507b9ddc0f72",
+   },
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE,
+   .handle = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
+   .uuid_str = "bf9baaee-b618-11ea-b181-507b9ddc0f72"
+   },
+};
+
+struct ndtest_dimm dimm_group2[] = {
+   {
+   .type = NDTEST_REGION_TYPE_PMEM,
+   .size = DIMM_SIZE * 2,
+   .handle = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0),
+   .uuid_str = "ca0817e2-b618-11ea-9db3-507b9ddc0f72",
+   },
+};
+
+struct ndtest_config bus_configs[NUM_INSTANCES] = {
+   /* bus 1 */
+   {
+   .dimm_start = 0,
+   .dimm_count = ARRAY_SIZE(dimm_group1),
+   .dimm = dimm_group1,
+   },
+   /* bus 2 */
+   {
+   .dimm_start = ARRAY_SIZE(dimm_group1),
+   .dimm_count = ARRAY_SIZE(dimm_group2),
+   .dimm = dimm_group2,
+   },
+};
+
+static DEFINE_SPINLOCK(nfit_test_lock);
+struct ndtest_priv *instances[NUM_INSTANCES];
+static struct 

[PATCH ndctl v2] infoblock: Set the default alignment to the platform alignment

2020-07-08 Thread Santosh Sivaraj
The default alignment for write-infoblock command is set to 2M. Change
that to use the platform's supported alignment or PAGE_SIZE. The first
supported alignment is taken as the default.

Signed-off-by: Santosh Sivaraj 
---
 ndctl/namespace.c | 69 ++-
 1 file changed, 56 insertions(+), 13 deletions(-)

v2: Get the 'write-infoblock all' path right [Ira]

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 0550580..8aa5a42 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -175,7 +175,7 @@ OPT_STRING('m', "mode", , "operation-mode", \
 OPT_STRING('s', "size", , "size", \
"override the image size to instantiate the infoblock"), \
 OPT_STRING('a', "align", , "align", \
-   "specify the expected physical alignment (default: 2M)"), \
+   "specify the expected physical alignment"), \
 OPT_STRING('u', "uuid", , "uuid", \
"specify the uuid for the infoblock (default: autogenerate)"), \
 OPT_STRING('M', "map", , "memmap-location", \
@@ -325,23 +325,15 @@ static int set_defaults(enum device_action action)
sysconf(_SC_PAGE_SIZE));
rc = -EINVAL;
}
-   } else if (action == ACTION_WRITE_INFOBLOCK)
-   param.align = "2M";
+   }
 
if (param.size) {
unsigned long long size = parse_size64(param.size);
-   unsigned long long align = parse_size64(param.align);
 
if (size == ULLONG_MAX) {
error("failed to parse namespace size '%s'\n",
param.size);
rc = -EINVAL;
-   } else if (action == ACTION_WRITE_INFOBLOCK
-   && align < ULLONG_MAX
-   && !IS_ALIGNED(size, align)) {
-   error("--size=%s not aligned to %s\n", param.size,
-   param.align);
-   rc = -EINVAL;
}
}
 
@@ -1982,6 +1974,23 @@ out:
return rc;
 }
 
+static unsigned long ndctl_get_default_alignment(struct ndctl_namespace *ndns)
+{
+   unsigned long long align = 0;
+   struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns);
+   struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
+
+   if (ndctl_namespace_get_mode(ndns) == NDCTL_NS_MODE_FSDAX && pfn)
+   align = ndctl_pfn_get_supported_alignment(pfn, 1);
+   else if (ndctl_namespace_get_mode(ndns) == NDCTL_NS_MODE_DEVDAX && dax)
+   align = ndctl_dax_get_supported_alignment(dax, 1);
+
+   if (!align)
+   align =  sysconf(_SC_PAGE_SIZE);
+
+   return align;
+}
+
 static int namespace_rw_infoblock(struct ndctl_namespace *ndns,
struct read_infoblock_ctx *ri_ctx, int write)
 {
@@ -2013,9 +2022,40 @@ static int namespace_rw_infoblock(struct ndctl_namespace 
*ndns,
}
 
sprintf(path, "/dev/%s", ndctl_namespace_get_block_device(ndns));
-   if (write)
-   rc = file_write_infoblock(path);
-   else
+   if (write) {
+   unsigned long long align;
+   bool align_provided = true;
+
+   if (!param.align) {
+   align = ndctl_get_default_alignment(ndns);
+
+   if (asprintf((char **), "%llu", align) < 0) 
{
+   rc = -EINVAL;
+   goto out;
+   }
+   align_provided = false;
+   }
+
+   if (param.size) {
+   unsigned long long size = parse_size64(param.size);
+   align = parse_size64(param.align);
+
+   if (align < ULLONG_MAX && !IS_ALIGNED(size, align)) {
+   error("--size=%s not aligned to %s\n", 
param.size,
+   param.align);
+
+   rc = -EINVAL;
+   }
+   }
+
+   if (!rc)
+   rc = file_write_infoblock(path);
+
+   if (!align_provided) {
+   free((char *)param.align);
+   param.align = NULL;
+   }
+   } else
rc = file_read_infoblock(path, ndns, ri_ctx);
param.parent_uuid = save;
 out:
@@ -2060,6 +2100,9 @@ static int do_xaction_namespace(const char *namespace,
}
 
if (action == ACTION_WRITE_INFOBLOCK && !namespace) {
+   if (!param.align)
+   param.align = "2M";
+
rc = file_write_infoblock(param.outfile);
if (rc >= 0)
(*processed)++;
-- 
2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [ndctl PATCH] Documentation: write-infoblock namespace as mutually exclusive

2020-07-08 Thread Santosh Sivaraj


Hi,

Harish  writes:

> The write-infoblock command allows user to write to only one of
> namespace, stdout or to a file. Document that explicitly and also
> change the usage string to indicate mutual exclusion.
>
> Signed-off-by: Harish 
> ---
>  Documentation/ndctl/ndctl-write-infoblock.txt | 14 --
>  ndctl/namespace.c |  4 +++-
>  2 files changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/ndctl/ndctl-write-infoblock.txt 
> b/Documentation/ndctl/ndctl-write-infoblock.txt
> index 8197559..c29327d 100644
> --- a/Documentation/ndctl/ndctl-write-infoblock.txt
> +++ b/Documentation/ndctl/ndctl-write-infoblock.txt
> @@ -61,19 +61,21 @@ read 1 infoblock
>  
>  OPTIONS
>  ---
> -::
> - One or more 'namespaceX.Y' device names. The keyword 'all' can be 
> specified to
> - operate on every namespace in the system, optionally filtered by bus id 
> (see
> ---bus= option), or region id (see --region= option).
> +::
> + Write the infoblock to 'namespaceX.Y' device name. The keyword 'all' 
> can be
> + specified to operate on every namespace in the system, optionally 
> filtered
> + by bus id (see --bus= option), or region id (see --region= option).
> + (mutually exclusive with --stdout and --output)
>  
>  -c::
>  --stdout::
> - Write the infoblock to stdout
> + Write the infoblock to stdout (mutually
> + exclusive with  and --output)
>  
>  -o::
>  --output=::
>   Write the infoblock to the given file (mutually
> - exclusive with --stdout).
> + exclusive with  and --stdout).
>  
>  -m::
>  --mode=::
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index 0550580..cf6c4ea 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -2346,7 +2346,9 @@ int cmd_read_infoblock(int argc, const char **argv, 
> struct ndctl_ctx *ctx)
>  
>  int cmd_write_infoblock(int argc, const char **argv, struct ndctl_ctx *ctx)
>  {
> - char *xable_usage = "ndctl write-infoblock  []";
> + char *xable_usage = "ndctl write-infoblock [ | -o  "
> + "| --stdout] []";
> +

This is now consistent with the man-page.

Since size (-s) mandatory with --stdout, should that be included in the usage
too?

  Usage: ndctl write-infoblock [ | -o  | -s SIZE --stdout] 
[]

Reviewed-by: Santosh S 

Thanks,
Santosh
>   const char *namespace = parse_namespace_options(argc, argv,
>   ACTION_WRITE_INFOBLOCK, write_infoblock_options,
>   xable_usage);
> -- 
> 2.26.2
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


Re: [PATCH ndctl] infoblock: Set the default alignment to the platform alignment

2020-07-08 Thread Santosh Sivaraj
Ira Weiny  writes:

> On Tue, Jul 07, 2020 at 06:26:41AM +0530, Santosh Sivaraj wrote:
>> The default alignment for write-infoblock command is set to 2M. Change
>> that to use the platform's supported alignment or PAGE_SIZE. The first
>> supported alignment is taken as the default.
>> 
>> Signed-off-by: Santosh Sivaraj 
>> ---
>
> [snip]
>
>> @@ -1992,12 +2001,36 @@ static int namespace_rw_infoblock(struct 
>> ndctl_namespace *ndns,
>>  const char *save;
>>  const char *cmd = write ? "write-infoblock" : "read-infoblock";
>>  const char *devname = ndctl_namespace_get_devname(ndns);
>> +unsigned long long align;
>>  
>>  if (ndctl_namespace_is_active(ndns)) {
>>  pr_verbose("%s: %s enabled, must be disabled\n", cmd, devname);
>>  return -EBUSY;
>>  }
>>  
>> +if (write) {
>> +if (!param.align) {
>> +align = ndctl_get_default_alignment(ndns);
>> +
>> +if (asprintf((char **), "%llu", align) < 0) 
>> {
>
> If we are looping through namespaces doesn't param.align need to be localized
> to this function as well?

Thanks for reviewing!

Right, I missed the "all" case. I will get that fixed this in v2.

Thanks,
Santosh

>
> Ira
>
>> +rc = -EINVAL;
>> +goto out;
>> +}
>> +}
>> +
>> +if (param.size) {
>> +unsigned long long size = parse_size64(param.size);
>> +align = parse_size64(param.align);
>> +
>> +if (align < ULLONG_MAX && !IS_ALIGNED(size, align)) {
>> +error("--size=%s not aligned to %s\n", 
>> param.size,
>> +  param.align);
>> +rc = -EINVAL;
>> +goto out;
>> +}
>> +}
>> +}
>> +
>>  ndctl_namespace_set_raw_mode(ndns, 1);
>>  rc = ndctl_namespace_enable(ndns);
>>  if (rc < 0) {
>> @@ -2060,6 +2093,9 @@ static int do_xaction_namespace(const char *namespace,
>>  }
>>  
>>  if (action == ACTION_WRITE_INFOBLOCK && !namespace) {
>> +if (!param.align)
>> +param.align = "2M";
>> +
>>  rc = file_write_infoblock(param.outfile);
>>  if (rc >= 0)
>>  (*processed)++;
>> -- 
>> 2.26.2
>> ___
>> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
>> To unsubscribe send an email to linux-nvdimm-le...@lists.01.org
___
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org


  1   2   >