Blame SOURCES/0024-libndctl-papr-Fix-probe-for-papr-scm-compatible-nvdi.patch

e0018b
From e086106b4d81a2079141c848db7695451c04e877 Mon Sep 17 00:00:00 2001
e0018b
From: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Date: Mon, 17 May 2021 21:18:24 +0530
e0018b
Subject: [PATCH 024/217] libndctl/papr: Fix probe for papr-scm compatible
e0018b
 nvdimms
e0018b
e0018b
With recent changes introduced for unification of PAPR and NFIT
e0018b
families the probe for papr-scm nvdimms is broken since they don't
e0018b
expose 'handle' or 'phys_id' sysfs attributes. These attributes are
e0018b
only exposed by NFIT and 'nvdimm_test' nvdimms. Since 'unable to read'
e0018b
these sysfs attributes is a non-recoverable error hence this prevents
e0018b
probing of 'PAPR-SCM' nvdimms and ndctl reports following error:
e0018b
e0018b
$ sudo NDCTL_LOG=debug ndctl list -DH
e0018b
libndctl: ndctl_new: ctx 0x10015342c70 created
e0018b
libndctl: add_dimm: nmem1: probe failed: Operation not permitted
e0018b
libndctl: __sysfs_device_parse: nmem1: add_dev() failed
e0018b
libndctl: add_dimm: nmem0: probe failed: Operation not permitted
e0018b
libndctl: __sysfs_device_parse: nmem0: add_dev() failed
e0018b
e0018b
Fixing this bug is complicated by the fact these attributes are needed
e0018b
for by the 'nvdimm_test' nvdimms which also uses the
e0018b
NVDIMM_FAMILY_PAPR. Adding a two way comparison for these two
e0018b
attributes in populate_dimm_attributes() to distinguish between
e0018b
'nvdimm_test' and papr-scm nvdimms will be clunky and make future
e0018b
updates to populate_dimm_attributes() error prone.
e0018b
e0018b
So, this patch proposes to fix the issue by re-introducing
e0018b
add_papr_dimm() to probe both papr-scm and 'nvdimm_test' nvdimms. The
e0018b
'compatible' sysfs attribute associated with the PAPR device is used
e0018b
to distinguish between the two nvdimm types and in case an
e0018b
'nvdimm_test' device is detected then forward its probe to
e0018b
populate_dimm_attributes().
e0018b
e0018b
families")
e0018b
e0018b
Link: https://lore.kernel.org/r/20210517154824.142237-1-vaibhav@linux.ibm.com
e0018b
Fixes: daef3a386a9c("libndctl: Unify adding dimms for papr and nfit
e0018b
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 ndctl/lib/libndctl.c | 57 ++++++++++++++++++++++++++++++++++++++++++--
e0018b
 1 file changed, 55 insertions(+), 2 deletions(-)
e0018b
e0018b
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
e0018b
index 3a496ed..aa36a3c 100644
e0018b
--- a/ndctl/lib/libndctl.c
e0018b
+++ b/ndctl/lib/libndctl.c
e0018b
@@ -1754,6 +1754,58 @@ static int populate_dimm_attributes(struct ndctl_dimm *dimm,
e0018b
 	return rc;
e0018b
 }
e0018b
 
e0018b
+static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
e0018b
+{
e0018b
+	int rc = -ENODEV;
e0018b
+	char buf[SYSFS_ATTR_SIZE];
e0018b
+	struct ndctl_ctx *ctx = dimm->bus->ctx;
e0018b
+	char *path = calloc(1, strlen(dimm_base) + 100);
e0018b
+	const char * const devname = ndctl_dimm_get_devname(dimm);
e0018b
+
e0018b
+	dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
e0018b
+
e0018b
+	if (!path)
e0018b
+		return -ENOMEM;
e0018b
+
e0018b
+	/* Check the compatibility of the probed nvdimm */
e0018b
+	sprintf(path, "%s/../of_node/compatible", dimm_base);
e0018b
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
e0018b
+		dbg(ctx, "%s: Unable to read compatible field\n", devname);
e0018b
+		rc =  -ENODEV;
e0018b
+		goto out;
e0018b
+	}
e0018b
+
e0018b
+	dbg(ctx, "%s:Compatible of_pmem = '%s'\n", devname, buf);
e0018b
+
e0018b
+	/* Probe for papr-scm memory */
e0018b
+	if (strcmp(buf, "ibm,pmemory") == 0) {
e0018b
+		/* Read the dimm flags file */
e0018b
+		sprintf(path, "%s/papr/flags", dimm_base);
e0018b
+		if (sysfs_read_attr(ctx, path, buf) < 0) {
e0018b
+			rc = -errno;
e0018b
+			err(ctx, "%s: Unable to read dimm-flags\n", devname);
e0018b
+			goto out;
e0018b
+		}
e0018b
+
e0018b
+		dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, buf);
e0018b
+		dimm->cmd_family = NVDIMM_FAMILY_PAPR;
e0018b
+
e0018b
+		/* Parse dimm flags */
e0018b
+		parse_papr_flags(dimm, buf);
e0018b
+
e0018b
+		/* Allocate monitor mode fd */
e0018b
+		dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
e0018b
+		rc = 0;
e0018b
+
e0018b
+	} else if (strcmp(buf, "nvdimm_test") == 0) {
e0018b
+		/* probe via common populate_dimm_attributes() */
e0018b
+		rc = populate_dimm_attributes(dimm, dimm_base, "papr");
e0018b
+	}
e0018b
+out:
e0018b
+	free(path);
e0018b
+	return rc;
e0018b
+}
e0018b
+
e0018b
 static void *add_dimm(void *parent, int id, const char *dimm_base)
e0018b
 {
e0018b
 	int formats, i, rc = -ENODEV;
e0018b
@@ -1845,8 +1897,9 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
e0018b
 	/* Check if the given dimm supports nfit */
e0018b
 	if (ndctl_bus_has_nfit(bus)) {
e0018b
 		rc = populate_dimm_attributes(dimm, dimm_base, "nfit");
e0018b
-	} else if (ndctl_bus_has_of_node(bus))
e0018b
-		rc = populate_dimm_attributes(dimm, dimm_base, "papr");
e0018b
+	} else if (ndctl_bus_has_of_node(bus)) {
e0018b
+		rc = add_papr_dimm(dimm, dimm_base);
e0018b
+	}
e0018b
 
e0018b
 	if (rc == -ENODEV) {
e0018b
 		/* Unprobed dimm with no family */
e0018b
-- 
e0018b
2.27.0
e0018b