From 85390939190e4b7eeba57765e344947c328cd166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Wed, 22 Mar 2017 16:11:13 +0000 Subject: ui/console: ensure do_safe_dpy_refresh holds BQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I missed the fact that when an exclusive work item runs it drops the BQL to ensure all no vCPUs are stuck waiting for it, hence causing a deadlock. However the actual helper needs to take the BQL especially as we'll be messing with device emulation bits during the update which all assume BQL is held. We make a minor cpu_reloading_memory_map which must try and unlock the RCU if we are actually outside the running context. Reported-by: Laurent Desnogues Signed-off-by: Alex Bennée Reviewed-by: Paolo Bonzini Reviewed-by: Gerd Hoffmann --- ui/console.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ui') diff --git a/ui/console.c b/ui/console.c index 937c950..dd27c95 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1586,7 +1586,9 @@ bool dpy_gfx_check_format(QemuConsole *con, static void do_safe_dpy_refresh(CPUState *cpu, run_on_cpu_data opaque) { DisplayChangeListener *dcl = opaque.host_ptr; + qemu_mutex_lock_iothread(); dcl->ops->dpy_refresh(dcl); + qemu_mutex_unlock_iothread(); } static void dpy_refresh(DisplayState *s) -- cgit v1.1 From 0096109052c5b83ee6894c88acedfd59b76d0113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 24 Mar 2017 15:39:05 +0000 Subject: ui/console: use exclusive mechanism directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit (8bb93c6f99) using async_safe_run_on_cpu() doesn't work on graphics sub-system which restrict which threads can do GUI updates. Rather the special casing MacOS we just directly call the helper and move all the exclusive handling into do_dafe_dpy_refresh(). The unfortunate bouncing of the BQL is to ensure there is no deadlock as vCPUs waiting on the BQL are kicked into their quiescent state. Signed-off-by: Alex Bennée Reviewed-by: Paolo Bonzini Reviewed-by: Gerd Hoffmann --- ui/console.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'ui') diff --git a/ui/console.c b/ui/console.c index dd27c95..419b098 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1576,19 +1576,22 @@ bool dpy_gfx_check_format(QemuConsole *con, } /* - * Safe DPY refresh for TCG guests. This runs when the TCG vCPUs are - * quiescent so we can avoid races between dirty page tracking for - * direct frame-buffer access by the guest. + * Safe DPY refresh for TCG guests. We use the exclusive mechanism to + * ensure the TCG vCPUs are quiescent so we can avoid races between + * dirty page tracking for direct frame-buffer access by the guest. * * This is a temporary stopgap until we've fixed the dirty tracking * races in display adapters. */ -static void do_safe_dpy_refresh(CPUState *cpu, run_on_cpu_data opaque) +static void do_safe_dpy_refresh(DisplayChangeListener *dcl) { - DisplayChangeListener *dcl = opaque.host_ptr; + qemu_mutex_unlock_iothread(); + start_exclusive(); qemu_mutex_lock_iothread(); dcl->ops->dpy_refresh(dcl); qemu_mutex_unlock_iothread(); + end_exclusive(); + qemu_mutex_lock_iothread(); } static void dpy_refresh(DisplayState *s) @@ -1598,8 +1601,7 @@ static void dpy_refresh(DisplayState *s) QLIST_FOREACH(dcl, &s->listeners, next) { if (dcl->ops->dpy_refresh) { if (tcg_enabled()) { - async_safe_run_on_cpu(first_cpu, do_safe_dpy_refresh, - RUN_ON_CPU_HOST_PTR(dcl)); + do_safe_dpy_refresh(dcl); } else { dcl->ops->dpy_refresh(dcl); } -- cgit v1.1