Skip to contentSkip to conversation

Error reporting for AER-incapable devices

PATCH Applied Lukas Wunner 5 participants 21 messages Nov 18 – Nov 20

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

v2 cover Error reporting for AER-incapable devices

Bjorn suggests "the PCI core should do pci_enable_pcie_error_reporting() independent of whether the device has an AER Capability":

https://lore.kernel.org/r/20260826212619.GA1566339@bhelgaas/

This is done in patch [7/7]. The preceding patches contain prep work.

For context, PCIe r7.1 sec 6.2.1 defines two error reporting paradigms:
AER and baseline capability. The latter relies (solely) on the error enable/status bits in the Device Control and Device Status registers, which exist on every PCIe device. The kernel has supported the AER paradigm for 20 years. With the present series, it gains support for the baseline capability paradigm.

Patches [1/7] and [2/7] reinstate DPC on AER-incapable Downstream Ports. The kernel used to support this until 2018. It is hereby fixed because it eases introduction of baseline capability error reporting in the subsequent patches.

Changes v1 -> v2:

* Patch [1/7]:
* On AER-capable devices, infer severity from AER Extended Capability instead of Device Status register because the latter also logs masked errors (Sathya).
* Fix storytelling in commit message because 4e5fad429bd1 changed

    behavior, not 708b20003624 (Sathya).

* Patch [3/7]:
* New patch to clear error status bits more selectively (sashiko).

* Patch [4/7]:
* Clear Fatal Errors as well on recovery failure (Sathya, sashiko).

* Patch [6/7]:
* Amend kernel-doc of pci_aer_unmask_internal_errors() (Sathya).

* Patch [7/7]:
* Convert AER severity to Device Status bit with new severity2devsta[] array, instead of renumbering AER severity (sashiko).
* On entry of aer_get_device_error_info(), clear info->mask and

    info->first_error (Sathya, sashiko).

* Emit "(no details available)" message for AER-incapable devices as well as for devices whose AER registers are deliberately not read on Fatal Errors (Sathya).
* Amend commit message to inform that System Errors may be raised by AER-incapable devices if they have no AER- or DPC-capable port in their ancestry (Sathya).

Link to v1:

https://lore.kernel.org/r/[email protected]/

Lukas Wunner (6):
PCI/DPC: Avoid access to non-existent AER capability PCI/DPC: Reinstate support for AER-incapable ports PCI/ERR: Clear error status bits more selectively PCI/AER: Drop AER native check from handles_cxl_errors() PCI/AER: Move AER capability check out of pcie_aer_is_native() PCI/AER: Enable baseline capability error reporting

Yury Murashka (1):
PCI/ERR: Avoid stale error status bits on recovery failure

 .../ABI/testing/sysfs-bus-pci-devices-aer     | 26 +++++--
 Documentation/PCI/pcieaer-howto.rst           |  9 +--
 drivers/pci/pcie/aer.c                        | 76 +++++++++++++------
 drivers/pci/pcie/aer_cxl_rch.c                |  3 +-
 drivers/pci/pcie/dpc.c                        | 46 +++++++----
 drivers/pci/pcie/err.c                        | 14 +++-
 6 files changed, 120 insertions(+), 54 deletions(-)

base-commit: 6d69eeae8966bc3bea0facbd550f45ef9de41cc4

Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/7 PCI/DPC: Avoid access to non-existent AER capability

Downstream Port Containment does not mandate presence of an Advanced Error Reporting capability, so a Downstream Port may support DPC, but not AER (PCIe r7.1 sec 6.2.11.2).

In February 2019, commit 9f08a5d896ce ("PCI/DPC: Fix print AER status in DPC event handling") amended the DPC driver to access the AER capability without checking for its presence.

This did not cause actual problems because in March 2018, commit 4e5fad429bd1 ("PCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS") had seemingly inadvertently prevented instantiation of a DPC port service on AER-incapable ports.

However in October 2019, commit 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control") made it possible to override this: The DPC driver may access a non-existent AER capability if "pcie_ports=dpc-native" is passed on the command line.

Fix it by making the DPC driver cope with AER-unsupporting Downstream Ports.

There are two places where the AER capability is accessed:

- dpc_get_aer_uncorrect_severity() uses it to discern whether a Fatal or Non-Fatal Error triggered DPC. Access the Device Status Register instead, in accordance with PCIe r7.1 sec 6.2.5.

- dpc_is_surprise_removal() uses it to detect whether a Surprise Down Error triggered DPC. Return false on AER-unsupporting devices. The function works around an AMD-specific quirk and it seems reasonable to assume that all affected products are AER-supporting. In any case the detection is not possible without AER capability.

Insert a temporary check for an AER capability after the call to aer_get_device_error_info() because the function currently returns false for AER-unsupporting devices. The check will become obsolete and will be removed with the imminent baseline capability error reporting.

Fixes 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control")

---
Changes v1 -> v2:
* On AER-capable devices, infer severity from AER Extended Capability instead of Device Status register because the latter also logs masked errors (Sathya).
* Fix storytelling in commit message because 4e5fad429bd1 changed

    behavior, not 708b20003624 (Sathya).
 drivers/pci/pcie/dpc.c | 45 ++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/pci/pcie/dpc.c +32 -13
index 2b779bd1d861..d02cbbbe3143 100644
@@ -238,19 +238,35 @@ static int dpc_get_aer_uncorrect_severity(struct pci_dev *dev,
 {
 	int pos = dev->aer_cap;
 	u32 status, mask, sev;
+	u16 devsta;
 
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
-	status &= ~mask;
-	if (!status)
-		return 0;
-
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &sev);
-	status &= sev;
-	if (status)
-		info->severity = AER_FATAL;
-	else
-		info->severity = AER_NONFATAL;
+	/*
+	 * Infer severity from AER Extended Capability if present, else from
+	 * Device Status register.  The latter cannot be used on AER-capable
+	 * ports because it also logs masked errors (PCIe r7.1 sec 7.5.3.5).
+	 */
+	if (pos) {
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
+		status &= ~mask;
+		if (!status)
+			return 0;
+
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &sev);
+		status &= sev;
+		if (status)
+			info->severity = AER_FATAL;
+		else
+			info->severity = AER_NONFATAL;
+	} else {
+		pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &devsta);
+		if (devsta & PCI_EXP_DEVSTA_FED)
+			info->severity = AER_FATAL;
+		else if (devsta & PCI_EXP_DEVSTA_NFED)
+			info->severity = AER_NONFATAL;
+		else
+			return 0;
+	}
 
 	info->level = KERN_ERR;
 
@@ -275,7 +291,7 @@ void dpc_process_error(struct pci_dev *pdev)
 		pci_warn(pdev, "containment event, status:%#06x: unmasked uncorrectable error detected\n",
 			 status);
 		if (dpc_get_aer_uncorrect_severity(pdev, &info) &&
-		    aer_get_device_error_info(&info, 0)) {
+		    (aer_get_device_error_info(&info, 0) || !pdev->aer_cap)) {
 			aer_print_error(&info, 0);
 			pci_aer_clear_nonfatal_status(pdev);
 			pci_aer_clear_fatal_status(pdev);
@@ -353,6 +369,9 @@ static bool dpc_is_surprise_removal(struct pci_dev *pdev)
 	if (!pdev->is_hotplug_bridge)
 		return false;
 
+	if (!pdev->aer_cap)
+		return false;
+
 	if (pci_read_config_word(pdev, pdev->aer_cap + PCI_ERR_UNCOR_STATUS,
 				 &status))
 		return false;
Signature · 1 line
2.53.0
#4 lore raw

PATCH v2 2/7 PCI/DPC: Reinstate support for AER-incapable ports

In reply to Lukas Wunner

Downstream Port Containment does not mandate presence of an Advanced Error Reporting capability, so a Downstream Port may support DPC, but not AER (PCIe r7.1 sec 6.2.11.2).

Commit 708b20003624 ("PCI/AER: Remove HEST/FIRMWARE_FIRST parsing for AER ownership") seemingly inadvertently constrained DPC to AER-supporting Downstream Ports by inserting a call to pcie_aer_is_native() in dpc_probe(), which implicitly checks for presence of an AER capability.

Drop the call. It is superfluous because it duplicates the conditions applied by the PCIe port service driver when it decides whether to instantiate a DPC port service (see get_port_device_capability()). If the conditions are not met, no port service is instantiated and dpc_probe() isn't executed.

The only difference between the conditions in dpc_probe() and the ones in get_port_device_capability() is the check for the AER capability, so by removing the checks from dpc_probe(), DPC is supported on AER-incapable Downstream Ports again.

Fixes 708b20003624 ("PCI/AER: Remove HEST/FIRMWARE_FIRST parsing for AER ownership")
---
 drivers/pci/pcie/dpc.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/pci/pcie/dpc.c +0 -3
index d02cbbbe3143..a0880e3cd68c 100644
@@ -496,9 +496,6 @@ static int dpc_probe(struct pcie_device *dev)
 	int status;
 	u16 cap;
 
-	if (!pcie_aer_is_native(pdev) && !pcie_ports_dpc_native)
-		return -ENOTSUPP;
-
 	status = devm_request_threaded_irq(device, dev->irq, dpc_irq,
 					   dpc_handler, IRQF_SHARED,
 					   "pcie-dpc", pdev);
Signature · 1 line
2.53.0
#6 lore raw

PATCH v2 3/7 PCI/ERR: Clear error status bits more selectively

In reply to Lukas Wunner

After recovery from a PCIe error, all of the error status bits in the Device Status register are cleared indiscriminately, regardless of the error's severity.

So when a Correctable Error occurs simultaneously to an Uncorrectable Error, after the former is handled, it is cleared alongside the latter. As a result, the Uncorrectable Error isn't handled at all.

Conversely, an Uncorrectable Error occurring shortly before a Correctable Error may cause the latter to be cleared and thus ignored.

Avoid by clearing only the error bits corresponding to the error severity being handled.

---
Changes v1 -> v2:
* New patch to clear error status bits more selectively (sashiko).

 drivers/pci/pcie/aer.c | 20 +++++++++++++++++++-
 drivers/pci/pcie/err.c |  7 ++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
drivers/pci/pcie/aer.c +19 -1
index 6f2460231422..51cf2ff8c85a 100644
@@ -141,6 +141,12 @@ struct aer_info {
 					PCI_ERR_ROOT_MULTI_COR_RCV |	\
 					PCI_ERR_ROOT_MULTI_UNCOR_RCV)
 
+static const u8 severity2devsta[] = {
+	[AER_NONFATAL]    = PCI_EXP_DEVSTA_NFED,
+	[AER_FATAL]       = PCI_EXP_DEVSTA_FED,
+	[AER_CORRECTABLE] = PCI_EXP_DEVSTA_CED,
+};
+
 static bool pcie_aer_disable;
 static pci_ers_result_t aer_root_reset(struct pci_dev *dev);
 
@@ -1314,6 +1320,17 @@ bool is_aer_internal_error(struct aer_err_info *info)
 }
 #endif
 
+static void pcie_clear_device_status_sev(struct pci_dev *dev, u8 severity,
+					 u32 uncor_status)
+{
+	u16 devsta = severity2devsta[severity];
+
+	if (uncor_status & PCI_ERR_UNC_UNSUP)
+		devsta |= PCI_EXP_DEVSTA_URD;
+
+	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, devsta);
+}
+
 /**
  * pci_aer_handle_error - handle logging error into an event log
  * @dev: pointer to pci_dev data structure of error source device
@@ -1344,7 +1361,8 @@ static void pci_aer_handle_error(struct pci_dev *dev, struct aer_err_info *info)
 			if (pdrv && pdrv->err_handler &&
 			    pdrv->err_handler->cor_error_detected)
 				pdrv->err_handler->cor_error_detected(dev);
-			pcie_clear_device_status(dev);
+			pcie_clear_device_status_sev(dev, AER_CORRECTABLE,
+						     info->anfe_status);
 		}
 	} else if (info->severity == AER_NONFATAL)
 		pcie_do_recovery(dev, pci_channel_io_normal, aer_root_reset);
drivers/pci/pcie/err.c +6 -1
index 1a7fc71c79d8..24a8a8263c2e 100644
@@ -21,6 +21,10 @@
 #include "portdrv.h"
 #include "../pci.h"
 
+#define PCI_EXP_DEVSTA_UNC_MASK	(PCI_EXP_DEVSTA_NFED | \
+				 PCI_EXP_DEVSTA_FED | \
+				 PCI_EXP_DEVSTA_URD)
+
 static pci_ers_result_t merge_result(enum pci_ers_result orig,
 				  enum pci_ers_result new)
 {
@@ -274,7 +278,8 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	 * signaling device may not even be visible to the OS.
 	 */
 	if (host->native_aer) {
-		pcie_clear_device_status(dev);
+		pcie_capability_write_word(dev, PCI_EXP_DEVSTA,
+					   PCI_EXP_DEVSTA_UNC_MASK);
 		pci_aer_clear_nonfatal_status(dev);
 	}
 
Signature · 1 line
2.53.0
#9 lore raw

PATCH v2 4/7 PCI/ERR: Avoid stale error status bits on recovery failure

In reply to Lukas Wunner

From: Yury Murashka <[email protected]>

pcie_do_recovery() only clears the error status bits of an error-reporting device if recovery succeeds, but not if it fails. (E.g. because reset failed, drivers are missing pci_error_handlers or those handlers failed.)

One undesirable consequence is that the AER driver may subsequently identify a wrong device when searching for error-reporting devices in is_error_source(), due to stale bits on an unaffected device.

Avoid by clearing error status bits on recovery failure.

If recovery succeeds, Fatal Errors are generally cleared by a call to pci_restore_state() from drivers' ->slot_reset() callbacks. If recovery fails, those callbacks may not have been invoked or they may not be implemented. Hence clear Fatal Errors as well on recovery failure.

---
Changes v1 -> v2:
* Clear Fatal Errors as well on recovery failure (Sathya, sashiko).

 drivers/pci/pcie/err.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/pci/pcie/err.c +7 -0
index 24a8a8263c2e..a450146fb285 100644
@@ -289,6 +289,13 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	return status;
 
 failed:
+	if (host->native_aer) {
+		pcie_capability_write_word(dev, PCI_EXP_DEVSTA,
+					   PCI_EXP_DEVSTA_UNC_MASK);
+		pci_aer_clear_nonfatal_status(dev);
+		pci_aer_clear_fatal_status(dev);
+	}
+
 	pci_walk_bridge(bridge, pci_pm_runtime_put, NULL);
 
 	pci_walk_bridge(bridge, report_perm_failure_detected, NULL);
Signature · 1 line
2.53.0
#12 lore raw

PATCH v2 5/7 PCI/AER: Drop AER native check from handles_cxl_errors()

In reply to Lukas Wunner

Drop a superfluous call to pcie_aer_is_native() from handles_cxl_errors().

The call is superfluous because the function is only called from:

aer_probe()
cxl_rch_enable_rcec()
handles_cxl_errors()

...and aer_probe() is only invoked if an AER port service was instantiated in get_port_device_capability(), which is conditional on:

  (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT ||
   pci_pcie_type(dev) == PCI_EXP_TYPE_RC_EC) &&
  pci_aer_available() &&
  dev->aer_cap && (pcie_ports_native || host->native_aer))

...and the last line of those conditions is equivalent to pcie_aer_is_native().

---
 drivers/pci/pcie/aer_cxl_rch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pci/pcie/aer_cxl_rch.c +1 -2
index b480dad8bbf4..dfcedb7d277d 100644
@@ -87,8 +87,7 @@ static bool handles_cxl_errors(struct pci_dev *rcec)
 {
 	bool handles_cxl = false;
 
-	if (pci_pcie_type(rcec) == PCI_EXP_TYPE_RC_EC &&
-	    pcie_aer_is_native(rcec))
+	if (pci_pcie_type(rcec) == PCI_EXP_TYPE_RC_EC)
 		pcie_walk_rcec(rcec, handles_cxl_error_iter, &handles_cxl);
 
 	return handles_cxl;
Signature · 1 line
2.53.0
#14 lore raw

PATCH v2 6/7 PCI/AER: Move AER capability check out of pcie_aer_is_native()

In reply to Lukas Wunner

When firmware grants control of Advanced Error Reporting to the operating system, that not only encompasses the AER capability, but also error enable/status bits in the Device Control and Device Status registers (PCI Firmware r3.3 table 4-6 bit 3).

PCIe devices without AER capability still support baseline capability error reporting through these enable/status bits (PCIe r7.1 sec 6.2.1), but the bits must not be modified unless AER control was granted.

pcie_aer_is_native() is unsuitable to check for control of AER-incapable devices because it implicitly checks for presence of an AER capability.

Move that check to its callers (where needed) to allow using the function for the imminent baseline capability error reporting.

---
Changes v1 -> v2:
* Amend kernel-doc of pci_aer_unmask_internal_errors() (Sathya).

 drivers/pci/pcie/aer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/pci/pcie/aer.c +3 -6
index 51cf2ff8c85a..9bb8e2127849 100644
@@ -263,9 +263,6 @@ int pcie_aer_is_native(struct pci_dev *dev)
 {
 	struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
 
-	if (!dev->aer_cap)
-		return 0;
-
 	return host->native_aer;
 }
 EXPORT_SYMBOL_NS_GPL(pcie_aer_is_native, "CXL");
@@ -286,7 +283,7 @@ int pci_aer_clear_nonfatal_status(struct pci_dev *dev)
 	int aer = dev->aer_cap;
 	u32 status, sev;
 
-	if (!pcie_aer_is_native(dev))
+	if (!aer || !pcie_aer_is_native(dev))
 		return -EIO;
 
 	/* Clear status bits for ERR_NONFATAL errors only */
@@ -305,7 +302,7 @@ void pci_aer_clear_fatal_status(struct pci_dev *dev)
 	int aer = dev->aer_cap;
 	u32 status, sev;
 
-	if (!pcie_aer_is_native(dev))
+	if (!aer || !pcie_aer_is_native(dev))
 		return;
 
 	/* Clear status bits for ERR_FATAL errors only */
@@ -1288,7 +1285,7 @@ static bool find_source_device(struct pci_dev *parent,
  * Mask registers.
  *
  * Note: AER must be enabled and supported by the device which must be
- * checked in advance, e.g. with pcie_aer_is_native().
+ * checked in advance, e.g. with dev->aer_cap && pcie_aer_is_native(dev).
  */
 void pci_aer_unmask_internal_errors(struct pci_dev *dev)
 {
Signature · 1 line
2.53.0
#16 lore raw

PATCH v2 7/7 PCI/AER: Enable baseline capability error reporting

In reply to Lukas Wunner

PCIe r7.1 sec 6.2.1 defines two error reporting paradigms: Baseline capability and Advanced Error Reporting Extended Capability (AER).

So far the kernel only supports the AER paradigm. Enable the baseline capability paradigm to complete the kernel's support for error reporting.

Baseline capability (solely) relies on the error enable/status bits in the Device Control and Device Status registers, which exist on every PCIe device. One difference between baseline capability and AER is that the severity of Uncorrectable Errors cannot be controlled. Another difference is that Advisory Non-Fatal Errors are not reported at all (PCIe r7.1 sec 6.2.5).

But the main difference to AER is that no detailed error information is
available: It is only known that an error occurred and which severity it had, but not its type or the Prefix / Header of the TLP that caused it. An exception are Unsupported Request Errors which are signaled with a dedicated bit in the Device Status register. Report these as if the Unsupported Request Error Status bit in the Uncorrectable Error Status register was set, for consistency with the AER paradigm.

Error recovery works the same for baseline capability as it already does for AER: Drivers are informed about errors through the pci_error_handlers callbacks. Recovery from Fatal Errors (and from Non-Fatal Errors, if chosen by drivers) is attempted through a Secondary Bus Reset.

Similarly to commit f26e58bf6f54 ("PCI/AER: Enable error reporting when AER is native"), which universally enabled error reporting on AER-capable devices, the present commit is invasive because it universally enables error reporting on AER-incapable devices. Previously those errors were neither reported nor recovered. It may be necessary to amend more drivers with pci_error_handlers callbacks to recover from newly reported errors.

Baseline capability is only enabled if firmware grants AER control to the operating system. Otherwise firmware owns the error enable/status bits in the Device Control and Device Status registers (PCI Firmware r3.3 table 4-6 bit 3).

Baseline capability support is initially only implemented for native error handling, not Firmware First error handling: ghes_handle_aer() would have to be amended to pass the Device Control and Device Status registers to aer_recover_queue(), and to only pass an AER capability structure if it is present in the CPER record. It's not clear whether any firmware actually generates such CPER records and whether implementing support for it is worthwhile, so postpone that for now.

Devices without AER-capable Root Ports or DPC-capable Downstream Ports in their ancestry may cause System Errors if the corresponding bits in the Root Control register have been set by platform firmware or the user. Previously this could only occur with AER-capable devices. The present commit extends it to AER-incapable devices.

---
Changes v1 -> v2:
* Convert AER severity to Device Status bit with new severity2devsta[] array, instead of renumbering AER severity (sashiko).
* On entry of aer_get_device_error_info(), clear info->mask and

    info->first_error (Sathya, sashiko).

* Emit "(no details available)" message for AER-incapable devices as well as for devices whose AER registers are deliberately not read on Fatal Errors (Sathya).
* Amend commit message to inform that System Errors may be raised by AER-incapable devices if they have no AER- or DPC-capable port in their ancestry (Sathya).

 .../ABI/testing/sysfs-bus-pci-devices-aer     | 26 ++++++----
 Documentation/PCI/pcieaer-howto.rst           |  9 ++--
 drivers/pci/pcie/aer.c                        | 47 ++++++++++++-------
 drivers/pci/pcie/dpc.c                        |  2 +-
 4 files changed, 54 insertions(+), 30 deletions(-)
Documentation/ABI/testing/sysfs-bus-pci-devices-aer +18 -8
index 5ed284523956..9e772e1ed9b3 100644
@@ -1,9 +1,9 @@
 PCIe Device AER statistics
 --------------------------
 
-These attributes show up under all the devices that are AER capable. These
+These attributes show up under all PCIe devices (AER capable or not). These
 statistical counters indicate the errors "as seen/reported by the device".
-Note that this may mean that if an endpoint is causing problems, the AER
+Note that this may mean that if an endpoint is causing problems, the error
 counters may increment at its link partner (e.g. root port) because the
 errors may be "seen" / reported by the link partner and not the
 problematic endpoint itself (which may report all counters as 0 as it never
@@ -17,7 +17,10 @@ Description:	List of correctable errors seen and reported by this
 		PCI device using ERR_COR. Note that since multiple errors may
 		be reported using a single ERR_COR message, thus
 		TOTAL_ERR_COR at the end of the file may not match the actual
-		total of all the errors in the file. Sample output::
+		total of all the errors in the file.
+		For PCIe devices without AER Extended Capability, only the
+		total counter is meaningful while all other counters remain 0.
+		Sample output::
 
 		    localhost /sys/devices/pci0000:00/0000:00:1c.0 # cat aer_dev_correctable
 		    Receiver Error 2
@@ -38,7 +41,10 @@ Description:	List of uncorrectable fatal errors seen and reported by this
 		PCI device using ERR_FATAL. Note that since multiple errors may
 		be reported using a single ERR_FATAL message, thus
 		TOTAL_ERR_FATAL at the end of the file may not match the actual
-		total of all the errors in the file. Sample output::
+		total of all the errors in the file.
+		For PCIe devices without AER Extended Capability, only the
+		total counter is meaningful while all other counters remain 0.
+		Sample output::
 
 		    localhost /sys/devices/pci0000:00/0000:00:1c.0 # cat aer_dev_fatal
 		    Undefined 0
@@ -68,7 +74,11 @@ Description:	List of uncorrectable nonfatal errors seen and reported by this
 		PCI device using ERR_NONFATAL. Note that since multiple errors
 		may be reported using a single ERR_FATAL message, thus
 		TOTAL_ERR_NONFATAL at the end of the file may not match the
-		actual total of all the errors in the file. Sample output::
+		actual total of all the errors in the file.
+		For PCIe devices without AER Extended Capability, only the
+		total counter and the Unsupported Request counter is meaningful
+		while all other counters remain 0.
+		Sample output::
 
 		    localhost /sys/devices/pci0000:00/0000:00:1c.0 # cat aer_dev_nonfatal
 		    Undefined 0
@@ -121,7 +131,7 @@ Description:	Total number of ERR_NONFATAL messages reported to rootport.
 PCIe AER ratelimits
 -------------------
 
-These attributes show up under all the devices that are AER capable.
+These attributes show up under all PCIe devices (AER capable or not).
 They represent configurable ratelimits of logs per error type.
 
 See Documentation/PCI/pcieaer-howto.rst for more info on ratelimits.
@@ -130,7 +140,7 @@ What:		/sys/bus/pci/devices/<dev>/aer/correctable_ratelimit_interval_ms
 Date:		May 2025
 KernelVersion:	6.16.0
 Contact:	[email protected]
-Description:	Writing 0 disables AER correctable error log ratelimiting.
+Description:	Writing 0 disables Correctable Error log ratelimiting.
 		Writing a positive value sets the ratelimit interval in ms.
 		Default is DEFAULT_RATELIMIT_INTERVAL (5000 ms).
 
@@ -147,7 +157,7 @@ What:		/sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_interval_ms
 Date:		May 2025
 KernelVersion:	6.16.0
 Contact:	[email protected]
-Description:	Writing 0 disables AER non-fatal uncorrectable error log
+Description:	Writing 0 disables Non-Fatal Uncorrectable Error log
 		ratelimiting. Writing a positive value sets the ratelimit
 		interval in ms. Default is DEFAULT_RATELIMIT_INTERVAL
 		(5000 ms).
Documentation/PCI/pcieaer-howto.rst +4 -5
index 90fdfddd3ae5..e969e563b61d 100644
@@ -34,9 +34,8 @@ set of error reporting requirements. Advanced Error Reporting
 capability is implemented with a PCIe Advanced Error Reporting
 extended capability structure providing more robust error reporting.
 
-The PCIe AER driver provides the infrastructure to support PCIe Advanced
-Error Reporting capability. The PCIe AER driver provides three basic
-functions:
+The PCIe AER driver provides the infrastructure to support both paradigms.
+It provides three basic functions:
 
   - Gathers the comprehensive error information if errors occurred.
   - Reports error to the users.
@@ -69,7 +68,7 @@ Specification for details regarding _OSC usage.
 AER error output
 ----------------
 
-When a PCIe AER error is captured, an error message will be output to
+When a PCIe error is captured, an error message will be output to
 console. If it's a correctable error, it is output as a warning message.
 Otherwise, it is printed as an error. So users could choose different
 log level to filter out correctable error messages.
@@ -113,7 +112,7 @@ See Documentation/ABI/testing/sysfs-bus-pci-devices-aer.
 AER Statistics / Counters
 -------------------------
 
-When PCIe AER errors are captured, the counters / statistics are also exposed
+When PCIe errors are captured, the counters / statistics are also exposed
 in the form of sysfs attributes which are documented at
 Documentation/ABI/testing/sysfs-bus-pci-devices-aer.
 
drivers/pci/pcie/aer.c +31 -16

99 lines not on this page · raw message

drivers/pci/pcie/dpc.c +1 -1
index a0880e3cd68c..bf5295fe1f4f 100644
@@ -291,7 +291,7 @@ void dpc_process_error(struct pci_dev *pdev)
 		pci_warn(pdev, "containment event, status:%#06x: unmasked uncorrectable error detected\n",
 			 status);
 		if (dpc_get_aer_uncorrect_severity(pdev, &info) &&
-		    (aer_get_device_error_info(&info, 0) || !pdev->aer_cap)) {
+		    aer_get_device_error_info(&info, 0)) {
 			aer_print_error(&info, 0);
 			pci_aer_clear_nonfatal_status(pdev);
 			pci_aer_clear_fatal_status(pdev);
Signature · 1 line
2.53.0
#13 lore raw

Re: [PATCH v2 5/7] PCI/AER: Drop AER native check from handles_cxl_errors()

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

Drop a superfluous call to pcie_aer_is_native() from handles_cxl_errors().

The call is superfluous because the function is only called from:

aer_probe()
cxl_rch_enable_rcec()
handles_cxl_errors()

...and aer_probe() is only invoked if an AER port service was instantiated in get_port_device_capability(), which is conditional on:

  (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT ||
   pci_pcie_type(dev) == PCI_EXP_TYPE_RC_EC) &&
  pci_aer_available() &&
  dev->aer_cap && (pcie_ports_native || host->native_aer))
Quoted 4 lines

...and the last line of those conditions is equivalent to pcie_aer_is_native().

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#5 lore raw

Re: [PATCH v2 2/7] PCI/DPC: Reinstate support for AER-incapable ports

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

Downstream Port Containment does not mandate presence of an Advanced Error Reporting capability, so a Downstream Port may support DPC, but not AER (PCIe r7.1 sec 6.2.11.2).

Commit 708b20003624 ("PCI/AER: Remove HEST/FIRMWARE_FIRST parsing for AER ownership") seemingly inadvertently constrained DPC to AER-supporting Downstream Ports by inserting a call to pcie_aer_is_native() in dpc_probe(), which implicitly checks for presence of an AER capability.

Drop the call. It is superfluous because it duplicates the conditions applied by the PCIe port service driver when it decides whether to instantiate a DPC port service (see get_port_device_capability()). If the conditions are not met, no port service is instantiated and dpc_probe() isn't executed.

Quoted 7 lines

The only difference between the conditions in dpc_probe() and the ones in get_port_device_capability() is the check for the AER capability, so by removing the checks from dpc_probe(), DPC is supported on AER-incapable Downstream Ports again.

Fixes 708b20003624 ("PCI/AER: Remove HEST/FIRMWARE_FIRST parsing for AER ownership")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#2 lore raw

Re: [PATCH v2 1/7] PCI/DPC: Avoid access to non-existent AER capability

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

Downstream Port Containment does not mandate presence of an Advanced Error Reporting capability, so a Downstream Port may support DPC, but not AER (PCIe r7.1 sec 6.2.11.2).

In February 2019, commit 9f08a5d896ce ("PCI/DPC: Fix print AER status in DPC event handling") amended the DPC driver to access the AER capability without checking for its presence.

This did not cause actual problems because in March 2018, commit 4e5fad429bd1 ("PCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS") had seemingly inadvertently prevented instantiation of a DPC port service on AER-incapable ports.

Quoted 8 lines

However in October 2019, commit 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control") made it [ ... ]
for AER-unsupporting devices. The check will become obsolete and will be removed with the imminent baseline capability error reporting.

Fixes 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#7 lore raw

Re: [PATCH v2 3/7] PCI/ERR: Clear error status bits more selectively

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

After recovery from a PCIe error, all of the error status bits in the Device Status register are cleared indiscriminately, regardless of the error's severity.

So when a Correctable Error occurs simultaneously to an Uncorrectable Error, after the former is handled, it is cleared alongside the latter. As a result, the Uncorrectable Error isn't handled at all.

Quoted 7 lines

Conversely, an Uncorrectable Error occurring shortly before a Correctable Error may cause the latter to be cleared and thus ignored.

Avoid by clearing only the error bits corresponding to the error severity being handled.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#15 lore raw

Re: [PATCH v2 6/7] PCI/AER: Move AER capability check out of pcie_aer_is_native()

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

When firmware grants control of Advanced Error Reporting to the operating system, that not only encompasses the AER capability, but also error enable/status bits in the Device Control and Device Status registers (PCI Firmware r3.3 table 4-6 bit 3).

PCIe devices without AER capability still support baseline capability error reporting through these enable/status bits (PCIe r7.1 sec 6.2.1), but the bits must not be modified unless AER control was granted.

Quoted 7 lines

pcie_aer_is_native() is unsuitable to check for control of AER-incapable devices because it implicitly checks for presence of an AER capability.

Move that check to its callers (where needed) to allow using the function for the imminent baseline capability error reporting.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#10 lore raw

Re: [PATCH v2 4/7] PCI/ERR: Avoid stale error status bits on recovery failure

In reply to Lukas Wunner
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

From: Yury Murashka <[email protected]>

pcie_do_recovery() only clears the error status bits of an error-reporting device if recovery succeeds, but not if it fails. (E.g. because reset failed, drivers are missing pci_error_handlers or those handlers failed.)

One undesirable consequence is that the AER driver may subsequently identify a wrong device when searching for error-reporting devices in is_error_source(), due to stale bits on an unaffected device.

Avoid by clearing error status bits on recovery failure.

If recovery succeeds, Fatal Errors are generally cleared by a call to pci_restore_state() from drivers' ->slot_reset() callbacks. If recovery fails, those callbacks may not have been invoked or they may not be implemented. Hence clear Fatal Errors as well on recovery failure.

Quoted 4 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#17 lore raw

Re: [PATCH v2 7/7] PCI/AER: Enable baseline capability error reporting

In reply to Lukas Wunner
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] PCI/AER: aer_get_device_error_info() misclassifies fatal errors when !aer - [Medium] PCI/AER…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] PCI/AER: aer_get_device_error_info() misclassifies fatal errors when !aer
- [Medium] PCI/AER: aer_stats_attrs_are_visible() exposes rootport attrs when !aer_cap
- [Medium] PCI/AER: RsvdP PCI_EXP_AER_FLAGS in VF PCI_EXP_DEVCTL breaks VF baseline AER
--

commit 9287c85cae40e6093499911042f25e70c5543c73
Author: Lukas Wunner <[email protected]>

PCI/AER: Enable baseline capability error reporting

This commit enables PCIe baseline capability error reporting on devices that do not implement the Advanced Error Reporting Extended Capability, using the Device Control and Device Status registers.

Quoted 18 lines
drivers/pci/pcie/aer.c +2 -4
index 9bb8e2127849e..3c28afca5d037 100644
@@ -403,21 +403,22 @@ void pci_aer_init(struct pci_dev *dev)
 {
 	int n;
 
-	dev->aer_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
-	if (!dev->aer_cap)
+	if (!pci_is_pcie(dev))
 		return;
 
 	dev->aer_info = kzalloc_obj(*dev->aer_info);
-	if (!dev->aer_info) {
-		dev->aer_cap = 0;
+	if (!dev->aer_info)
 		return;

drivers/pci/pcie/aer.c void pci_aer_init(struct pci_dev *dev) · line 420

Quoted 10 lines
drivers/pci/pcie/aer.c +3 -1
-	}
 
 	ratelimit_state_init(&dev->aer_info->correctable_ratelimit,
 			     DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
 	ratelimit_state_init(&dev->aer_info->nonfatal_ratelimit,
 			     DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
 
+	dev->aer_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
+	if (!dev->aer_cap)
+		goto enable;

[Severity: Medium]
Does allocating dev->aer_info for all PCIe devices cause aer_stats_attrs_are_visible() to expose the aer_rootport_total_err_* sysfs attributes on Root Ports and RCECs that lack an AER Extended Capability?

drivers/pci/pcie/aer.c:aer_stats_attrs_are_visible() {
	...
	if (!pdev->aer_info)
		return 0;

	if ((a == &dev_attr_aer_rootport_total_err_cor.attr ||
	     a == &dev_attr_aer_rootport_total_err_fatal.attr ||
	     a == &dev_attr_aer_rootport_total_err_nonfatal.attr) &&
	    ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
	     (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_EC)))
		return 0;
	...
}

Those counters are only updated from PCI_ERR_ROOT_STATUS in the AER capability and Documentation/ABI/testing/sysfs-bus-pci-devices-aer states that they only appear under AER-capable Root Ports or RCECs, so aer_stats_attrs_are_visible() should also require pdev->aer_cap for them.

[ ... ]

drivers/pci/pcie/aer.c static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info) · line 1213

Quoted 11 lines
drivers/pci/pcie/aer.c +5 -2
@@ -1204,8 +1206,11 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
 	if (!(reg16 & PCI_EXP_AER_FLAGS))
 		return false;
 
-	if (!aer)
-		return false;
+	if (!aer) {
+		pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &reg16);
+		return reg16 & severity2devsta[e_info->severity] &&
+		       !PCI_POSSIBLE_ERROR(reg16);
+	}

[Severity: Medium]
Does checking PCI_EXP_AER_FLAGS in dev's own PCI_EXP_DEVCTL prevent is_error_source() and clear_status_iter() from working on SR-IOV Virtual Functions?

Per PCIe r7.1 sec 7.5.3.4 and sec 9.5.1.2, the PCI_EXP_AER_FLAGS bits in PCI_EXP_DEVCTL are RsvdP and hardwired to 0b on VFs, which inherit the associated Physical Function's PCI_EXP_DEVCTL settings while implementing per-VF status bits in PCI_EXP_DEVSTA. Reading PCI_EXP_DEVCTL on a VF therefore always sees 0 for PCI_EXP_AER_FLAGS, so is_error_source() never checks PCI_EXP_DEVSTA on VFs and clear_status_iter() never clears it; meanwhile pci_enable_pcie_error_reporting() writes 1s to those RsvdP bits on VFs.

[ ... ]

Quoted 12 lines
drivers/pci/pcie/aer.c +2 -1
@@ -1531,13 +1537,22 @@ int aer_get_device_error_info(struct aer_err_info *info, int i)
 
 	/* Must reset in this function */
 	info->status = 0;
+	info->mask = 0;
 	info->anfe_status = 0;
+	info->first_error = 0;
 	info->tlp_header_valid = 0;
 	info->is_cxl = pcie_is_cxl(dev);
 
 	/* The device might not support AER */
-	if (!aer)

drivers/pci/pcie/aer.c int aer_get_device_error_info(struct aer_err_info *info, int i) · line 1555

Quoted 10 lines
drivers/pci/pcie/aer.c +9 -1
-		return 0;
+	if (!aer) {
+		if (info->severity != AER_CORRECTABLE) {
+			pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &devsta);
+			if (devsta & PCI_EXP_DEVSTA_URD &&
+			    !PCI_POSSIBLE_ERROR(devsta))
+				info->status = PCI_ERR_UNC_UNSUP;
+		}
+		return 1;
+	}

[Severity: Medium]
Should the !aer branch check info->severity == AER_NONFATAL instead of info->severity != AER_CORRECTABLE?

Without an AER capability, error severities are fixed to their defaults where Unsupported Request is always Non-Fatal (PCIe r7.1 sec 6.2.7), yet PCI_EXP_DEVSTA_URD is also set by prior Advisory Non-Fatal or Non-Fatal Unsupported Requests (sec 6.2.5 and 7.5.3.5). When an AER_FATAL error occurs on an AER-incapable device, reading PCI_EXP_DEVSTA accesses config space on an Endpoint or Upstream Port whose link may be down, and any set PCI_EXP_DEVSTA_URD bit causes aer_print_error() to misreport the fatal error as UnsupReq and increment the Unsupported Request counter in aer_dev_fatal (which Documentation/ABI/testing/sysfs-bus-pci-devices-aer says must remain 0).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Reviewed-by on v2 1/7
#3 lore raw

Re: [PATCH v2 1/7] PCI/DPC: Avoid access to non-existent AER capability

In reply to Lukas Wunner
Quoted 38 lines · Lukas Wunner

Downstream Port Containment does not mandate presence of an Advanced Error Reporting capability, so a Downstream Port may support DPC, but not AER (PCIe r7.1 sec 6.2.11.2).

In February 2019, commit 9f08a5d896ce ("PCI/DPC: Fix print AER status in DPC event handling") amended the DPC driver to access the AER capability without checking for its presence.

This did not cause actual problems because in March 2018, commit 4e5fad429bd1 ("PCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS") had seemingly inadvertently prevented instantiation of a DPC port service on AER-incapable ports.

However in October 2019, commit 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control") made it possible to override this: The DPC driver may access a non-existent AER capability if "pcie_ports=dpc-native" is passed on the command line.

Fix it by making the DPC driver cope with AER-unsupporting Downstream Ports.

There are two places where the AER capability is accessed:

- dpc_get_aer_uncorrect_severity() uses it to discern whether a Fatal or Non-Fatal Error triggered DPC. Access the Device Status Register instead, in accordance with PCIe r7.1 sec 6.2.5.

- dpc_is_surprise_removal() uses it to detect whether a Surprise Down Error triggered DPC. Return false on AER-unsupporting devices. The function works around an AMD-specific quirk and it seems reasonable to assume that all affected products are AER-supporting. In any case the detection is not possible without AER capability.

Insert a temporary check for an AER capability after the call to aer_get_device_error_info() because the function currently returns false for AER-unsupporting devices. The check will become obsolete and will be removed with the imminent baseline capability error reporting.

Quoted 4 lines
Fixes 35a0b2378c19 ("PCI/DPC: Add "pcie_ports=dpc-native" to allow DPC without AER control")

---

Looks good to me.

Quoted 81 lines

Changes v1 -> v2:
* On AER-capable devices, infer severity from AER Extended Capability instead of Device Status register because the latter also logs masked errors (Sathya).
* Fix storytelling in commit message because 4e5fad429bd1 changed

    behavior, not 708b20003624 (Sathya).
 drivers/pci/pcie/dpc.c | 45 ++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/pci/pcie/dpc.c +32 -13
index 2b779bd1d861..d02cbbbe3143 100644
@@ -238,19 +238,35 @@ static int dpc_get_aer_uncorrect_severity(struct pci_dev *dev,
 {
 	int pos = dev->aer_cap;
 	u32 status, mask, sev;
+	u16 devsta;
 
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
-	status &= ~mask;
-	if (!status)
-		return 0;
-
-	pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &sev);
-	status &= sev;
-	if (status)
-		info->severity = AER_FATAL;
-	else
-		info->severity = AER_NONFATAL;
+	/*
+	 * Infer severity from AER Extended Capability if present, else from
+	 * Device Status register.  The latter cannot be used on AER-capable
+	 * ports because it also logs masked errors (PCIe r7.1 sec 7.5.3.5).
+	 */
+	if (pos) {
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
+		status &= ~mask;
+		if (!status)
+			return 0;
+
+		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &sev);
+		status &= sev;
+		if (status)
+			info->severity = AER_FATAL;
+		else
+			info->severity = AER_NONFATAL;
+	} else {
+		pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &devsta);
+		if (devsta & PCI_EXP_DEVSTA_FED)
+			info->severity = AER_FATAL;
+		else if (devsta & PCI_EXP_DEVSTA_NFED)
+			info->severity = AER_NONFATAL;
+		else
+			return 0;
+	}
 
 	info->level = KERN_ERR;
 
@@ -275,7 +291,7 @@ void dpc_process_error(struct pci_dev *pdev)
 		pci_warn(pdev, "containment event, status:%#06x: unmasked uncorrectable error detected\n",
 			 status);
 		if (dpc_get_aer_uncorrect_severity(pdev, &info) &&
-		    aer_get_device_error_info(&info, 0)) {
+		    (aer_get_device_error_info(&info, 0) || !pdev->aer_cap)) {
 			aer_print_error(&info, 0);
 			pci_aer_clear_nonfatal_status(pdev);
 			pci_aer_clear_fatal_status(pdev);
@@ -353,6 +369,9 @@ static bool dpc_is_surprise_removal(struct pci_dev *pdev)
 	if (!pdev->is_hotplug_bridge)
 		return false;
 
+	if (!pdev->aer_cap)
+		return false;
+
 	if (pci_read_config_word(pdev, pdev->aer_cap + PCI_ERR_UNCOR_STATUS,
 				 &status))
 		return false;
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Reviewed-by on v2 3/7
#8 lore raw

Re: [PATCH v2 3/7] PCI/ERR: Clear error status bits more selectively

In reply to Lukas Wunner
Quoted 8 lines · Lukas Wunner

After recovery from a PCIe error, all of the error status bits in the Device Status register are cleared indiscriminately, regardless of the error's severity.

So when a Correctable Error occurs simultaneously to an Uncorrectable Error, after the former is handled, it is cleared alongside the latter. As a result, the Uncorrectable Error isn't handled at all.

Quoted 8 lines

Conversely, an Uncorrectable Error occurring shortly before a Correctable Error may cause the latter to be cleared and thus ignored.

Avoid by clearing only the error bits corresponding to the error severity being handled.

---

Quoted 77 lines

Changes v1 -> v2:
* New patch to clear error status bits more selectively (sashiko).

 drivers/pci/pcie/aer.c | 20 +++++++++++++++++++-
 drivers/pci/pcie/err.c |  7 ++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
drivers/pci/pcie/aer.c +19 -1
index 6f2460231422..51cf2ff8c85a 100644
@@ -141,6 +141,12 @@ struct aer_info {
 					PCI_ERR_ROOT_MULTI_COR_RCV |	\
 					PCI_ERR_ROOT_MULTI_UNCOR_RCV)
 
+static const u8 severity2devsta[] = {
+	[AER_NONFATAL]    = PCI_EXP_DEVSTA_NFED,
+	[AER_FATAL]       = PCI_EXP_DEVSTA_FED,
+	[AER_CORRECTABLE] = PCI_EXP_DEVSTA_CED,
+};
+
 static bool pcie_aer_disable;
 static pci_ers_result_t aer_root_reset(struct pci_dev *dev);
 
@@ -1314,6 +1320,17 @@ bool is_aer_internal_error(struct aer_err_info *info)
 }
 #endif
 
+static void pcie_clear_device_status_sev(struct pci_dev *dev, u8 severity,
+					 u32 uncor_status)
+{
+	u16 devsta = severity2devsta[severity];
+
+	if (uncor_status & PCI_ERR_UNC_UNSUP)
+		devsta |= PCI_EXP_DEVSTA_URD;
+
+	pcie_capability_write_word(dev, PCI_EXP_DEVSTA, devsta);
+}
+
 /**
  * pci_aer_handle_error - handle logging error into an event log
  * @dev: pointer to pci_dev data structure of error source device
@@ -1344,7 +1361,8 @@ static void pci_aer_handle_error(struct pci_dev *dev, struct aer_err_info *info)
 			if (pdrv && pdrv->err_handler &&
 			    pdrv->err_handler->cor_error_detected)
 				pdrv->err_handler->cor_error_detected(dev);
-			pcie_clear_device_status(dev);
+			pcie_clear_device_status_sev(dev, AER_CORRECTABLE,
+						     info->anfe_status);
 		}
 	} else if (info->severity == AER_NONFATAL)
 		pcie_do_recovery(dev, pci_channel_io_normal, aer_root_reset);
drivers/pci/pcie/err.c +6 -1
index 1a7fc71c79d8..24a8a8263c2e 100644
@@ -21,6 +21,10 @@
 #include "portdrv.h"
 #include "../pci.h"
 
+#define PCI_EXP_DEVSTA_UNC_MASK	(PCI_EXP_DEVSTA_NFED | \
+				 PCI_EXP_DEVSTA_FED | \
+				 PCI_EXP_DEVSTA_URD)
+
 static pci_ers_result_t merge_result(enum pci_ers_result orig,
 				  enum pci_ers_result new)
 {
@@ -274,7 +278,8 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	 * signaling device may not even be visible to the OS.
 	 */
 	if (host->native_aer) {
-		pcie_clear_device_status(dev);
+		pcie_capability_write_word(dev, PCI_EXP_DEVSTA,
+					   PCI_EXP_DEVSTA_UNC_MASK);
 		pci_aer_clear_nonfatal_status(dev);
 	}
 
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Reviewed-by on v2 4/7
#11 lore raw

Re: [PATCH v2 4/7] PCI/ERR: Avoid stale error status bits on recovery failure

In reply to Lukas Wunner
Quoted 17 lines · Lukas Wunner

From: Yury Murashka <[email protected]>

pcie_do_recovery() only clears the error status bits of an error-reporting device if recovery succeeds, but not if it fails. (E.g. because reset failed, drivers are missing pci_error_handlers or those handlers failed.)

One undesirable consequence is that the AER driver may subsequently identify a wrong device when searching for error-reporting devices in is_error_source(), due to stale bits on an unaffected device.

Avoid by clearing error status bits on recovery failure.

If recovery succeeds, Fatal Errors are generally cleared by a call to pci_restore_state() from drivers' ->slot_reset() callbacks. If recovery fails, those callbacks may not have been invoked or they may not be implemented. Hence clear Fatal Errors as well on recovery failure.

Quoted 5 lines

---

Quoted 24 lines

Changes v1 -> v2:
* Clear Fatal Errors as well on recovery failure (Sathya, sashiko).

 drivers/pci/pcie/err.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/pci/pcie/err.c +7 -0
index 24a8a8263c2e..a450146fb285 100644
@@ -289,6 +289,13 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	return status;
 
 failed:
+	if (host->native_aer) {
+		pcie_capability_write_word(dev, PCI_EXP_DEVSTA,
+					   PCI_EXP_DEVSTA_UNC_MASK);
+		pci_aer_clear_nonfatal_status(dev);
+		pci_aer_clear_fatal_status(dev);
+	}
+
 	pci_walk_bridge(bridge, pci_pm_runtime_put, NULL);
 
 	pci_walk_bridge(bridge, report_perm_failure_detected, NULL);
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
#18 lore raw

Re: [PATCH v2 7/7] PCI/AER: Enable baseline capability error reporting

In reply to [email protected]
Quoted 18 lines · On Wed, Nov 18, 2026 at 11:19:03AM +0000, [email protected] wrote:

Does allocating dev->aer_info for all PCIe devices cause aer_stats_attrs_are_visible() to expose the aer_rootport_total_err_* sysfs attributes on Root Ports and RCECs that lack an AER Extended Capability?

drivers/pci/pcie/aer.c:aer_stats_attrs_are_visible() {
	...
	if (!pdev->aer_info)
		return 0;

	if ((a == &dev_attr_aer_rootport_total_err_cor.attr ||
	     a == &dev_attr_aer_rootport_total_err_fatal.attr ||
	     a == &dev_attr_aer_rootport_total_err_nonfatal.attr) &&
	    ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
	     (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_EC)))
		return 0;
	...
}
Quoted 4 lines

Those counters are only updated from PCI_ERR_ROOT_STATUS in the AER capability and Documentation/ABI/testing/sysfs-bus-pci-devices-aer states that they only appear under AER-capable Root Ports or RCECs, so aer_stats_attrs_are_visible() should also require pdev->aer_cap for them.

A valid point.

Quoted 16 lines

Review static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info) · line 1213

Quoted 11 lines
(quoted diff) +5 -2
@@ -1204,8 +1206,11 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
 	if (!(reg16 & PCI_EXP_AER_FLAGS))
 		return false;
 
-	if (!aer)
-		return false;
+	if (!aer) {
+		pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &reg16);
+		return reg16 & severity2devsta[e_info->severity] &&
+		       !PCI_POSSIBLE_ERROR(reg16);
+	}

Does checking PCI_EXP_AER_FLAGS in dev's own PCI_EXP_DEVCTL prevent is_error_source() and clear_status_iter() from working on SR-IOV Virtual Functions?

Quoted 8 lines

Per PCIe r7.1 sec 7.5.3.4 and sec 9.5.1.2, the PCI_EXP_AER_FLAGS bits in PCI_EXP_DEVCTL are RsvdP and hardwired to 0b on VFs, which inherit the associated Physical Function's PCI_EXP_DEVCTL settings while implementing per-VF status bits in PCI_EXP_DEVSTA. Reading PCI_EXP_DEVCTL on a VF therefore always sees 0 for PCI_EXP_AER_FLAGS, so is_error_source() never checks PCI_EXP_DEVSTA on VFs and clear_status_iter() never clears it; meanwhile pci_enable_pcie_error_reporting() writes 1s to those RsvdP bits on VFs.

Hallucination. Section 7.5.3.4 does not say anything about error bits being "RsvdP and hardwired to 0b on VFs". There is no section 9.5.1.2 in PCIe r7.1.

Quoted 17 lines

Review static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)

Quoted 12 lines
(quoted diff) +9 -2
 	/* The device might not support AER */
-	if (!aer)
-		return 0;
+	if (!aer) {
+		if (info->severity != AER_CORRECTABLE) {
+			pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &devsta);
+			if (devsta & PCI_EXP_DEVSTA_URD &&
+			    !PCI_POSSIBLE_ERROR(devsta))
+				info->status = PCI_ERR_UNC_UNSUP;
+		}
+		return 1;
+	}

[Severity: Medium]
Should the !aer branch check info->severity == AER_NONFATAL instead of info->severity != AER_CORRECTABLE?

Quoted 2 lines

Without an AER capability, error severities are fixed to their defaults where Unsupported Request is always Non-Fatal (PCIe r7.1 sec 6.2.7),

Indeed checking against AER_NONFATAL makes more sense here, although this is nowhere near as critical an issue as sashiko thinks:

Quoted 2 lines

yet PCI_EXP_DEVSTA_URD is also set by prior Advisory Non-Fatal or Non-Fatal Unsupported Requests (sec 6.2.5 and 7.5.3.5).

Advisory Non-Fatal Errors are not signaled on AER-incapable devices (as stated in the commit message).

Quoted 5 lines

When an AER_FATAL error occurs
on an AER-incapable device, reading PCI_EXP_DEVSTA accesses config space on an Endpoint or Upstream Port whose link may be down, and any set PCI_EXP_DEVSTA_URD bit causes aer_print_error() to misreport the fatal error as UnsupReq

No, the "!PCI_POSSIBLE_ERROR(devsta)" prevents that.

Below is a fixup patch for the two valid sashiko findings:

-- >8 --

drivers/pci/pcie/aer.c +11 -7
index 3c28afca5d03..83682bc7764e 100644
@@ -680,12 +680,16 @@ static umode_t aer_stats_attrs_are_visible(struct kobject *kobj,
 	if (!pdev->aer_info)
 		return 0;
 
-	if ((a == &dev_attr_aer_rootport_total_err_cor.attr ||
-	     a == &dev_attr_aer_rootport_total_err_fatal.attr ||
-	     a == &dev_attr_aer_rootport_total_err_nonfatal.attr) &&
-	    ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
-	     (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_EC)))
-		return 0;
+	if (a == &dev_attr_aer_rootport_total_err_cor.attr ||
+	    a == &dev_attr_aer_rootport_total_err_fatal.attr ||
+	    a == &dev_attr_aer_rootport_total_err_nonfatal.attr) {
+		if ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
+		    (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_EC))
+			return 0;
+
+		if (!pdev->aer_cap)
+			return 0;
+	}
 
 	return a->mode;
 }
@@ -1545,7 +1549,7 @@ int aer_get_device_error_info(struct aer_err_info *info, int i)
 
 	/* The device might not support AER */
 	if (!aer) {
-		if (info->severity != AER_CORRECTABLE) {
+		if (info->severity == AER_NONFATAL) {
 			pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &devsta);
 			if (devsta & PCI_EXP_DEVSTA_URD &&
 			    !PCI_POSSIBLE_ERROR(devsta))
Tested-by on the v2 series
#19 lore raw
In reply to Lukas Wunner

Tested the full v2 series on v7.4-rc3 (plus out-of-tree T2 patches) on four x86 machines: two MacBookPro16,1 (Apple T2), an ASUS ROG Zephyrus M15 GU502LV, and an HP desktop with an Intel 800-series chipset.

Before/after with the same base kernel built with and without the
series: the number of devices that have no AER capability but have all four Device Control error-enable bits (CorrErr, NonFatalErr, FatalErr, UnsupReq) set went from 0 of 6 to 5 of 6 (MacBookPro16,1), 0 of 3 to 2 of 3 (ASUS, which needs pcie_ports=native because its firmware answers "platform does not support [AER]" in _OSC), and 0 of 4 to 2 of 4 (HP). AER-capable devices were already fully enabled. I did not look into why the remaining devices (for example the integrated GPU on the ASUS) stay off.

Thunderbolt 4 dock unplug/replug on both MacBooks: no AER or DPC events and the link came back normally. 10 suspend/resume cycles on each of the two MacBooks and the ASUS, plus one 25-minute suspend: no AER or DPC messages and no device loss.

I did not test error injection, so the error-handling paths in patches 3 and 4 were not exercised.

#20 lore raw
In reply to Lukas Wunner
Quoted 66 lines · Lukas Wunner

Bjorn suggests "the PCI core should do pci_enable_pcie_error_reporting() independent of whether the device has an AER Capability":

https://lore.kernel.org/r/20260826212619.GA1566339@bhelgaas/

This is done in patch [7/7]. The preceding patches contain prep work.

For context, PCIe r7.1 sec 6.2.1 defines two error reporting paradigms:
AER and baseline capability. The latter relies (solely) on the error enable/status bits in the Device Control and Device Status registers, which exist on every PCIe device. The kernel has supported the AER paradigm for 20 years. With the present series, it gains support for the baseline capability paradigm.

Patches [1/7] and [2/7] reinstate DPC on AER-incapable Downstream Ports. The kernel used to support this until 2018. It is hereby fixed because it eases introduction of baseline capability error reporting in the subsequent patches.

Changes v1 -> v2:

* Patch [1/7]:
* On AER-capable devices, infer severity from AER Extended Capability instead of Device Status register because the latter also logs masked errors (Sathya).
* Fix storytelling in commit message because 4e5fad429bd1 changed

    behavior, not 708b20003624 (Sathya).

* Patch [3/7]:
* New patch to clear error status bits more selectively (sashiko).

* Patch [4/7]:
* Clear Fatal Errors as well on recovery failure (Sathya, sashiko).

* Patch [6/7]:
* Amend kernel-doc of pci_aer_unmask_internal_errors() (Sathya).

* Patch [7/7]:
* Convert AER severity to Device Status bit with new severity2devsta[] array, instead of renumbering AER severity (sashiko).
* On entry of aer_get_device_error_info(), clear info->mask and

    info->first_error (Sathya, sashiko).

* Emit "(no details available)" message for AER-incapable devices as well as for devices whose AER registers are deliberately not read on Fatal Errors (Sathya).
* Amend commit message to inform that System Errors may be raised by AER-incapable devices if they have no AER- or DPC-capable port in their ancestry (Sathya).

Link to v1:

https://lore.kernel.org/r/[email protected]/

Lukas Wunner (6):
PCI/DPC: Avoid access to non-existent AER capability PCI/DPC: Reinstate support for AER-incapable ports PCI/ERR: Clear error status bits more selectively PCI/AER: Drop AER native check from handles_cxl_errors() PCI/AER: Move AER capability check out of pcie_aer_is_native() PCI/AER: Enable baseline capability error reporting

Yury Murashka (1):
PCI/ERR: Avoid stale error status bits on recovery failure

Quoted 7 lines
 .../ABI/testing/sysfs-bus-pci-devices-aer     | 26 +++++--
 Documentation/PCI/pcieaer-howto.rst           |  9 +--
 drivers/pci/pcie/aer.c                        | 76 +++++++++++++------
 drivers/pci/pcie/aer_cxl_rch.c                |  3 +-
 drivers/pci/pcie/dpc.c                        | 46 +++++++----
 drivers/pci/pcie/err.c                        | 14 +++-
 6 files changed, 120 insertions(+), 54 deletions(-)

Applied to pci/aer for v7.5, thanks!