Skip to content

Commit b4fe739

Browse files
Jon Pan-Dohbjorn-helgaas
authored andcommitted
PCI/AER: Add sysfs attributes for log ratelimits
Allow userspace to read/write log ratelimits per device (including enable/disable). Create aer/ sysfs directory to store them and any future AER configs. The new sysfs files are: /sys/bus/pci/devices/*/aer/correctable_ratelimit_burst /sys/bus/pci/devices/*/aer/correctable_ratelimit_interval_ms /sys/bus/pci/devices/*/aer/nonfatal_ratelimit_burst /sys/bus/pci/devices/*/aer/nonfatal_ratelimit_interval_ms The default values are ratelimit_burst=10, ratelimit_interval_ms=5000, so if we try to emit more than 10 messages in a 5 second period, some are suppressed. Update AER sysfs ABI filename to reflect the broader scope of AER sysfs attributes (e.g. stats and ratelimits). Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats -> sysfs-bus-pci-devices-aer Tested using aer-inject[1]. Configured correctable log ratelimit to 5. Sent 6 AER errors. Observed 5 errors logged while AER stats (cat /sys/bus/pci/devices/<dev>/aer_dev_correctable) shows 6. Disabled ratelimiting and sent 6 more AER errors. Observed all 6 errors logged and accounted in AER stats (12 total errors). [1] https://git.kernel.org/pub/scm/linux/kernel/git/gong.chen/aer-inject.git [bhelgaas: note fatal errors are not ratelimited, "aer_report" -> "aer_info", replace ratelimit_log_enable toggle with *_ratelimit_interval_ms] Signed-off-by: Karolina Stolarek <[email protected]> Signed-off-by: Jon Pan-Doh <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 24816cc commit b4fe739

File tree

5 files changed

+155
-1
lines changed

5 files changed

+155
-1
lines changed

Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats renamed to Documentation/ABI/testing/sysfs-bus-pci-devices-aer

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,47 @@ Date: July 2018
117117
KernelVersion: 4.19.0
118118
119119
Description: Total number of ERR_NONFATAL messages reported to rootport.
120+
121+
PCIe AER ratelimits
122+
-------------------
123+
124+
These attributes show up under all the devices that are AER capable.
125+
They represent configurable ratelimits of logs per error type.
126+
127+
See Documentation/PCI/pcieaer-howto.rst for more info on ratelimits.
128+
129+
What: /sys/bus/pci/devices/<dev>/aer/correctable_ratelimit_interval_ms
130+
Date: May 2025
131+
KernelVersion: 6.16.0
132+
133+
Description: Writing 0 disables AER correctable error log ratelimiting.
134+
Writing a positive value sets the ratelimit interval in ms.
135+
Default is DEFAULT_RATELIMIT_INTERVAL (5000 ms).
136+
137+
What: /sys/bus/pci/devices/<dev>/aer/correctable_ratelimit_burst
138+
Date: May 2025
139+
KernelVersion: 6.16.0
140+
141+
Description: Ratelimit burst for correctable error logs. Writing a value
142+
changes the number of errors (burst) allowed per interval
143+
before ratelimiting. Reading gets the current ratelimit
144+
burst. Default is DEFAULT_RATELIMIT_BURST (10).
145+
146+
What: /sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_interval_ms
147+
Date: May 2025
148+
KernelVersion: 6.16.0
149+
150+
Description: Writing 0 disables AER non-fatal uncorrectable error log
151+
ratelimiting. Writing a positive value sets the ratelimit
152+
interval in ms. Default is DEFAULT_RATELIMIT_INTERVAL
153+
(5000 ms).
154+
155+
What: /sys/bus/pci/devices/<dev>/aer/nonfatal_ratelimit_burst
156+
Date: May 2025
157+
KernelVersion: 6.16.0
158+
159+
Description: Ratelimit burst for non-fatal uncorrectable error logs.
160+
Writing a value changes the number of errors (burst)
161+
allowed per interval before ratelimiting. Reading gets the
162+
current ratelimit burst. Default is DEFAULT_RATELIMIT_BURST
163+
(10).

Documentation/PCI/pcieaer-howto.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ DPC errors, are not ratelimited.
9797
AER uses the default ratelimit of DEFAULT_RATELIMIT_BURST (10 events) over
9898
DEFAULT_RATELIMIT_INTERVAL (5 seconds).
9999

100+
Ratelimits are exposed in the form of sysfs attributes and configurable.
101+
See Documentation/ABI/testing/sysfs-bus-pci-devices-aer.
102+
100103
AER Statistics / Counters
101104
-------------------------
102105

103106
When PCIe AER errors are captured, the counters / statistics are also exposed
104107
in the form of sysfs attributes which are documented at
105-
Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats
108+
Documentation/ABI/testing/sysfs-bus-pci-devices-aer.
106109

107110
Developer Guide
108111
===============

drivers/pci/pci-sysfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ const struct attribute_group *pci_dev_attr_groups[] = {
18051805
&pcie_dev_attr_group,
18061806
#ifdef CONFIG_PCIEAER
18071807
&aer_stats_attr_group,
1808+
&aer_attr_group,
18081809
#endif
18091810
#ifdef CONFIG_PCIEASPM
18101811
&aspm_ctrl_attr_group,

drivers/pci/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ void pci_no_aer(void);
965965
void pci_aer_init(struct pci_dev *dev);
966966
void pci_aer_exit(struct pci_dev *dev);
967967
extern const struct attribute_group aer_stats_attr_group;
968+
extern const struct attribute_group aer_attr_group;
968969
void pci_aer_clear_fatal_status(struct pci_dev *dev);
969970
int pci_aer_clear_status(struct pci_dev *dev);
970971
int pci_aer_raw_clear_status(struct pci_dev *dev);

drivers/pci/pcie/aer.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,111 @@ const struct attribute_group aer_stats_attr_group = {
627627
.is_visible = aer_stats_attrs_are_visible,
628628
};
629629

630+
/*
631+
* Ratelimit interval
632+
* <=0: disabled with ratelimit.interval = 0
633+
* >0: enabled with ratelimit.interval in ms
634+
*/
635+
#define aer_ratelimit_interval_attr(name, ratelimit) \
636+
static ssize_t \
637+
name##_show(struct device *dev, struct device_attribute *attr, \
638+
char *buf) \
639+
{ \
640+
struct pci_dev *pdev = to_pci_dev(dev); \
641+
\
642+
return sysfs_emit(buf, "%d\n", \
643+
pdev->aer_info->ratelimit.interval); \
644+
} \
645+
\
646+
static ssize_t \
647+
name##_store(struct device *dev, struct device_attribute *attr, \
648+
const char *buf, size_t count) \
649+
{ \
650+
struct pci_dev *pdev = to_pci_dev(dev); \
651+
int interval; \
652+
\
653+
if (!capable(CAP_SYS_ADMIN)) \
654+
return -EPERM; \
655+
\
656+
if (kstrtoint(buf, 0, &interval) < 0) \
657+
return -EINVAL; \
658+
\
659+
if (interval <= 0) \
660+
interval = 0; \
661+
else \
662+
interval = msecs_to_jiffies(interval); \
663+
\
664+
pdev->aer_info->ratelimit.interval = interval; \
665+
\
666+
return count; \
667+
} \
668+
static DEVICE_ATTR_RW(name);
669+
670+
#define aer_ratelimit_burst_attr(name, ratelimit) \
671+
static ssize_t \
672+
name##_show(struct device *dev, struct device_attribute *attr, \
673+
char *buf) \
674+
{ \
675+
struct pci_dev *pdev = to_pci_dev(dev); \
676+
\
677+
return sysfs_emit(buf, "%d\n", \
678+
pdev->aer_info->ratelimit.burst); \
679+
} \
680+
\
681+
static ssize_t \
682+
name##_store(struct device *dev, struct device_attribute *attr, \
683+
const char *buf, size_t count) \
684+
{ \
685+
struct pci_dev *pdev = to_pci_dev(dev); \
686+
int burst; \
687+
\
688+
if (!capable(CAP_SYS_ADMIN)) \
689+
return -EPERM; \
690+
\
691+
if (kstrtoint(buf, 0, &burst) < 0) \
692+
return -EINVAL; \
693+
\
694+
pdev->aer_info->ratelimit.burst = burst; \
695+
\
696+
return count; \
697+
} \
698+
static DEVICE_ATTR_RW(name);
699+
700+
#define aer_ratelimit_attrs(name) \
701+
aer_ratelimit_interval_attr(name##_ratelimit_interval_ms, \
702+
name##_ratelimit) \
703+
aer_ratelimit_burst_attr(name##_ratelimit_burst, \
704+
name##_ratelimit)
705+
706+
aer_ratelimit_attrs(correctable)
707+
aer_ratelimit_attrs(nonfatal)
708+
709+
static struct attribute *aer_attrs[] = {
710+
&dev_attr_correctable_ratelimit_interval_ms.attr,
711+
&dev_attr_correctable_ratelimit_burst.attr,
712+
&dev_attr_nonfatal_ratelimit_interval_ms.attr,
713+
&dev_attr_nonfatal_ratelimit_burst.attr,
714+
NULL
715+
};
716+
717+
static umode_t aer_attrs_are_visible(struct kobject *kobj,
718+
struct attribute *a, int n)
719+
{
720+
struct device *dev = kobj_to_dev(kobj);
721+
struct pci_dev *pdev = to_pci_dev(dev);
722+
723+
if (!pdev->aer_info)
724+
return 0;
725+
726+
return a->mode;
727+
}
728+
729+
const struct attribute_group aer_attr_group = {
730+
.name = "aer",
731+
.attrs = aer_attrs,
732+
.is_visible = aer_attrs_are_visible,
733+
};
734+
630735
static void pci_dev_aer_stats_incr(struct pci_dev *pdev,
631736
struct aer_err_info *info)
632737
{

0 commit comments

Comments
 (0)