cxl: Add endpoint decoder flags clear when PCI reset happens
Dave Jiang
maintainerPATCH v3 1/1 cxl: Add endpoint decoder flags clear when PCI reset happens
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during cxl_reset_done() to clear the relevant endpoint decoder flags for all decoders of the endpoint device.
---
v3:
- Rename cxl_decoder_clear_flags() to cxl_endpoint_decoder_clear_reset_flags() (Ben)
- Make the function single purpose rather than taking a flag. (Jonathan)
--- drivers/cxl/cxl.h | 1 + drivers/cxl/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
drivers/cxl/cxl.h +1 -0
@@ -333,6 +333,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6) +#define CXL_DECODER_F_RESET_MASK (CXL_DECODER_F_ENABLE | CXL_DECODER_F_LOCK)enum cxl_decoder_type {CXL_DECODER_DEVMEM =2 ,
drivers/cxl/pci.c +16 -0
@@ -1030,6 +1030,19 @@ static void cxl_error_resume(struct pci_dev *pdev) dev->driver ? "successful" : "failed"); } +static int cxl_endpoint_decoder_clear_reset_flags (struct device *dev,void *data) +{ +struct cxl_endpoint_decoder *cxled; + +if (!is_endpoint_decoder (dev)) +return 0 ; + + cxled =to_cxl_endpoint_decoder (dev); + cxled->cxld.flags &= ~CXL_DECODER_F_RESET_MASK ; + +return 0 ; +} +static void cxl_reset_done (struct pci_dev *pdev) {struct cxl_dev_state *cxlds =pci_get_drvdata (pdev);
@@ -1045,6 +1058,9 @@ static void cxl_reset_done(struct pci_dev *pdev)guard (device)(&cxlmd->dev);if (cxlmd->endpoint &&cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +device_for_each_child (&cxlmd->endpoint->dev,NULL , + cxl_endpoint_decoder_clear_reset_flags); +dev_crit (dev,"SBR happened without memory regions removal.\n" );dev_crit (dev,"System may be unstable if regions hosted system memory.\n" );add_taint (TAINT_USER ,LOCKDEP_STILL_OK );
base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
Signature · 1 line
2.53.0
Alison Schofield
maintainerQuoted 4 lines · Dave Jiang
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during
cxl_reset_done()to clear the relevant endpoint decoder flags for all decoders of the endpoint device.
LGTM still
Quoted 4 lines
Reported-by Dan Williams <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Quoted 8 lines · On Thu, 19 Mar 2026 08:25:41 -0700 Dave Jiang <[email protected]> wrote:
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during
cxl_reset_done()to clear the relevant endpoint decoder flags for all decoders of the endpoint device.Reported-by Dan Williams <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Thanks for quick turnaround! Major advantage for me being rare case where I could still remember the context without having to go reread the earlier threads :)
Quoted 8 lines · Dave Jiang
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during
cxl_reset_done()to clear the relevant endpoint decoder flags for all decoders of the endpoint device.Reported-by Dan Williams <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Applied to cxl/next7974835aa9d5 ("cxl: Add endpoint decoder flags clear when PCI reset happens")
Quoted 58 lines
---
v3:
- Renamecxl_decoder_clear_flags()tocxl_endpoint_decoder_clear_reset_flags()(Ben)
- Make the function single purpose rather than taking a flag. (Jonathan)--- drivers/cxl/cxl.h | 1 + drivers/cxl/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)drivers/cxl/cxl.h +1
-0@@ -333,6 +333,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6) +#define CXL_DECODER_F_RESET_MASK (CXL_DECODER_F_ENABLE | CXL_DECODER_F_LOCK)enum cxl_decoder_type {CXL_DECODER_DEVMEM =2 ,drivers/cxl/pci.c +16
-0@@ -1030,6 +1030,19 @@ static void cxl_error_resume(struct pci_dev *pdev) dev->driver ? "successful" : "failed"); } +static int cxl_endpoint_decoder_clear_reset_flags (struct device *dev,void *data) +{ +struct cxl_endpoint_decoder *cxled; + +if (!is_endpoint_decoder (dev)) +return 0 ; + + cxled =to_cxl_endpoint_decoder (dev); + cxled->cxld.flags &= ~CXL_DECODER_F_RESET_MASK ; + +return 0 ; +} +static void cxl_reset_done (struct pci_dev *pdev) {struct cxl_dev_state *cxlds =pci_get_drvdata (pdev);@@ -1045,6 +1058,9 @@ static void cxl_reset_done(struct pci_dev *pdev)guard (device)(&cxlmd->dev);if (cxlmd->endpoint &&cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +device_for_each_child (&cxlmd->endpoint->dev,NULL , + cxl_endpoint_decoder_clear_reset_flags); +dev_crit (dev,"SBR happened without memory regions removal.\n" );dev_crit (dev,"System may be unstable if regions hosted system memory.\n" );add_taint (TAINT_USER ,LOCKDEP_STILL_OK );base-commit:
f338e77383789c0cae23ca3d48adcc5e9e137e3c