stdvga: fix screen blanking
PATCH 1/1 stdvga: fix screen blanking
In case the display surface uses a shared buffer (i.e. uses vga vram directly instead of a shadow) go unshare the buffer before clearing it.
This avoids vga memory corruption, which in turn fixes unblanking not working properly with X11.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067
--- hw/display/vga.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/display/vga.c +6 -0
@@ -1762,6 +1762,12 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ; +if (is_buffer_shared (surface)) { +/* unshare buffer, otherwise the blanking corrupts vga vram */ +qemu_console_resize (s->con, s->last_scr_width, s->last_scr_height); + surface =qemu_console_surface (s->con); + } + w = s->last_scr_width *surface_bytes_per_pixel (surface); d =surface_data (surface);for (i =0 ; i < s->last_scr_height; i++) {
Signature · 1 line
2.45.1
Hi
Quoted 18 lines · Gerd Hoffmann
In case the display surface uses a shared buffer (i.e. uses vga vram directly instead of a shadow) go unshare the buffer before clearing it.
This avoids vga memory corruption, which in turn fixes unblanking not working properly with X11.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067Signed-off-by Gerd Hoffmann <[email protected]>--- hw/display/vga.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/vga.c +0
-0
hw/display/vga.c static void vga_draw_blank(VGACommonState *s, int · line 1767
Quoted 6 lines
hw/display/vga.c +1
-0@@ -1762,6 +1762,12 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ; +if (is_buffer_shared (surface)) {
It might be a good time to rename this function. surface_is_borrowed() ?
hw/display/vga.c static void vga_draw_blank(VGACommonState *s, int · line 1770
Quoted 4 lines
hw/display/vga.c +2
-0+/* unshare buffer, otherwise the blanking corrupts vga vram */ +qemu_console_resize (s->con, s->last_scr_width, s->last_scr_height);
If we want to guarantee that a new surface is created, we should leave a comment on qemu_console_resize(), or perhaps make it take a new/alloc argument?
+ surface = qemu_console_surface(s->con);
Quoted 10 lines
hw/display/vga.c +2
-1+ } + w = s->last_scr_width *surface_bytes_per_pixel (surface); d =surface_data (surface);for (i =0 ; i < s->last_scr_height; i++) { --2.45.1
thanks
Signature · 1 line
Marc-André Lureau
Quoted 26 lines · Marc-André Lureau
Hi
Quoted 22 lines · Gerd Hoffmann
In case the display surface uses a shared buffer (i.e. uses vga vram directly instead of a shadow) go unshare the buffer before clearing it.
This avoids vga memory corruption, which in turn fixes unblanking not working properly with X11.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067Signed-off-by Gerd Hoffmann <[email protected]>--- hw/display/vga.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/vga.c +0
-0@@ -1762,6 +1762,12 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ;
Quoted 4 lines
hw/display/vga.c static void vga_draw_blank(VGACommonState *s, int · line 1767
Quoted 2 lines
hw/display/vga.c +1
-0+if (is_buffer_shared (surface)) {It might be a good time to rename this function.
surface_is_borrowed()?
"shared" means memory shared between guest and host (typically vga vram).
I doubt using the term "borrowed" instead clarifies things much, especially as this isn't an rust-style "borrow" (which I guess you are referring to). Nothing prevents the host from writing to the surface as the bug clearly shows. Also qemu is a C project, so I wouldn't expect developers being familiar with rust semantics and terminology.
Quoted 6 lines
hw/display/vga.c static void vga_draw_blank(VGACommonState *s, int · line 1770
Quoted 3 lines
hw/display/vga.c +2
-0+/* unshare buffer, otherwise the blanking corrupts vga vram */ +qemu_console_resize (s->con, s->last_scr_width, s->last_scr_height);If we want to guarantee that a new surface is created, we should leave a comment on
qemu_console_resize(),
I left the comment there exactly because it isn't obvious that the qemu_console_resize() will create a new (not shared) surface. So not sure what exactly you are suggesting here?
Quoted 1 line
or perhaps make it take a new/alloc argument?
Right now qemu_console_resize() does a bunch of checks to figure whenever it can take a shortcut (because width + height didn't change) or not.
We could certainly pass a boolean in instead and have the caller decide that way. Didn't check whenever that makes sense, and IMHO that is well beyond the scope of a 3-lines bugfix.
kraxel@sirius ~/projects/qemu# git grep qemu_console_resize | wc -l 35
take care,
Gerd
Hi
Quoted 28 lines · Gerd Hoffmann
Quoted 17 lines · Marc-André Lureau
Hi
Quoted 13 lines · Gerd Hoffmann
In case the display surface uses a shared buffer (i.e. uses vga vram directly instead of a shadow) go unshare the buffer before clearing it.
This avoids vga memory corruption, which in turn fixes unblanking not working properly with X11.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067Signed-off-by Gerd Hoffmann <[email protected]>--- hw/display/vga.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 5 lines
hw/display/vga.c static void vga_draw_blank(VGACommonState *s,
Quoted 5 lines
hw/display/vga.c +0
-0@@ -1762,6 +1762,12 @@ static void vga_draw_blank(VGACommonState *s,int
Quoted 4 lines
Quoted 4 lines
hw/display/vga.c +0
-0full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ;
Quoted 8 lines
Quoted 4 lines
hw/display/vga.c static void vga_draw_blank(VGACommonState *s, · line 1767
Quoted 2 lines
hw/display/vga.c +1
-0+if (is_buffer_shared (surface)) {It might be a good time to rename this function.
surface_is_borrowed()?"shared" means memory shared between guest and host (typically vga vram).
In this context, but this is now confusing because we also have shared memory surface support for win32.
static inline int is_buffer_shared(DisplaySurface *surface)
{
return !(surface->flags & QEMU_ALLOCATED_FLAG);
}!allocated = the surface memory is not owned.
Quoted 7 lines
I doubt using the term "borrowed" instead clarifies things much, especially as this isn't an rust-style "borrow" (which I guess you are referring to). Nothing prevents the host from writing to the surface as the bug clearly shows. Also qemu is a C project, so I wouldn't expect developers being familiar with rust semantics and terminology.
Borrowing is not a term specific to Rust :) (and you can have mutable borrows btw)
I'd rather use "shared" memory for IPC purposes.
The lack of surface_ function prefix is also annoying.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
hw/display/vga.c +2
-0+/* unshare buffer, otherwise the blanking corrupts vga vram */ +qemu_console_resize (s->con, s->last_scr_width, s->last_scr_height);
Quoted 8 lines
Quoted 2 lines
If we want to guarantee that a new surface is created, we should leave a comment on
qemu_console_resize(),I left the comment there exactly because it isn't obvious that the
qemu_console_resize()will create a new (not shared) surface. So not sure what exactly you are suggesting here?
I meant to document qemu_console_resize() function itself, as it would be too easy to miss and break this case.
Quoted 6 lines
Quoted 1 line
or perhaps make it take a new/alloc argument?
Right now
qemu_console_resize()does a bunch of checks to figure whenever it can take a shortcut (because width + height didn't change) or not.
Quoted 7 lines
We could certainly pass a boolean in instead and have the caller decide that way. Didn't check whenever that makes sense, and IMHO that is well beyond the scope of a 3-lines bugfix.
kraxel@sirius ~/projects/qemu# git grep
qemu_console_resize| wc -l 35
Maybe introduce a new function then?
Signature · 1 line
Marc-André Lureau