[PATCH v2 2/4] PCI/AER: Reject negative ratelimit interval and burst values

From: Yazen Ghannam

Date: Mon Nov 23 2026 - 09:59:07 EST


The AER "*_ratelimit_interval_ms" and "*_ratelimit_burst" sysfs
attributes accept negative values. A negative interval is treated as
0, which disables ratelimiting. A negative burst is stored as is, and
___ratelimit() then warns about an uninitialized ratelimit_state.

However, a negative value has no meaningful interpretation for either
attribute.

Return -EINVAL for negative input.

Also, document 'burst=0' 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>
---
Replaces "PCI/AER: Clamp negative ratelimit burst to zero" on pci/aer.

v1->v2:
- Return -EINVAL for negative interval and burst values instead of
clamping. (Bjorn)
- Keep the original interval descriptions.
- Describe what a burst of 0 does.

The rest of pci/aer applies on top. The only conflict is in "PCI/AER:
Enable baseline capability error reporting", in the two interval
descriptions. The resolution keeps Lukas's capitalization without
"or any negative value":

Writing 0 disables Correctable Error log ratelimiting.
Writing 0 disables Non-Fatal Uncorrectable Error log ratelimiting.

Tested in a QEMU guest with injected correctable and non-fatal errors,
for every combination of interval {-1, 0, positive} and burst {-1, 0,
positive}. Negative writes fail with -EINVAL. Every error is counted
and traced. Interval 0 logs every error, whatever the burst. A positive
interval with burst 0 logs none.

An LLM coding assistant helped check the ___ratelimit() semantics,
draft the change, resolve the conflict and write the QEMU test.

v1: https://lore.kernel.org/r/20261110215614.3931232-3-yazen.ghannam@xxxxxxx

.../ABI/testing/sysfs-bus-pci-devices-aer | 9 +++++++++
drivers/pci/pcie/aer.c | 14 +++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
index 5ed284523956..e4c39839cc6a 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
+++ b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer
@@ -143,6 +143,10 @@ 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 suppresses all correctable error log messages.
+
+ Burst value is only used when interval is greater than zero.
+
What: /sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_interval_ms
Date: May 2025
KernelVersion: 6.16.0
@@ -161,3 +165,8 @@ 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 suppresses all non-fatal uncorrectable error log
+ messages.
+
+ Burst value is only used when interval is greater than zero.
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 6f2460231422..2c42d6e8bd9a 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -690,7 +690,8 @@ const struct attribute_group aer_stats_attr_group = {

/*
* Ratelimit interval
- * <=0: disabled with ratelimit.interval = 0
+ * <0: rejected
+ * 0: disabled with ratelimit.interval = 0
* >0: enabled with ratelimit.interval in ms
*/
#define aer_ratelimit_interval_attr(name, ratelimit) \
@@ -717,10 +718,10 @@ const struct attribute_group aer_stats_attr_group = {
if (kstrtoint(buf, 0, &interval) < 0) \
return -EINVAL; \
\
- if (interval <= 0) \
- interval = 0; \
- else \
- interval = msecs_to_jiffies(interval); \
+ if (interval < 0) \
+ return -EINVAL; \
+ \
+ interval = msecs_to_jiffies(interval); \
\
pdev->aer_info->ratelimit.interval = interval; \
\
@@ -752,6 +753,9 @@ const struct attribute_group aer_stats_attr_group = {
if (kstrtoint(buf, 0, &burst) < 0) \
return -EINVAL; \
\
+ if (burst < 0) \
+ return -EINVAL; \
+ \
pdev->aer_info->ratelimit.burst = burst; \
\
return count; \
--
2.55.0