Skip to content

Commit 2da9ad0

Browse files
Yuquan Wangdavejiang
authored andcommitted
cxl/pmem: debug invalid serial number data
In a nvdimm interleave-set each device with an invalid or zero serial number may cause pmem region initialization to fail, but in cxl case such device could still set cookies of nd_interleave_set and create a nvdimm pmem region. This adds the validation of serial number in cxl pmem region creation. The event of no serial number would cause to fail to set the cookie and pmem region. For cxl-test to work properly, always +1 on mock device's serial number. Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://patch.msgid.link/20250219040029.515451-2-wangyuquan1236@phytium.com.cn Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent e0feac2 commit 2da9ad0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

drivers/cxl/pmem.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,23 @@ static int cxl_pmem_region_probe(struct device *dev)
375375
goto out_nvd;
376376
}
377377

378+
if (cxlds->serial == 0) {
379+
/* include missing alongside invalid in this error message. */
380+
dev_err(dev, "%s: invalid or missing serial number\n",
381+
dev_name(&cxlmd->dev));
382+
rc = -ENXIO;
383+
goto out_nvd;
384+
}
385+
info[i].serial = cxlds->serial;
386+
info[i].offset = m->start;
387+
378388
m->cxl_nvd = cxl_nvd;
379389
mappings[i] = (struct nd_mapping_desc) {
380390
.nvdimm = nvdimm,
381391
.start = m->start,
382392
.size = m->size,
383393
.position = i,
384394
};
385-
info[i].offset = m->start;
386-
info[i].serial = cxlds->serial;
387395
}
388396
ndr_desc.num_mappings = cxlr_pmem->nr_mappings;
389397
ndr_desc.mapping = mappings;

tools/testing/cxl/test/mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
15341534
mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf;
15351535
INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work);
15361536

1537-
cxlds->serial = pdev->id;
1537+
cxlds->serial = pdev->id + 1;
15381538
if (is_rcd(pdev))
15391539
cxlds->rcd = true;
15401540

0 commit comments

Comments
 (0)