Skip to contentSkip to conversation

hw/display: Do not allow multiple (identical) VGA devices

PATCH In review Philippe Mathieu-Daudé 5 participants 11 messages Nov 18, 2021 – Nov 19, 2021

lore
Share & tools
lore
#0 lore raw

cover hw/display: Do not allow multiple (identical) VGA devices

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

 hw/display/vga_int.h        |  2 +-
 hw/display/ati.c            |  4 +++-
 hw/display/cirrus_vga.c     |  4 +++-
 hw/display/cirrus_vga_isa.c |  4 +++-
 hw/display/qxl.c            |  4 +++-
 hw/display/vga-isa-mm.c     |  3 ++-
 hw/display/vga-isa.c        | 11 ++---------
 hw/display/vga-pci.c        |  8 ++++++--
 hw/display/vga.c            | 17 ++++++++++++++++-
 hw/display/virtio-vga.c     |  4 +++-
 hw/display/vmware_vga.c     |  2 +-
 11 files changed, 43 insertions(+), 20 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 hw/display: Add Error* handle to vga_common_init()

We want vga_common_init() to fail gracefully,
therefore allow it to take an Error* handle.

---
 hw/display/vga_int.h        | 2 +-
 hw/display/ati.c            | 4 +++-
 hw/display/cirrus_vga.c     | 4 +++-
 hw/display/cirrus_vga_isa.c | 4 +++-
 hw/display/qxl.c            | 4 +++-
 hw/display/vga-isa-mm.c     | 3 ++-
 hw/display/vga-isa.c        | 4 +++-
 hw/display/vga-pci.c        | 8 ++++++--
 hw/display/vga.c            | 4 +++-
 hw/display/virtio-vga.c     | 4 +++-
 hw/display/vmware_vga.c     | 2 +-
 11 files changed, 31 insertions(+), 12 deletions(-)
hw/display/vga_int.h +1 -1
index 847e784ca6a..305e700014d 100644
@@ -156,7 +156,7 @@ static inline int c6_to_8(int v)
     return (v << 2) | (b << 1) | b;
 }
 
-void vga_common_init(VGACommonState *s, Object *obj);
+bool vga_common_init(VGACommonState *s, Object *obj, Error **errp);
 void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,
               MemoryRegion *address_space_io, bool init_vga_ports);
 MemoryRegion *vga_init_io(VGACommonState *s, Object *obj,
hw/display/ati.c +3 -1
index 31f22754dce..6e38e005022 100644
@@ -955,7 +955,9 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp)
     }
 
     /* init vga bits */
-    vga_common_init(vga, OBJECT(s));
+    if (!vga_common_init(vga, OBJECT(s), errp)) {
+        return;
+    }
     vga_init(vga, OBJECT(s), pci_address_space(dev),
              pci_address_space_io(dev), true);
     vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, &s->vga);
hw/display/cirrus_vga.c +3 -1
index fdca6ca659f..5a7ddb84ff0 100644
@@ -2954,7 +2954,9 @@ static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp)
          return;
      }
      /* setup VGA */
-     vga_common_init(&s->vga, OBJECT(dev));
+    if (!vga_common_init(&s->vga, OBJECT(dev), errp)) {
+        return;
+    }
      cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),
                         pci_address_space_io(dev));
      s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga);
hw/display/cirrus_vga_isa.c +3 -1
index 4f6fb1af3bd..96144bd6906 100644
@@ -56,7 +56,9 @@ static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp)
         return;
     }
     s->global_vmstate = true;
-    vga_common_init(s, OBJECT(dev));
+    if (!vga_common_init(s, OBJECT(dev), errp)) {
+        return;
+    }
     cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0,
                        isa_address_space(isadev),
                        isa_address_space_io(isadev));
hw/display/qxl.c +3 -1
index 29c80b4289b..16eb98c25d8 100644
@@ -2198,7 +2198,9 @@ static void qxl_realize_primary(PCIDevice *dev, Error **errp)
     qxl_init_ramsize(qxl);
     vga->vbe_size = qxl->vgamem_size;
     vga->vram_size_mb = qxl->vga.vram_size / MiB;
-    vga_common_init(vga, OBJECT(dev));
+    if (!vga_common_init(vga, OBJECT(dev), errp)) {
+        return;
+    }
     vga_init(vga, OBJECT(dev),
              pci_address_space(dev), pci_address_space_io(dev), false);
     portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list,
hw/display/vga-isa-mm.c +2 -1
index 7321b7a06d5..420da1d7467 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/bitops.h"
 #include "qemu/units.h"
+#include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "hw/display/vga.h"
 #include "vga_int.h"
@@ -101,7 +102,7 @@ int isa_vga_mm_init(hwaddr vram_base,
 
     s->vga.vram_size_mb = VGA_RAM_SIZE / MiB;
     s->vga.global_vmstate = true;
-    vga_common_init(&s->vga, NULL);
+    vga_common_init(&s->vga, NULL, &error_fatal);
     vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
 
     s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s);
hw/display/vga-isa.c +3 -1
index 8cea84f2bea..2782012196a 100644
@@ -72,7 +72,9 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     }
 
     s->global_vmstate = true;
-    vga_common_init(s, OBJECT(dev));
+    if (!vga_common_init(s, OBJECT(dev), errp)) {
+        return;
+    }
     s->legacy_address_space = isa_address_space(isadev);
     vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
     isa_register_portio_list(isadev, &d->portio_vga,
hw/display/vga-pci.c +6 -2
index 62fb5c38c1f..3e5bc259f7a 100644
@@ -239,7 +239,9 @@ static void pci_std_vga_realize(PCIDevice *dev, Error **errp)
     bool edid = false;
 
     /* vga + console init */
-    vga_common_init(s, OBJECT(dev));
+    if (!vga_common_init(s, OBJECT(dev), errp)) {
+        return;
+    }
     vga_init(s, OBJECT(dev), pci_address_space(dev), pci_address_space_io(dev),
              true);
 
@@ -275,7 +277,9 @@ static void pci_secondary_vga_realize(PCIDevice *dev, Error **errp)
     bool edid = false;
 
     /* vga + console init */
-    vga_common_init(s, OBJECT(dev));
+    if (!vga_common_init(s, OBJECT(dev), errp)) {
+        return;
+    }
     s->con = graphic_console_init(DEVICE(dev), 0, s->hw_ops, s);
 
     /* mmio bar */
hw/display/vga.c +3 -1
index 9d1f66af402..a6759c7e934 100644
@@ -2168,7 +2168,7 @@ static inline uint32_t uint_clamp(uint32_t val, uint32_t vmin, uint32_t vmax)
     return val;
 }
 
-void vga_common_init(VGACommonState *s, Object *obj)
+bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
 {
     int i, j, v, b;
 
@@ -2237,6 +2237,8 @@ void vga_common_init(VGACommonState *s, Object *obj)
     s->default_endian_fb = false;
 #endif
     vga_dirty_log_start(s);
+
+    return true;
 }
 
 static const MemoryRegionPortio vga_portio_list[] = {
hw/display/virtio-vga.c +3 -1
index 9e57f61e9ed..d89735d7301 100644
@@ -119,7 +119,9 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 
     /* init vga compat bits */
     vga->vram_size_mb = 8;
-    vga_common_init(vga, OBJECT(vpci_dev));
+    if (!vga_common_init(vga, OBJECT(vpci_dev), errp)) {
+        return;
+    }
     vga_init(vga, OBJECT(vpci_dev), pci_address_space(&vpci_dev->pci_dev),
              pci_address_space_io(&vpci_dev->pci_dev), true);
     pci_register_bar(&vpci_dev->pci_dev, 0,
hw/display/vmware_vga.c +1 -1
index e2969a6c81c..d67318e6e46 100644
@@ -1248,7 +1248,7 @@ static void vmsvga_init(DeviceState *dev, struct vmsvga_state_s *s,
                            &error_fatal);
     s->fifo_ptr = memory_region_get_ram_ptr(&s->fifo_ram);
 
-    vga_common_init(&s->vga, OBJECT(dev));
+    vga_common_init(&s->vga, OBJECT(dev), &error_fatal);
     vga_init(&s->vga, OBJECT(dev), address_space, io, true);
     vmstate_register(NULL, 0, &vmstate_vga_common, &s->vga);
     s->new_depth = 32;
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/2 hw/display: Do not allow multiple identical VGA devices

In reply to Philippe Mathieu-Daudé

vga_common_init() create a MemoryRegion named "vga.vram", used as a singleton for the device class. When creating the same device type multiple times, we get:

  $ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
  RAMBlock "vga.vram" already registered, abort!
  Aborted (core dumped)

Commit 7852a77f598 ("vga: don't abort when adding a duplicate isa-vga device") added a check for a single device, generalize it to all VGA devices which call vga_common_init():

  $ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
  qemu-system-mips64: -device isa-cirrus-vga: at most one isa-cirrus-vga device is permitted

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/44

---
 hw/display/vga-isa.c |  9 ---------
 hw/display/vga.c     | 13 +++++++++++++
 2 files changed, 13 insertions(+), 9 deletions(-)
hw/display/vga-isa.c +0 -9
index 2782012196a..b930c8d2667 100644
@@ -62,15 +62,6 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
 
-    /*
-     * make sure this device is not being added twice, if so
-     * exit without crashing qemu
-     */
-    if (object_resolve_path_type("", TYPE_ISA_VGA, NULL)) {
-        error_setg(errp, "at most one %s device is permitted", TYPE_ISA_VGA);
-        return;
-    }
-
     s->global_vmstate = true;
     if (!vga_common_init(s, OBJECT(dev), errp)) {
         return;
hw/display/vga.c +13 -0
index a6759c7e934..8f0d5cc9019 100644
@@ -2172,6 +2172,19 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
 {
     int i, j, v, b;
 
+    if (obj) {
+        const char *typename = object_get_typename(obj);
+
+        /*
+         * make sure this device is not being added twice,
+         * if so exit without crashing qemu
+         */
+        if (object_resolve_path_type("", typename, NULL)) {
+            error_setg(errp, "at most one %s device is permitted", typename);
+            return false;
+        }
+    }
+
     for(i = 0;i < 256; i++) {
         v = 0;
         for(j = 0; j < 8; j++) {
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH-for-6.2 2/2] hw/display: Do not allow multiple identical VGA devices

hw/display/vga.c bool vga_common_init(VGACommonState *s, Object *obj, Error **errp) · line 2187

Quoted 13 lines · Philippe Mathieu-Daudé
hw/display/vga.c +13 -0
+    if (obj) {
+        const char *typename = object_get_typename(obj);
+
+        /*
+         * make sure this device is not being added twice,
+         * if so exit without crashing qemu
+         */
+        if (object_resolve_path_type("", typename, NULL)) {
+            error_setg(errp, "at most one %s device is permitted", typename);
+            return false;
+        }
+    }
+

Wouldn't it give the same error with one ISA and one PCI VGA?

Paolo

#4 lore raw

Re: [PATCH-for-6.2 2/2] hw/display: Do not allow multiple identical VGA devices

Quoted 17 lines · Paolo Bonzini
Quoted 6 lines · Philippe Mathieu-Daudé

+    if (obj) {
+        const char *typename = object_get_typename(obj); +
+        /*
+         * make sure this device is not being added twice, +         * if so exit without crashing qemu

Quoted 8 lines

+         */
+        if (object_resolve_path_type("", typename, NULL)) { +            error_setg(errp, "at most one %s device is permitted", typename);
+            return false;
+        }
+    }
+

Wouldn't it give the same error with one ISA and one PCI VGA?

In that case I'd expect the object path to be different...

Anyhow, the fix from commit 7852a77f598 doesn't seem to work well:

$ qemu-system-x86_64 -M q35 -nodefaults -device isa-vga
qemu-system-x86_64: -device isa-vga: at most one isa-vga device is permitted
#5 lore raw

Re: [PATCH-for-6.2 2/2] hw/display: Do not allow multiple identical VGA devices

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

vga_common_init() create a MemoryRegion named "vga.vram", used as a singleton for the device class. When creating the same device type multiple times, we get:

  $ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
  RAMBlock "vga.vram" already registered, abort!
  Aborted (core dumped)

Admittedly that would Callers that aren't ready to

Quoted 4 lines

Commit 7852a77f598 ("vga: don't abort when adding a duplicate isa-vga device") added a check for a single device, generalize it to all VGA devices which call vga_common_init():

Not all current VGA devices abort though

 $ qemu-system-x86_64 -device cirrus-vga -device cirrus-vga

runs without aborting.

Your goal was to eliminate the abort() scenario, which makes sense, but we hit other scenarios too.

How about we instead have vmstate_register_ram() gain an "Error **errp" so it can propagate the failure into vga_common_init rather than aborting. That would ensure we only affect scenarios that curently abort and nothing more.

Other callers can pass &error_abort if they dont want to gracefully handle this scenario.

Quoted 60 lines
  $ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
  qemu-system-mips64: -device isa-cirrus-vga: at most one isa-cirrus-vga device is permitted

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/44

---
 hw/display/vga-isa.c |  9 ---------
 hw/display/vga.c     | 13 +++++++++++++
 2 files changed, 13 insertions(+), 9 deletions(-)
hw/display/vga-isa.c +0 -9
index 2782012196a..b930c8d2667 100644
@@ -62,15 +62,6 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
 
-    /*
-     * make sure this device is not being added twice, if so
-     * exit without crashing qemu
-     */
-    if (object_resolve_path_type("", TYPE_ISA_VGA, NULL)) {
-        error_setg(errp, "at most one %s device is permitted", TYPE_ISA_VGA);
-        return;
-    }
-
     s->global_vmstate = true;
     if (!vga_common_init(s, OBJECT(dev), errp)) {
         return;
hw/display/vga.c +13 -0
index a6759c7e934..8f0d5cc9019 100644
@@ -2172,6 +2172,19 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
 {
     int i, j, v, b;
 
+    if (obj) {
+        const char *typename = object_get_typename(obj);
+
+        /*
+         * make sure this device is not being added twice,
+         * if so exit without crashing qemu
+         */
+        if (object_resolve_path_type("", typename, NULL)) {
+            error_setg(errp, "at most one %s device is permitted", typename);
+            return false;
+        }
+    }
+
     for(i = 0;i < 256; i++) {
         v = 0;
         for(j = 0; j < 8; j++) {
Signature · 1 line
2.31.1

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

Quoted 12 lines
  hw/display/vga_int.h        |  2 +-
  hw/display/ati.c            |  4 +++-
  hw/display/cirrus_vga.c     |  4 +++-
  hw/display/cirrus_vga_isa.c |  4 +++-
  hw/display/qxl.c            |  4 +++-
  hw/display/vga-isa-mm.c     |  3 ++-
  hw/display/vga-isa.c        | 11 ++---------
  hw/display/vga-pci.c        |  8 ++++++--
  hw/display/vga.c            | 17 ++++++++++++++++-
  hw/display/virtio-vga.c     |  4 +++-
  hw/display/vmware_vga.c     |  2 +-
  11 files changed, 43 insertions(+), 20 deletions(-)

Hi Phil,

I don't think this is correct for non-ISA devices: for example years ago I had a PC running Windows 98SE with 2 identical PCI graphics cards configured in dual-head mode.

IIRC the BIOS would bring up the first graphics card and configure it to use the legacy ISA VGA ioports for compatibility, and then once the main OS drivers loaded both cards were switched to PCI mode and configured using the BARs as normal.

ATB,

Mark.

#7 lore raw
Quoted 26 lines · Mark Cave-Ayland
Quoted 20 lines · Philippe Mathieu-Daudé

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
   hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

  hw/display/vga_int.h        |  2 +- hw/display/ati.c            |  4 +++- hw/display/cirrus_vga.c     |  4 +++- hw/display/cirrus_vga_isa.c |  4 +++- hw/display/qxl.c            |  4 +++- hw/display/vga-isa-mm.c     |  3 ++- hw/display/vga-isa.c        | 11 ++--------- hw/display/vga-pci.c        |  8 ++++++-- hw/display/vga.c            | 17 ++++++++++++++++- hw/display/virtio-vga.c     |  4 +++- hw/display/vmware_vga.c     |  2 +-

Quoted 1 line
  11 files changed, 43 insertions(+), 20 deletions(-)

Hi Phil,

Quoted 8 lines

I don't think this is correct for non-ISA devices: for example years ago I had a PC running Windows 98SE with 2 identical PCI graphics cards configured in dual-head mode.

IIRC the BIOS would bring up the first graphics card and configure it to use the legacy ISA VGA ioports for compatibility, and then once the main OS drivers loaded both cards were switched to PCI mode and configured using the BARs as normal.

The problem here is QEMU technical debt, not the hardware.

When vga_common_init() calls memory_region_init_ram_nomigrate() with obj=NULL, "vga.vram" is registered as a QOM singleton.

Updating it would 1/ require non-QOM devices to be QOM'ified and 2/ break migration unless using HPFM which I don't master.

#8 lore raw
Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Mark Cave-Ayland
Quoted 9 lines · Philippe Mathieu-Daudé

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
   hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

Quoted 12 lines
   hw/display/vga_int.h        |  2 +-
   hw/display/ati.c            |  4 +++-
   hw/display/cirrus_vga.c     |  4 +++-
   hw/display/cirrus_vga_isa.c |  4 +++-
   hw/display/qxl.c            |  4 +++-
   hw/display/vga-isa-mm.c     |  3 ++-
   hw/display/vga-isa.c        | 11 ++---------
   hw/display/vga-pci.c        |  8 ++++++--
   hw/display/vga.c            | 17 ++++++++++++++++-
   hw/display/virtio-vga.c     |  4 +++-
   hw/display/vmware_vga.c     |  2 +-
   11 files changed, 43 insertions(+), 20 deletions(-)

Hi Phil,

Quoted 8 lines

I don't think this is correct for non-ISA devices: for example years ago I had a PC running Windows 98SE with 2 identical PCI graphics cards configured in dual-head mode.

IIRC the BIOS would bring up the first graphics card and configure it to use the legacy ISA VGA ioports for compatibility, and then once the main OS drivers loaded both cards were switched to PCI mode and configured using the BARs as normal.

Quoted 7 lines

The problem here is QEMU technical debt, not the hardware.

When vga_common_init() calls memory_region_init_ram_nomigrate() with obj=NULL, "vga.vram" is registered as a QOM singleton.

Updating it would
1/ require non-QOM devices to be QOM'ified

So sounds like that's the right way to go here.

Quoted 1 line

and 2/ break migration unless using HPFM which I don't master.

What's HPFM?

Thomas

#9 lore raw
Quoted 42 lines · Thomas Huth
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Mark Cave-Ayland
Quoted 20 lines · Philippe Mathieu-Daudé

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
    hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

   hw/display/vga_int.h        |  2 +- hw/display/ati.c            |  4 +++- hw/display/cirrus_vga.c     |  4 +++- hw/display/cirrus_vga_isa.c |  4 +++- hw/display/qxl.c            |  4 +++- hw/display/vga-isa-mm.c     |  3 ++- hw/display/vga-isa.c        | 11 ++--------- hw/display/vga-pci.c        |  8 ++++++-- hw/display/vga.c            | 17 ++++++++++++++++- hw/display/virtio-vga.c     |  4 +++- hw/display/vmware_vga.c     |  2 +-

Quoted 1 line
   11 files changed, 43 insertions(+), 20 deletions(-)

Hi Phil,

Quoted 8 lines

I don't think this is correct for non-ISA devices: for example years ago I had a PC running Windows 98SE with 2 identical PCI graphics cards configured in dual-head mode.

IIRC the BIOS would bring up the first graphics card and configure it to use the legacy ISA VGA ioports for compatibility, and then once the main OS drivers loaded both cards were switched to PCI mode and configured using the BARs as normal.

The problem here is QEMU technical debt, not the hardware.

When vga_common_init() calls memory_region_init_ram_nomigrate() with obj=NULL, "vga.vram" is registered as a QOM singleton.

Quoted 8 lines
Quoted 2 lines

Updating it would
1/ require non-QOM devices to be QOM'ified

So sounds like that's the right way to go here.

Quoted 1 line

and 2/ break migration unless using HPFM which I don't master.

What's HPFM?

Hocus Pocus Freakin' Magic

#10 lore raw
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 45 lines · Thomas Huth
Quoted 43 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Mark Cave-Ayland
Quoted 9 lines · Philippe Mathieu-Daudé

Commit 7852a77f598 fixed creating multiple TYPE_ISA_VGA devices, generalize the fix to all VGA devices.

See https://gitlab.com/qemu-project/qemu/-/issues/44

Philippe Mathieu-Daudé (2):
    hw/display: Add Error* handle to vga_common_init() hw/display: Do not allow multiple identical VGA devices

Quoted 12 lines
    hw/display/vga_int.h        |  2 +-
    hw/display/ati.c            |  4 +++-
    hw/display/cirrus_vga.c     |  4 +++-
    hw/display/cirrus_vga_isa.c |  4 +++-
    hw/display/qxl.c            |  4 +++-
    hw/display/vga-isa-mm.c     |  3 ++-
    hw/display/vga-isa.c        | 11 ++---------
    hw/display/vga-pci.c        |  8 ++++++--
    hw/display/vga.c            | 17 ++++++++++++++++-
    hw/display/virtio-vga.c     |  4 +++-
    hw/display/vmware_vga.c     |  2 +-
    11 files changed, 43 insertions(+), 20 deletions(-)

Hi Phil,

Quoted 8 lines

I don't think this is correct for non-ISA devices: for example years ago I had a PC running Windows 98SE with 2 identical PCI graphics cards configured in dual-head mode.

IIRC the BIOS would bring up the first graphics card and configure it to use the legacy ISA VGA ioports for compatibility, and then once the main OS drivers loaded both cards were switched to PCI mode and configured using the BARs as normal.

The problem here is QEMU technical debt, not the hardware.

When vga_common_init() calls memory_region_init_ram_nomigrate() with obj=NULL, "vga.vram" is registered as a QOM singleton.

Updating it would
1/ require non-QOM devices to be QOM'ified

Quoted 7 lines
Quoted 5 lines

So sounds like that's the right way to go here.

Quoted 1 line

and 2/ break migration unless using HPFM which I don't master.

What's HPFM?

Hocus Pocus Freakin' Magic

LOL, ok, thanks, TIL.

Anyway, IMHO I'd rather fix this issue by properly QOM'ifying the vga-isa-mm.c code and breaking migration here (who's migrating such old ISA devices anyway?) instead of introducing more kludges that might cause other trouble (see also https://gitlab.com/qemu-project/qemu/-/issues/733 ).

Thomas