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