Message ID | 166983620459.2734609.10175456773200251184.stgit@djiang5-desk3.ch.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Introduce security commands for CXL pmem device | expand |
Dave Jiang wrote: > Set the cxlds->serial as the dimm_id to be fed to __nvdimm_create(). The > security code uses that as the key description for the security key of the > memory device. The nvdimm unlock code cannot find the respective key > without the dimm_id. > > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > Signed-off-by: Dave Jiang <dave.jiang@intel.com> > Link: https://lore.kernel.org/r/166863357043.80269.4337575149671383294.stgit@djiang5-desk3.ch.intel.com > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > --- > drivers/cxl/core/pmem.c | 10 ++++++++++ > drivers/cxl/cxl.h | 3 +++ > drivers/cxl/pmem.c | 3 ++- > 3 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c > index 36aa5070d902..f985d41f8f8e 100644 > --- a/drivers/cxl/core/pmem.c > +++ b/drivers/cxl/core/pmem.c > @@ -224,6 +224,7 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_memdev *cxlmd) > { > struct cxl_nvdimm *cxl_nvd; > struct device *dev; > + int rc; > > cxl_nvd = kzalloc(sizeof(*cxl_nvd), GFP_KERNEL); > if (!cxl_nvd) > @@ -239,6 +240,15 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_memdev *cxlmd) > dev->bus = &cxl_bus_type; > dev->type = &cxl_nvdimm_type; > > + rc = snprintf(cxl_nvd->dev_id, CXL_DEV_ID_LEN, "%llx", > + cxlmd->cxlds->serial); So ->dev_id at 19 bytes can fit any value of serial, so there is no need to check for errors here even if the 0x prefix is included. I notice that for the nfit case this value is a string not a number so it's ok to leave off the 0x. Any concerns with me just deleting this error case when I apply it? > + if (rc <= 0) { > + kfree(cxl_nvd); > + if (rc == 0) > + rc = -ENXIO; > + return ERR_PTR(rc); > + } > + > return cxl_nvd; > } > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > index 7d07127eade3..b433e541a054 100644 > --- a/drivers/cxl/cxl.h > +++ b/drivers/cxl/cxl.h > @@ -420,11 +420,14 @@ struct cxl_nvdimm_bridge { > enum cxl_nvdimm_brige_state state; > }; > > +#define CXL_DEV_ID_LEN 19 > + > struct cxl_nvdimm { > struct device dev; > struct cxl_memdev *cxlmd; > struct cxl_nvdimm_bridge *bridge; > struct xarray pmem_regions; > + u8 dev_id[CXL_DEV_ID_LEN]; /* for nvdimm, string of 'serial' */ Any reason to use u8 instead of char? It really is just a string.
diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c index 36aa5070d902..f985d41f8f8e 100644 --- a/drivers/cxl/core/pmem.c +++ b/drivers/cxl/core/pmem.c @@ -224,6 +224,7 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_memdev *cxlmd) { struct cxl_nvdimm *cxl_nvd; struct device *dev; + int rc; cxl_nvd = kzalloc(sizeof(*cxl_nvd), GFP_KERNEL); if (!cxl_nvd) @@ -239,6 +240,15 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_memdev *cxlmd) dev->bus = &cxl_bus_type; dev->type = &cxl_nvdimm_type; + rc = snprintf(cxl_nvd->dev_id, CXL_DEV_ID_LEN, "%llx", + cxlmd->cxlds->serial); + if (rc <= 0) { + kfree(cxl_nvd); + if (rc == 0) + rc = -ENXIO; + return ERR_PTR(rc); + } + return cxl_nvd; } diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 7d07127eade3..b433e541a054 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -420,11 +420,14 @@ struct cxl_nvdimm_bridge { enum cxl_nvdimm_brige_state state; }; +#define CXL_DEV_ID_LEN 19 + struct cxl_nvdimm { struct device dev; struct cxl_memdev *cxlmd; struct cxl_nvdimm_bridge *bridge; struct xarray pmem_regions; + u8 dev_id[CXL_DEV_ID_LEN]; /* for nvdimm, string of 'serial' */ }; struct cxl_pmem_region_mapping { diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index 403e41bcbf2b..ab40c93c44e5 100644 --- a/drivers/cxl/pmem.c +++ b/drivers/cxl/pmem.c @@ -117,7 +117,8 @@ static int cxl_nvdimm_probe(struct device *dev) set_bit(ND_CMD_SET_CONFIG_DATA, &cmd_mask); nvdimm = __nvdimm_create(cxl_nvb->nvdimm_bus, cxl_nvd, cxl_dimm_attribute_groups, flags, - cmd_mask, 0, NULL, NULL, cxl_security_ops, NULL); + cmd_mask, 0, NULL, cxl_nvd->dev_id, + cxl_security_ops, NULL); if (!nvdimm) { rc = -ENOMEM; goto out;