[Qemu-devel] [PATCH] Fix coredump when using virtio-vga

08005325@163.com posted 1 patch 6 years, 8 months ago
Test asan passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu failed
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1551413588-36475-1-git-send-email-08005325@163.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
hw/display/virtio-gpu-pci.c | 5 +++++
1 file changed, 5 insertions(+)
[Qemu-devel] [PATCH] Fix coredump when using virtio-vga
Posted by 08005325@163.com 6 years, 8 months ago
From: Michael Qiu <qiudayu@huayun.com>

When using command -device virtio-vga,virgl=on
the default max_outputs is 0, this will lead coredump,

    (con=0x0, hw_ops=0x5555564452e0 <virtio_vga_ops>,
     opaque=0x55555754ec60) at ui/console.c:1872
    (vpci_dev=0x55555754ec60, errp=0x7fffffffdbb8)
     at qemu/hw/display/virtio-vga.c:160
    (pci_dev=0x55555754ec60, errp=0x7fffffffdbb8)
     at hw/virtio/virtio-pci.c:1786
...

This patch force ths max_outputs to 1 when it not greater
than 0.

Signed-off-by: Michael Qiu <qiudayu@huayun.com>
---
 hw/display/virtio-gpu-pci.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index bdcd33c..59b571d 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -46,6 +46,11 @@ static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     int i;
     Error *local_error = NULL;
 
+    if (g->conf.max_outputs <= 0) {
+        qemu_log("WARNING: virtio gpu max_outputs must greater than 1");
+        g->conf.max_outputs = 1;
+    }
+
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
     virtio_pci_force_virtio_1(vpci_dev);
     object_property_set_bool(OBJECT(vdev), true, "realized", &local_error);
-- 
1.8.3.1


Re: [Qemu-devel] [PATCH] Fix coredump when using virtio-vga
Posted by Gerd Hoffmann 6 years, 8 months ago
On Fri, Mar 01, 2019 at 12:13:08PM +0800, 08005325@163.com wrote:
> From: Michael Qiu <qiudayu@huayun.com>
> 
> When using command -device virtio-vga,virgl=on
> the default max_outputs is 0, this will lead coredump,

The default is 1.

> @@ -46,6 +46,11 @@ static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
>      int i;
>      Error *local_error = NULL;
>  
> +    if (g->conf.max_outputs <= 0) {
> +        qemu_log("WARNING: virtio gpu max_outputs must greater than 1");
> +        g->conf.max_outputs = 1;
> +    }

There already is a sanity check in virtio_gpu_device_realize().
You can extend that to also throw an error in case max_outputs
is 0.  Fixing things up and continuing is a bad idea.  Yes there
are places in the qemu code base still doing that, for backward
compatibility with old versions, but we should not add new
instances of this.

cheers,
  Gerd