ui: fix refresh of VNC server surface
PATCH v2 1/1 ui: fix refresh of VNC server surface
In previous commit
commit c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100
vnc: only alloc server surface with clients connected
the VNC server was changed so that the 'vd->server' pixman image was only allocated when a client is connected.
Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into vnc_update_server_surface() so it is guaranteed to be call in all code paths that re-create the surface instead of only in vnc_dpy_switch()
---
NB This should go into 2.5 & 2.6 stable branches too
ui/vnc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
ui/vnc.c +11 -9
@@ -692,6 +692,8 @@ void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y)static void vnc_update_server_surface (VncDisplay *vd) { +int width, height; +qemu_pixman_image_unref (vd->server); vd->server =NULL ;
@@ -699,10 +701,15 @@ static void vnc_update_server_surface(VncDisplay *vd)return ; } + width =vnc_width (vd); + height =vnc_height (vd); vd->server =pixman_image_create_bits (VNC_SERVER_FB_FORMAT , -vnc_width (vd), -vnc_height (vd), + width, height,NULL ,0 ); + +memset (vd->guest.dirty,0x00 ,sizeof (vd->guest.dirty)); +vnc_set_area_dirty (vd->guest.dirty, vd,0 ,0 , + width, height); } static void vnc_dpy_switch(DisplayChangeListener *dcl,
@@ -710,7 +717,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, {VncDisplay *vd =container_of (dcl, VncDisplay, dcl);VncState *vs; -int width, height;vnc_abort_display_jobs (vd); vd->ds = surface;
@@ -722,11 +728,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,qemu_pixman_image_unref (vd->guest.fb); vd->guest.fb =pixman_image_ref (surface->image); vd->guest.format = surface->format; - width =vnc_width (vd); - height =vnc_height (vd); -memset (vd->guest.dirty,0x00 ,sizeof (vd->guest.dirty)); -vnc_set_area_dirty (vd->guest.dirty, vd,0 ,0 , - width, height); QTAILQ_FOREACH(vs, &vd->clients, next) {vnc_colordepth (vs);
@@ -736,7 +737,8 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, }memset (vs->dirty,0x00 ,sizeof (vs->dirty));vnc_set_area_dirty (vs->dirty, vd,0 ,0 , - width, height); +vnc_width (vd), +vnc_height (vd)); } }
Signature · 1 line
2.7.4
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 22 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
Quoted 7 lines
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>
I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Peter
Quoted 30 lines · Peter Lieven
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 29 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()
Quoted 5 lines
Quoted 1 line
Signed-off-by Daniel P. Berrange <[email protected]>I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Dan, Gerd -- we're going to need an rc5 anyway -- can you comment on whether this patch is "should be in rc5" material? (If it is I can commit it to master directly.)
thanks
-- PMM
Quoted 34 lines · Peter Maydell
Quoted 33 lines · Peter Lieven
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 30 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>
Quoted 6 lines
Quoted 2 lines
I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Dan, Gerd -- we're going to need an rc5 anyway -- can you comment on whether this patch is "should be in rc5" material? (If it is I can commit it to master directly.)
I think it should be, as the VNC server is pretty unusable when it does not refresh the screen when you connect, but I'll let Gerd decide in case there's some implication in my patch that I've mis-understood.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Am 24.08.2016 um 17:49 schrieb Daniel P. Berrange:
Quoted 33 lines · Peter Maydell
Quoted 32 lines · Peter Lieven
Quoted 31 lines
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 29 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Dan, Gerd -- we're going to need an rc5 anyway -- can you comment on whether this patch is "should be in rc5" material? (If it is I can commit it to master directly.)
I think it should be, as the VNC server is pretty unusable when it does not refresh the screen when you connect, but I'll let Gerd decide in case there's some implication in my patch that I've mis-understood.
Hi Daniel,
I have had a look at the code and currently I do not understand why you ran into a blank screen. The server surface is not created if there is no client connected, this is correct. But the dirty bitmap for the server exists even if there is no client connected. So the status of the dirty bitmap should be the same with or without your patch.
Can you tell what exactly you tried out to reproduce a potential issue?
Thanks,
Peter
Quoted 43 lines · Peter Lieven
Am 24.08.2016 um 17:49 schrieb Daniel P. Berrange:
Quoted 33 lines · Peter Maydell
Quoted 32 lines · Peter Lieven
Quoted 31 lines
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 29 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Dan, Gerd -- we're going to need an rc5 anyway -- can you comment on whether this patch is "should be in rc5" material? (If it is I can commit it to master directly.)
I think it should be, as the VNC server is pretty unusable when it does not refresh the screen when you connect, but I'll let Gerd decide in case there's some implication in my patch that I've mis-understood.
Quoted 7 lines
Hi Daniel,
I have had a look at the code and currently I do not understand why you ran into a blank screen. The server surface is not created if there is no client connected, this is correct. But the dirty bitmap for the server exists even if there is no client connected. So the status of the dirty bitmap should be the same with or without your patch.
IIUC, the dirty bitmap is used to decide when to update the server surface from the guest framebuffer. When the new client connects and we create a new server surface, the dirty bitmap is clean, so QEMU never copies the guest framebuffer into the new server surface hence I just get a blank screen.
Quoted 1 line
Can you tell what exactly you tried out to reproduce a potential issue?
Boot a Fedora guest, in text mode (ie no Xorg graphics). Then simply disconnect & connect and I'll always get a black screen until I do something that causes Linux to update the screen.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Am 25.08.2016 um 14:46 schrieb Daniel P. Berrange:
Quoted 49 lines · Peter Lieven
Quoted 41 lines
Am 24.08.2016 um 17:49 schrieb Daniel P. Berrange:
Quoted 32 lines · Peter Maydell
Quoted 31 lines · Peter Lieven
Quoted 30 lines
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 29 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I noticed that these patches is as well not in master yet and therefore not included in the 2.7.0-rc4 tagged yesterday.
Dan, Gerd -- we're going to need an rc5 anyway -- can you comment on whether this patch is "should be in rc5" material? (If it is I can commit it to master directly.)
I think it should be, as the VNC server is pretty unusable when it does not refresh the screen when you connect, but I'll let Gerd decide in case there's some implication in my patch that I've mis-understood.
Quoted 7 lines
Hi Daniel,
I have had a look at the code and currently I do not understand why you ran into a blank screen. The server surface is not created if there is no client connected, this is correct. But the dirty bitmap for the server exists even if there is no client connected. So the status of the dirty bitmap should be the same with or without your patch.
Quoted 5 lines
IIUC, the dirty bitmap is used to decide when to update the server surface from the guest framebuffer. When the new client connects and we create a new server surface, the dirty bitmap is clean, so QEMU never copies the guest framebuffer into the new server surface hence I just get a blank screen.
Okay, but this can only happen at the second connection. The first vnc connection works, you disconnect, reconnect and then get a blank screen. Indeed in this case there is in theory no vnc_dpy_switch in between. However, I have the feeling that something else is additionally wrong - see below.
Quoted 5 lines
Quoted 2 lines
Can you tell what exactly you tried out to reproduce a potential issue?
Boot a Fedora guest, in text mode (ie no Xorg graphics). Then simply disconnect & connect and I'll always get a black screen until I do something that causes Linux to update the screen.
I can reproduce an issue if I have 2 VNC connections in paralell.
If I open the first VNC connection to a VM that does not update the screen, I have the following calls to vnc_dpy_switch and vnc_update_server_surface.
# qemu start vnc_update_server_surface: no clients vnc_dpy_switch: 640 480
# first vnc client connects vnc_update_server_surface: no clients vnc_dpy_switch: 720 400 vnc_connect: 0x5582ceb56000 vnc_init_state: 0x5582ceb56000 (first_client 1) vnc_update_server_surface vnc_update_server_surface vnc_dpy_switch: 720 400
# first client disconnects vnc_disconnect_finished: 0x562b79aa3850 (last_client 1) vnc_update_server_surface: no clients
# first client connects again vnc_connect: 0x562b79aa3850 vnc_init_state: 0x562b79aa3850 (first_client 1) vnc_update_server_surface vnc_update_server_surface vnc_dpy_switch: 720 400
# second client connects vnc_connect: 0x562b79a6d890 vnc_init_state: 0x562b79a6d890 (first_client 0) vnc_update_server_surface vnc_dpy_switch: 720 400
# second client disconnects vnc_disconnect_finished: 0x562b79a6d890 (last_client 0)
# first client disconnects vnc_disconnect_finished: 0x562b79aa3850 (last_client 1) vnc_update_server_surface: no clients
Strange enough, I see no issues with the first client, but I wonder why each vnc connect triggers multiple vnc_update_server_surface and vnc_dpy_switch and secondly my second client has a blank screen.
So at first I think your patch is correct, we need to mark the server surface dirty in vnc_update_server_surface cause there are other callers to it than vnc_dpy_switch.
But there seems to be another issue. I try to figure out what it is.
Peter
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 88 lines
In previous commit
commit
c7628bff4138ce906a3620d12e0820c1cf6c140d
Author: Gerd Hoffmann <[email protected]>
Date: Fri Oct 30 12:10:09 2015 +0100vnc: only alloc server surface with clients connected
the VNC server was changed so that the '
vd->server' pixman image was only allocated when a client is connected.Since then if a client disconnects and then reconnects to the VNC server all they will see is a black screen until they do something that triggers a refresh. On a graphical desktop this is not often noticed since there's many things going on which cause a refresh. On a plain text console it is really obvious since nothing refreshes frequently.
The problem is that the VNC server didn't update the guest dirty bitmap, so still believes its server image is in sync with the guest contents.
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>---
NB This should go into 2.5 & 2.6 stable branches too
ui/vnc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)ui/vnc.c +9
-8@@ -692,6 +692,8 @@ void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y)static void vnc_update_server_surface (VncDisplay *vd) { +int width, height; +qemu_pixman_image_unref (vd->server); vd->server =NULL ;@@ -699,10 +701,15 @@ static void vnc_update_server_surface(VncDisplay *vd)return ; } + width =vnc_width (vd); + height =vnc_height (vd); vd->server =pixman_image_create_bits (VNC_SERVER_FB_FORMAT , -vnc_width (vd), -vnc_height (vd), + width, height,NULL ,0 ); + +memset (vd->guest.dirty,0x00 ,sizeof (vd->guest.dirty)); +vnc_set_area_dirty (vd->guest.dirty, vd,0 ,0 , + width, height); } static void vnc_dpy_switch(DisplayChangeListener *dcl,@@ -710,7 +717,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, {VncDisplay *vd =container_of (dcl, VncDisplay, dcl);VncState *vs; -int width, height;vnc_abort_display_jobs (vd); vd->ds = surface;@@ -722,11 +728,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,qemu_pixman_image_unref (vd->guest.fb); vd->guest.fb =pixman_image_ref (surface->image); vd->guest.format = surface->format; - width =vnc_width (vd); - height =vnc_height (vd); -memset (vd->guest.dirty,0x00 ,sizeof (vd->guest.dirty)); -vnc_set_area_dirty (vd->guest.dirty, vd,0 ,0 , - width, height); QTAILQ_FOREACH(vs, &vd->clients, next) {vnc_colordepth (vs);
ui/vnc.c static void vnc_dpy_switch(DisplayChangeListener *dcl, · line 744
Quoted 9 lines
ui/vnc.c +2
-1@@ -736,7 +737,8 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, }memset (vs->dirty,0x00 ,sizeof (vs->dirty));vnc_set_area_dirty (vs->dirty, vd,0 ,0 , - width, height); +vnc_width (vd), +vnc_height (vd)); } }
I can confirm this issue now. Its only visible if the VNC client does not send a SET_PIXEL_FORMAT message. Which my client does and this masked the issue for me. The set pixel format routine invalidates the whole display which results in a vnc_dpy_switch which masks the guest fb dirty. Why this invalidation takes place I do not understand, but this can be sorted out lated.
For this patch:
Peter
Peter Maydell
AppliedQuoted 18 lines · Peter Lieven
Am 16.08.2016 um 18:30 schrieb Daniel P. Berrange:
Quoted 7 lines
To fix this we must explicitly mark the entire guest desktop as dirty after re-creating the server surface. Move this logic into
vnc_update_server_surface()so it is guaranteed to be call in all code paths that re-create the surface instead of only invnc_dpy_switch()Signed-off-by Daniel P. Berrange <[email protected]>I can confirm this issue now. Its only visible if the VNC client does not send a
SET_PIXEL_FORMATmessage.
Which my client does and this masked the issue for me. The set pixel format routine invalidates
the whole display which results in avnc_dpy_switchwhich masks the guest fb dirty. Why this invalidation
takes place I do not understand, but this can be sorted out lated.
Quoted 3 lines
For this patch:
Tested-by Peter Lieven <[email protected]>Reviewed-by Peter Lieven <[email protected]>
Applied to master for 2.7, thanks.
-- PMM