Re: [PATCH v8 18/20] PCI/AER: Ratelimit correctable and non-fatal error logging

Bjorn Helgaas
2025-05-23T16:07:00Z

On Thu, May 22, 2025 at 04:56:56PM -0700, Sathyanarayanan Kuppuswamy wrote:
> On 5/22/25 4:21 PM, Bjorn Helgaas wrote:
> > From: Jon Pan-Doh <pandoh@google.com>
> >
> > Spammy devices can flood kernel logs with AER errors and slow/stall
> > execution. Add per-device ratelimits for AER correctable and non-fatal
> > uncorrectable errors that use the kernel defaults (10 per 5s). Logging of
> > fatal errors is not ratelimited.

> > +static int aer_ratelimit(struct pci_dev *dev, unsigned int severity)
> > +{
> > + struct ratelimit_state *ratelimit;
> > +
> > + if (severity == AER_FATAL)
> > + return 1; /* AER_FATAL not ratelimited */
> > +
> > + if (severity == AER_CORRECTABLE)
> > + ratelimit = &dev->aer_info->correctable_ratelimit;
> > + else
> > + ratelimit = &dev->aer_info->nonfatal_ratelimit;
> > +
> > + return __ratelimit(ratelimit);
> > +}
> > +
>
> Why not combine severity checks? May be something like below:
>
>     switch (severity) {
>     case AER_NONFATAL:
>         return __ratelimit(&dev->aer_info->nonfatal_ratelimit);
>     case AER_CORRECTABLE:
>         return __ratelimit(&dev->aer_info->correctable_ratelimit);
>     default:
>         return 1; /* Don't rate-limit fatal errors */
>     }

Beautiful, adopted, thank you!