Skip to contentSkip to conversation

xen/vpci: zero guest-visible BAR addresses to ensure domU asssigns its own

PATCH In review Ariadne Conill 4 participants 5 messages Feb 24 – Mar 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/vpci: zero guest-visible BAR addresses to ensure domU asssigns its own

From: Steven Noonan <[email protected]>

If we just use the host's BAR addresses, the domU might not attempt to reconfigure the BAR ranges and may never try to map them with the IOMMU. Zeroing them ensures the guest kernel knows the BARs are not configured and needs to make its own choices about where to map the BARs.

---
 xen/drivers/vpci/header.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/vpci/header.c +2 -2
index 739a5f610e..852dfd8ae3 100644
@@ -1011,7 +1011,7 @@ int vpci_init_header(struct pci_dev *pdev)
         }
 
         bars[i].addr = addr;
-        bars[i].guest_addr = addr;
+        bars[i].guest_addr = is_hwdom ? addr : 0;
         bars[i].size = size;
         bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH;
 
@@ -1034,7 +1034,7 @@ int vpci_init_header(struct pci_dev *pdev)
         rom->type = VPCI_BAR_ROM;
         rom->size = size;
         rom->addr = addr;
-        rom->guest_addr = addr;
+        rom->guest_addr = is_hwdom ? addr : 0;
         header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) &
                               PCI_ROM_ADDRESS_ENABLE;
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 6 lines · Ariadne Conill

From: Steven Noonan <[email protected]>

If we just use the host's BAR addresses, the domU might not attempt to reconfigure the BAR ranges and may never try to map them with the IOMMU. Zeroing them ensures the guest kernel knows the BARs are not configured and needs to make its own choices about where to map the BARs.

Yet for this, don't we first need to expose a full topology to the guest, i.e. at least a host bridge, and maybe further bridges?

Jan

#2 lore raw
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Ariadne Conill

From: Steven Noonan <[email protected]>

If we just use the host's BAR addresses, the domU might not attempt to reconfigure the BAR ranges and may never try to map them with the IOMMU. Zeroing them ensures the guest kernel knows the BARs are not configured and needs to make its own choices about where to map the BARs.

Yet for this, don't we first need to expose a full topology to the guest, i.e. at least a host bridge, and maybe further bridges?

While we eventually do want to expose (a) virtual bridge(s) to vPCI domUs (this work is currently in development), I don't think it's pre-requisite for the code change herein: clearly, leaking host BAR addresses to domUs isn't right, and there's no need to wait to address that.

With that said, the commit title/description don't align well with the code change. Assuming we want to move the code change forward, for v2 of the patch I suggest dropping the 2nd half of the title, and reworking the commit description to focus on describing the code change at hand and less on what the domU might do.

#3 lore raw
Quoted 16 lines · Stewart Hildebrand
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Ariadne Conill

From: Steven Noonan <[email protected]>

If we just use the host's BAR addresses, the domU might not attempt to reconfigure the BAR ranges and may never try to map them with the IOMMU. Zeroing them ensures the guest kernel knows the BARs are not configured and needs to make its own choices about where to map the BARs.

Yet for this, don't we first need to expose a full topology to the guest, i.e. at least a host bridge, and maybe further bridges?

While we eventually do want to expose (a) virtual bridge(s) to vPCI domUs (this work is currently in development), I don't think it's pre-requisite for the code change herein: clearly, leaking host BAR addresses to domUs isn't right, and there's no need to wait to address that.

Quoted 5 lines

With that said, the commit title/description don't align well with the code change. Assuming we want to move the code change forward, for v2 of the patch I suggest dropping the 2nd half of the title, and reworking the commit description to focus on describing the code change at hand and less on what the domU might do.

That would indeed work for me.

Jan

#4 lore raw
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Stewart Hildebrand
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Ariadne Conill

From: Steven Noonan <[email protected]>

If we just use the host's BAR addresses, the domU might not attempt to reconfigure the BAR ranges and may never try to map them with the IOMMU. Zeroing them ensures the guest kernel knows the BARs are not configured and needs to make its own choices about where to map the BARs.

Yet for this, don't we first need to expose a full topology to the guest, i.e. at least a host bridge, and maybe further bridges?

While we eventually do want to expose (a) virtual bridge(s) to vPCI domUs (this work is currently in development), I don't think it's pre-requisite for the code change herein: clearly, leaking host BAR addresses to domUs isn't right, and there's no need to wait to address that.

Quoted 7 lines
Quoted 5 lines

With that said, the commit title/description don't align well with the code change. Assuming we want to move the code change forward, for v2 of the patch I suggest dropping the 2nd half of the title, and reworking the commit description to focus on describing the code change at hand and less on what the domU might do.

That would indeed work for me.

+1. The "try to map them with the IOMMU" wording is not accurate IMO, and wants replacing.

It would also be nice to mention that zeroing unconditionally is fine, because for domUs the memory decoding bit is also unconditionally cleared, so there will be no attempt to map the BARs into the guest p2m by vpci_init_header().

Thanks, Roger.