* [PATCH v5 0/1] cxl/pmem: debug invalid serial number data
@ 2025-02-19 4:00 Yuquan Wang
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
0 siblings, 1 reply; 6+ messages in thread
From: Yuquan Wang @ 2025-02-19 4:00 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
v4 -> v5:
- Put the info[i].offset assignment after the info[i].serial
v3 -> v4:
- Pull the info[i] assignment and check code up
v2 -> v3:
- Add an inline comment
- Debug serial number before its assignment
v1 -> v2:
- Change 'dev_dbg' to 'dev_err'
Background
==========
A device with missing or invalid serial number is not compliant with the
spec. 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 | 12 ++++++++++--
tools/testing/cxl/test/mem.c | 2 +-
2 files changed, 11 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/1] cxl/pmem: debug invalid serial number data
2025-02-19 4:00 [PATCH v5 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
@ 2025-02-19 4:00 ` Yuquan Wang
2025-02-19 19:29 ` Alison Schofield
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Yuquan Wang @ 2025-02-19 4:00 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 | 12 ++++++++++--
tools/testing/cxl/test/mem.c | 2 +-
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
index f9c95996e937..11c5a65acacf 100644
--- a/drivers/cxl/pmem.c
+++ b/drivers/cxl/pmem.c
@@ -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;
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] 6+ messages in thread
* Re: [PATCH v5 1/1] cxl/pmem: debug invalid serial number data
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
@ 2025-02-19 19:29 ` Alison Schofield
2025-02-19 21:20 ` Ira Weiny
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Alison Schofield @ 2025-02-19 19:29 UTC (permalink / raw)
To: Yuquan Wang
Cc: dave, jonathan.cameron, dave.jiang, vishal.l.verma, ira.weiny,
dan.j.williams, linux-cxl, linux-kernel, chenbaozi
On Wed, Feb 19, 2025 at 12:00:29PM +0800, Yuquan Wang 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>
Re-applying my tag-
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
snip
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/1] cxl/pmem: debug invalid serial number data
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
2025-02-19 19:29 ` Alison Schofield
@ 2025-02-19 21:20 ` Ira Weiny
2025-02-20 17:30 ` Jonathan Cameron
2025-02-20 18:57 ` Dave Jiang
3 siblings, 0 replies; 6+ messages in thread
From: Ira Weiny @ 2025-02-19 21:20 UTC (permalink / raw)
To: Yuquan Wang, dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, chenbaozi, Yuquan Wang
Yuquan Wang 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>
Seems good.
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
[snip]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/1] cxl/pmem: debug invalid serial number data
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
2025-02-19 19:29 ` Alison Schofield
2025-02-19 21:20 ` Ira Weiny
@ 2025-02-20 17:30 ` Jonathan Cameron
2025-02-20 18:57 ` Dave Jiang
3 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2025-02-20 17:30 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 Wed, 19 Feb 2025 12:00:29 +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>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/1] cxl/pmem: debug invalid serial number data
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
` (2 preceding siblings ...)
2025-02-20 17:30 ` Jonathan Cameron
@ 2025-02-20 18:57 ` Dave Jiang
3 siblings, 0 replies; 6+ messages in thread
From: Dave Jiang @ 2025-02-20 18:57 UTC (permalink / raw)
To: Yuquan Wang, dave, jonathan.cameron, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, chenbaozi
On 2/18/25 9:00 PM, Yuquan Wang 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>
Applied to cxl/next
> ---
> drivers/cxl/pmem.c | 12 ++++++++++--
> tools/testing/cxl/test/mem.c | 2 +-
> 2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
> index f9c95996e937..11c5a65acacf 100644
> --- a/drivers/cxl/pmem.c
> +++ b/drivers/cxl/pmem.c
> @@ -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;
> 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] 6+ messages in thread
end of thread, other threads:[~2025-02-20 18:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-19 4:00 [PATCH v5 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
2025-02-19 4:00 ` [PATCH v5 1/1] " Yuquan Wang
2025-02-19 19:29 ` Alison Schofield
2025-02-19 21:20 ` Ira Weiny
2025-02-20 17:30 ` Jonathan Cameron
2025-02-20 18:57 ` Dave Jiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox