Fix wrong dpa checking in PPR operation
Li Ming
reviewerv6 cover Fix wrong dpa checking in PPR operation
In cxl_do_ppr(), there is a checking to check if a DPA is valid, the implementation of the checking is check if the DPA is 0, if yes, consider that DPA is valid. the checking is not right, the correct implementation is checking if the DPA is in the CXL device DPA range, if yes, it is valid.
The patchset also includes another part implementing a general helper function cxl_resource_contains_addr() in cxl core so that cxl drivers can use it for all DPA/HPA/SPA availability checking.
v6:
- Fix reviewed-by tag mistake.
v5:
- Reverse checkings order in cxl_do_ppr(). (Alison)
v4:
- Add cxl_ prefix to resource_contains_addr(). (Andy & Alison)
- Add impact statement to the commit log of Patch #2. (Alison)
- Add review tags.
v3:
- Move resource_contains_addr() from include/linux/ioport.h to cxl/core/hdm.c. (Andy)
v2:
- Implement a general helper resource_contains_addr() for DPA/HPA resource. (Alison)
base-commit: d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af cxl/fixes
Li Ming (3):
cxl/core: Introduce a new helper cxl_resource_contains_addr() cxl/edac: Fix wrong dpa checking for PPR operation cxl/core: Using cxl_resource_contains_addr() to check address
availability
drivers/cxl/core/core.h | 1 + drivers/cxl/core/edac.c | 9 ++++++--- drivers/cxl/core/hdm.c | 7 +++++++ drivers/cxl/core/memdev.c | 2 +- drivers/cxl/core/region.c | 6 +++--- 5 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
Li Ming
reviewerPATCH v6 1/3 cxl/core: Introduce a new helper cxl_resource_contains_addr()
In CXL subsystem, many functions need to check an address availability by checking if the resource range contains the address. Providing a new helper function cxl_resource_contains_addr() to check if the resource range contains the input address.
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/hdm.c | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/cxl/core/core.h +1 -0
@@ -80,6 +80,7 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size);int cxl_dpa_free (struct cxl_endpoint_decoder *cxled);resource_size_t cxl_dpa_size (struct cxl_endpoint_decoder *cxled);resource_size_t cxl_dpa_resource_start (struct cxl_endpoint_decoder *cxled); +bool cxl_resource_contains_addr (const struct resource *res,const resource_size_t addr);enum cxl_rcrb {CXL_RCRB_DOWNSTREAM ,
drivers/cxl/core/hdm.c +7 -0
@@ -547,6 +547,13 @@ resource_size_t cxl_dpa_resource_start(struct cxl_endpoint_decoder *cxled)return base; } +bool cxl_resource_contains_addr (const struct resource *res,const resource_size_t addr) +{ +struct resource _addr =DEFINE_RES_MEM (addr,1 ); + +return resource_contains (res, &_addr); +} +int cxl_dpa_free (struct cxl_endpoint_decoder *cxled) {struct cxl_port *port =cxled_to_port (cxled);
Signature · 1 line
2.34.1
Re: [PATCH v6 1/3] cxl/core: Introduce a new helper cxl_resource_contains_addr()
Quoted 4 lines · Li Ming
In CXL subsystem, many functions need to check an address availability by checking if the resource range contains the address. Providing a new helper function
cxl_resource_contains_addr()to check if the resource range contains the input address.
Quoted 7 lines
Suggested-by Alison Schofield <[email protected]>Signed-off-by Li Ming <[email protected]>Tested-by Shiju Jose <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Dave Jiang <[email protected]>---
Re: [PATCH v6 1/3] cxl/core: Introduce a new helper cxl_resource_contains_addr()
In reply to Li MingQuoted 10 lines · On Fri, 11 Jul 2025 11:23:55 +0800 Li Ming <[email protected]> wrote:
In CXL subsystem, many functions need to check an address availability by checking if the resource range contains the address. Providing a new helper function
cxl_resource_contains_addr()to check if the resource range contains the input address.Suggested-by Alison Schofield <[email protected]>Signed-off-by Li Ming <[email protected]>Tested-by Shiju Jose <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Dave Jiang <[email protected]>
Li Ming
reviewerPATCH v6 2/3 cxl/edac: Fix wrong dpa checking for PPR operation
In reply to Li MingPer Table 8-143. "Get Partition Info Output Payload" in CXL r3.2 section 8.2.10.9.2.1 "Get Partition Info(Opcode 4100h)", DPA 0 is a valid address of a CXL device. However, cxl_do_ppr() considers it as an invalid address, so that user will get an -EINVAL when user calls the sysfs interface of the edac driver to trigger a Post Package Repair(PPR) operation for DPA 0 on a CXL device. The correct implementation should be checking if the input DPA is in the DPA range of the CXL device.
--- drivers/cxl/core/edac.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/cxl/core/edac.c +4 -1
@@ -1923,8 +1923,11 @@ static int cxl_ppr_set_nibble_mask(struct device *dev, void *drv_data,static int cxl_do_ppr (struct device *dev,void *drv_data,u32 val) {struct cxl_ppr_context *cxl_ppr_ctx = drv_data; +struct cxl_memdev *cxlmd = cxl_ppr_ctx->cxlmd; +struct cxl_dev_state *cxlds = cxlmd->cxlds; -if (!cxl_ppr_ctx->dpa || val !=EDAC_DO_MEM_REPAIR ) +if (val !=EDAC_DO_MEM_REPAIR || + !cxl_resource_contains_addr (&cxlds->dpa_res, cxl_ppr_ctx->dpa))return -EINVAL ;return cxl_mem_perform_ppr (cxl_ppr_ctx);
Signature · 1 line
2.34.1
Re: [PATCH v6 2/3] cxl/edac: Fix wrong dpa checking for PPR operation
Quoted 8 lines · On Fri, 11 Jul 2025 11:23:56 +0800 Li Ming <[email protected]> wrote:
Per Table 8-143. "Get Partition Info Output Payload" in CXL r3.2 section 8.2.10.9.2.1 "Get Partition Info(Opcode 4100h)", DPA 0 is a valid address of a CXL device. However,
cxl_do_ppr()considers it as an invalid address, so that user will get an-EINVALwhen user calls the sysfs interface of the edac driver to trigger a Post Package Repair(PPR) operation for DPA 0 on a CXL device. The correct implementation should be checking if the input DPA is in the DPA range of the CXL device.
Quoted 6 lines
Fixes be9b359e056a ("cxl/edac: Add CXL memory device soft PPR control feature")Signed-off-by Li Ming <[email protected]>Tested-by Shiju Jose <[email protected]>Reviewed-by Shiju Jose <[email protected]>Reviewed-by Dave Jiang <[email protected]>Reviewed-by Alison Schofield <[email protected]>
LGTM
Li Ming
reviewerPATCH v6 3/3 cxl/core: Using cxl_resource_contains_addr() to check address availability
In reply to Li MingHelper function cxl_resource_contains_addr() can be used to check if a resource range contains an input address. Use it to replace all code that checks whether a resource range contains a DPA/HPA/SPA.
--- drivers/cxl/core/edac.c | 4 ++-- drivers/cxl/core/memdev.c | 2 +- drivers/cxl/core/region.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/cxl/core/edac.c +2 -2
@@ -1523,7 +1523,7 @@ static int cxl_mem_sparing_set_dpa(struct device *dev, void *drv_data, u64 dpa)struct cxl_memdev *cxlmd = ctx->cxlmd;struct cxl_dev_state *cxlds = cxlmd->cxlds; -if (dpa < cxlds->dpa_res.start || dpa > cxlds->dpa_res.end) +if (!cxl_resource_contains_addr (&cxlds->dpa_res, dpa))return -EINVAL ; ctx->dpa = dpa;
@@ -1892,7 +1892,7 @@ static int cxl_ppr_set_dpa(struct device *dev, void *drv_data, u64 dpa)struct cxl_memdev *cxlmd = cxl_ppr_ctx->cxlmd;struct cxl_dev_state *cxlds = cxlmd->cxlds; -if (dpa < cxlds->dpa_res.start || dpa > cxlds->dpa_res.end) +if (!cxl_resource_contains_addr (&cxlds->dpa_res, dpa))return -EINVAL ; cxl_ppr_ctx->dpa = dpa;
drivers/cxl/core/memdev.c +1 -1
@@ -267,7 +267,7 @@ static int cxl_validate_poison_dpa(struct cxl_memdev *cxlmd, u64 dpa)dev_dbg (cxlds->dev,"device has no dpa resource\n" );return -EINVAL ; } -if (dpa < cxlds->dpa_res.start || dpa > cxlds->dpa_res.end) { +if (!cxl_resource_contains_addr (&cxlds->dpa_res, dpa)) {dev_dbg (cxlds->dev,"dpa:0x%llx not in resource:%pR\n" , dpa, &cxlds->dpa_res);return -EINVAL ;
drivers/cxl/core/region.c +3 -3
@@ -2847,7 +2847,7 @@ static int __cxl_dpa_to_region(struct device *dev, void *arg)if (!cxled || !cxled->dpa_res || !resource_size (cxled->dpa_res))return 0 ; -if (dpa > cxled->dpa_res->end || dpa < cxled->dpa_res->start) +if (!cxl_resource_contains_addr (cxled->dpa_res, dpa))return 0 ;/*
@@ -2959,7 +2959,7 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,if (cxlrd->hpa_to_spa) hpa = cxlrd->hpa_to_spa (cxlrd, hpa); -if (hpa < p->res->start || hpa > p->res->end) { +if (!cxl_resource_contains_addr (p->res, hpa)) {dev_dbg (&cxlr->dev,"Addr trans fail: hpa 0x%llx not in region\n" , hpa);return ULLONG_MAX ;
@@ -3499,7 +3499,7 @@ u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa)xa_for_each (&endpoint->regions, index, iter) {struct cxl_region_params *p = &iter->region->params; -if (p->res->start <= spa && spa <= p->res->end) { +if (cxl_resource_contains_addr (p->res, spa)) {if (!p->cache_size)return ~0ULL ;
Signature · 1 line
2.34.1
Re: [PATCH v6 3/3] cxl/core: Using cxl_resource_contains_addr() to check address availability
Quoted 7 lines · On Fri, 11 Jul 2025 11:23:57 +0800 Li Ming <[email protected]> wrote:
Helper function
cxl_resource_contains_addr()can be used to check if a resource range contains an input address. Use it to replace all code that checks whether a resource range contains a DPA/HPA/SPA.Signed-off-by Li Ming <[email protected]>Reviewed-by Dave Jiang <[email protected]>Reviewed-by Alison Schofield <[email protected]>
Nice
Dave Jiang
maintainerQuoted 9 lines · Li Ming
In
cxl_do_ppr(), there is a checking to check if a DPA is valid, the implementation of the checking is check if the DPA is 0, if yes, consider that DPA is valid. the checking is not right, the correct implementation is checking if the DPA is in the CXL device DPA range, if yes, it is valid.The patchset also includes another part implementing a general helper function
cxl_resource_contains_addr()in cxl core so that cxl drivers can use it for all DPA/HPA/SPA availability checking.
applied to cxl/nextbdf2d9fd3a86 cxl/core: Using cxl_resource_contains_addr() to check address availability 03ff65c02559 cxl/edac: Fix wrong dpa checking for PPR operation 5b6031c832c2 cxl/core: Introduce a new helper cxl_resource_contains_addr()
Quoted 35 lines
v6:
- Fix reviewed-by tag mistake.v5:
- Reverse checkings order incxl_do_ppr(). (Alison)v4:
- Addcxl_prefix toresource_contains_addr(). (Andy & Alison)
- Add impact statement to the commit log of Patch #2. (Alison)
- Add review tags.v3:
- Moveresource_contains_addr()frominclude/linux/ioport.htocxl/core/hdm.c. (Andy)v2:
- Implement a general helperresource_contains_addr()for DPA/HPA resource. (Alison)base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81afcxl/fixesLi Ming (3):
cxl/core: Introduce a new helpercxl_resource_contains_addr()cxl/edac: Fix wrong dpa checking for PPR operation cxl/core: Usingcxl_resource_contains_addr()to check address
availabilitydrivers/cxl/core/core.h | 1 + drivers/cxl/core/edac.c | 9 ++++++--- drivers/cxl/core/hdm.c | 7 +++++++ drivers/cxl/core/memdev.c | 2 +- drivers/cxl/core/region.c | 6 +++--- 5 files changed, 18 insertions(+), 7 deletions(-)