Skip to contentSkip to conversation

vga: don't abort when adding a duplicate isa-vga device

PATCH Superseded Jose R. Ziviani 4 participants 5 messages Aug 13, 2021 – Aug 24, 2021

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vga: don't abort when adding a duplicate isa-vga device

If users try to add an isa-vga device that was already registered, still in command line, qemu will crash:

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

That particular board registers such device automaticaly, so it's not obvious that a VGA device already exists. This patch changes this behavior by displaying a message and ignoring that device, starting qemu normally.

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

---
 hw/display/vga-isa.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/display/vga-isa.c +9 -0
index 90851e730b..69db502dde 100644
@@ -61,6 +61,15 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
 
+    /*
+     * some machines register VGA by default, so instead of aborting
+     * it, show a message and ignore this device.
+     */
+    if (qemu_ram_block_by_name("vga.vram")) {
+        error_report("vga.vram is already registered, ignoring this device");
+        return;
+    }
+
     s->global_vmstate = true;
     vga_common_init(s, OBJECT(dev));
     s->legacy_address_space = isa_address_space(isadev);
Signature · 1 line
2.32.0
#1 lore raw
Quoted 24 lines · Jose R. Ziviani

If users try to add an isa-vga device that was already registered, still in command line, qemu will crash:

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

That particular board registers such device automaticaly, so it's not obvious that a VGA device already exists. This patch changes this behavior by displaying a message and ignoring that device, starting qemu normally.

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

---
  hw/display/vga-isa.c | 9 +++++++++
  1 file changed, 9 insertions(+)
hw/display/vga-isa.c +0 -0
index 90851e730b..69db502dde 100644
@@ -61,6 +61,15 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
      MemoryRegion *vga_io_memory;

hw/display/vga-isa.c static void vga_isa_realizefn(DeviceState *dev, Error **errp) · line 71

Quoted 10 lines
hw/display/vga-isa.c +8 -0
      const MemoryRegionPortio *vga_ports, *vbe_ports;
 
+    /*
+     * some machines register VGA by default, so instead of aborting
+     * it, show a message and ignore this device.
+     */
+    if (qemu_ram_block_by_name("vga.vram")) {
+        error_report("vga.vram is already registered, ignoring this device");
+        return;
+    }

I think we should not ignore the error, but rather turn this into a proper error (instead of aborting).

So if you replace error_report(...) with error_setg(errp, ...), the patch should be fine.

Thomas

#2 lore raw

Hi,

Quoted 7 lines

hw/display/vga-isa.c static void vga_isa_realizefn(DeviceState *dev, Error **errp) · line 71

Quoted 4 lines
hw/display/vga-isa.c +4 -0
+    if (qemu_ram_block_by_name("vga.vram")) {
+        error_report("vga.vram is already registered, ignoring this device");
+        return;
+    }

I think we should not ignore the error, but rather turn this into a proper error (instead of aborting).

Yes. Silently fixing up things automatically tends to be worse long-term.

take care,
Gerd

#3 lore raw

Hello Thomas and Gerd,

Thank you for reviewing it. Sending a v2 soon.

Thank you very much!

Quoted 13 lines · Gerd Hoffmann
   Hi,
Quoted 6 lines

hw/display/vga-isa.c static void vga_isa_realizefn(DeviceState *dev, Error **errp) · line 71

Quoted 4 lines
hw/display/vga-isa.c +4 -0
+    if (qemu_ram_block_by_name("vga.vram")) {
+        error_report("vga.vram is already registered, ignoring this device");
+        return;
+    }

I think we should not ignore the error, but rather turn this into a proper error (instead of aborting).

Yes. Silently fixing up things automatically tends to be worse long-term.

take care,
Gerd

#4 lore raw
In reply to Thomas Huth
Quoted 34 lines · Thomas Huth
Quoted 19 lines · Jose R. Ziviani

If users try to add an isa-vga device that was already registered, still in command line, qemu will crash:

$ qemu-system-mips64el -M pica61 -device isa-vga
RAMBlock "vga.vram" already registered, abort!
Aborted (core dumped)
That particular board registers such device automaticaly, so it's
not obvious that a VGA device already exists. This patch changes
this behavior by displaying a message and ignoring that device,
starting qemu normally.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/44
Signed-off-by: Jose R. Ziviani <[email protected]>
---
  hw/display/vga-isa.c | 9 +++++++++
  1 file changed, 9 insertions(+)
hw/display/vga-isa.c +0 -0
index 90851e730b..69db502dde 100644

hw/display/vga-isa.c static void vga_isa_realizefn(DeviceState *dev, Error **errp) · line 70

Quoted 10 lines
hw/display/vga-isa.c +8 -0
@@ -61,6 +61,15 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
      MemoryRegion *vga_io_memory;
      const MemoryRegionPortio *vga_ports, *vbe_ports;
+    /*
+     * some machines register VGA by default, so instead of aborting
+     * it, show a message and ignore this device.
+     */
+    if (qemu_ram_block_by_name("vga.vram")) {
+        error_report("vga.vram is already registered, ignoring this device");
+        return;
+    }

I think we should not ignore the error, but rather turn this into a proper error (instead of aborting).

Quoted 2 lines

So if you replace error_report(...) with error_setg(errp, ...), the patch should be fine.

Agreed.

error_report() in a function with an Error **errp parameter is almost always wrong.