Skip to contentSkip to conversation

xen/vpci: automatically use iomem_permit_access for PCI device BARs

PATCH In review Ariadne Conill 2 participants 2 messages Feb 24 – Feb 25

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/vpci: automatically use iomem_permit_access for PCI device BARs

From: Steven Noonan <[email protected]>

With vPCI, you shouldn't need to use xen-pciback for the device, so the memory access permissions need to be defined somewhere. This allows vPCI to automatically define the access permissions so that the domU can map the BARs via IOMMU.

---
 xen/drivers/vpci/header.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
xen/drivers/vpci/header.c +24 -0
index 1f930b2a1f..ad3c09667f 100644
@@ -1017,6 +1017,18 @@ int vpci_init_header(struct pci_dev *pdev)
         bars[i].size = size;
         bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH;
 
+        if ( !is_hwdom )
+        {
+            int rc = iomem_permit_access(pdev->domain,
+                                        PFN_DOWN(addr),
+                                        PFN_DOWN(addr + size - 1));
+            if ( rc )
+            {
+                printk(XENLOG_WARNING "Failed to grant MMIO access for BAR%d: %d\n", i, rc);
+                goto fail;
+            }
+        }
+
         rc = vpci_add_register(pdev->vpci,
                                is_hwdom ? vpci_hw_read32 : guest_mem_bar_read,
                                is_hwdom ? bar_write : guest_mem_bar_write,
@@ -1040,6 +1052,18 @@ int vpci_init_header(struct pci_dev *pdev)
         header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) &
                               PCI_ROM_ADDRESS_ENABLE;
 
+        if ( !is_hwdom )
+        {
+            int rc = iomem_permit_access(pdev->domain,
+                                        PFN_DOWN(addr),
+                                        PFN_DOWN(addr + size - 1));
+            if ( rc )
+            {
+                printk(XENLOG_WARNING "Failed to grant MMIO access for ROM BAR: %d\n", rc);
+                goto fail;
+            }
+        }
+
         rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, rom_reg,
                                4, rom);
         if ( rc )
Signature · 1 line
2.53.0
#1 lore raw
Quoted 6 lines · Ariadne Conill

From: Steven Noonan <[email protected]>

With vPCI, you shouldn't need to use xen-pciback for the device, so the memory access permissions need to be defined somewhere. This allows vPCI to automatically define the access permissions so that the domU can map the BARs via IOMMU.

What if XSM had something to say about this? IOW no, I don't think this is permissible. xen-pciback needed or not, that's not where permissions are granted. It's still the toolstack which needs to do that.

Also you're never undoing the granting of the extra permissions.

Jan