]> www.infradead.org Git - linux.git/commitdiff
cxl/pmem: debug invalid serial number data
authorYuquan Wang <wangyuquan1236@phytium.com.cn>
Wed, 19 Feb 2025 04:00:29 +0000 (12:00 +0800)
committerDave Jiang <dave.jiang@intel.com>
Fri, 14 Mar 2025 22:01:04 +0000 (15:01 -0700)
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>
drivers/cxl/pmem.c
tools/testing/cxl/test/mem.c

index f9c95996e937ed495e2fd9ac8547c9e3102ad7cc..11c5a65acacfe0c2225e713b7797bf8181927f67 100644 (file)
@@ -375,6 +375,16 @@ static int cxl_pmem_region_probe(struct device *dev)
                        goto out_nvd;
                }
 
+               if (cxlds->serial == 0) {
+                       /* include missing alongside invalid in this error message. */
+                       dev_err(dev, "%s: invalid or missing serial number\n",
+                               dev_name(&cxlmd->dev));
+                       rc = -ENXIO;
+                       goto out_nvd;
+               }
+               info[i].serial = cxlds->serial;
+               info[i].offset = m->start;
+
                m->cxl_nvd = cxl_nvd;
                mappings[i] = (struct nd_mapping_desc) {
                        .nvdimm = nvdimm,
@@ -382,8 +392,6 @@ static int cxl_pmem_region_probe(struct device *dev)
                        .size = m->size,
                        .position = i,
                };
-               info[i].offset = m->start;
-               info[i].serial = cxlds->serial;
        }
        ndr_desc.num_mappings = cxlr_pmem->nr_mappings;
        ndr_desc.mapping = mappings;
index 495199238335446324c3536157ee9e0686dec2ea..4cbfafdf5371afa84ee8c2ee1ebf2bb6a2adcc61 100644 (file)
@@ -1534,7 +1534,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
        mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf;
        INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work);
 
-       cxlds->serial = pdev->id;
+       cxlds->serial = pdev->id + 1;
        if (is_rcd(pdev))
                cxlds->rcd = true;