[PATCH v6 24/24] PCI/sysfs: Limit BAR resize attribute scope to platforms with PCI mmap
Krzysztof Wilczyński
kwilczynski at kernel.org
Thu Apr 23 02:14:07 AEST 2026
The resourceN_resize sysfs attributes allow users to resize
Resizable BARs (ReBAR). After a successful resize, the resource
attribute groups are removed and recreated so that the updated
BAR sizes are reflected in the sysfs files.
Resizable BARs are a PCI Express extended capability
(PCI_EXT_CAP_ID_REBAR), which requires PCIe extended config
space.
Every PCIe-capable architecture defines either HAVE_PCI_MMAP or
ARCH_GENERIC_PCI_MMAP_RESOURCE (via the relevant arch headers
or the generic asm-generic/pci.h fallback). On platforms that
define neither, the resource files are not created and the sysfs
group remove and create calls in __resource_resize_store() are
no-ops.
Thus, move the resize show and store helpers, the per-BAR attribute
definitions, and the attribute group behind the existing #ifdef
HAVE_PCI_MMAP || ARCH_GENERIC_PCI_MMAP_RESOURCE guard, and fold
the group reference in pci_dev_groups[] into the existing #if block.
Signed-off-by: Krzysztof Wilczyński <kwilczynski at kernel.org>
---
drivers/pci/pci-sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index b167e32d55ac..37c1990124d0 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1690,6 +1690,7 @@ static const struct attribute_group pci_dev_reset_method_attr_group = {
.is_visible = pci_dev_reset_attr_is_visible,
};
+#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
static ssize_t __resource_resize_show(struct device *dev, int n, char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
@@ -1804,6 +1805,7 @@ static const struct attribute_group pci_dev_resource_resize_attr_group = {
.attrs = resource_resize_attrs,
.is_visible = resource_resize_attr_is_visible,
};
+#endif
static struct attribute *pci_dev_dev_attrs[] = {
&dev_attr_boot_vga.attr,
@@ -1878,8 +1880,8 @@ const struct attribute_group *pci_dev_groups[] = {
&pci_dev_resource_io_attr_group,
&pci_dev_resource_uc_attr_group,
&pci_dev_resource_wc_attr_group,
-#endif
&pci_dev_resource_resize_attr_group,
+#endif
&pci_dev_config_attr_group,
&pci_dev_rom_attr_group,
&pci_dev_reset_attr_group,
--
2.54.0
More information about the Linuxppc-dev
mailing list