[PATCH] qxl: don't assert() if device isn't yet initialized

marcandre.lureau@redhat.com posted 1 patch 9 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230814193331.375778-1-marcandre.lureau@redhat.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
hw/display/qxl.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] qxl: don't assert() if device isn't yet initialized
Posted by marcandre.lureau@redhat.com 9 months, 1 week ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

If the PCI BAR isn't yet mapped or was unmapped, QXL_IO_SET_MODE will
assert(). Instead, report a guest bug and keep going.

This can be reproduced with:

cat << EOF | ./qemu-system-x86_64 -vga qxl -m 2048 -nodefaults -qtest stdio
outl 0xcf8 0x8000101c
outl 0xcfc 0xc000
outl 0xcf8 0x80001001
outl 0xcfc 0x01000000
outl 0xc006 0x00
EOF

Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1829

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/qxl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index f1c0eb7dfc..70b73820b2 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1591,7 +1591,10 @@ static void qxl_set_mode(PCIQXLDevice *d, unsigned int modenr, int loadvm)
     }
 
     d->guest_slots[0].slot = slot;
-    assert(qxl_add_memslot(d, 0, devmem, QXL_SYNC) == 0);
+    if (qxl_add_memslot(d, 0, devmem, QXL_SYNC) != 0) {
+        qxl_set_guest_bug(d, "device isn't initialized yet");
+        return;
+    }
 
     d->guest_primary.surface = surface;
     qxl_create_guest_primary(d, 0, QXL_SYNC);
-- 
2.41.0


Re: [PATCH] qxl: don't assert() if device isn't yet initialized
Posted by Thomas Huth 9 months ago
On 14/08/2023 21.33, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> If the PCI BAR isn't yet mapped or was unmapped, QXL_IO_SET_MODE will
> assert(). Instead, report a guest bug and keep going.
> 
> This can be reproduced with:
> 
> cat << EOF | ./qemu-system-x86_64 -vga qxl -m 2048 -nodefaults -qtest stdio
> outl 0xcf8 0x8000101c
> outl 0xcfc 0xc000
> outl 0xcf8 0x80001001
> outl 0xcfc 0x01000000
> outl 0xc006 0x00
> EOF
> 
> Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1829
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/display/qxl.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/display/qxl.c b/hw/display/qxl.c
> index f1c0eb7dfc..70b73820b2 100644
> --- a/hw/display/qxl.c
> +++ b/hw/display/qxl.c
> @@ -1591,7 +1591,10 @@ static void qxl_set_mode(PCIQXLDevice *d, unsigned int modenr, int loadvm)
>       }
>   
>       d->guest_slots[0].slot = slot;
> -    assert(qxl_add_memslot(d, 0, devmem, QXL_SYNC) == 0);
> +    if (qxl_add_memslot(d, 0, devmem, QXL_SYNC) != 0) {
> +        qxl_set_guest_bug(d, "device isn't initialized yet");
> +        return;
> +    }
>   
>       d->guest_primary.surface = surface;
>       qxl_create_guest_primary(d, 0, QXL_SYNC);

Reviewed-by: Thomas Huth <thuth@redhat.com>