From nobody Sat May 4 05:49:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489589346723453.61685084169414; Wed, 15 Mar 2017 07:49:06 -0700 (PDT) Received: from localhost ([::1]:37860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coAEb-0002so-E8 for importer@patchew.org; Wed, 15 Mar 2017 10:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coADz-0002rS-3Y for qemu-devel@nongnu.org; Wed, 15 Mar 2017 10:48:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coADv-0004lA-6X for qemu-devel@nongnu.org; Wed, 15 Mar 2017 10:48:27 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:34118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1coADu-0004kI-V4 for qemu-devel@nongnu.org; Wed, 15 Mar 2017 10:48:23 -0400 Received: by mail-wr0-x233.google.com with SMTP id l37so12665396wrc.1 for ; Wed, 15 Mar 2017 07:48:22 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k10sm767891wmg.10.2017.03.15.07.48.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 07:48:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 8AECF3E07A1; Wed, 15 Mar 2017 14:48:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AfthxglxthghpY683kChANbUrR0tevLjJb3+xvdlXjE=; b=YvPzf5ce5gwahOBGs43URaCbvfdJBcDAnpB6Md6x3fG26bXsXtEddv9oJQ/NtZGJGq +AiV+9Y/VO+KGcLHTfdegc5x/YT6rhoJ/Qj/TkLMaobbIJeEdrF6EUeH54Th4vm/sOcA NaElClpr78okY4E3/sspgaUXC1RrIcA/oLBxM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AfthxglxthghpY683kChANbUrR0tevLjJb3+xvdlXjE=; b=d1Kk4OAGhRtBueWg/oG4WCxnsY27Tl69yKcJTtFAxMJC9bBqMxLAqMhvpl6sOIpcnq DUOVymC5rzr6Ecmv+TK6zFAA/kDiptmhmGXo3WdBUSRZZeS7Yaulkzgcb4+e2y0LEIF9 HUq8/29Gb265e0tA+sRkIhWzxk65ZZXtTkE2fqh4bDL0nEVJPbLFx45OVuzozd4KVqnO wrPYGpyQq+o2fdZa4g72gOw73C+QF7e6w/lH14u0lHDzfqArbJz6gDW8K+341vIQqzaq OZEun0vh5UCVT7Q2D8+Zcq/KPjprXq7EIUrxbHM/2sHXEk46KIjeAKaVOJDLQjbR8qPS cmtg== X-Gm-Message-State: AFeK/H0IExMBrUS7rOVin6I+enkgwzr6yN1nxG6Qt4inGALGbR1deVVaDc8BZ6hCBEYgj408 X-Received: by 10.223.170.200 with SMTP id i8mr3896703wrc.79.1489589301558; Wed, 15 Mar 2017 07:48:21 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mark.cave-ayland@ilande.co.uk, balaton@eik.bme.hu Date: Wed, 15 Mar 2017 14:48:25 +0000 Message-Id: <20170315144825.3108-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::233 Subject: [Qemu-devel] [RFC PATCH] ui/console: ensure graphic updates don't race with TCG vCPUs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org, Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Commit 8d04fb55.. tcg: drop global lock during TCG code execution ..broke the assumption that updates to the GUI couldn't happen at the same time as TCG vCPUs where running. As a result the TCG vCPU could still be updating a directly mapped frame-buffer while the display side was updating. This would cause artefacts to appear when the update code assumed that memory block hadn't changed. The simplest solution is to ensure the two things can't happen at the same time like the old BQL locking scheme. Here we use the solution introduced for MTTCG and schedule the update as async_safe_work when we know no vCPUs can be running. Reported-by: Mark Cave-Ayland Cc: BALATON Zoltan Cc: Gerd Hoffmann Signed-off-by: Alex Benn=C3=A9e Reported-by: Laurent Desnogues Tested-by: Laurent Desnogues --- ui/console.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ui/console.c b/ui/console.c index d1ff7504ec..37a69e27de 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1575,13 +1575,29 @@ bool dpy_gfx_check_format(QemuConsole *con, return true; } =20 +/* + * 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. + */ +static void do_safe_dpy_refresh(CPUState *cpu, run_on_cpu_data opaque) +{ + DisplayChangeListener *dcl =3D opaque.host_ptr; + dcl->ops->dpy_refresh(dcl); +} + static void dpy_refresh(DisplayState *s) { DisplayChangeListener *dcl; =20 QLIST_FOREACH(dcl, &s->listeners, next) { if (dcl->ops->dpy_refresh) { - dcl->ops->dpy_refresh(dcl); + if (tcg_enabled()) { + async_safe_run_on_cpu(first_cpu, do_safe_dpy_refresh, + RUN_ON_CPU_HOST_PTR(dcl)); + } else { + dcl->ops->dpy_refresh(dcl); + } } } } --=20 2.11.0