* [PATCH v2 0/1] cxl/pmem: debug invalid serial number data
@ 2025-02-14 3:09 Yuquan Wang
2025-02-14 3:09 ` [PATCH v2 1/1] " Yuquan Wang
2025-02-14 13:26 ` [PATCH v2 0/1] " Jonathan Cameron
0 siblings, 2 replies; 4+ messages in thread
From: Yuquan Wang @ 2025-02-14 3:09 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, chenbaozi, Yuquan Wang
Background
==========
In Qemu environment, the default serial number of cxl-type3 device
is UI64_NULL. But we could still use it to create a nvdimm pmem region
and set a non-zero cookie of nd_interleave_set, for example:
1. create a cxl pmem region interleaved with 2 devices (one with
serial number 0 and the other with serial number 1), and the cookie
would be non-zero/valid.
2. create the second cxl pmem region by 1 device with no serial number
and this region would have a non-zero cookie because the offset of
dpa is non-zero.
Problem
=======
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.
CXL Pmem Validation
===================
This patch 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.
cxl-test
========
A mock serial number is set from the platform device id and 0 is a valid
platform device id. For cxl-test to work properly, always +1 on mock
device's serial number.
Yuquan Wang (1):
cxl/pmem: debug invalid serial number data
drivers/cxl/pmem.c | 7 +++++++
tools/testing/cxl/test/mem.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/1] cxl/pmem: debug invalid serial number data
2025-02-14 3:09 [PATCH v2 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
@ 2025-02-14 3:09 ` Yuquan Wang
2025-02-14 13:31 ` Jonathan Cameron
2025-02-14 13:26 ` [PATCH v2 0/1] " Jonathan Cameron
1 sibling, 1 reply; 4+ messages in thread
From: Yuquan Wang @ 2025-02-14 3:09 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, chenbaozi, Yuquan Wang
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>
---
drivers/cxl/pmem.c | 7 +++++++
tools/testing/cxl/test/mem.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
index f9c95996e937..cc854169e50b 100644
--- a/drivers/cxl/pmem.c
+++ b/drivers/cxl/pmem.c
@@ -384,6 +384,13 @@ static int cxl_pmem_region_probe(struct device *dev)
};
info[i].offset = m->start;
info[i].serial = cxlds->serial;
+
+ if (info[i].serial == 0) {
+ dev_err(dev, "%s: invalid serial number\n",
+ dev_name(&cxlmd->dev));
+ rc = -ENXIO;
+ goto out_nvd;
+ }
}
ndr_desc.num_mappings = cxlr_pmem->nr_mappings;
ndr_desc.mapping = mappings;
diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index 8d731bd63988..9e098cf06603 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -1533,7 +1533,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;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 1/1] cxl/pmem: debug invalid serial number data
2025-02-14 3:09 ` [PATCH v2 1/1] " Yuquan Wang
@ 2025-02-14 13:31 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-02-14 13:31 UTC (permalink / raw)
To: Yuquan Wang
Cc: dave, dave.jiang, alison.schofield, vishal.l.verma, ira.weiny,
dan.j.williams, linux-cxl, linux-kernel, chenbaozi
On Fri, 14 Feb 2025 11:09:52 +0800
Yuquan Wang <wangyuquan1236@phytium.com.cn> wrote:
> 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>
A minor comment inline. Thanks for sorting this out.
Jonathan
> ---
> drivers/cxl/pmem.c | 7 +++++++
> tools/testing/cxl/test/mem.c | 2 +-
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
> index f9c95996e937..cc854169e50b 100644
> --- a/drivers/cxl/pmem.c
> +++ b/drivers/cxl/pmem.c
> @@ -384,6 +384,13 @@ static int cxl_pmem_region_probe(struct device *dev)
> };
> info[i].offset = m->start;
> info[i].serial = cxlds->serial;
> +
Even though it's error path, it seems odd to check the serial
number is valid just after 'using' it.
I would do
info[i].offset = m->start;
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 = -NEXIO;
goto out_nvd;
}
info[i].serial = cxlds->serial;
> + if (info[i].serial == 0) {
> + dev_err(dev, "%s: invalid serial number\n",
> + dev_name(&cxlmd->dev));
> + rc = -ENXIO;
> + goto out_nvd;
> + }
> }
> ndr_desc.num_mappings = cxlr_pmem->nr_mappings;
> ndr_desc.mapping = mappings;
> diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> index 8d731bd63988..9e098cf06603 100644
> --- a/tools/testing/cxl/test/mem.c
> +++ b/tools/testing/cxl/test/mem.c
> @@ -1533,7 +1533,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;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/1] cxl/pmem: debug invalid serial number data
2025-02-14 3:09 [PATCH v2 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
2025-02-14 3:09 ` [PATCH v2 1/1] " Yuquan Wang
@ 2025-02-14 13:26 ` Jonathan Cameron
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-02-14 13:26 UTC (permalink / raw)
To: Yuquan Wang
Cc: dave, dave.jiang, alison.schofield, vishal.l.verma, ira.weiny,
dan.j.williams, linux-cxl, linux-kernel, chenbaozi
On Fri, 14 Feb 2025 11:09:51 +0800
Yuquan Wang <wangyuquan1236@phytium.com.cn> wrote:
> Background
> ==========
> In Qemu environment, the default serial number of cxl-type3 device
> is UI64_NULL.
Doesn't matter but technically it's just not presented by QEMU unless
specified.
The internal default is UI64_NULL but if we match that when creating
the config space stuff we just skip the serial number capability.
I'm glad to see some hardening around this as I ran into same thing
long ago (that's when I realized we were missing serial number support :(
Jonathan
> But we could still use it to create a nvdimm pmem region
> and set a non-zero cookie of nd_interleave_set, for example:
> 1. create a cxl pmem region interleaved with 2 devices (one with
> serial number 0 and the other with serial number 1), and the cookie
> would be non-zero/valid.
> 2. create the second cxl pmem region by 1 device with no serial number
> and this region would have a non-zero cookie because the offset of
> dpa is non-zero.
>
> Problem
> =======
> 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.
>
> CXL Pmem Validation
> ===================
> This patch 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.
>
> cxl-test
> ========
> A mock serial number is set from the platform device id and 0 is a valid
> platform device id. For cxl-test to work properly, always +1 on mock
> device's serial number.
>
> Yuquan Wang (1):
> cxl/pmem: debug invalid serial number data
>
> drivers/cxl/pmem.c | 7 +++++++
> tools/testing/cxl/test/mem.c | 2 +-
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-14 13:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 3:09 [PATCH v2 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
2025-02-14 3:09 ` [PATCH v2 1/1] " Yuquan Wang
2025-02-14 13:31 ` Jonathan Cameron
2025-02-14 13:26 ` [PATCH v2 0/1] " Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox