mbox series

[v2,0/3] Fix crash when adding a second ISA VGA device

Message ID 20220317083027.16688-1-thuth@redhat.com (mailing list archive)
Headers show
Series Fix crash when adding a second ISA VGA device | expand

Message

Thomas Huth March 17, 2022, 8:30 a.m. UTC
QEMU currently abort()s if the user tries to add a second ISA VGA
device, for example:

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

Such a crash should never happen just because of giving bad parameters
at the command line, we should give a proper error message instead
and exit gracefully.

Note: There have been previous attempts to fix this problem, but the
first committed solution had bad side effects and got reverted
(https://gitlab.com/qemu-project/qemu/-/issues/733). There was another
idea to fix it by QOM'ifying the related devices (see the commits around
23f6e3b11be74abae), but after having another close look at the problem,
I think this doesn't work either: For getting unique names in the
vmstate_register_ram() function, the devices need to return unique names
from the qdev_get_dev_path() function, and those ISA VGA devices don't
support that there (unlike PCI, ISA devices don't have a slot id ...
they could be distinguished by their I/O port base address, but all the
ISA VGA cards currently use the same address there, so that doesn't
work either). ==> So the very original idea of checking for the availability
of the "vga.vram" memory region still seems the only usable approach to
me right now. While the original patch by Jose R. Ziviani only fixed the
issue for the isa-vga device, I'm taking a more general approach now by
adding the fix in the vga_common_init() function, so that it works for
the isa-cirrus-vga device, too.

v2: Rework error handling in 2nd patch, vga_common_init() returns bool now

Thomas Huth (3):
  hw/display/cirrus_vga: Clean up indentation in
    pci_cirrus_vga_realize()
  hw/display: Allow vga_common_init() to return errors
  hw/display/vga: Report a proper error when adding a 2nd ISA VGA

 hw/display/vga_int.h        |  2 +-
 hw/display/ati.c            |  4 ++-
 hw/display/cirrus_vga.c     | 59 +++++++++++++++++++------------------
 hw/display/cirrus_vga_isa.c |  4 ++-
 hw/display/qxl.c            |  6 +++-
 hw/display/vga-isa.c        |  5 +++-
 hw/display/vga-mmio.c       |  5 +++-
 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, 76 insertions(+), 40 deletions(-)