Skip to contentSkip to conversation

PCI/ERR: handle disconnected devices in report_error_detected

PATCH In review Christoph Hellwig 3 participants 3 messages Jun 1, 2022 – Jun 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/ERR: handle disconnected devices in report_error_detected

When a device is already unplugged by pciehp by the time that the AER handler is invoked, the PCIe device will lready be in the pci_channel_io_perm_failure state. In that case we should simply return PCI_ERS_RESULT_DISCONNECT instead of trying to do a state transition that will fail.

Also untangle the state transition failure from the lack of methods to improve the debugging output in case it will happen ever again.

---
 drivers/pci/pcie/err.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/pcie/err.c +8 -4
index 0c5a143025af4..59c90d04a609a 100644
@@ -55,10 +55,14 @@ static int report_error_detected(struct pci_dev *dev,
 
 	device_lock(&dev->dev);
 	pdrv = dev->driver;
-	if (!pci_dev_set_io_state(dev, state) ||
-		!pdrv ||
-		!pdrv->err_handler ||
-		!pdrv->err_handler->error_detected) {
+	if (pci_dev_is_disconnected(dev)) {
+		vote = PCI_ERS_RESULT_DISCONNECT;
+	} else if (!pci_dev_set_io_state(dev, state)) {
+		pci_info(dev, "can't recover (state transition %u -> %u invalid)\n",
+			dev->error_state, state);
+		vote = PCI_ERS_RESULT_NONE;
+	} else if (!pdrv || !pdrv->err_handler ||
+		   !pdrv->err_handler->error_detected) {
 		/*
 		 * If any device in the subtree does not have an error_detected
 		 * callback, PCI_ERS_RESULT_NO_AER_DRIVER prevents subsequent
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 2 lines · Christoph Hellwig

When a device is already unplugged by pciehp by the time that the AER handler is invoked, the PCIe device will lready be in the

/s/lready/already

Quoted 6 lines

pci_channel_io_perm_failure state. In that case we should simply return PCI_ERS_RESULT_DISCONNECT instead of trying to do a state transition that will fail.

Also untangle the state transition failure from the lack of methods to improve the debugging output in case it will happen ever again.

Otherwise, it looks good to me.

Quoted 29 lines
---
  drivers/pci/pcie/err.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/pcie/err.c +8 -4
index 0c5a143025af4..59c90d04a609a 100644
@@ -55,10 +55,14 @@ static int report_error_detected(struct pci_dev *dev,
 
  	device_lock(&dev->dev);
  	pdrv = dev->driver;
-	if (!pci_dev_set_io_state(dev, state) ||
-		!pdrv ||
-		!pdrv->err_handler ||
-		!pdrv->err_handler->error_detected) {
+	if (pci_dev_is_disconnected(dev)) {
+		vote = PCI_ERS_RESULT_DISCONNECT;
+	} else if (!pci_dev_set_io_state(dev, state)) {
+		pci_info(dev, "can't recover (state transition %u -> %u invalid)\n",
+			dev->error_state, state);
+		vote = PCI_ERS_RESULT_NONE;
+	} else if (!pdrv || !pdrv->err_handler ||
+		   !pdrv->err_handler->error_detected) {
  		/*
  		 * If any device in the subtree does not have an error_detected
  		 * callback, PCI_ERS_RESULT_NO_AER_DRIVER prevents subsequent
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
#2 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

When a device is already unplugged by pciehp by the time that the AER handler is invoked, the PCIe device will lready be in the pci_channel_io_perm_failure state. In that case we should simply return PCI_ERS_RESULT_DISCONNECT instead of trying to do a state transition that will fail.

Also untangle the state transition failure from the lack of methods to improve the debugging output in case it will happen ever again.

Applied with Sathy's reviewed-by to pci/err for v5.20, thanks!

Quoted 30 lines
---
 drivers/pci/pcie/err.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/pcie/err.c +8 -4
index 0c5a143025af4..59c90d04a609a 100644
@@ -55,10 +55,14 @@ static int report_error_detected(struct pci_dev *dev,
 
 	device_lock(&dev->dev);
 	pdrv = dev->driver;
-	if (!pci_dev_set_io_state(dev, state) ||
-		!pdrv ||
-		!pdrv->err_handler ||
-		!pdrv->err_handler->error_detected) {
+	if (pci_dev_is_disconnected(dev)) {
+		vote = PCI_ERS_RESULT_DISCONNECT;
+	} else if (!pci_dev_set_io_state(dev, state)) {
+		pci_info(dev, "can't recover (state transition %u -> %u invalid)\n",
+			dev->error_state, state);
+		vote = PCI_ERS_RESULT_NONE;
+	} else if (!pdrv || !pdrv->err_handler ||
+		   !pdrv->err_handler->error_detected) {
 		/*
 		 * If any device in the subtree does not have an error_detected
 		 * callback, PCI_ERS_RESULT_NO_AER_DRIVER prevents subsequent
Signature · 1 line
2.30.2