Re: [PATCH 2/4] PCI/AER: Clamp negative ratelimit burst to zero

From: Bjorn Helgaas

Date: Fri Nov 20 2026 - 19:12:19 EST


On Fri, Nov 20, 2026 at 04:13:07PM -0500, Yazen Ghannam wrote:
> On Fri, Nov 20, 2026 at 12:10:43PM -0600, Bjorn Helgaas wrote:
> > On Tue, Nov 10, 2026 at 03:56:12PM -0600, Yazen Ghannam wrote:
> > > The correctable and nonfatal "_ratelimit_burst" attributes store
> > > whatever kstrtoint() parses, so a negative value lands directly in
> > > ratelimit_state.burst.
> > >
> > > ___ratelimit() reads a negative burst as an uninitialized
> > > ratelimit_state and gives a WARNing.
> > >
> > > Clamp negative values to zero and document the clamping behavior.
> > > ...
> >
> > > Fixes: b4fe7398def6 ("PCI/AER: Add sysfs attributes for log ratelimits")
> > > Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> > > Closes: https://lore.kernel.org/linux-pci/20260714191826.BA81E1F000E9@xxxxxxxxxxxxxxx/
> > > Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
> > > ---
> > > .../ABI/testing/sysfs-bus-pci-devices-aer | 21 ++++++++++++-------
> > > drivers/pci/pcie/aer.c | 3 +++
> > > 2 files changed, 17 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
> > > index 5ed284523956..215cf8bd4c30 100644
> > > --- a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
> > > +++ b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
> > > @@ -130,9 +130,10 @@ What: /sys/bus/pci/devices/<dev>/aer/correctable_ratelimit_interval_ms
> > > Date: May 2025
> > > KernelVersion: 6.16.0
> > > Contact: linux-pci@xxxxxxxxxxxxxxx
> > > -Description: Writing 0 disables AER correctable error log ratelimiting.
> > > - Writing a positive value sets the ratelimit interval in ms.
> > > - Default is DEFAULT_RATELIMIT_INTERVAL (5000 ms).
> > > +Description: Writing 0, or any negative value, disables AER correctable
> > > + error log ratelimiting. Writing a positive value sets the
> > > + ratelimit interval in ms. Default is
> > > + DEFAULT_RATELIMIT_INTERVAL (5000 ms).
> > >
> > > What: /sys/bus/pci/devices/<dev>/aer/correctable_ratelimit_burst
> > > Date: May 2025
> > > @@ -143,14 +144,17 @@ Description: Ratelimit burst for correctable error logs. Writing a value
> > > before ratelimiting. Reading gets the current ratelimit
> > > burst. Default is DEFAULT_RATELIMIT_BURST (10).
> > >
> > > + Writing 0, or any negative value, suppresses all logs
> > > + unless the interval attribute is also 0.
> > > +
> > > What: /sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_interval_ms
> > > Date: May 2025
> > > KernelVersion: 6.16.0
> > > Contact: linux-pci@xxxxxxxxxxxxxxx
> > > -Description: Writing 0 disables AER non-fatal uncorrectable error log
> > > - ratelimiting. Writing a positive value sets the ratelimit
> > > - interval in ms. Default is DEFAULT_RATELIMIT_INTERVAL
> > > - (5000 ms).
> > > +Description: Writing 0, or any negative value, disables AER non-fatal
> > > + uncorrectable error log ratelimiting. Writing a positive
> > > + value sets the ratelimit interval in ms. Default is
> > > + DEFAULT_RATELIMIT_INTERVAL (5000 ms).
> > >
> > > What: /sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_burst
> > > Date: May 2025
> > > @@ -161,3 +165,6 @@ Description: Ratelimit burst for non-fatal uncorrectable error logs.
> > > allowed per interval before ratelimiting. Reading gets the
> > > current ratelimit burst. Default is DEFAULT_RATELIMIT_BURST
> > > (10).
> > > +
> > > + Writing 0, or any negative value, suppresses all logs
> > > + unless the interval attribute is also 0.
> > > diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> > > index 6f2460231422..401cd3a1b3d0 100644
> > > --- a/drivers/pci/pcie/aer.c
> > > +++ b/drivers/pci/pcie/aer.c
> > > @@ -752,6 +752,9 @@ const struct attribute_group aer_stats_attr_group = {
> > > if (kstrtoint(buf, 0, &burst) < 0) \
> > > return -EINVAL; \
> > > \
> > > + if (burst < 0) \
> > > + burst = 0; \
> >
> > Why don't we just return -EINVAL if the user writes a negative value
> > to either *_ratelimit_interval_ms or *_ratelimit_burst?
> >
> > I don't think there's any reasonable interpretation of negative
> > values in either case.
>
> Right, that's fair. I think the reason to clamp was to be consistent
> with the current code.
>
> Would you like a follow up patch?
>
> > Any non-negative value for the interval makes sense (0 disables).
> >
> > Any positive value makes sense for burst; I don't know what a 0 burst
> > value could mean, so maybe that should be an error too?
>
> "burst == 0" came from here:
> 084a990ded63 ("ratelimit: Allow zero ->burst to disable ratelimiting")
>
> IIUC, the goal is to **always** hide/disable the messages. IOW, keep
> logging the errors internally based on the interval, but don't print any
> kernel messages for them. The user can still get the error logs from the
> trace event and leave the kernel buffer alone.

OK, so burst==0 should have the "usual" semantics (disable
ratelimiting IIUC).

Can we make a replacement for this patch?

- Return -EINVAL for negative values written to either
*_ratelimit_interval_ms or *_ratelimit_burst

- I think the existing *_ratelimit_interval_ms documentation would
be fine, no change required

- *_ratelimit_burst documentation needs something, but I don't know
what. 084a990ded63 ("ratelimit: Allow zero ->burst to disable
ratelimiting") suggests that burst==0 disables ratelimiting, but
you wrote "suppresses all logs", which sounds like the opposite of
disabling ratelimiting.

Also, I don't know what "unless the interval attribute is also 0"
means. What *does* happen when interval==0 and burst==0?

The pci/aer branch is mutable, so we can just replace the existing
patch.