[6989] Fix display breakage when resizing the screen (v2) (Avi Kivity)
Revision: 6989
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6989 Author: aliguori Date: 2009-04-05 18:41:18 +0000 (Sun, 05 Apr 2009)
Log Message:
-----------
Fix display breakage when resizing the screen (v2) (Avi Kivity)
When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.
Fix by reallocating the display immediately when the resolution changes.
Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).
Changes from v1:
- fix segfault when switching virtual consoles with curses
Modified Paths:
--------------
trunk/hw/cirrus_vga.c
trunk/hw/vga.c
trunk/hw/vga_int.h
Modified: trunk/hw/cirrus_vga.c
===================================================================
hw/cirrus_vga.c +10 -1
@@ -1392,6 +1392,8 @@break ; } +vga_update_resolution ((VGAState *)s); +return CIRRUS_HOOK_HANDLED ; }
@@ -1419,6 +1421,7 @@#endif } s->cirrus_hidden_dac_lockindex =0 ; +vga_update_resolution ((VGAState *)s); }/***************************************
@@ -1705,6 +1708,8 @@break ; } +vga_update_resolution ((VGAState *)s); +return CIRRUS_HOOK_HANDLED ; }
@@ -2830,6 +2835,7 @@if (s->ar_flip_flop ==0 ) { val &=0x3f ; s->ar_index = val; +vga_update_resolution ((VGAState *)s); }else { index = s->ar_index &0x1f ;switch (index) {
@@ -2923,6 +2929,7 @@/* can always write bit 4 of CR7 */ if (s->cr_index ==7 ) s->cr[7 ] = (s->cr[7 ] & ~0x10 ) | (val &0x10 ); +vga_update_resolution ((VGAState *)s);return ; }switch (s->cr_index) {
@@ -2951,6 +2958,7 @@ s->update_retrace_info ((VGAState *) s);break ; } +vga_update_resolution ((VGAState *)s);break ;case 0x3ba :case 0x3da :
@@ -3157,7 +3165,8 @@cirrus_update_memory_access (s);/* force refresh */ - s->graphic_mode =-1 ; +vga_update_resolution ((VGAState *)s); + s->want_full_update =1 ;cirrus_update_bank_ptr (s,0 );cirrus_update_bank_ptr (s,1 );return 0 ;
Modified: trunk/hw/vga.c
===================================================================
hw/vga.c +156 -119
496 lines not on this page · raw message
Modified: trunk/hw/vga_int.h
===================================================================
hw/vga_int.h +4 -0
@@ -147,8 +147,11 @@DisplayState *ds; \uint32_t font_offsets[2 ]; \int graphic_mode; \ +int want_full_update; \uint8_t shift_control; \uint8_t double_scan; \ +uint8_t multi_run; \ +uint8_t multi_scan; \uint32_t line_offset; \uint32_t line_compare; \uint32_t start_addr; \
@@ -195,6 +198,7 @@ ram_addr_t vga_ram_offset, int vga_ram_size);void vga_init (VGAState *s);void vga_reset (void *s); +void vga_update_resolution (VGAState *s);void vga_dirty_log_start (VGAState *s);void vga_dirty_log_stop (VGAState *s);
Quoted 16 lines · Anthony Liguori
Revision: 6989
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6989 Author: aliguori Date: 2009-04-05 18:41:18 +0000 (Sun, 05 Apr 2009)Log Message:
-----------
Fix display breakage when resizing the screen (v2) (Avi Kivity)When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.
Fix by reallocating the display immediately when the resolution changes.
Quoted 8 lines
Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).
Changes from v1:
- fix segfault when switching virtual consoles with cursesSigned-off-by Avi Kivity <[email protected]>Signed-off-by Anthony Liguori <[email protected]>
While I understand the problem this patch tries to fix I think the way it fixes it is wrong.
First of all this patch breaks the VC switching mechanism in qemu: just execute sleep 2; startx; in the first VC, then switch to the monitor and wait.
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is. In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.
For these reasons I think this patch should be reverted.
Quoted 14 lines · Stefano Stabellini
Anthony Liguori wrote:
While I understand the problem this patch tries to fix I think the way it fixes it is wrong.
First of all this patch breaks the VC switching mechanism in qemu: just execute sleep 2; startx; in the first VC, then switch to the monitor and wait.
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is. In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.
Quoted 2 lines
For these reasons I think this patch should be reverted.
Avi/Stefano, can one of you guys put together a proper patch?
Right now, it's better not to revert this patch because without it, our test suite cannot run. However, I agree this is the wrong fix so we need to get a proper fix as soon as we can.
Regards,
Anthony Liguori
Quoted 2 lines
Quoted 15 lines · Anthony Liguori
Quoted 14 lines · Stefano Stabellini
Anthony Liguori wrote:
While I understand the problem this patch tries to fix I think the way it fixes it is wrong.
First of all this patch breaks the VC switching mechanism in qemu: just execute sleep 2; startx; in the first VC, then switch to the monitor and wait.
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is. In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.
Quoted 9 lines
Quoted 2 lines
For these reasons I think this patch should be reverted.
Avi/Stefano, can one of you guys put together a proper patch?
Right now, it's better not to revert this patch because without it, our test suite cannot run. However, I agree this is the wrong fix so we need to get a proper fix as soon as we can.
Can you please let me know a simple way to reproduce the breakage Avi was trying to fix?
Quoted 29 lines · Stefano Stabellini
Quoted 16 lines · Anthony Liguori
Revision: 6989
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6989 Author: aliguori Date: 2009-04-05 18:41:18 +0000 (Sun, 05 Apr 2009)Log Message:
-----------
Fix display breakage when resizing the screen (v2) (Avi Kivity)When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.
Fix by reallocating the display immediately when the resolution changes.
Quoted 9 lines
Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).
Changes from v1:
- fix segfault when switching virtual consoles with cursesSigned-off-by Avi Kivity <[email protected]>Signed-off-by Anthony Liguori <[email protected]>
Quoted 7 lines
While I understand the problem this patch tries to fix I think the way it fixes it is wrong.
First of all this patch breaks the VC switching mechanism in qemu: just execute sleep 2; startx; in the first VC, then switch to the monitor and wait.
I guess, this can be fixed by not reallocating the display surface if vga is not the active console?
Quoted 6 lines
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is. In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.
This happens through cirrus_do_copy(), which implies that the display surface is involved. Is that wrong?
Quoted 1 line
For these reasons I think this patch should be reverted
Can you suggest a better fix? The failure (without the patch) is pretty disastrous from my point of view.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 3 lines · Stefano Stabellini
Can you please let me know a simple way to reproduce the breakage Avi was trying to fix?
The trigger is kvm-autotest; I think you can easily reproduce it by booting a guest with vnc (unconnected), and issueing a screendump through the monitor (use -monitor stdio, not on the console...) every second.
-vnc may be unnecessary, haven't tried.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 8 lines · Avi Kivity
Quoted 6 lines
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is. In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.This happens through
cirrus_do_copy(), which implies that the display surface is involved. Is that wrong?
I think what you're saying is, we shouldn't call qemu_console_copy() in cirrus_do_copy() if vga is not displayed on the console?
(and conversely, if it is displayed, we shouldn't call cirrus_invalidate_region).
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 8 lines
Secondly it doesn't follow the basic idea behind the DisplayState
surface: it is supposed to be a pixel surface provided by the vga emulator to the frontends, cirrus shouldn't have to care what size it is.
In fact cirrus emulates bitblit operations on the emulated framebuffer, not on the DisplayState surface; if it does so is a bug and should be fixed.
Quoted 9 lines
Quoted 2 lines
This happens through
cirrus_do_copy(), which implies that the display surface is involved. Is that wrong?I think what you're saying is, we shouldn't call
qemu_console_copy()incirrus_do_copy()if vga is not displayed on the console?(and conversely, if it is displayed, we shouldn't call
cirrus_invalidate_region).
I tried several times to manually reproduce the issue with no luck: if no vnc clients are supposed to be connected, how do you make the cirrus emulated hw do a bitblit?
In any case it makes sense that the problem is in qemu_console_copy() rather than in the rop function itself that only operates on the emulated framebuffer.
But calling qemu_console_copy() in cirrus_do_copy() shouldn't be risky because before that, we call vga_hw_update() that should do the resize.
Without a better understanding of the bug I will refrain from making any suggestion.
Quoted 4 lines · Stefano Stabellini
I tried several times to manually reproduce the issue with no luck: if no vnc clients are supposed to be connected, how do you make the cirrus emulated hw do a bitblit?
The guest will boot and do it by itself.
Quoted 6 lines
In any case it makes sense that the problem is in
qemu_console_copy()rather than in the rop function itself that only operates on the emulated framebuffer.
But callingqemu_console_copy()incirrus_do_copy()shouldn't be risky because before that, we callvga_hw_update()that should do the resize.
vga_hw_update() may not actually do anything if the conditions are right, and maybe that's the case here.
Quoted 4 lines
Without a better understanding of the bug I will refrain from making any suggestion.
There's a backtrace in https://bugzilla.redhat.com/show_bug.cgi?id=494002. I'll also try to generate a good scenario for reproducing this.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Stefano Stabellini
I tried several times to manually reproduce the issue with no luck: if no vnc clients are supposed to be connected, how do you make the cirrus emulated hw do a bitblit?
The guest will boot and do it by itself.
what is the OS?
Quoted 9 lines
Quoted 6 lines
In any case it makes sense that the problem is in
qemu_console_copy()rather than in the rop function itself that only operates on the emulated framebuffer.
But callingqemu_console_copy()incirrus_do_copy()shouldn't be risky because before that, we callvga_hw_update()that should do the resize.
vga_hw_update()may not actually do anything if the conditions are right, and maybe that's the case here.
I thought about it, but if vga_hw_update does nothing, then qemu_console_copy does nothing too.
Quoted 9 lines
Quoted 4 lines
Without a better understanding of the bug I will refrain from making any suggestion.
There's a backtrace in
https://bugzilla.redhat.com/show_bug.cgi?id=494002. I'll also try to generate a good scenario for reproducing this.
thanks, that would be very useful (if it doesn't require me to compile kvm it would be even better :)).
Quoted 10 lines · Stefano Stabellini
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Stefano Stabellini
I tried several times to manually reproduce the issue with no luck: if no vnc clients are supposed to be connected, how do you make the cirrus emulated hw do a bitblit?
Quoted 6 lines
Quoted 2 lines
The guest will boot and do it by itself.
what is the OS?
In the cases I saw, I think it was Windows. Sorry, I can't be sure and I didn't keep any records.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
In any case it makes sense that the problem is in
qemu_console_copy()rather than in the rop function itself that only operates on the emulated framebuffer.
But callingqemu_console_copy()incirrus_do_copy()shouldn't be risky because before that, we callvga_hw_update()that should do the resize.
Quoted 6 lines
Quoted 2 lines
vga_hw_update()may not actually do anything if the conditions are right, and maybe that's the case here.I thought about it, but if
vga_hw_updatedoes nothing, thenqemu_console_copydoes nothing too.
True.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Without a better understanding of the bug I will refrain from making any suggestion.
Quoted 8 lines
Quoted 3 lines
There's a backtrace in https://bugzilla.redhat.com/show_bug.cgi?id=494002. I'll also try to generate a good scenario for reproducing this.
thanks, that would be very useful (if it doesn't require me to compile kvm it would be even better :)).
If you're running a recent distro it's already built in :)
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 9 lines · Avi Kivity
Quoted 3 lines · Stefano Stabellini
Can you please let me know a simple way to reproduce the breakage Avi was trying to fix?
The trigger is kvm-autotest; I think you can easily reproduce it by booting a guest with vnc (unconnected), and issueing a screendump through the monitor (use -monitor stdio, not on the console...) every second.
yeah, and btw, with this patch merged into kvm-userspace as of today, I'm still tripping over it[1] on some guests (RHEL5.3 x86_64 install).
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 8 lines · Ryan Harper
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Stefano Stabellini
Can you please let me know a simple way to reproduce the breakage Avi was trying to fix?
Quoted 10 lines
Quoted 2 lines
The trigger is kvm-autotest; I think you can easily reproduce it by booting a guest with vnc (unconnected), and issueing a screendump through the monitor (use -monitor stdio, not on the console...) every second.
yeah, and btw, with this patch merged into kvm-userspace as of today, I'm still tripping over it[1] on some guests (RHEL5.3
x86_64install).
I found the real cause - vga_screen_dump() left values for the current display resolution in s->last_width and s->last_height. This caused the next vga_draw_graphic() to render to the 640x400 display surface it had without resizing it.
The bug is triggered if you manage to screendump after a screen resolution change, but before the next bitblit or console refresh. If no vnc or sdl client is connected, that's just the next bitblt so the window is considerably longer.
I'll follow up with a patch. Anthony, please revert 6989 before applying it. Thanks to Stefano for pointing out the problems with the patch.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 9 lines · Avi Kivity
I found the real cause -
vga_screen_dump()left values for the current display resolution ins->last_widthands->last_height. This caused the nextvga_draw_graphic()to render to the 640x400 display surface it had without resizing it.The bug is triggered if you manage to screendump after a screen resolution change, but before the next bitblit or console refresh. If no vnc or sdl client is connected, that's just the next bitblt so the window is considerably longer.
This explains why it is so hard to reproduce.
Quoted 4 lines
I'll follow up with a patch. Anthony, please revert 6989 before applying it. Thanks to Stefano for pointing out the problems with the patch.
No problem :)