]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
libnvdimm: handle locked label storage areas
authorDan Williams <dan.j.williams@intel.com>
Thu, 4 May 2017 18:47:22 +0000 (11:47 -0700)
committerDan Williams <dan.j.williams@intel.com>
Thu, 4 May 2017 22:41:39 +0000 (15:41 -0700)
Per the latest version of the "NVDIMM DSM Interface Example" [1], the
label data retrieval routine can report a "locked" status. In this case
all regions associated with that DIMM are disabled until the label area
is unlocked. Provide generic libnvdimm enabling for NVDIMMs with label
data area locking capabilities.

[1]: http://pmem.io/documents/

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/acpi/nfit/core.c
drivers/nvdimm/dimm.c
drivers/nvdimm/dimm_devs.c
drivers/nvdimm/namespace_devs.c
include/uapi/linux/ndctl.h

index a26c2297c1ed0d7287b97f605fd1af34a49621f8..891bd49ada0b8ec3761815dd0eb016be976c4784 100644 (file)
@@ -184,14 +184,29 @@ static int xlat_bus_status(void *buf, unsigned int cmd, u32 status)
        return 0;
 }
 
+static int xlat_nvdimm_status(void *buf, unsigned int cmd, u32 status)
+{
+       switch (cmd) {
+       case ND_CMD_GET_CONFIG_SIZE:
+               if (status >> 16 & ND_CONFIG_LOCKED)
+                       return -EACCES;
+               break;
+       default:
+               break;
+       }
+
+       /* all other non-zero status results in an error */
+       if (status)
+               return -EIO;
+       return 0;
+}
+
 static int xlat_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
                u32 status)
 {
        if (!nvdimm)
                return xlat_bus_status(buf, cmd, status);
-       if (status)
-               return -EIO;
-       return 0;
+       return xlat_nvdimm_status(buf, cmd, status);
 }
 
 int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
index ee0b412827bfb43fc739d5e03e873f12254517fa..e0f0e3ce1a32ec284317a22c1ff172c7205a185d 100644 (file)
@@ -49,6 +49,8 @@ static int nvdimm_probe(struct device *dev)
        kref_init(&ndd->kref);
 
        rc = nvdimm_init_nsarea(ndd);
+       if (rc == -EACCES)
+               nvdimm_set_locked(dev);
        if (rc)
                goto err;
 
index 7d1a3dbc7d5df49d8e88c1243169cbe9dad87c72..fac1e9fbd11d8dbcfbb1ca2d0ca868f83b1073e7 100644 (file)
@@ -67,6 +67,7 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd)
        struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
        struct nvdimm_bus_descriptor *nd_desc;
        int rc = validate_dimm(ndd);
+       int cmd_rc = 0;
 
        if (rc)
                return rc;
@@ -76,8 +77,11 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd)
 
        memset(cmd, 0, sizeof(*cmd));
        nd_desc = nvdimm_bus->nd_desc;
-       return nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
-                       ND_CMD_GET_CONFIG_SIZE, cmd, sizeof(*cmd), NULL);
+       rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
+                       ND_CMD_GET_CONFIG_SIZE, cmd, sizeof(*cmd), &cmd_rc);
+       if (rc < 0)
+               return rc;
+       return cmd_rc;
 }
 
 int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
index 2f2d8afc684a59c15421396c59f24db5d415232e..2f9dfbd2dbece55277df04d4462bf5460090f4af 100644 (file)
@@ -2236,14 +2236,21 @@ static int init_active_labels(struct nd_region *nd_region)
                int count, j;
 
                /*
-                * If the dimm is disabled then prevent the region from
-                * being activated if it aliases DPA.
+                * If the dimm is disabled then we may need to prevent
+                * the region from being activated.
                 */
                if (!ndd) {
-                       if (!test_bit(NDD_ALIASING, &nvdimm->flags))
+                       if (test_bit(NDD_LOCKED, &nvdimm->flags))
+                               /* fail, label data may be unreadable */;
+                       else if (test_bit(NDD_ALIASING, &nvdimm->flags))
+                               /* fail, labels needed to disambiguate dpa */;
+                       else
                                return 0;
-                       dev_dbg(&nd_region->dev, "%s: is disabled, failing probe\n",
-                                       dev_name(&nd_mapping->nvdimm->dev));
+
+                       dev_err(&nd_region->dev, "%s: is %s, failing probe\n",
+                                       dev_name(&nd_mapping->nvdimm->dev),
+                                       test_bit(NDD_LOCKED, &nvdimm->flags)
+                                       ? "locked" : "disabled");
                        return -ENXIO;
                }
                nd_mapping->ndd = ndd;
index ede5c6a62164ae182f4495724bf4a518e5b1b93b..7ad3863cb88b5b86766521bcee795e1a794faba3 100644 (file)
@@ -169,6 +169,7 @@ enum {
 enum {
        ND_ARS_VOLATILE = 1,
        ND_ARS_PERSISTENT = 2,
+       ND_CONFIG_LOCKED = 1,
 };
 
 static inline const char *nvdimm_bus_cmd_name(unsigned cmd)