From nobody Thu May 2 15:28:19 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.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532068382772438.97539719024996; Thu, 19 Jul 2018 23:33:02 -0700 (PDT) Received: from localhost ([::1]:46635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgOyA-0005rs-OJ for importer@patchew.org; Fri, 20 Jul 2018 02:32:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgOwe-0005IQ-2c for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgOwb-0007d5-Tl for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:16 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:50787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fgOwb-0007cd-M7 for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:13 -0400 Received: by mail-wm0-x241.google.com with SMTP id v25-v6so8373028wmc.0 for ; Thu, 19 Jul 2018 23:31:13 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-156-57.clienti.tiscali.it. [78.12.156.57]) by smtp.gmail.com with ESMTPSA id t140-v6sm1232459wmd.14.2018.07.19.23.31.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 23:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=t/0luRRBSugvQckUMedWczmnmJ5dw3DLmlDA8sj4QFw=; b=VxuuDPRv8ILvVv6fMX8ynrnZDUiULkv7WAJaW8C2XSxj89bklI/ge56943StOHa2O9 1yirEmheq3upOHme3biQ95d4YYarq+314ASjlXv/Egh5oov0gdLNYhXZj/7yVCgGn1pU 1aqeUSd4/OTyfGUj2ey8wvVyO+6VebJWipdWEv0e9ZnWzeHec/T3wZyqBsnxqfFIHPPq KiZmbk4bKOvEQCm1+aWe+L+dVyXn1t+NtfBZETswfdaWdIqgacfMfxgXg1AQJWxfw06a yX25gVTODIR69yb8sci34c+TaxRcSTH6KUKoED3UNDdqIrROHK0+1Vc4jGPXU7ewBzJY zRFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=t/0luRRBSugvQckUMedWczmnmJ5dw3DLmlDA8sj4QFw=; b=al4LqeIP9EXpmn0K/Zze7RBGp9GwCOBFod0LyHi0DYO03RqO1sGu5kM2QG6M0k/1tT CUpZUl7IGaj7jKPFYRBwWL62OdB410c6BaNC9ONhhwFYVsFgifwuCrXfsQnFZpnb7aRa yF7DdrzRwKR+WnEekkC0ViO1dQcQ0TJR8L4ymm75U+tabqVwQbfvWko1hOHSNL9UpDqX WGbZ1m5RJ+FFEVn3pD0LEjZ/pQNZzIjrOjcOxG9VjKKtQmzoCLRiBPn6fR+VlcXdKuct BHS7jrsruSxeslJWYYWA2nOlIMsXKEoILD2UYYc+WoR/O0BBKjxLAZE3fuxbuoiq1wAj nURw== X-Gm-Message-State: AOUpUlH5RT2wn4hM8WPBl4DulvIoQyiCMu46bhJeby3VFUdwPcD4WnFC rhcif9r+KFim4irpRZSMedv/CkOV X-Google-Smtp-Source: AAOMgpec38jmgxLTk10nkHrp1firnBnO1L/Ok2BuouZP+z+//cuufQl4Sg4Z8lye5ONFeLtmSA/qVg== X-Received: by 2002:a1c:1802:: with SMTP id 2-v6mr621765wmy.81.1532068272522; Thu, 19 Jul 2018 23:31:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 20 Jul 2018 08:31:08 +0200 Message-Id: <20180720063109.4631-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180720063109.4631-1-pbonzini@redhat.com> References: <20180720063109.4631-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 1/2] spice-display: access ptr_x/ptr_y under Mutex 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?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The OpenGL-enabled SPICE code was not accessing the cursor position under the SimpleSpiceDisplay lock. Fix this. Signed-off-by: Paolo Bonzini Reviewed-by: Marc-Andr=C3=A9 Lureau --- ui/spice-display.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index fe734821dd..46df673cd7 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -976,8 +976,10 @@ static void qemu_spice_gl_cursor_position(DisplayChang= eListener *dcl, { SimpleSpiceDisplay *ssd =3D container_of(dcl, SimpleSpiceDisplay, dcl); =20 + qemu_mutex_lock(&ssd->lock); ssd->ptr_x =3D pos_x; ssd->ptr_y =3D pos_y; + qemu_mutex_unlock(&ssd->lock); } =20 static void qemu_spice_gl_release_dmabuf(DisplayChangeListener *dcl, @@ -1055,10 +1057,15 @@ static void qemu_spice_gl_update(DisplayChangeListe= ner *dcl, } =20 if (render_cursor) { + int x, y; + qemu_mutex_lock(&ssd->lock); + x =3D ssd->ptr_x; + y =3D ssd->ptr_y; + qemu_mutex_unlock(&ssd->lock); egl_texture_blit(ssd->gls, &ssd->blit_fb, &ssd->guest_fb, !y_0_top); egl_texture_blend(ssd->gls, &ssd->blit_fb, &ssd->cursor_fb, - !y_0_top, ssd->ptr_x, ssd->ptr_y); + !y_0_top, x, y); glFlush(); } =20 --=20 2.17.1 From nobody Thu May 2 15:28:19 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.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532068472626560.5226450501992; Thu, 19 Jul 2018 23:34:32 -0700 (PDT) Received: from localhost ([::1]:46640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgOzn-0006lj-Gr for importer@patchew.org; Fri, 20 Jul 2018 02:34:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgOwe-0005IT-9h for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgOwd-0007e4-5x for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:16 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:53888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fgOwc-0007dQ-VT for qemu-devel@nongnu.org; Fri, 20 Jul 2018 02:31:15 -0400 Received: by mail-wm0-x22a.google.com with SMTP id s9-v6so8352223wmh.3 for ; Thu, 19 Jul 2018 23:31:14 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-156-57.clienti.tiscali.it. [78.12.156.57]) by smtp.gmail.com with ESMTPSA id t140-v6sm1232459wmd.14.2018.07.19.23.31.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 23:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=jX0LD5cYSrlcxj+e6wdEPAsapqid8mPyXiVaT8iaWfo=; b=jxYw0Rau+N9pNX2o6suMesNk26tZNjX2pzajPfR8TZGtNWRAl8Tq7Ub/dVoVZXRWDP tAg7e9SkxL3jL3DJv237j3ckFlLecKq51bepSBE2AzeQQk2kSJLwHDDulGSizhOQYEjm BtZHBdjapN9zfRsvSkcVMZyTpekUZZ/l8Fep3eUbAN4ztrn9G4Ff6mRNgyU29TdYpc5T BEaaKF3ampdAjJwQK0a2hjSJwOB7nfHi0f50RGYJINqPqXz6dPyJAIi0nCPSX3fXRdCw ASKyyfvH96cd8aC3ZlfY1deDnc+vvwt1VVpGKCUldDyvyQyQIlvBN+AYUqnufGqRVRcH qYmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jX0LD5cYSrlcxj+e6wdEPAsapqid8mPyXiVaT8iaWfo=; b=em9EVQj5YXlJa6fE/LqqGyo9MF7tc/SYzo8UF9lsJV9h97OpezLwL1st7XnvVzpbO3 BXG3UUaoNCCeWtT1QQOdhi30dcIlSsHkxQTWZWm+g1azG8McCxNr/5wmLRhKi0TTNF5X k+D+F7vY/VwEXhJcrk9qvOCKai7keOcaK6CgQwsIYbo0wnrJ2l7UnPRouLYWqOWgmuis AkfkDFF8py5lyyzXGXNHHfkLvw56X31BhQ7I3KtgVVGBfnGq4VhuC6bW2CfTN4PCrTA9 P9mc6qRhmyp0WF3rFshm4+rVGTOh28hGSQjqNJpM4MZyZI02gLfmHnRzbPYK8cs5js/9 3KzA== X-Gm-Message-State: AOUpUlFIPngYy2xW2Yq3pwNK0iEabXn45IMT1+ar1KDhbN8xvcvMmrf3 4sbGZ9KTYorZh3+B087un0zzjY1Q X-Google-Smtp-Source: AAOMgpea3N4efdGn7KeSvDTaVWPWqDAoKbS52Dkv+de0tt+5tOnnHJUy1e1QsryJmpeKvObpRHbE7Q== X-Received: by 2002:a1c:7501:: with SMTP id o1-v6mr672826wmc.133.1532068273734; Thu, 19 Jul 2018 23:31:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 20 Jul 2018 08:31:09 +0200 Message-Id: <20180720063109.4631-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180720063109.4631-1-pbonzini@redhat.com> References: <20180720063109.4631-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22a Subject: [Qemu-devel] [PATCH 2/2] spice-display: fix qemu_spice_cursor_refresh_bh locking 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?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" spice-display should not call the ui/console.c functions dpy_cursor_define and dpy_moues_set with the SimpleSpiceDisplay lock taken. That will cause a deadlock, because the DisplayChangeListener callbacks will take the lock again. It is also in general a bad idea to invoke generic callbacks with a lock taken, because it can cause AB-BA deadlocks in the long run. The only thing that requires care is that the cursor may disappear as soon as the mutex is released, so you need an extra cursor_get/cursor_put pair. Signed-off-by: Paolo Bonzini Reviewed-by: Marc-Andr=C3=A9 Lureau --- ui/spice-display.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 46df673cd7..f1d341091a 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -450,29 +450,35 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ss= d, qemu_mutex_unlock(&ssd->lock); } =20 -static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd) +void qemu_spice_cursor_refresh_bh(void *opaque) { + SimpleSpiceDisplay *ssd =3D opaque; + + qemu_mutex_lock(&ssd->lock); if (ssd->cursor) { + QEMUCursor *c =3D ssd->cursor; assert(ssd->dcl.con); + cursor_get(c); + qemu_mutex_unlock(&ssd->lock); dpy_cursor_define(ssd->dcl.con, ssd->cursor); + qemu_mutex_lock(&ssd->lock); + cursor_put(c); } + if (ssd->mouse_x !=3D -1 && ssd->mouse_y !=3D -1) { + int x, y; assert(ssd->dcl.con); - dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1); + x =3D ssd->mouse_x; + y =3D ssd->mouse_y; ssd->mouse_x =3D -1; ssd->mouse_y =3D -1; + qemu_mutex_unlock(&ssd->lock); + dpy_mouse_set(ssd->dcl.con, x, y, 1); + } else { + qemu_mutex_unlock(&ssd->lock); } } =20 -void qemu_spice_cursor_refresh_bh(void *opaque) -{ - SimpleSpiceDisplay *ssd =3D opaque; - - qemu_mutex_lock(&ssd->lock); - qemu_spice_cursor_refresh_unlocked(ssd); - qemu_mutex_unlock(&ssd->lock); -} - void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) { graphic_hw_update(ssd->dcl.con); --=20 2.17.1