Skip to contentSkip to conversation

PCI: decline to resize resources if boot config must be preserved

PATCH In review Ard Biesheuvel 2 participants 3 messages Jan 9, 2021 – Jan 13, 2021 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: decline to resize resources if boot config must be preserved

The _DSM #5 method in the ACPI host bridge object tells us whether the OS is permitted to deviate from the resource assignment configured by the firmware. If this is not the case, we should not permit drivers to resize BARs on the fly. So make pci_resize_resource() take this into account.

---
 drivers/pci/setup-res.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/setup-res.c +6 -0
index 43eda101fcf4..3b38be081e93 100644
@@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
 int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 {
 	struct resource *res = dev->resource + resno;
+	struct pci_host_bridge *host;
 	int old, ret;
 	u32 sizes;
 	u16 cmd;
 
+	/* Check if we must preserve the firmware's resource assignment */
+	host = pci_find_host_bridge(dev->bus);
+	if (host->preserve_config)
+		return -ENOTSUPP;
+
 	/* Make sure the resource isn't assigned before resizing it. */
 	if (!(res->flags & IORESOURCE_UNSET))
 		return -EBUSY;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 8 lines · Ard Biesheuvel

The _DSM #5 method in the ACPI host bridge object tells us whether the OS is permitted to deviate from the resource assignment configured by the firmware. If this is not the case, we should not permit drivers to resize BARs on the fly. So make pci_resize_resource() take this into account.

Capitalized subject to match convention and applied to pci/resource for v5.11, thanks!

Is there an email, bug report, etc that prompted this change?

Quoted 28 lines
---
 drivers/pci/setup-res.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/setup-res.c +6 -0
index 43eda101fcf4..3b38be081e93 100644
@@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
 int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 {
 	struct resource *res = dev->resource + resno;
+	struct pci_host_bridge *host;
 	int old, ret;
 	u32 sizes;
 	u16 cmd;
 
+	/* Check if we must preserve the firmware's resource assignment */
+	host = pci_find_host_bridge(dev->bus);
+	if (host->preserve_config)
+		return -ENOTSUPP;
+
 	/* Make sure the resource isn't assigned before resizing it. */
 	if (!(res->flags & IORESOURCE_UNSET))
 		return -EBUSY;
Signature · 1 line
2.17.1
#2 lore raw
Quoted 8 lines · Bjorn Helgaas
Quoted 6 lines · Ard Biesheuvel

The _DSM #5 method in the ACPI host bridge object tells us whether the OS is permitted to deviate from the resource assignment configured by the firmware. If this is not the case, we should not permit drivers to resize BARs on the fly. So make pci_resize_resource() take this into account.

Quoted 8 lines
Quoted 2 lines

Capitalized subject to match convention and applied to pci/resource for v5.11, thanks!

Is there an email, bug report, etc that prompted this change?

No, I was just reviewing the recent Tianocore changes to perform BAR resizing before resource assignment even takes places, which is obviously a more appropriate time to do it, as it does not require the OS to modify the firmware configuration at all. This reminded me of _DSM #5 and the fact that the OS may not even be permitted to make any changes.

Quoted 28 lines
Quoted 28 lines
---
 drivers/pci/setup-res.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/setup-res.c +6 -1
index 43eda101fcf4..3b38be081e93 100644
@@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
 int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 {
      struct resource *res = dev->resource + resno;
+     struct pci_host_bridge *host;
      int old, ret;
      u32 sizes;
      u16 cmd;
 
+     /* Check if we must preserve the firmware's resource assignment */
+     host = pci_find_host_bridge(dev->bus);
+     if (host->preserve_config)
+             return -ENOTSUPP;
+
      /* Make sure the resource isn't assigned before resizing it. */
      if (!(res->flags & IORESOURCE_UNSET))
              return -EBUSY;
--

2.17.1