Skip to contentSkip to conversation

virtio-vga: fix virtio-vga bar ordering

PATCH Superseded Anthoine Bourgeois 3 participants 7 messages Apr 21, 2020 – Apr 23, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-vga: fix virtio-vga bar ordering

With virtio-vga, pci bar are reordered. Bar #2 is used for compatibility with stdvga. By default, bar #2 is used by virtio modern io bar. This bar is the last one introduce in the virtio pci bar layout and it's crushed by the virtio-vga reordering. So virtio-vga and modern-pio-notify are incompatible because virtio-vga failed to initialize with this option.

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

---
 hw/display/virtio-vga.c | 2 +-
 hw/virtio/virtio-pci.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-vga.c +1 -1
index 2b4c2aa126..f5f8737c60 100644
@@ -113,7 +113,7 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
      * the stdvga mmio registers at the start of bar #2.
      */
     vpci_dev->modern_mem_bar_idx = 2;
-    vpci_dev->msix_bar_idx = 4;
+    vpci_dev->modern_io_bar_idx = 4;
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
         /*
hw/virtio/virtio-pci.c +1 -0
index 4cb784389c..9c5efaa06e 100644
@@ -1705,6 +1705,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
      *
      *   region 0   --  virtio legacy io bar
      *   region 1   --  msi-x bar
+     *   region 2   --  virtio modern io bar
      *   region 4+5 --  virtio modern memory (64bit) bar
      *
      */
Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · Anthoine Bourgeois

With virtio-vga, pci bar are reordered. Bar #2 is used for compatibility with stdvga. By default, bar #2 is used by virtio modern io bar. This bar is the last one introduce in the virtio pci bar layout and it's crushed by the virtio-vga reordering. So virtio-vga and modern-pio-notify are incompatible because virtio-vga failed to initialize with this option.

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

Such changes generally need to be tied to machine version.

Quoted 32 lines
---
 hw/display/virtio-vga.c | 2 +-
 hw/virtio/virtio-pci.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-vga.c +1 -1
index 2b4c2aa126..f5f8737c60 100644
@@ -113,7 +113,7 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
      * the stdvga mmio registers at the start of bar #2.
      */
     vpci_dev->modern_mem_bar_idx = 2;
-    vpci_dev->msix_bar_idx = 4;
+    vpci_dev->modern_io_bar_idx = 4;
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
         /*
hw/virtio/virtio-pci.c +1 -0
index 4cb784389c..9c5efaa06e 100644
@@ -1705,6 +1705,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
      *
      *   region 0   --  virtio legacy io bar
      *   region 1   --  msi-x bar
+     *   region 2   --  virtio modern io bar
      *   region 4+5 --  virtio modern memory (64bit) bar
      *
      */
Signature · 1 line
2.20.1
#2 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Anthoine Bourgeois

With virtio-vga, pci bar are reordered. Bar #2 is used for compatibility with stdvga. By default, bar #2 is used by virtio modern io bar. This bar is the last one introduce in the virtio pci bar layout and it's crushed by the virtio-vga reordering. So virtio-vga and modern-pio-notify are incompatible because virtio-vga failed to initialize with this option.

Quoted 6 lines
Quoted 4 lines

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

Such changes generally need to be tied to machine version.

Given that modern-pio-notify is off by default and virtio-vga,modern-pio-notify=on is broken I think we don't need to worry about compatibility in this specific case (assuming the patch is updated to not shuffle around the msix bar, see other reply).

cheers,
Gerd

#3 lore raw
Quoted 16 lines · Gerd Hoffmann
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Anthoine Bourgeois

With virtio-vga, pci bar are reordered. Bar #2 is used for compatibility with stdvga. By default, bar #2 is used by virtio modern io bar. This bar is the last one introduce in the virtio pci bar layout and it's crushed by the virtio-vga reordering. So virtio-vga and modern-pio-notify are incompatible because virtio-vga failed to initialize with this option.

Quoted 6 lines
Quoted 4 lines

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

Such changes generally need to be tied to machine version.

Quoted 7 lines

Given that modern-pio-notify is off by default and virtio-vga,modern-pio-notify=on is broken I think we don't need to worry about compatibility in this specific case (assuming the patch is updated to not shuffle around the msix bar, see other reply).

cheers,
Gerd

OK, just worth documenting that this will break cross-version migration if modern-pio-notify is enabled.

#4 lore raw
In reply to Anthoine Bourgeois
Quoted 2 lines

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

Well, msix was placed in bar 4 intentionally. That keeps bar 1 (default msix location) free, so we have the option to turn bar 0 (vga compat vram) into a 64bit bar without shuffling around things.

Quoted 1 line

- vpci_dev->msix_bar_idx = 4;

Please don't.

Quoted 1 line

+ vpci_dev->modern_io_bar_idx = 4;

We can use bar 5 instead.

Alternatively just throw an error saying that modern-pio-notify is not supported.

hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1709

Quoted 10 lines
hw/virtio/virtio-pci.c +1 -0
index 4cb784389c..9c5efaa06e 100644
@@ -1705,6 +1705,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
      *
      *   region 0   --  virtio legacy io bar
      *   region 1   --  msi-x bar
+     *   region 2   --  virtio modern io bar
      *   region 4+5 --  virtio modern memory (64bit) bar

Separate patch please. Also worth noting that the modern io bar is off by default.

cheers,
Gerd

#5 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines

This fix exchange the modern io bar with the modern memory bar, replacing the msix bar that is never impacted anyway.

Well, msix was placed in bar 4 intentionally. That keeps bar 1 (default msix location) free, so we have the option to turn bar 0 (vga compat vram) into a 64bit bar without shuffling around things.

That's a really good reason I didn't think of.
Just a question, why didn't we choose the virtio-vga order to avoid shuffling from the beginning? Vga came after and we keep the compatibility ?

Quoted 11 lines
Quoted 2 lines

- vpci_dev->msix_bar_idx = 4;

Please don't.

Quoted 1 line

+ vpci_dev->modern_io_bar_idx = 4;

We can use bar 5 instead.

Alternatively just throw an error saying that modern-pio-notify is not supported.

As you like. I sent a v2 with modern_io_bar_idx to 5 but I can do a v3 with an error thrown.

Quoted 14 lines

hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1709

Quoted 11 lines
hw/virtio/virtio-pci.c +1 -0
index 4cb784389c..9c5efaa06e 100644
@@ -1705,6 +1705,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
      *
      *   region 0   --  virtio legacy io bar
      *   region 1   --  msi-x bar
+     *   region 2   --  virtio modern io bar
      *   region 4+5 --  virtio modern memory (64bit) bar

Separate patch please. Also worth noting that the modern io bar is off by default.

Done.

Thank you,
Anthoine

#6 lore raw

Hi,

Quoted 3 lines

Just a question, why didn't we choose the virtio-vga order to avoid shuffling from the beginning? Vga came after and we keep the compatibility ?

Well, transitional virtio devices need bar 0 for legacy virtio compatibility (io bar), so using bar 1 for msix makes sense in that case.

virtio-vga is new enough that it supports modern only so it doesn't need to worry about legacy virtio compatibility. It does have to worry about vga compatibility though. Therefore it uses a bar layout different from anyone else ...

cheers,
Gerd