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

Thomas Huth posted 3 patches 2 years, 1 month ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220316132402.1190346-1-thuth@redhat.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
hw/display/ati.c            |  7 ++++-
hw/display/cirrus_vga.c     | 62 ++++++++++++++++++++-----------------
hw/display/cirrus_vga_isa.c |  7 ++++-
hw/display/qxl.c            |  6 +++-
hw/display/vga-isa.c        |  9 +++++-
hw/display/vga-mmio.c       |  8 ++++-
hw/display/vga-pci.c        | 15 +++++++--
hw/display/vga.c            | 15 +++++++--
hw/display/vga_int.h        |  2 +-
hw/display/virtio-vga.c     |  7 ++++-
hw/display/vmware_vga.c     |  2 +-
11 files changed, 100 insertions(+), 40 deletions(-)
[PATCH 0/3] Fix crash when adding a second ISA VGA device
Posted by Thomas Huth 2 years, 1 month ago
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.

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/ati.c            |  7 ++++-
 hw/display/cirrus_vga.c     | 62 ++++++++++++++++++++-----------------
 hw/display/cirrus_vga_isa.c |  7 ++++-
 hw/display/qxl.c            |  6 +++-
 hw/display/vga-isa.c        |  9 +++++-
 hw/display/vga-mmio.c       |  8 ++++-
 hw/display/vga-pci.c        | 15 +++++++--
 hw/display/vga.c            | 15 +++++++--
 hw/display/vga_int.h        |  2 +-
 hw/display/virtio-vga.c     |  7 ++++-
 hw/display/vmware_vga.c     |  2 +-
 11 files changed, 100 insertions(+), 40 deletions(-)

-- 
2.27.0