Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <karolina.stolarek@oracle.com>
Signed-off-by: Jon Pan-Doh <pandoh@google.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Link: https://patch.msgid.link/20250522232339.1525671-21-helgaas@kernel.org

authored by

Jon Pan-Doh and committed by
Bjorn Helgaas
b4fe7398 24816cc2

+155 -1
+44
Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats Documentation/ABI/testing/sysfs-bus-pci-devices-aer
··· 117 117 KernelVersion: 4.19.0 118 118 Contact: linux-pci@vger.kernel.org, rajatja@google.com 119 119 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 + Contact: linux-pci@vger.kernel.org 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 + Contact: linux-pci@vger.kernel.org 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 + Contact: linux-pci@vger.kernel.org 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 + Contact: linux-pci@vger.kernel.org 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).
+4 -1
Documentation/PCI/pcieaer-howto.rst
··· 97 97 AER uses the default ratelimit of DEFAULT_RATELIMIT_BURST (10 events) over 98 98 DEFAULT_RATELIMIT_INTERVAL (5 seconds). 99 99 100 + Ratelimits are exposed in the form of sysfs attributes and configurable. 101 + See Documentation/ABI/testing/sysfs-bus-pci-devices-aer. 102 + 100 103 AER Statistics / Counters 101 104 ------------------------- 102 105 103 106 When PCIe AER errors are captured, the counters / statistics are also exposed 104 107 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. 106 109 107 110 Developer Guide 108 111 ===============
+1
drivers/pci/pci-sysfs.c
··· 1805 1805 &pcie_dev_attr_group, 1806 1806 #ifdef CONFIG_PCIEAER 1807 1807 &aer_stats_attr_group, 1808 + &aer_attr_group, 1808 1809 #endif 1809 1810 #ifdef CONFIG_PCIEASPM 1810 1811 &aspm_ctrl_attr_group,
+1
drivers/pci/pci.h
··· 965 965 void pci_aer_init(struct pci_dev *dev); 966 966 void pci_aer_exit(struct pci_dev *dev); 967 967 extern const struct attribute_group aer_stats_attr_group; 968 + extern const struct attribute_group aer_attr_group; 968 969 void pci_aer_clear_fatal_status(struct pci_dev *dev); 969 970 int pci_aer_clear_status(struct pci_dev *dev); 970 971 int pci_aer_raw_clear_status(struct pci_dev *dev);
+105
drivers/pci/pcie/aer.c
··· 627 627 .is_visible = aer_stats_attrs_are_visible, 628 628 }; 629 629 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 + 630 735 static void pci_dev_aer_stats_incr(struct pci_dev *pdev, 631 736 struct aer_err_info *info) 632 737 {