Skip to contentSkip to conversation

xen/vpci: fix backport of 53859596c0d3

PATCH In review Roger Pau Monne 2 participants 3 messages Oct 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/vpci: fix backport of 53859596c0d3

Commit 53859596c0d3 depends on the behavioral change introduced in ee2eb6849d50 that inverted the initialization of the MSI-X and header vPCI handlers. 53859596c0d3 requires the header to be initialized before MSI-X.

Change the order of initialization and adjust init_msix() to carve holes for the MSI-X tables if necessary, since it will now run after the BARs have been possibly mapped into the domain p2m.

Fixes f9aea52a9747 ("vpci/msix: improve handling of bogus MSI-X capabilities")

---
Cc: [email protected]
Cc: [email protected]

---
 xen/drivers/vpci/header.c | 2 +-
 xen/drivers/vpci/msix.c   | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
xen/drivers/vpci/header.c +1 -1
index 1f48f2aac64e..b002eb207243 100644
@@ -1016,7 +1016,7 @@ static int cf_check init_header(struct pci_dev *pdev)
     pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
     return rc;
 }
-REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_MIDDLE);
+REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_HIGH);
 
 /*
  * Local variables:
xen/drivers/vpci/msix.c +7 -2
index faa7c1cd494a..94fb645377e5 100644
@@ -792,9 +792,14 @@ static int cf_check init_msix(struct pci_dev *pdev)
     pdev->vpci->msix = msix;
     list_add(&msix->next, &d->arch.hvm.msix_tables);
 
-    return 0;
+    /*
+     * vPCI header initialization will have mapped the whole BAR into the
+     * p2m, as MSI-X capability was not yet initialized.  Crave a hole for
+     * the MSI-X table here, so that Xen can trap accesses.
+     */
+    return vpci_make_msix_hole(pdev);
 }
-REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_HIGH);
+REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_MIDDLE);
 
 /*
  * Local variables:
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Roger Pau Monne

Commit 53859596c0d3 depends on the behavioral change introduced in ee2eb6849d50 that inverted the initialization of the MSI-X and header vPCI handlers. 53859596c0d3 requires the header to be initialized before MSI-X.

Change the order of initialization and adjust init_msix() to carve holes for the MSI-X tables if necessary, since it will now run after the BARs have been possibly mapped into the domain p2m.

Fixes f9aea52a9747 ("vpci/msix: improve handling of bogus MSI-X capabilities")
Quoted 17 lines
xen/drivers/vpci/header.c +1 -1
@@ -1016,7 +1016,7 @@ static int cf_check init_header(struct pci_dev *pdev)
     pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
     return rc;
 }
-REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_MIDDLE);
+REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_HIGH);
 
 /*
  * Local variables:
xen/drivers/vpci/msix.c +0 -0
@@ -792,9 +792,14 @@ static int cf_check init_msix(struct pci_dev *pdev)
     pdev->vpci->msix = msix;
     list_add(&msix->next, &d->arch.hvm.msix_tables);
 

xen/drivers/vpci/msix.c static int cf_check init_msix(struct pci_dev *pdev) · line 802

Quoted 10 lines
xen/drivers/vpci/msix.c +7 -2
-    return 0;
+    /*
+     * vPCI header initialization will have mapped the whole BAR into the
+     * p2m, as MSI-X capability was not yet initialized.  Crave a hole for
+     * the MSI-X table here, so that Xen can trap accesses.
+     */
+    return vpci_make_msix_hole(pdev);
 }
-REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_HIGH);
+REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_MIDDLE);

Aiui this could as well be VPCI_PRIORITY_LOW now, much like in staging init order between MSI, MSI-X, and ReBar isn't enforced anymore?

Jan

#2 lore raw
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monne

Commit 53859596c0d3 depends on the behavioral change introduced in ee2eb6849d50 that inverted the initialization of the MSI-X and header vPCI handlers. 53859596c0d3 requires the header to be initialized before MSI-X.

Quoted 8 lines
Quoted 6 lines

Change the order of initialization and adjust init_msix() to carve holes for the MSI-X tables if necessary, since it will now run after the BARs have been possibly mapped into the domain p2m.

Fixes f9aea52a9747 ("vpci/msix: improve handling of bogus MSI-X capabilities")

Thanks.

Quoted 17 lines
Quoted 17 lines
xen/drivers/vpci/header.c +1 -1
@@ -1016,7 +1016,7 @@ static int cf_check init_header(struct pci_dev *pdev)
     pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
     return rc;
 }
-REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_MIDDLE);
+REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_HIGH);
 
 /*
  * Local variables:
xen/drivers/vpci/msix.c +0 -0
@@ -792,9 +792,14 @@ static int cf_check init_msix(struct pci_dev *pdev)
     pdev->vpci->msix = msix;
     list_add(&msix->next, &d->arch.hvm.msix_tables);
 
Quoted 13 lines

xen/drivers/vpci/msix.c static int cf_check init_msix(struct pci_dev *pdev) · line 802

Quoted 10 lines
xen/drivers/vpci/msix.c +7 -2
-    return 0;
+    /*
+     * vPCI header initialization will have mapped the whole BAR into the
+     * p2m, as MSI-X capability was not yet initialized.  Crave a hole for
+     * the MSI-X table here, so that Xen can trap accesses.
+     */
+    return vpci_make_msix_hole(pdev);
 }
-REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_HIGH);
+REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_MIDDLE);

Aiui this could as well be VPCI_PRIORITY_LOW now, much like in staging init order between MSI, MSI-X, and ReBar isn't enforced anymore?

Yes, that's my understating also, I however didn't want to make that change to avoid any surprises. This way MSI-X and header are still the first ones to initialize. Also that would render VPCI_PRIORITY_MIDDLE effectively unused in the code, which might be confusing for readers.

Roger.