[PATCH v3 1/2] PCI/AER: Reject negative ratelimit interval and burst values

From: Yazen Ghannam

Date: Tue Nov 24 2026 - 22:29:25 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.

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" in place on
pci/aer. Patch 2/2 (docs) goes on top of the pci/aer tip.

v2->v3:
- Split the documentation into its own patch. (Bjorn)

v1->v2:
- Return -EINVAL for negative interval and burst values instead of
clamping. (Bjorn)

This no longer touches the ABI file, so "PCI/AER: Enable baseline
capability error reporting" applies on top as Lukas posted it, without
the "or any negative value" merge fixup in its two interval
descriptions. The rest of pci/aer applies unchanged.

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,
split and rebase the patches, resolve the conflict and write the QEMU
test.

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

drivers/pci/pcie/aer.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

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