On 11/18/26 02:40, Lukas Wunner wrote:
> 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.
> 
> Signed-off-by: Lukas Wunner <[email protected]>
> ---

Reviewed-by: Kuppuswamy Sathyanarayanan 
<[email protected]>


> 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(-)
> 
> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index 6f2460231422..51cf2ff8c85a 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -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);
> diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
> index 1a7fc71c79d8..24a8a8263c2e 100644
> --- a/drivers/pci/pcie/err.c
> +++ b/drivers/pci/pcie/err.c
> @@ -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);
>       }
>  

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer


Reply via email to