Skip to contentSkip to conversation

cxl: Add endpoint decoder flags clear when PCI reset happens

PATCH Superseded Dave Jiang 3 participants 6 messages Mar 17 – Mar 19 CXL

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

PATCH v2 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.

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

---
 drivers/cxl/cxl.h |  1 +
 drivers/cxl/pci.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
drivers/cxl/cxl.h +1 -0
index 9b947286eb9b..d09c84bcc015 100644
@@ -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 +19 -0
index fbb300a01830..a0bba4b4db92 100644
@@ -1030,6 +1030,20 @@ static void cxl_error_resume(struct pci_dev *pdev)
 		 dev->driver ? "successful" : "failed");
 }
 
+static int cxl_decoder_clear_flags(struct device *dev, void *data)
+{
+	struct cxl_endpoint_decoder *cxled;
+	unsigned long *flags = data;
+
+	if (!is_endpoint_decoder(dev))
+		return 0;
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	cxled->cxld.flags &= ~(*flags);
+
+	return 0;
+}
+
 static void cxl_reset_done(struct pci_dev *pdev)
 {
 	struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
@@ -1045,6 +1059,11 @@ static void cxl_reset_done(struct pci_dev *pdev)
 	guard(device)(&cxlmd->dev);
 	if (cxlmd->endpoint &&
 	    cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
+		unsigned long flags = CXL_DECODER_F_RESET_MASK;
+
+		device_for_each_child(&cxlmd->endpoint->dev, &flags,
+				      cxl_decoder_clear_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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 35 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.

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

---
 drivers/cxl/cxl.h |  1 +
 drivers/cxl/pci.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
drivers/cxl/cxl.h +1 -0
index 9b947286eb9b..d09c84bcc015 100644
@@ -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 +0 -0
index fbb300a01830..a0bba4b4db92 100644

drivers/cxl/pci.c static void cxl_error_resume(struct pci_dev *pdev) · line 1039

Quoted 10 lines
drivers/cxl/pci.c +7 -0
@@ -1030,6 +1030,20 @@ static void cxl_error_resume(struct pci_dev *pdev)
 		 dev->driver ? "successful" : "failed");
 }
 
+static int cxl_decoder_clear_flags(struct device *dev, void *data)
+{
+	struct cxl_endpoint_decoder *cxled;
+	unsigned long *flags = data;
+
+	if (!is_endpoint_decoder(dev))
+		return 0;

I would either a) rename this function to cxl_endpoint_decoder_clear_flags() or b) change it to use struct cxl_decoder devices directly. The generality of option b is nicer imo, but you'd have to throw in an extra check for switch decoders (or add a is_cxl_decoder() helper).

With either of those:

Thanks,
Ben

Quoted 24 lines
drivers/cxl/pci.c +12 -0
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	cxled->cxld.flags &= ~(*flags);
+
+	return 0;
+}
+
 static void cxl_reset_done(struct pci_dev *pdev)
 {
 	struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
@@ -1045,6 +1059,11 @@ static void cxl_reset_done(struct pci_dev *pdev)
 	guard(device)(&cxlmd->dev);
 	if (cxlmd->endpoint &&
 	    cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
+		unsigned long flags = CXL_DECODER_F_RESET_MASK;
+
+		device_for_each_child(&cxlmd->endpoint->dev, &flags,
+				      cxl_decoder_clear_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

author maintainer
#2 lore raw
Quoted 39 lines · Benjamin
Quoted 38 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.

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

---
 drivers/cxl/cxl.h |  1 +
 drivers/cxl/pci.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
drivers/cxl/cxl.h +1 -0
index 9b947286eb9b..d09c84bcc015 100644
@@ -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 +0 -0
index fbb300a01830..a0bba4b4db92 100644
@@ -1030,6 +1030,20 @@ static void cxl_error_resume(struct pci_dev *pdev)
 		 dev->driver ? "successful" : "failed");
 }
 
Quoted 11 lines

drivers/cxl/pci.c static void cxl_error_resume(struct pci_dev *pdev) · line 1039

Quoted 7 lines
drivers/cxl/pci.c +7 -0
+static int cxl_decoder_clear_flags(struct device *dev, void *data)
+{
+	struct cxl_endpoint_decoder *cxled;
+	unsigned long *flags = data;
+
+	if (!is_endpoint_decoder(dev))
+		return 0;

I would either a) rename this function to cxl_endpoint_decoder_clear_flags() or b) change it to use struct cxl_decoder devices directly. The generality of option b is nicer imo, but you'd have to throw in an extra check for switch decoders (or add a is_cxl_decoder() helper).

Thanks for the review Ben. We can probably do both to make it extra clear.

DJ

Quoted 31 lines

With either of those:

Thanks,
Ben

Quoted 24 lines
drivers/cxl/pci.c +12 -0
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	cxled->cxld.flags &= ~(*flags);
+
+	return 0;
+}
+
 static void cxl_reset_done(struct pci_dev *pdev)
 {
 	struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
@@ -1045,6 +1059,11 @@ static void cxl_reset_done(struct pci_dev *pdev)
 	guard(device)(&cxlmd->dev);
 	if (cxlmd->endpoint &&
 	    cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
+		unsigned long flags = CXL_DECODER_F_RESET_MASK;
+
+		device_for_each_child(&cxlmd->endpoint->dev, &flags,
+				      cxl_decoder_clear_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

author maintainer
#3 lore raw
Quoted 54 lines · Dave Jiang
Quoted 39 lines · Benjamin
Quoted 38 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.

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

---
 drivers/cxl/cxl.h |  1 +
 drivers/cxl/pci.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
drivers/cxl/cxl.h +1 -0
index 9b947286eb9b..d09c84bcc015 100644
@@ -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 +0 -0
index fbb300a01830..a0bba4b4db92 100644
@@ -1030,6 +1030,20 @@ static void cxl_error_resume(struct pci_dev *pdev)
 		 dev->driver ? "successful" : "failed");
 }
 
Quoted 11 lines

drivers/cxl/pci.c static void cxl_error_resume(struct pci_dev *pdev) · line 1039

Quoted 7 lines
drivers/cxl/pci.c +7 -0
+static int cxl_decoder_clear_flags(struct device *dev, void *data)
+{
+	struct cxl_endpoint_decoder *cxled;
+	unsigned long *flags = data;
+
+	if (!is_endpoint_decoder(dev))
+		return 0;

I would either a) rename this function to cxl_endpoint_decoder_clear_flags() or b) change it to use struct cxl_decoder devices directly. The generality of option b is nicer imo, but you'd have to throw in an extra check for switch decoders (or add a is_cxl_decoder() helper).

Quoted 1 line

Thanks for the review Ben. We can probably do both to make it extra clear.

Actually we can't go with option B because the decoders come in as the child device and not passed in as we iterate through device_for_each_child(). So I'll just go with option a.

Quoted 35 lines

DJ

Quoted 31 lines

With either of those:

Thanks,
Ben

Quoted 24 lines
drivers/cxl/pci.c +12 -0
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	cxled->cxld.flags &= ~(*flags);
+
+	return 0;
+}
+
 static void cxl_reset_done(struct pci_dev *pdev)
 {
 	struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
@@ -1045,6 +1059,11 @@ static void cxl_reset_done(struct pci_dev *pdev)
 	guard(device)(&cxlmd->dev);
 	if (cxlmd->endpoint &&
 	    cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
+		unsigned long flags = CXL_DECODER_F_RESET_MASK;
+
+		device_for_each_child(&cxlmd->endpoint->dev, &flags,
+				      cxl_decoder_clear_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

#4 lore raw
In reply to Dave Jiang
Quoted 5 lines · On Tue, 17 Mar 2026 16:49:26 -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.

Quoted 8 lines

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

Unless we know of another use for this helper, I'd have gone with Alison's other alternative of just giving it a more specific name and not passing in a flags parameter. Feels like a bit of premature generalization!

author maintainer
#5 lore raw
Quoted 16 lines · Jonathan Cameron
Quoted 5 lines · On Tue, 17 Mar 2026 16:49:26 -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.

Quoted 8 lines

---
v2:
- Rename CLEAR_MASK to RESET_MASK (Alison)
- Make the helper function take a mask argument to specify which flags to clear (Alison)

Quoted 5 lines

Unless we know of another use for this helper, I'd have gone with Alison's other alternative of just giving it a more specific name and not passing in a flags parameter. Feels like a bit of premature generalization!

Ok will do.