Skip to contentSkip to conversation

PCI/AER: Take mask into account while clearing error bits

PATCH Superseded Oza Pawandeep 4 participants 16 messages Jun 7, 2018 – Jun 11, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 PCI/AER: Take mask into account while clearing error bits

PCIe ERR_NONFATAL and ERR_FATAL are uncorrectable errors, and clearing uncorrectable error bits should take error mask into account.

drivers/pci/pcie/aer/aerdrv.c +1 -7
index 377e576..8cbc62b 100644
@@ -341,8 +341,6 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
  */
 static void aer_error_resume(struct pci_dev *dev)
 {
-	int pos;
-	u32 status, mask;
 	u16 reg16;
 
 	/* Clean up Root device status */
@@ -350,11 +348,7 @@ static void aer_error_resume(struct pci_dev *dev)
 	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
 
 	/* Clean AER Root Error Status */
-	pos = dev->aer_cap;
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
-	status &= ~mask; /* Clear corresponding nonfatal bits */
-	pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
+	pci_cleanup_aer_uncorrect_error_status(dev);
 }
 
 /**
drivers/pci/pcie/aer/aerdrv_core.c +5 -1
index 946f3f6..309f3f5 100644
@@ -50,13 +50,17 @@ EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 {
 	int pos;
-	u32 status;
+	u32 status, mask;
 
 	pos = dev->aer_cap;
 	if (!pos)
 		return -EIO;
 
+	/* Clean AER Root Error Status */
+	pos = dev->aer_cap;
 	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
+	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
+	status &= ~mask; /* Clear corresponding nonfatal bits */
 	if (status)
 		pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/6 PCI/AER: Clear uncorrectable fatal error status bits

During ERR_FATAL handling, AER calls pci_cleanup_aer_uncorrect_error_status which should handle pci_channel_io_frozen case in order to determine if it has to clear fatal bits or nonfatal bits.

drivers/pci/pcie/aer/aerdrv_core.c +6 -1
index 309f3f5..6745e37 100644
@@ -60,7 +60,12 @@ int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 	pos = dev->aer_cap;
 	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
 	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
-	status &= ~mask; /* Clear corresponding nonfatal bits */
+
+	if (dev->error_state == pci_channel_io_normal)
+		status &= ~mask; /* Clear corresponding nonfatal bits */
+	else
+		status &= mask; /* Clear corresponding fatal bits */
+
 	if (status)
 		pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
 
drivers/pci/pcie/err.c +2 -0
index f7ce0cb..00d2875 100644
@@ -288,6 +288,7 @@ void pcie_do_fatal_recovery(struct pci_dev *dev, u32 service)
 	struct pci_dev *pdev, *temp;
 	pci_ers_result_t result;
 
+	dev->error_state = pci_channel_io_frozen;
 	if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
 		udev = dev;
 	else
@@ -323,6 +324,7 @@ void pcie_do_fatal_recovery(struct pci_dev *dev, u32 service)
 		if (pcie_wait_for_link(udev, true))
 			pci_rescan_bus(udev->bus);
 		pci_info(dev, "Device recovery from fatal error successful\n");
+		dev->error_state = pci_channel_io_normal;
 	} else {
 		pci_uevent_ers(dev, PCI_ERS_RESULT_DISCONNECT);
 		pci_info(dev, "Device recovery from fatal error failed\n");
Signature · 1 line
2.7.4
#2 lore raw

PATCH 3/6 PCI/ERR: Cleanup ERR_FATAL of error broadcast

In reply to Oza Pawandeep

ERR_FATAL is handled by resetting the Link in software, skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, so now no more ERR_FATAL handling is required inside pci_broadcast_error_message()

drivers/pci/pcie/err.c +3 -8
index 00d2875..3998ed7 100644
@@ -259,15 +259,10 @@ static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
 		/*
 		 * If the error is reported by an end point, we think this
 		 * error is related to the upstream link of the end point.
+		 * The error is non fatal so the bus is ok, just invoke
+		 * the callback for the function that logged the error.
 		 */
-		if (state == pci_channel_io_normal)
-			/*
-			 * the error is non fatal so the bus is ok, just invoke
-			 * the callback for the function that logged the error.
-			 */
-			cb(dev, &result_data);
-		else
-			pci_walk_bus(dev->bus, cb, &result_data);
+		cb(dev, &result_data);
 	}
 
 	return result_data.result;
Signature · 1 line
2.7.4
#3 lore raw

PATCH 4/6 PCI/AER: Clear device status error bits during ERR_FATAL and ERR_NONFATAL

In reply to Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, the device status has to be cleared, which fixes BUG existed before.

drivers/pci/pcie/aer/aerdrv.c +1 -5
index 8cbc62b..0d9eaba 100644
@@ -341,12 +341,8 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
  */
 static void aer_error_resume(struct pci_dev *dev)
 {
-	u16 reg16;
-
 	/* Clean up Root device status */
-	pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &reg16);
-	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
-
+	pci_cleanup_aer_error_device_status(dev);
 	/* Clean AER Root Error Status */
 	pci_cleanup_aer_uncorrect_error_status(dev);
 }
drivers/pci/pcie/aer/aerdrv_core.c +11 -0
index 6745e37..95e9828 100644
@@ -47,6 +47,17 @@ int pci_disable_pcie_error_reporting(struct pci_dev *dev)
 }
 EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
 
+int pci_cleanup_aer_error_device_status(struct pci_dev *dev)
+{
+	u16 reg16;
+
+	/* Clean up Root device status */
+	pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &reg16);
+	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
+
+	return 0;
+}
+
 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 {
 	int pos;
drivers/pci/pcie/err.c +2 -0
index 3998ed7..e1e642c 100644
@@ -252,6 +252,7 @@ static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
 			dev->error_state = state;
 		pci_walk_bus(dev->subordinate, cb, &result_data);
 		if (cb == report_resume) {
+			pci_cleanup_aer_error_device_status(dev);
 			pci_cleanup_aer_uncorrect_error_status(dev);
 			dev->error_state = pci_channel_io_normal;
 		}
@@ -312,6 +313,7 @@ void pcie_do_fatal_recovery(struct pci_dev *dev, u32 service)
 		 * do error recovery on all subordinates of the bridge instead
 		 * of the bridge and clear the error status of the bridge.
 		 */
+		pci_cleanup_aer_error_device_status(dev);
 		pci_cleanup_aer_uncorrect_error_status(dev);
 	}
 
include/linux/aer.h +5 -0
index 514bffa..165a147 100644
@@ -44,6 +44,7 @@ struct aer_capability_regs {
 /* PCIe port driver needs this function to enable AER */
 int pci_enable_pcie_error_reporting(struct pci_dev *dev);
 int pci_disable_pcie_error_reporting(struct pci_dev *dev);
+int pci_cleanup_aer_error_device_status(struct pci_dev *dev);
 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev);
 int pci_cleanup_aer_error_status_regs(struct pci_dev *dev);
 #else
@@ -55,6 +56,10 @@ static inline int pci_disable_pcie_error_reporting(struct pci_dev *dev)
 {
 	return -EINVAL;
 }
+static inline int pci_cleanup_aer_error_device_status(struct pci_dev *dev)
+{
+	return -EINVAL;
+}
 static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 {
 	return -EINVAL;
Signature · 1 line
2.7.4
#4 lore raw

PATCH 5/6 PCI/AER: Clear correctable status bits in device register

In reply to Oza Pawandeep

In case of correctable error Device Status Register sets Correctable Error Detected, which should be cleared after handling the error

drivers/pci/pcie/aer/aerdrv_core.c +1 -0
index 95e9828..0e4e99a 100644
@@ -271,6 +271,7 @@ static void handle_error_source(struct pcie_device *aerdev,
 		if (pos)
 			pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
 					info->status);
+		pci_cleanup_aer_error_device_status(dev);
 	} else if (info->severity == AER_NONFATAL)
 		pcie_do_nonfatal_recovery(dev);
 	else if (info->severity == AER_FATAL)
Signature · 1 line
2.7.4
#5 lore raw

PATCH 6/6 PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

In reply to Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -19
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }
 
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 34 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it restores the config space, enable device, set master and enable error reporting.... and as far as I understand this is being done for upstream link (bridges etc..)

why was it done at the first point (I checked the commit description, but could not really get it) and do we need to handle the same thing in ERR_FATAL now ?

Regards,
Oza.

#7 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

#8 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 8 lines
Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

Keith,

do you know why in ERR_FATAL case following was done ?
have a look at pcie_portdrv_slot_reset() handling (for bridges, switches etc..)

Regards,
Oza.

#9 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 5 lines · On Thu, Jun 07, 2018 at 09:47:42PM -0700, [email protected] wrote:

Keith,

do you know why in ERR_FATAL case following was done ?
have a look at pcie_portdrv_slot_reset() handling (for bridges, switches etc..)

Not sure, but I was looking into some issues in this area anyway.

I'm finding that non-hotpluggable bridges that support D3 are getting put into that low-power mode, and that pretty much breaks the re-enumeration.

#10 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

In reply to Bjorn Helgaas
Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 8 lines
Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

Yes Bjorn thats right.
I am trying to understand it but no clue.
since it is restoring the stuffs in ERR_FATAL case, why would PCIe bridge loose all the settings ? [config space, aer bits, master, device enable etc..) Max we do is link_reset in ERR_FATAL case, and Secondary bus reset should affect downstream components (not upstream)

#11 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 72 lines · On 2018-06-08 00:57, [email protected] wrote:
Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 8 lines
Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

Quoted 7 lines

Yes Bjorn thats right.
I am trying to understand it but no clue.
since it is restoring the stuffs in ERR_FATAL case, why would PCIe bridge loose all the settings ? [config space, aer bits, master, device enable etc..)
Max we do is link_reset in ERR_FATAL case, and Secondary bus reset should affect downstream components (not upstream)

Our first generation controller had this problem. There could be others too.

#12 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

In reply to Bjorn Helgaas
Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 8 lines
Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

Hi Bjorn and Keith,

broadcast_error_message()

if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
        .....
        pci_walk_bus(dev->subordinate, cb, &result_data);

so in case of ERR_FATAL, the walk bus is happening on subordinates, and if I understand the walk right then, pcie_portdrv_slot_reset() is called only on BRIDGES/Switches

If is never called on Root-Ports

having said that, now since we are removing the devices (compare to previous error callback handling in ERR_FATAL) I dont see the need of the above code anymore.

because there is nothing to restore to any more. as we are initiating re-enumeration.

Regards,
Oza.

#13 lore raw

Re: [PATCH NEXT 6/6] PCI/PORTDRV: Remove ERR_FATAL handling from pcie_portdrv_slot_reset()

Quoted 83 lines · On 2018-06-11 15:31, [email protected] wrote:
Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · On Thu, Jun 07, 2018 at 07:18:03PM +0530, [email protected] wrote:
Quoted 35 lines · Oza Pawandeep

We are handling ERR_FATAL by resetting the Link in software,skipping the driver pci_error_handlers callbacks, removing the devices from the PCI subsystem, and re-enumerating, as a result of that, no more calling pcie_portdrv_slot_reset in ERR_FATAL case.

drivers/pci/pcie/portdrv_pci.c +0 -11
index 973f1b8..92f5d330 100644
@@ -42,17 +42,6 @@ __setup("pcie_ports=", pcie_port_setup);
 
 /* global data */
 
-static int pcie_portdrv_restore_config(struct pci_dev *dev)
-{
-	int retval;
-
-	retval = pci_enable_device(dev);
-	if (retval)
-		return retval;
-	pci_set_master(dev);
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int pcie_port_runtime_suspend(struct device *dev)
 {
@@ -162,14 +151,6 @@ static pci_ers_result_t
 pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 
 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 {

drivers/pci/pcie/portdrv_pci.c static pci_ers_result_t · line 156

Quoted 10 lines
drivers/pci/pcie/portdrv_pci.c +0 -8
-	/* If fatal, restore cfg space for possible link reset at upstream */
-	if (dev->error_state == pci_channel_io_frozen) {
-		dev->state_saved = true;
-		pci_restore_state(dev);
-		pcie_portdrv_restore_config(dev);
-		pci_enable_pcie_error_reporting(dev);
-	}
-
 	return PCI_ERS_RESULT_RECOVERED;
 }

Hi Bjorn,

the above patch removes ERR_FATAL handling from pcie_portdrv_slot_reset() because now we are handling ERR_FATAL differently than before.

I tried to dig into pcie_portdrv_slot_reset() handling for ERR_FATAL case where it
restores the config space, enable device, set master and enable error reporting....
and as far as I understand this is being done for upstream link (bridges etc..)

Quoted 8 lines
Quoted 3 lines

why was it done at the first point (I checked the commit description, but could not really get it)
and do we need to handle the same thing in ERR_FATAL now ?

You mean 4bf3392e0bf5 ("PCI-Express AER implemetation: pcie_portdrv error handler"), which added pcie_portdrv_slot_reset()? I agree, that commit log has no useful information. I don't know any of the history behind it.

Hi Bjorn and Keith,

broadcast_error_message()

if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
        .....
        pci_walk_bus(dev->subordinate, cb, &result_data);

so in case of ERR_FATAL, the walk bus is happening on subordinates, and if I understand the walk right
then, pcie_portdrv_slot_reset() is called only on BRIDGES/Switches

Quoted 6 lines

If is never called on Root-Ports

having said that, now since we are removing the devices (compare to previous error callback handling in ERR_FATAL)
I dont see the need of the above code anymore.

when I say above code, I meant this patch itself which removes ERR_FATAL handling out of pcie_portdrv_slot_reset

Quoted 5 lines

because there is nothing to restore to any more. as we are initiating re-enumeration.

Regards,
Oza.

#14 lore raw
In reply to Oza Pawandeep
Quoted 4 lines · Oza Pawandeep

PCIe ERR_NONFATAL and ERR_FATAL are uncorrectable errors, and clearing uncorrectable error bits should take error mask into account.

If/when you repost these, please include a [0/6] cover letter with an overview of the purpose of the series.

I assume these are for v4.19, so I'll look at them after the merge window.

If they fix issues introduced during the v4.18 merge window, we may be able to merge them during the v4.18 -rc cycle. In this case, I would need specifics about what exactly the problems are.

Quoted 52 lines
drivers/pci/pcie/aer/aerdrv.c +1 -7
index 377e576..8cbc62b 100644
@@ -341,8 +341,6 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
  */
 static void aer_error_resume(struct pci_dev *dev)
 {
-	int pos;
-	u32 status, mask;
 	u16 reg16;
 
 	/* Clean up Root device status */
@@ -350,11 +348,7 @@ static void aer_error_resume(struct pci_dev *dev)
 	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
 
 	/* Clean AER Root Error Status */
-	pos = dev->aer_cap;
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
-	status &= ~mask; /* Clear corresponding nonfatal bits */
-	pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
+	pci_cleanup_aer_uncorrect_error_status(dev);
 }
 
 /**
drivers/pci/pcie/aer/aerdrv_core.c +5 -1
index 946f3f6..309f3f5 100644
@@ -50,13 +50,17 @@ EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 {
 	int pos;
-	u32 status;
+	u32 status, mask;
 
 	pos = dev->aer_cap;
 	if (!pos)
 		return -EIO;
 
+	/* Clean AER Root Error Status */
+	pos = dev->aer_cap;
 	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
+	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
+	status &= ~mask; /* Clear corresponding nonfatal bits */
 	if (status)
 		pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
 
Signature · 1 line
2.7.4
#15 lore raw
Quoted 9 lines · Bjorn Helgaas
Quoted 4 lines · Oza Pawandeep

PCIe ERR_NONFATAL and ERR_FATAL are uncorrectable errors, and clearing uncorrectable error bits should take error mask into account.

If/when you repost these, please include a [0/6] cover letter with an overview of the purpose of the series.

Quoted 6 lines

I assume these are for v4.19, so I'll look at them after the merge window.

If they fix issues introduced during the v4.18 merge window, we may be able to merge them during the v4.18 -rc cycle. In this case, I would need specifics about what exactly the problems are.

sure Bjorn, will include cover letter.
Mostly these fixes the things which existed before 4.18 as well. I have a question, please clarify when you get a chance.

I am posting the question on tops of PATCH-6.

Regards,
Oza.

Quoted 55 lines
Quoted 55 lines
drivers/pci/pcie/aer/aerdrv.c +0 -2
index 377e576..8cbc62b 100644
@@ -341,8 +341,6 @@ static pci_ers_result_t aer_root_reset(struct 
 pci_dev *dev)
  */
 static void aer_error_resume(struct pci_dev *dev)
 {
-	int pos;
-	u32 status, mask;
 	u16 reg16;
 
drivers/pci/pcie/aer/aerdrv.c +1 -5
 	/* Clean up Root device status */
@@ -350,11 +348,7 @@ static void aer_error_resume(struct pci_dev *dev)
 	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
 
 	/* Clean AER Root Error Status */
-	pos = dev->aer_cap;
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
-	status &= ~mask; /* Clear corresponding nonfatal bits */
-	pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
+	pci_cleanup_aer_uncorrect_error_status(dev);
 }
 
 /**
drivers/pci/pcie/aer/aerdrv_core.c +5 -2
index 946f3f6..309f3f5 100644
@@ -50,13 +50,17 @@ 
 EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
 {
 	int pos;
-	u32 status;
+	u32 status, mask;
 
 	pos = dev->aer_cap;
 	if (!pos)
 		return -EIO;
 
+	/* Clean AER Root Error Status */
+	pos = dev->aer_cap;
 	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
+	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
+	status &= ~mask; /* Clear corresponding nonfatal bits */
 	if (status)
 		pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
 
--

2.7.4