From nobody Mon Nov 23 04:34:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484202; cv=none; d=zohomail.com; s=zohoarc; b=jldQh7u7mq2tnul2UoUF9fxsFJ/Rj47wsX75t+RKueN9FXOMHZDSiaW0HzgeO7YoYQAjUqq8lCn0wD140bcg3Y26JzbP3OKZVxfqqWt0rgq5BE+Lep7aLo72ZzetxvN/yiRqQXWY5nVWNQLZNlqDPoXsa92bbLPDtakfwcmePuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484202; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=myvU7VHQsjIx1s8dll/6g1zFVCE4Qz+CRbq6HuXdb9g=; b=SrKM5dQvEa42z6r/uM6cPDIv+ETSXxffY9NWQILCPP5VYPm76G9oBZVolmF2LX8fe+3SgEC9zOR0E29TWVbk5a8SBH6FnnPzVrVLjF5koARMaMD+JYQ7kE8N9F1eRJmVcHz5pqoPlfpTPIAmbaOe2Njmek6lHRK5TB9GQcLJkC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484202492452.8721467377186; Thu, 12 Nov 2026 03:50:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTJ2-0003QG-9a; Thu, 12 Nov 2026 06:49:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIz-0003PI-23 for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIw-0001GQ-He for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:24 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-o5D-dvgUNVSy8wzZ3jA42Q-1; Thu, 12 Nov 2026 06:49:08 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 205AE18B5D0F; Thu, 12 Nov 2026 11:49:06 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 79CF830000D3; Thu, 12 Nov 2026 11:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=myvU7VHQsjIx1s8dll/6g1zFVCE4Qz+CRbq6HuXdb9g=; b=iEQ9EchzqYvMfZU4l3s6wLeNJI8j2Vgkt0ZQ5XKnymqvr9LLF8733EeOy39VsVYvZBdBR3 Ud+4Jxr5eA3p49gtzOW7H2S4WLihJ6SG9M8nmZaShHh7tlPzbCB5Xt1yG24PBHxRhyv9Rg CDYR3FqG7xi3IcXC0jrdaCLk2QJaNjE= X-MC-Unique: o5D-dvgUNVSy8wzZ3jA42Q-1 X-Mimecast-MFC-AGG-ID: o5D-dvgUNVSy8wzZ3jA42Q_1794484146 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:44 +0400 Subject: [PATCH 1/7] contrib/vhost-user-gpu: don't fence commands waiting for a reply MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-1-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=5433; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=r45qIpAeabUjtt4mezq9lfM/Kih3ZL/m4hfeTwP/hE0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aepwVq8/8ZaRGI2qe9tbpy8hp9lki1Eb+rh7 V9JuZ4oX/2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqQAKCRDa6OEJdZac 5VzrD/4rgc2oluC9+mkhSdnGFhG6n8L8wsraW1fdXwQKgEDrw2zgB6//z+aN7WOHilfks1I8bUc MoP6vINv5CAn47luW/x3mKOhY9jMjpDBlm1/XByd1hRuTLfkccf6pW87w1GvnYX+B9wWFZNqFF+ eZFA2khZGLnbmhQvonTTvNGB2SCcCvaimISzQ08m5Wt2E+nLR7aZnY52iPJhI24+vO0pWojrWzp IsR0ym+STaOEOQHEq1+Cgq1z8ecLyfNNXIh6iD7RAYvOkB+UDT3Wi2oayvBRJJ8+FthqMR0t8ty YELifJfDtMarpNoTptOiYs1KsKaVucev6todGlEz6TbF6+FSEar6xv14WcEqosWL+cGy31csUsH 32b70bQvaK46Gyg+IKI2Ds/rNGRI3IRwgV+y1m5TEfEYwkyUtA8+DNTGYqhLrp951zAyUmTPJLA AjuMM54ueZItvxKI/rMr7Z4SgGPYe5KlFL9TSzfgAXeg32af9Fgoh3XKKZvgys1o4m52QhgY4iI PZN4Igee3YbKaAp5f3os3Ey6kDjJhjqFj2qzgTht5eQHzLH/m/d5lO4t06NQZkujvsWzCjNgOjp zyD2iJ0cwKCRHDlM3n7/raqlH51v9YQ4aW8NgVLFLORhBVk9nczRFpVPqIFn/Xlm0g5/5P+Vgro YXVandz5funeFRQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484203027158500 virgl_write_fence() completes and frees every command on fenceq whose fence_id is not above the signalled fence, without checking its state. GET_DISPLAY_INFO and GET_EDID wait for a reply from the frontend on that same queue, in VG_CMD_STATE_PENDING with a zero fence_id, so the next signalled fence frees them. The reply callback then takes QTAILQ_LAST() of the queue, which is either empty or another command, and crashes or trips the type assertion. Keep the command that waits for the frontend reply in VuGpu instead, free it from the reply callback, and don't put it on fenceq at all, so that the queue and the inflight count only track commands submitted to virglrenderer. Fixes: bd690feb1554 ("vhost-user-gpu: handle display-info in a callback") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4848 Reported-by: Dmitry R Signed-off-by: Marc-Andr=C3=A9 Lureau Tested-by: Dmitry R --- contrib/vhost-user-gpu/vhost-user-gpu.c | 21 +++++++++++++++------ contrib/vhost-user-gpu/virgl.c | 4 ++++ contrib/vhost-user-gpu/vugpu.h | 3 +++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index f70b34c179f3..5240b171d538 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -268,17 +268,18 @@ get_display_info_cb(gint fd, GIOCondition condition, = gpointer user_data) { struct virtio_gpu_resp_display_info dpy_info =3D { {} }; VuGpu *vg =3D user_data; - struct virtio_gpu_ctrl_command *cmd =3D QTAILQ_LAST(&vg->fenceq); + struct virtio_gpu_ctrl_command *cmd =3D vg->pending_cmd; =20 g_debug("disp info cb"); - assert(cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_DISPLAY_INFO); + assert(cmd && cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_DISPLAY_INFO= ); if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_DISPLAY_INFO, sizeof(dpy_info), &dpy_info)) { return G_SOURCE_CONTINUE; } =20 - QTAILQ_REMOVE(&vg->fenceq, cmd, next); + vg->pending_cmd =3D NULL; vg_ctrl_response(vg, cmd, &dpy_info.hdr, sizeof(dpy_info)); + free(cmd); =20 vg->wait_in =3D 0; vg_handle_ctrl(&vg->dev.parent, 0); @@ -297,6 +298,7 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_c= ommand *cmd) assert(vg->wait_in =3D=3D 0); =20 vg_send_msg(vg, &msg, -1); + vg->pending_cmd =3D cmd; vg->wait_in =3D g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP, get_display_info_cb, vg); cmd->state =3D VG_CMD_STATE_PENDING; @@ -307,17 +309,18 @@ get_edid_cb(gint fd, GIOCondition condition, gpointer= user_data) { struct virtio_gpu_resp_edid resp_edid; VuGpu *vg =3D user_data; - struct virtio_gpu_ctrl_command *cmd =3D QTAILQ_LAST(&vg->fenceq); + struct virtio_gpu_ctrl_command *cmd =3D vg->pending_cmd; =20 g_debug("get edid cb"); - assert(cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_EDID); + assert(cmd && cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_EDID); if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_EDID, sizeof(resp_edid), &resp_edid)) { return G_SOURCE_CONTINUE; } =20 - QTAILQ_REMOVE(&vg->fenceq, cmd, next); + vg->pending_cmd =3D NULL; vg_ctrl_response(vg, cmd, &resp_edid.hdr, sizeof(resp_edid)); + free(cmd); =20 vg->wait_in =3D 0; vg_handle_ctrl(&vg->dev.parent, 0); @@ -344,6 +347,7 @@ vg_get_edid(VuGpu *vg, struct virtio_gpu_ctrl_command *= cmd) assert(vg->wait_in =3D=3D 0); =20 vg_send_msg(vg, &msg, -1); + vg->pending_cmd =3D cmd; vg->wait_in =3D g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP, get_edid_cb, vg); cmd->state =3D VG_CMD_STATE_PENDING; @@ -940,6 +944,11 @@ vg_handle_ctrl(VuDev *dev, int qidx) } } =20 + if (cmd->state =3D=3D VG_CMD_STATE_PENDING) { + /* freed by the frontend reply callback */ + continue; + } + if (cmd->state !=3D VG_CMD_STATE_FINISHED) { QTAILQ_INSERT_TAIL(&vg->fenceq, cmd, next); vg->inflight++; diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 0ef4b9d8c903..3242bf13586d 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -608,6 +608,10 @@ virgl_write_fence(void *opaque, uint32_t fence) * the guest can end up emitting fences out of order * so we should check all fenced cmds not just the first one. */ + if (cmd->state =3D=3D VG_CMD_STATE_PENDING) { + /* not fenced, completed by the frontend reply */ + continue; + } if (cmd->cmd_hdr.fence_id > fence) { continue; } diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index aaf2870cb24d..1c2b0ed4fbe8 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -147,6 +147,9 @@ typedef struct VuGpu { struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS]; QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist; QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq; + + /* command waiting for a reply from the frontend */ + struct virtio_gpu_ctrl_command *pending_cmd; } VuGpu; =20 enum { --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484265; cv=none; d=zohomail.com; s=zohoarc; b=T2QWdCWrqNhD4IchQUB+WxoOEqD72sxnm8kMCek6SOjWXXGCp5S3UXda2vIfi/Mp3exiaQFCZpJ+rS6H6m1Y2OtZ24e03Z7Kcfb6CFsC44VovcSwsUvoL5IRghnwN4tR728mKDXC4Nw7gc0jkySgNsVv5VB4XmroYmn2SwLJJeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484265; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9+Dk5PKwwKRZzq4ORQt8QKccXa6/lnN7ZXCXHfCU4a8=; b=aUMeS0a+gVGrMUOPpSXUD2pON2S6diWtCosKwRH3kYKw0yBoH/Ws8FLZ7S0IJ/C14cS72M6T1JNp4LLMQNviOcpGAOShBgOsKMVcClsP4e9KbO/rk5/fwrt/ipIXOpCnCDiyV5s+PRxkx0kHU0ekv0Qi0eCYDPdUAzHPQI8b8R8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484265747440.73513873119884; Thu, 12 Nov 2026 03:51:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTIy-0003Oz-2j; Thu, 12 Nov 2026 06:49:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIu-0003O9-A2 for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIq-0001G5-Ki for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:18 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-9k37bUFOO-a17texndaanQ-1; Thu, 12 Nov 2026 06:49:11 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 511CE1955F10; Thu, 12 Nov 2026 11:49:10 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CC9C01800446; Thu, 12 Nov 2026 11:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9+Dk5PKwwKRZzq4ORQt8QKccXa6/lnN7ZXCXHfCU4a8=; b=b/hSau9BKva2GPDhy4tFA27FuR5ZxCaq30aIydv9RvnBxKS9mXgdITzkcmAV3WN77zZwvo DmiJqTo8HJe1Fx5yyYEcu5qfFb0SpihI0ssUFlp3wZV7LDYLM8DFKnin35PyTr7c2OZZWz E6fAVoV/lIWMQKsXg+pljqo9IS/RXNA= X-MC-Unique: 9k37bUFOO-a17texndaanQ-1 X-Mimecast-MFC-AGG-ID: 9k37bUFOO-a17texndaanQ_1794484150 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:45 +0400 Subject: [PATCH 2/7] contrib/vhost-user-gpu: reset the frontend socket on stop and start MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-2-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=14162; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=wwg1LaIk5/c0z6ncUSaBpUmvufk9ZxTwtQXKTle7M50=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeqyrCY+d9ioGcqnU3UUXBeTv5hdNXKqw3iL bKRzLvRbdOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5eSAEACnuSs9UrgDUllfhQi+emEoOntLhezQoHZiRi8QB7dSs2RBba8zYwF3FzhRUoYzGZgcpms HRmeXK3zOXEw0VAuF2M2cWMoL7SQPrfWC741l4vkB0zOsvoqvEU2UyrBhVpbI2RXStEZ34XpJSu A9pt70gblmQ85fgs93MVcu34Klx2QAON+KMzTsG3Koz4x2/0yNVzwhOKo/L9m/Bh3i1TuCPTZDg YBP00TWn7Y6O/576bcZBwxgVSpiomBcG5EuSfp+A8AIaqBIH6AUi7ZlUgP9sLb36QKC5tjrpV7c CwTQPCYbzs/qOyRawy9c/JHr5gxUtpl/JeKTMOwKkz9jcx0DyK4PeUbnIMY3eorzgKw18R6CI9/ hGDKGzFA9ftu6+62O/XPeWfJI5y8eXROqfqKzBD5dvbixGgmSDbMtSS++KY+lAlQRnnh7P9uwgA A/8h9iHPBtl/euXXHrYpjSpey6KUxRpt0BQyAOEvS63rUE8BEjklk6BK5MDzM70dBhtHVr56SnK +EPf10vGXFXTJkzFKGcCbfUGnomP86K475L2znhGFGqCx59hwcTB6ljwU4mt0/c5aUO6dxxHSqJ a62zKBfbAIBHY2MdLcThKVKs7x9TJWJBt2PnoPNwhvEliR5bVk+3kMfbVPBo+GJH1G3z6IfZEWy K/qw+dAZ09qV47Q== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484267578158500 vhost_user_gpu_set_status() closes its end of the GPU socket when the device stops and sends a new one with SET_SOCKET on the next start. The backend keeps the old socket until a read or write fails and refuses the new one with g_return_val_if_fail(g->sock_fd =3D=3D -1), so it keeps writing into the dead socket and the guest loses its display. A command waiting for a frontend reply also leaves wait_in set, which blocks the control queue and trips the assertion in set_gpu_protocol_features() on the next start. A zero-length read from the closed socket is not detected as an error either, so the reply source keeps firing on EOF. Replace the previous socket when the frontend sends a new one, cancel any outstanding wait when the control queue stops, and treat a short read as an error. Complete a command left waiting for a reply with an error instead of dropping it, and do not register a wait when the socket is already gone. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4849 Reported-by: Dmitry R Signed-off-by: Marc-Andr=C3=A9 Lureau Tested-by: Dmitry R --- contrib/vhost-user-gpu/vhost-user-gpu.c | 148 ++++++++++++++++++++++++++--= ---- contrib/vhost-user-gpu/virgl.c | 18 ++-- contrib/vhost-user-gpu/vugpu.h | 4 +- 3 files changed, 138 insertions(+), 32 deletions(-) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 5240b171d538..eab52c662775 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -93,35 +93,77 @@ vg_cmd_to_string(int cmd) } } =20 -static int +static ssize_t vg_sock_fd_read(int sock, void *buf, ssize_t buflen) { - int ret; + ssize_t ret; =20 do { ret =3D read(sock, buf, buflen); } while (ret < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 - g_warn_if_fail(ret =3D=3D buflen); + if (ret < 0) { + g_debug("%s: read: %s", G_STRFUNC, g_strerror(errno)); + return -1; + } + if (ret =3D=3D 0) { + g_debug("%s: frontend closed the connection", G_STRFUNC); + return -1; + } + if (ret !=3D buflen) { + g_debug("%s: short read: %zd of %zd bytes", + G_STRFUNC, ret, buflen); + return -1; + } + return ret; } =20 +static void +vg_wait_drop(VuGpu *g) +{ + g_clear_handle_id(&g->wait_in, g_source_remove); + g_clear_pointer(&g->pending_cmd, free); +} + +static void +vg_wait_cancel(VuGpu *g) +{ + if (g->pending_cmd) { + /* the reply won't come, don't leave the guest waiting for it */ + vg_ctrl_response_nodata(g, g->pending_cmd, VIRTIO_GPU_RESP_ERR_UNS= PEC); + } + vg_wait_drop(g); +} + +/* stop waiting for a frontend reply and close the socket */ static void vg_sock_fd_close(VuGpu *g) { + vg_wait_cancel(g); + if (g->sock_fd >=3D 0) { close(g->sock_fd); g->sock_fd =3D -1; } } =20 +/* resume the control queue */ +static void +vg_ctrl_resume(VuGpu *g) +{ + vg_handle_ctrl(&g->dev.parent, 0); +} + static gboolean source_wait_cb(gint fd, GIOCondition condition, gpointer user_data) { VuGpu *g =3D user_data; =20 if (!vg_recv_msg(g, VHOST_USER_GPU_DMABUF_UPDATE, 0, NULL)) { - return G_SOURCE_CONTINUE; + /* vg_recv_msg() closed the socket */ + vg_ctrl_resume(g); + return G_SOURCE_REMOVE; } =20 /* resume */ @@ -131,12 +173,18 @@ source_wait_cb(gint fd, GIOCondition condition, gpoin= ter user_data) return G_SOURCE_REMOVE; } =20 -void +bool vg_wait_ok(VuGpu *g) { assert(g->wait_in =3D=3D 0); + + if (g->sock_fd < 0) { + return false; + } + g->wait_in =3D g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP, source_wait_cb, g); + return true; } =20 static int @@ -169,21 +217,34 @@ vg_sock_fd_write(int sock, const void *buf, ssize_t b= uflen, int fd) *((int *)CMSG_DATA(cmsg)) =3D fd; } =20 + /* the frontend may have gone away, don't raise SIGPIPE */ do { - ret =3D sendmsg(sock, &msg, 0); + ret =3D sendmsg(sock, &msg, MSG_NOSIGNAL); } while (ret =3D=3D -1 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 - g_warn_if_fail(ret =3D=3D buflen); + if (ret < 0) { + g_debug("%s: sendmsg: %s", G_STRFUNC, g_strerror(errno)); + return -1; + } + if (ret !=3D buflen) { + g_debug("%s: short write: %zd of %zd bytes", + G_STRFUNC, ret, buflen); + return -1; + } + return ret; } =20 -void +bool vg_send_msg(VuGpu *vg, const VhostUserGpuMsg *msg, int fd) { if (vg_sock_fd_write(vg->sock_fd, msg, VHOST_USER_GPU_HDR_SIZE + msg->size, fd) < 0) { vg_sock_fd_close(vg); + return false; } + + return true; } =20 bool @@ -198,9 +259,14 @@ vg_recv_msg(VuGpu *g, uint32_t expect_req, uint32_t ex= pect_size, goto err; } =20 - g_return_val_if_fail(req =3D=3D expect_req, false); - g_return_val_if_fail(flags & VHOST_USER_GPU_MSG_FLAG_REPLY, false); - g_return_val_if_fail(size =3D=3D expect_size, false); + if (!(req =3D=3D expect_req && + flags & VHOST_USER_GPU_MSG_FLAG_REPLY && + size =3D=3D expect_size)) { + g_debug("%s: bad reply req=3D0x%x flags=3D0x%x size=3D%u " + "(want req=3D0x%x size=3D%u)", G_STRFUNC, req, flags, size, + expect_req, expect_size); + goto err; + } =20 if (size && vg_sock_fd_read(g->sock_fd, payload, size) !=3D size) { goto err; @@ -274,7 +340,9 @@ get_display_info_cb(gint fd, GIOCondition condition, gp= ointer user_data) assert(cmd && cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_DISPLAY_INFO= ); if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_DISPLAY_INFO, sizeof(dpy_info), &dpy_info)) { - return G_SOURCE_CONTINUE; + /* vg_recv_msg() closed the socket */ + vg_ctrl_resume(vg); + return G_SOURCE_REMOVE; } =20 vg->pending_cmd =3D NULL; @@ -282,7 +350,7 @@ get_display_info_cb(gint fd, GIOCondition condition, gp= ointer user_data) free(cmd); =20 vg->wait_in =3D 0; - vg_handle_ctrl(&vg->dev.parent, 0); + vg_ctrl_resume(vg); =20 return G_SOURCE_REMOVE; } @@ -297,7 +365,10 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_= command *cmd) =20 assert(vg->wait_in =3D=3D 0); =20 - vg_send_msg(vg, &msg, -1); + if (!vg_send_msg(vg, &msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } vg->pending_cmd =3D cmd; vg->wait_in =3D g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP, get_display_info_cb, vg); @@ -315,7 +386,9 @@ get_edid_cb(gint fd, GIOCondition condition, gpointer u= ser_data) assert(cmd && cmd->cmd_hdr.type =3D=3D VIRTIO_GPU_CMD_GET_EDID); if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_EDID, sizeof(resp_edid), &resp_edid)) { - return G_SOURCE_CONTINUE; + /* vg_recv_msg() closed the socket */ + vg_ctrl_resume(vg); + return G_SOURCE_REMOVE; } =20 vg->pending_cmd =3D NULL; @@ -323,7 +396,7 @@ get_edid_cb(gint fd, GIOCondition condition, gpointer u= ser_data) free(cmd); =20 vg->wait_in =3D 0; - vg_handle_ctrl(&vg->dev.parent, 0); + vg_ctrl_resume(vg); =20 return G_SOURCE_REMOVE; } @@ -346,7 +419,10 @@ vg_get_edid(VuGpu *vg, struct virtio_gpu_ctrl_command = *cmd) =20 assert(vg->wait_in =3D=3D 0); =20 - vg_send_msg(vg, &msg, -1); + if (!vg_send_msg(vg, &msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } vg->pending_cmd =3D cmd; vg->wait_in =3D g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP, get_edid_cb, vg); @@ -729,7 +805,9 @@ vg_set_scanout(VuGpu *g, }; =20 if (vugbm_buffer_get_dmabuf_fd(buffer, &fd)) { - vg_send_msg(g, &msg, fd); + if (!vg_send_msg(g, &msg, fd)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } close(fd); } } else { @@ -742,7 +820,9 @@ vg_set_scanout(VuGpu *g, .height =3D scanout->height } }; - vg_send_msg(g, &msg, -1); + if (!vg_send_msg(g, &msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } } } =20 @@ -814,8 +894,12 @@ vg_resource_flush(VuGpu *g, .height =3D height, } }; - vg_send_msg(g, &vmsg, -1); - vg_wait_ok(g); + if (!vg_send_msg(g, &vmsg, -1) || !vg_wait_ok(g)) { + pixman_region_fini(®ion); + pixman_region_fini(&finalregion); + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + break; + } } else { size_t bpp =3D PIXMAN_FORMAT_BPP(pixman_image_get_format(res->image)) / 8; @@ -852,7 +936,9 @@ vg_resource_flush(VuGpu *g, 0, 0, 0, 0, width, height); pixman_image_unref(img); - vg_send_msg(g, msg, -1); + if (!vg_send_msg(g, msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } g_free(msg); } pixman_region_fini(®ion); @@ -1064,12 +1150,16 @@ vg_panic(VuDev *dev, const char *msg) static void vg_queue_set_started(VuDev *dev, int qidx, bool started) { + VuGpu *g =3D container_of(dev, VuGpu, dev.parent); VuVirtq *vq =3D vu_get_queue(dev, qidx); =20 g_debug("queue started %d:%d\n", qidx, started); =20 switch (qidx) { case 0: + if (!started) { + vg_wait_drop(g); + } vu_set_queue_handler(dev, vq, started ? vg_handle_ctrl : NULL); break; case 1: @@ -1093,7 +1183,9 @@ protocol_features_cb(gint fd, GIOCondition condition,= gpointer user_data) =20 if (!vg_recv_msg(g, msg.request, sizeof(protocol_features), &protocol_features)) { - return G_SOURCE_CONTINUE; + /* vg_recv_msg() closed the socket and removed this source */ + vg_ctrl_resume(g); + return G_SOURCE_REMOVE; } =20 protocol_features &=3D (protocol_edid | protocol_dmabuf2); @@ -1126,7 +1218,9 @@ set_gpu_protocol_features(VuGpu *g) .request =3D VHOST_USER_GPU_GET_PROTOCOL_FEATURES, }; =20 - vg_send_msg(g, &msg, -1); + if (!vg_send_msg(g, &msg, -1)) { + return; + } assert(g->wait_in =3D=3D 0); g->wait_in =3D g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP, protocol_features_cb, g); @@ -1140,7 +1234,8 @@ vg_process_msg(VuDev *dev, VhostUserMsg *msg, int *do= _reply) switch (msg->request) { case VHOST_USER_GPU_SET_SOCKET: { g_return_val_if_fail(msg->fd_num =3D=3D 1, 1); - g_return_val_if_fail(g->sock_fd =3D=3D -1, 1); + /* the frontend replaces the socket on device start */ + vg_sock_fd_close(g); g->sock_fd =3D msg->fds[0]; set_gpu_protocol_features(g); return 1; @@ -1230,6 +1325,9 @@ vg_destroy(VuGpu *g) { struct virtio_gpu_simple_resource *res, *tmp; =20 + /* the guest is gone, don't try to complete a pending command */ + vg_wait_drop(g); + vug_deinit(&g->dev); =20 vg_sock_fd_close(g); diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 3242bf13586d..c33b3dbeb8b7 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -120,7 +120,9 @@ virgl_cmd_resource_unref(VuGpu *g, .size =3D sizeof(VhostUserGpuDMABUFScanout), .payload.dmabuf_scanout.scanout_id =3D i, }; - vg_send_msg(g, &msg, -1); + if (!vg_send_msg(g, &msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } g->scanout[i].resource_id =3D 0; } } @@ -439,7 +441,9 @@ virgl_cmd_set_scanout(VuGpu *g, msg.size =3D sizeof(VhostUserGpuDMABUFScanout); } =20 - vg_send_msg(g, &msg, fd); + if (!vg_send_msg(g, &msg, fd)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } close(fd); } else { VhostUserGpuMsg msg =3D { @@ -448,7 +452,9 @@ virgl_cmd_set_scanout(VuGpu *g, .payload.dmabuf_scanout.scanout_id =3D ss.scanout_id, }; g_debug("disable scanout"); - vg_send_msg(g, &msg, -1); + if (!vg_send_msg(g, &msg, -1)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } } g->scanout[ss.scanout_id].resource_id =3D ss.resource_id; } @@ -480,8 +486,10 @@ virgl_cmd_resource_flush(VuGpu *g, .payload.update.width =3D rf.r.width, .payload.update.height =3D rf.r.height }; - vg_send_msg(g, &msg, -1); - vg_wait_ok(g); + if (!vg_send_msg(g, &msg, -1) || !vg_wait_ok(g)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } } } =20 diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index 1c2b0ed4fbe8..bfca1e0484ca 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -205,9 +205,9 @@ void vg_cleanup_mapping_iov(VuGpu *g, struct iovec *= iov, uint32_t count); void vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd= ); void vg_get_edid(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd); =20 -void vg_wait_ok(VuGpu *g); +bool vg_wait_ok(VuGpu *g); =20 -void vg_send_msg(VuGpu *g, const VhostUserGpuMsg *msg, int fd); +bool vg_send_msg(VuGpu *g, const VhostUserGpuMsg *msg, int fd); =20 bool vg_recv_msg(VuGpu *g, uint32_t expect_req, uint32_t expect_size, gpointer payload); --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484195; cv=none; d=zohomail.com; s=zohoarc; b=nJsDqbHYpDiP4cGmuFZxWUfCSRsUr7ozvmW6dANnnA0EKfsNKH5v86ZcMgozkuZmolWL1v1ox6ugvL9phQgGRgl25O5Fxnrs4/E6cVahHdh3E/WGc4mM3Nkicc4Edc0sZRjuUrlvva04LzD7xO8QoPfJarZd0yxb4WdSBfgjzQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484195; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8hJHVPX4Z50d1+1WXrfW7G3PiQ0uGdiOhPghZqI7BLg=; b=eYZcW22FroguresCFfU5TVSm4tbjuA6Go1MGpTe7J/qf4iUTTzTA6VAO8Xi+mcEtBUrGlB8NEgMR5DJKkcFFu+9p7sLNkTlGG+PYZh7BIPInWS2r8vmlKBkiRCtkSHJOHOtd0btwjFBU5CcIGHi2B713LD0aBL6lc6I/A8MlGbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484195429385.82429021595385; Thu, 12 Nov 2026 03:49:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTIz-0003P2-RK; Thu, 12 Nov 2026 06:49:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIu-0003OA-AJ for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIr-0001GB-KJ for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:18 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-Sy_GswzCNhiIRTRcraAhaw-1; Thu, 12 Nov 2026 06:49:14 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DECCB19344BB; Thu, 12 Nov 2026 11:49:13 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AE6D61956086; Thu, 12 Nov 2026 11:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8hJHVPX4Z50d1+1WXrfW7G3PiQ0uGdiOhPghZqI7BLg=; b=H6OAVqhBUqmzNPWfuUkWjXk2OgI+KYclX5h3tLRSHyBFoaX3z8ScLXCtcIAAKsftx9u5gs bR/RdB1+GF2DnOAL2am4DvncmqmiAmuaRgKo/Bi3k5Og25ewu1G/woC8xHnGGJZQIV8b6c lDyDL9qcSdIgGzssezGLjRKb2Vu6AN0= X-MC-Unique: Sy_GswzCNhiIRTRcraAhaw-1 X-Mimecast-MFC-AGG-ID: Sy_GswzCNhiIRTRcraAhaw_1794484154 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:46 +0400 Subject: [PATCH 3/7] hw/display/vhost-user-gpu: reset the console scanout on device reset MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-3-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=1775; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=xJedIrxMbpG+kWmFSdZzdD7IA4dWVdraRUDf0VqaGTQ=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeqaBNRcC5ZILbU+rinFOrkS5mDoh3PFGYFh 0thjkHR7uyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5Q6wD/4zpu8Drhy/M9p9UKCuuucz+o4kbb4fkOBCE+6vAuO+OFRJ1OzM5bmrVzUSkuYFeM6jaDy FpQ3ywEGaopqqABzwopEeuJakKCxdiNdgmUGV/RDvD1+oTF9EBc4qDqJ76M21SqspG1K61qcyWP p1kajT205Ba+HjOroDZfbZjSfumNU09JGVvaP/vurR7hcpxrfbIDEx9WfVXXjjMMlTL0QwQ+mVa q90Eac0vfuXuMbT2FvfzWfevdbYN/HRFbo75VbsvKun9p27/m1fsadmEq750YM+N6BC7CxS25OE 0ZRYMA5YK9rI6du3nSTjl5Bl/nILGhVYwWIJofNeFUw+o7pKrjsjYXV8QsJoKmP0KQM+TfXoB9c nZzY9MFDvvxmmCGTyYs9Sip5VaMlQQB3JQ37e0MuR20xa735d2T+LQhR7HaQwgIaOF3N78wLOU1 BTkolQBdeAkVIMzRS0N5cCIqO9FnnUsX0sJlUuxIIkYjpQuC5rWNwcPeu3gq2Sx3X4PDQjvazaX h/a3wA7o7/VK36gtRlYrQCAMJ4tClp1ixvxFncG4Au20AcZDtkMgDUnMI6qgCbcXLnm+TT0ZlHf Uet3aVybUW1hM2LdQQCcHcz9dloqZgZt1dOqejNQQ/Apx84NpJulIwhzAXYh3LT1fqYeCQlfo2w 6O+uUFePyV6Ctsg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484197289158500 vhost_user_gpu_reset() clears VirtIOGPUBase::enable, which makes the virtio-vga wrapper fall back to the legacy VGA display. The console is left in a GL scanout though, so qemu_console_surface() returns NULL and vga_update_display() dereferences it when the display refreshes: the host crashes on guest reboot or driver reload with a GL display. Release the frontend dmabufs, disable the GL scanout and install a placeholder surface for each output, as virtio_gpu_reset() does for the non vhost-user device. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4846 Reported-by: Dmitry R Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/vhost-user-gpu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index c09aca041135..d3b720d08a73 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -638,6 +638,20 @@ static void vhost_user_gpu_reset(VirtIODevice *vdev) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); + int i; + + /* release the scanouts before virtio_gpu_base_reset() drops ds */ + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[i]; + + /* the guest may have left a GL scanout behind */ + if (g->dmabuf[i]) { + qemu_console_gl_release_dmabuf(scanout->con, g->dmabuf[i]); + g_clear_pointer(&g->dmabuf[i], qemu_dmabuf_free); + } + qemu_console_gl_scanout_disable(scanout->con); + qemu_console_set_surface(scanout->con, NULL); + } =20 virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev)); =20 --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484231; cv=none; d=zohomail.com; s=zohoarc; b=FjGNkW01Xi4fr+KmGEhH0BClIkGw+ManzkRQE+hWHSW0CB9y+fTcTMd7NuZeK276oogQQcO/wBN95R0bKLpMt6cXkm02xuNVoI66bml7iIJsEHI23rN82P0t8K7YuYTgfunvLCCYSPlCt6WicQzZQcFDUu3e7+NtJpRu6vDT9sA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484231; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZCCXCffzQg1+aZAMaqS3SVUhskzDipSFM0OBHr+dK0M=; b=e8sfazb5dWVtajytMsDE8qUreLhUa9TGOsCXG29a4ZgMMT1pe10a85fq1+6QAIKaxhbZkacGp4Ql8alOtZvxGaOb1biibjOhkXrpBgsgDcYsAYgotiuNMSVa2hjz3Lb4K/c3yyqwBao2JSQOmMYYPFMZr9o14XmXKRixD/s8FLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484231646422.91011536539565; Thu, 12 Nov 2026 03:50:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTJ3-0003QR-Jq; Thu, 12 Nov 2026 06:49:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIy-0003PD-U1 for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIx-0001Gx-6r for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:24 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-Pg7VDtzwM0ORXuRB1ZEhvQ-1; Thu, 12 Nov 2026 06:49:19 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B32419344B6; Thu, 12 Nov 2026 11:49:18 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C033518004FF; Thu, 12 Nov 2026 11:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZCCXCffzQg1+aZAMaqS3SVUhskzDipSFM0OBHr+dK0M=; b=TC020tLuLi0urc0ObBnNtdWpEMMRUTiHvxckcNUJzlU3k4yoeoww7F2RZGuylaegjO1f64 KwBPdRt0/9sPPiYIgQqmnabIZEgascwlnScrZ/cs1Thq0/iD22ldgMXZTKAG0Gk3ZKRXqG e4XGTQQ8tLkBj5iWQumnf2JvO+XGmEo= X-MC-Unique: Pg7VDtzwM0ORXuRB1ZEhvQ-1 X-Mimecast-MFC-AGG-ID: Pg7VDtzwM0ORXuRB1ZEhvQ_1794484158 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:47 +0400 Subject: [PATCH 4/7] hw/display/vhost-user-gpu: don't set an fd handler without a socket MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-4-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=1381; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=NgyKPTxBvTPKwm1gJ9ARZN1u4JJqfRY8GI/vAtdhF4Y=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeqbjya2U+5SZFkMeO9GcSXTMQaOmAtmNhiy M4SyQYE3k6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5V97EACzhUbPMFSYVvqJMF50VeWe9xyNxtgcxYS9zTAW9KUP6KR7o6bVMcPElLKSCHZYCQR5hwy YTmfNm9Ady1stKHso8PiR20iPhVdQQCdRZPYwnmJCj6BUceMn0q5bxTdYJjTNQDcmjLwzoOuxm3 D0XJxdJyLuC2AhO2RYZg07HyjWfdOg89CLx0UNLipwkwbNIcYvxnS/UgCwSZYFqYj37MMSoMk2i +em8Tfn5cWyl0eaqo6iB5V8PluyYeAnWYStdkAnn2/vdJuHnkb+bekSwMdYmmQBYMoth/aDOUV4 BXJ7v4jZSE05jIzIlzMpygG+nyYAvVuyIl1beamnkO4EwWUBFyt4XRQgS4fW0NuIHLYhQc119P/ pIaGUm1Y/AwoHT08tckqRLt5bCs381GbTyBIQy98lFJvHREGCjgzjATV4+cCguKWejtiRTuI83W pcTpXqaw0ZdEeqUIHCIjC2+39G4u+vv3bn/AU+AJAS56ygd1jPQEuHHChLuQd9QAzqSW/eQSWeJ 4tJESgRNdFL2H4vEtcxjo+4nFZvX1q8j40LMkcBldU6NVjus+qyRN6CNa/gVWFeBHlW9a+Rg+XP tWGl5O3ohsGUHC1YqqMEC/3AqFLy702uPoSYCqCZVfP5aNXD4ufsubX0zCmtwGKokRooU92ckRX rhX+b+DIAxkatlg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484233240158500 A GL display client that stays attached across a device stop can unblock the console after vhost_gpu_fd has been reset to -1: the UpdateDMABUF reply or the one-second gl unblock timer reach vhost_user_gpu_gl_flushed(), which installs the display socket handler on fd -1. With the io_uring fd monitor, the failed poll of fd -1 is reported as readiness, so the handler runs and is re-armed forever. Only set the handler when the device has a display socket. Fixes: 3cddb8b9e0b5 ("display/ui: add a callback to indicate GL state is fl= ushed") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4847 Reported-by: Dmitry R Signed-off-by: Marc-Andr=C3=A9 Lureau Tested-by: Dmitry R --- hw/display/vhost-user-gpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index d3b720d08a73..d56be53b2964 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -448,6 +448,11 @@ end: static void vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked) { + /* the display socket doesn't exist before DRIVER_OK */ + if (g->vhost_gpu_fd =3D=3D -1) { + return; + } + qemu_set_fd_handler(g->vhost_gpu_fd, blocked ? NULL : vhost_user_gpu_chr_read, NULL, g); } --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484221; cv=none; d=zohomail.com; s=zohoarc; b=eLddSQ5g4213rLeHNrouyqVV8VbkKssgfnAbJI8khCgELeozx014aha8+zP9Af3KNB82O/WuJJancy8sdCMd84ZvRtPKVOro9DxVraiNEdbr60+AZRmYORaSyZRkZU4xdPz1ZSI701JQ8o1zkxwfqtzMeIjt1pBoBRWKAdMvSXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484221; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P7ppEmB3W5GZDtDcQoZJRPsasmUzyF2Ki14ZguYMaZU=; b=lbF9dNw6q7uCE077KIUibZLfZOCUq3NilPwQzUAd4LKz9tITIneqZTGaZQZgS9We+b3MroAbz3+UY96p2XYWhwQDoz91qPefqlnOkcbZQ09/xptHjLEWTJhqOH9Jo5VEoyg/7oCSTovrN0m3RIvaE+mhUdtxKOyZ19Lwg88BeSc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484221654977.0989751874989; Thu, 12 Nov 2026 03:50:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTJ5-0003RB-GQ; Thu, 12 Nov 2026 06:49:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTJ1-0003QE-RE for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTIy-0001HD-Sb for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:26 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-HTlQ0goHOqCuMgPIcFzjlg-1; Thu, 12 Nov 2026 06:49:22 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 88C12181C5C3; Thu, 12 Nov 2026 11:49:21 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9027818004D2; Thu, 12 Nov 2026 11:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P7ppEmB3W5GZDtDcQoZJRPsasmUzyF2Ki14ZguYMaZU=; b=OkpoG1RI+hY4B8z9AogJxrQczTsqHyMecjZOOXSoFljZ7xw1Ia/6g9ejltCad9/bDXaeUl U9dOeMhiJQcaWjrJOXTl+9p4OHCIiJASO5J4r8iDIMUgbN5nMbhNSZRj0Vbj7xkcsAhQdo JV5nQMJHpZdIYzUcyDfdp+XZkPKEG/0= X-MC-Unique: HTlQ0goHOqCuMgPIcFzjlg-1 X-Mimecast-MFC-AGG-ID: HTlQ0goHOqCuMgPIcFzjlg_1794484161 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:48 +0400 Subject: [PATCH 5/7] hw/display/vhost-user-gpu: resize the console on dmabuf scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-5-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=2637; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=NppntYNabgr84svQRwdgy12fbFyOBlj4Y77Z4w+/OWw=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeq4M8L/4w5O1bM9qAEaJFtLB8uCYdu8lskY DZyVUO+NriJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5QFcEACkFkUHxNijqkuYCRzNiO2cRGTHrI+a8q76WP/lSBuMdkP1xCiAosY7Yo5P+O/t7ZBy0jc gekCFbLtSXtj8iId47yXcCodGQeP2AvNlDscjGWEK9xjuE5ovibYt48E1dnhN+hh8vWkPxXR0II 2EAXrO+3+PMQGX1lKoI/9nHQwkMDQMmtuPbKKHpGFtf8MvSVx7QzNAwCYBTaZC7fWUxb2BdqB5I BThMl1WsxWktdT6r9rr1+Prn/HJOpVz0RIC8ih++rv9zYZ/2BDugLGJb3B0Qu5poi+rfPLR5545 N4nV9etaNErtLHwD9VSa8eyvSxjH+1M8XyWzqOpihiIbL9xj1GrlSloGt77o6BqBA90a1IHoICm kzx4v16DNipRZgGWipqe/USklLCAIwRXNIyR7pgF03r5TRQNRrpRMiNQ9l6e93Yg/8XOo6ghNHb hGFIdm5M4/wYYWm7vscLWwf23B+8lUh3ti2kqWOxdvZCYlYkQYrSSR1GS3Su1p4sBXq/4gn3mQe Yf/+AK6wkDIwK11CekD9NqB1CKrvjwsuw6KrKLf5bpIUWKTLnU84LKNMj7du3s2xMKGX2frRpfl 1Qj4B7p5794QlapVHlZYQbMkdOBUSfbm6rxXvFBBA6/eleLIZRgxaz6uoh0+CzgyYpI+OApwxog 6gCnBTIF5u2Im4g== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484223117158500 The frontend installs the backend dmabuf with qemu_console_gl_scanout_dmabuf() and never resizes the console, unlike the in-process virgl/udmabuf paths. The console surface, and with it the UI window and the EDID preferred mode reported to the guest, stay at the initial size, so the guest display is scaled. Resize the console to the scanout first, and release the previous dmabuf only after the new one is installed, as virtio_gpu_update_dmabuf() does. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/vhost-user-gpu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index d56be53b2964..4eab482f2181 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -278,7 +278,7 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUse= rGpuMsg *msg) uint32_t offset =3D 0; uint32_t stride =3D m->fd_stride; uint64_t modifier =3D DRM_FORMAT_MOD_INVALID; - QemuDmaBuf *dmabuf; + QemuDmaBuf *old, *dmabuf; =20 if (m->scanout_id >=3D g->parent_obj.conf.max_outputs) { error_report("invalid scanout: %d", m->scanout_id); @@ -290,16 +290,14 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostU= serGpuMsg *msg) =20 g->parent_obj.enable =3D 1; con =3D g->parent_obj.scanout[m->scanout_id].con; - dmabuf =3D g->dmabuf[m->scanout_id]; - - if (dmabuf) { - qemu_console_gl_release_dmabuf(con, dmabuf); - g_clear_pointer(&dmabuf, qemu_dmabuf_free); - } + old =3D g->dmabuf[m->scanout_id]; =20 if (fd =3D=3D -1) { + if (old) { + qemu_console_gl_release_dmabuf(con, old); + g_clear_pointer(&g->dmabuf[m->scanout_id], qemu_dmabuf_fre= e); + } qemu_console_gl_scanout_disable(con); - g->dmabuf[m->scanout_id] =3D NULL; break; } =20 @@ -315,8 +313,14 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUs= erGpuMsg *msg) &fd, 1, false, m->fd_flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP); =20 + qemu_console_resize(con, m->width, m->height); qemu_console_gl_scanout_dmabuf(con, dmabuf); g->dmabuf[m->scanout_id] =3D dmabuf; + + if (old) { + qemu_console_gl_release_dmabuf(con, old); + qemu_dmabuf_free(old); + } break; } case VHOST_USER_GPU_DMABUF_UPDATE: { --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484192; cv=none; d=zohomail.com; s=zohoarc; b=WOlG34Vc0UlS9hXy5HwLtMtCl7N341/f+sN9MiQJywDu/9HKZqqP2B7KwHdDtN4hUUgR9beghHkdMp9rgRbkSH9ca8wYuvz8rE1BLSNP/bVAMUp4NSikHwf8exBPxrhs4OthMHaHXx2KAAamThoWmeoMyvICCQrhmaTfJz8JEHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484192; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0YpShDEABGAmkxbnH3ihAp/aiDpRuOyakw9qerQE6qo=; b=IJBSp6J/+ujcDlJAf1yAGvyh0pgN7outx3kUCZutZh+FAJY71QikK3iWBvRTenZ+Qr9MuXGxIyuD4C5DSkfhVPDnU61yp4dOk334ShAGoF5ALzvep8cX5zQjtEpPkJ9MN3nI6LkSW6l9JoLnUESBetIM72TQl0NJ3E1APJHMOGw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484192679451.2532764759046; Thu, 12 Nov 2026 03:49:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTJ6-0003RQ-9e; Thu, 12 Nov 2026 06:49:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTJ4-0003R2-5N for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTJ2-0001Hu-JZ for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:29 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-hxR1MSrMPjqR51R1VKeGNA-1; Thu, 12 Nov 2026 06:49:26 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 23E56196C409; Thu, 12 Nov 2026 11:49:25 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4A4331800543; Thu, 12 Nov 2026 11:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0YpShDEABGAmkxbnH3ihAp/aiDpRuOyakw9qerQE6qo=; b=d6Ytd9TL4DTd2oIbLUP4NU/AI1mM+nvhTTivAyjv0iQLJ3fwn0c3WgK+OtQxHq4khVbGc/ QoaAndm7scMqh7KO+Qr3jxeNJRtdcCu2hNiqWDbXPEtr5DYdywfEMJow4VYJE5QwS4ZBHC TG49Op0WAfUDeGWWigY+/JhlsYfen70= X-MC-Unique: hxR1MSrMPjqR51R1VKeGNA-1 X-Mimecast-MFC-AGG-ID: hxR1MSrMPjqR51R1VKeGNA_1794484165 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:49 +0400 Subject: [PATCH 6/7] hw/display/vhost-user-gpu: fix scanout bookkeeping on the 2D path MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-6-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=3963; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=G/0MOx9MYapqfTMthJ2kS8S+QQ/MEe/7lXPDMexj9Fo=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeqIsoMd3USOHG2imD+cNhi/BTGGzuQM298o RAhhurra9KJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5UvHD/4i/Dsnvgbqu5M5d9+85Eg7MZ+aKsssWVqMk4tk6lAAaiuAeHNGdGvTjC9G1GARYV7CC60 cbFq3ft00GGpbxI165dpIPnLOpejCWKDygx+1Wek/CtvMJVG5LGVGFK0BE5pK2xp/IIuRCvL3xW L7y12X+Is4rgznDyLgPUBXULPtFLiKScmNlfUf7Gr/M4BQFvKtacNPzkoD9OjeDT8c/0f/SLw6S rYmV3gR6XpkAHKrMShaeUoxXk9ODuAH2CjD2IduSXESlcUv5+8ItdbMolwSDcE7oJQo3iB+fm9D ZmWLDMT5tDY499439WqhzqTcGrI6mHTGA47gpGNf/X+dmXdorz6Ows/O826PNzUE/93D8JdQ6h+ J0vYwqhB8VP9Xym8Vc3g1dgwER/IkdXarG8DAK4lwk6qBTJqLuyaIRmesu2qrY82QY5BOcqC+2W MPKErQxcu/xwaL9+N4ZR8I7A2HxOvgxGKsOEoIwXT5COz16t9F+X6GiGHaLzcha/6xGS4r8mslz xw3KcBYwLcSnCsxywER+I5eH5C0j3UtuZYPk71fN5kyZhQLHwR2/tlnhqHsVrqk7IRQDPYGXUxi C67WFraV1DIPYKNazG77D7mXoKIRsTVVodKJMmWkkQS4PvWxpM4/VqU1O+c9/nmSxW/nL5nGi5v t9Q8HT1JzdbP55Q== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484194942158500 The 2D and dmabuf scanout paths disagreed on who owns virtio_gpu_scanout::ds and on when the frontend dmabuf is released. Disabling the scanout (width =3D=3D 0) installs a placeholder surface through qemu_console_set_surface(), which frees the surface it replaces, leaving ds dangling. The next VHOST_USER_GPU_UPDATE then composited into the freed surface and installed it again. Only free a surface the console did not install, and drop updates that arrive without a scanout surface. Fixes: 267f664658fe ("hw/display: add vhost-user-vga & gpu-pci") Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/vhost-user-gpu.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 4eab482f2181..63776ab30ac5 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -192,6 +192,19 @@ vhost_user_gpu_unblock(VhostUserGPU *g) vhost_user_gpu_send_msg(g, &msg); } =20 +/* + * A surface not installed on the console is owned by the device, the + * installed one is freed by qemu_console_set_surface(). + */ +static void +vhost_user_gpu_clear_scanout_ds(struct virtio_gpu_scanout *s) +{ + if (s->ds && s->ds !=3D qemu_console_surface(s->con)) { + qemu_free_displaysurface(s->ds); + } + s->ds =3D NULL; +} + static void vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) { @@ -262,6 +275,13 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUs= erGpuMsg *msg) s =3D &g->parent_obj.scanout[m->scanout_id]; con =3D s->con; =20 + if (g->dmabuf[m->scanout_id]) { + qemu_console_gl_release_dmabuf(con, g->dmabuf[m->scanout_id]); + g_clear_pointer(&g->dmabuf[m->scanout_id], qemu_dmabuf_free); + } + + vhost_user_gpu_clear_scanout_ds(s); + if (m->width =3D=3D 0) { qemu_console_set_surface(con, NULL); } else { @@ -289,7 +309,8 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUse= rGpuMsg *msg) } =20 g->parent_obj.enable =3D 1; - con =3D g->parent_obj.scanout[m->scanout_id].con; + s =3D &g->parent_obj.scanout[m->scanout_id]; + con =3D s->con; old =3D g->dmabuf[m->scanout_id]; =20 if (fd =3D=3D -1) { @@ -297,6 +318,7 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUse= rGpuMsg *msg) qemu_console_gl_release_dmabuf(con, old); g_clear_pointer(&g->dmabuf[m->scanout_id], qemu_dmabuf_fre= e); } + vhost_user_gpu_clear_scanout_ds(s); qemu_console_gl_scanout_disable(con); break; } @@ -306,6 +328,8 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUse= rGpuMsg *msg) modifier =3D m2->modifier; } =20 + vhost_user_gpu_clear_scanout_ds(s); + dmabuf =3D qemu_dmabuf_new(m->width, m->height, &offset, &stride, 0, 0, m->fd_width, m->fd_height, @@ -360,6 +384,11 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUs= erGpuMsg *msg) =20 s =3D &g->parent_obj.scanout[m->scanout_id]; con =3D s->con; + if (!s->ds) { + error_report("vhost-user-gpu: no 2D scanout surface" + " for scanout %d", m->scanout_id); + break; + } pixman_image_t *image =3D pixman_image_create_bits(PIXMAN_x8r8g8b8, m->width, @@ -659,6 +688,7 @@ vhost_user_gpu_reset(VirtIODevice *vdev) g_clear_pointer(&g->dmabuf[i], qemu_dmabuf_free); } qemu_console_gl_scanout_disable(scanout->con); + vhost_user_gpu_clear_scanout_ds(scanout); qemu_console_set_surface(scanout->con, NULL); } =20 --=20 2.56.0.116.g6de20f6092dc From nobody Mon Nov 23 04:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1794484198; cv=none; d=zohomail.com; s=zohoarc; b=jjr4Me+luqoeTRDBe4zpNNoMuxUVMhuGJvD/IUKkgZIlI665ZAQ0EQ0tBEFu12cOzTp4q9hMWYn7azpvMb4eYnB9dmhbUAmOKr8EV2ZzyknLt+GY8b2zAm1mxhelwB03E1eypc+7w4zw5+VppvkbUXvjP5cZvv2AidfTQpev5Us= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484198; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=op7BkSuNZ8Zbo574r/FSSFlJolfv/40A7UhIg6j8YTE=; b=AKj3zlWmpcNUZM+zLY8HBgs/6h7u/VdoOvNwcXmnK1RE5AxXYkmjnEnS9BBDz1UiolPrUX2xjbuOcZkohCdWokhzIh4QvZEj1Yg8Qv3x8XE/nWW1M8lotZpYwrv0b1UfS0ia1JOLopyv49LX5avDvVF8b6C7YDG2Ms+qHxuEs/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794484198171859.312279407197; Thu, 12 Nov 2026 03:49:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRTJB-0003V8-Du; Thu, 12 Nov 2026 06:49:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTJ9-0003Tg-4P for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRTJ7-0001IS-Cy for qemu-devel@nongnu.org; Thu, 12 Nov 2026 06:49:34 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-gM_cOSHfNgmrs7x8ztacMg-1; Thu, 12 Nov 2026 06:49:29 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 72E2618ABC4F; Thu, 12 Nov 2026 11:49:28 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 88AA5421; Thu, 12 Nov 2026 11:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794484172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=op7BkSuNZ8Zbo574r/FSSFlJolfv/40A7UhIg6j8YTE=; b=OZ45JMbS9MNCSPaQ62PcmyY2fJDDr2xU+1XdvD9Vho9yn1QbMyDhGJXdAQ7Jz+RskrZsUP uhSVUL3FV/0ARBEMUtKNps9ELhHkGkvOyKaHQo7nvmIRqaumKs05eWpvLnEXcWxZTLl+1Q UsTssQoacuTrgYcXi/E8ZH9KvBC44ME= X-MC-Unique: gM_cOSHfNgmrs7x8ztacMg-1 X-Mimecast-MFC-AGG-ID: gM_cOSHfNgmrs7x8ztacMg_1794484168 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 12 Nov 2026 15:48:50 +0400 Subject: [PATCH 7/7] contrib/vhost-user-gpu: use the stride of the exported dmabuf MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-issue-4848-v1-7-aeba1cfe2c03@redhat.com> References: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> In-Reply-To: <20261112-issue-4848-v1-0-aeba1cfe2c03@redhat.com> To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Dmitry R , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Stefano Garzarella X-Developer-Signature: v=1; a=openpgp-sha256; l=3629; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=JgsUB5ABXypFnT7exHfSKyy7d0nafDLzLCjvZIaAWyk=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBq9aeqqjLZ7Nm/sycqIBn6pjv3yA488OKxCisFH CHoVkJuR0yJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCavWnqgAKCRDa6OEJdZac 5UpTEACEF/r7NKTuGlA1Fu6xko8nzS/tt7b4y95ZKAGtnGTRnRwh6BjEAXzhGOKhdJtw3WqkxBX uGAIaey872l95lBxZc6Lhfzu2ALAWohOud9irIbYRjLedlhYsWWxYvJ7QYBNZly27wha89T5XXV 00KIjrDxVxTRT1CJzikCzi45pF824UgAeSEoJql/7UxnVuzrcqWtNV0HvrUgVDpDyBw9vZDXWyi fq+eiXEUOI80cmRoQ2UucaMYyA+5pCI0WWnP29FbvVvrq49rfE1y1dojM/b9/Luzxs2NrZxTEDC rFOcPsFMILIgGTZXIhTE9Rycq/K4FHtmLffYUzCCAq3ZYlGBijdvJWEUVNXwEBnEiOyq8nZVo4v b7+8wAV6cDF9qXPVoc1IJNUJtX1ojFHG1AAA3zXw+pnDaPkJUYiFeLVrmzdVAa1tSLRz33YWp/P 1Cs7R593RzD/9Ib9ZkUEbYIlst2chflLAxQxM6JXjzrnHHrFaEE0hs434+JOBZT26iEZRikrhDh Lsx1qecusuYEP96GY8wjrr053qs8INQLipr3cdc7rV1TqcuxCOxrrRPbEuUxMpgVcFoxQdCIqPO d9oBkrEjqyRERGIz5VLVPDqfN6ZEe3yb7PMp8uPNHsLh2z0WPOHsAKXAb/UMy1LqX7vQN5dx8kP lYyYc96Qk/FtRFQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1794484198948158500 virgl_renderer_get_fd_for_texture2() returns the stride and offset that eglExportDMABUFImageMESA() gave the exported dmabuf. Use that stride. Reject a scanout with a non-zero offset, as the scanout message has no field to carry it. This fixes dmabuf import/sheared with Intel driver when the resolution stride is not 256-byte aligned. Left for later (after 11.2 release), add new message / field for offset. Signed-off-by: Marc-Andr=C3=A9 Lureau --- contrib/vhost-user-gpu/virgl.c | 48 +++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index c33b3dbeb8b7..4ab2c5fcdafc 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -18,6 +18,23 @@ =20 #include =20 +/* + * VIRGL_CHECK_VERSION available since libvirglrenderer 1.0.1 and was fixed + * in 1.1.0. Undefine bugged version of the macro and provide our own. + */ +#if defined(VIRGL_CHECK_VERSION) && \ + VIRGL_VERSION_MAJOR =3D=3D 1 && VIRGL_VERSION_MINOR < 1 +#undef VIRGL_CHECK_VERSION +#endif + +#ifndef VIRGL_CHECK_VERSION +#define VIRGL_CHECK_VERSION(major, minor, micro) \ + (VIRGL_VERSION_MAJOR > (major) || \ + VIRGL_VERSION_MAJOR =3D=3D (major) && VIRGL_VERSION_MINOR > (minor) |= | \ + VIRGL_VERSION_MAJOR =3D=3D (major) && VIRGL_VERSION_MINOR =3D=3D (min= or) && \ + VIRGL_VERSION_MICRO >=3D (micro)) +#endif + void vg_virgl_update_cursor_data(VuGpu *g, uint32_t resource_id, gpointer data) @@ -409,12 +426,33 @@ virgl_cmd_set_scanout(VuGpu *g, } =20 int fd =3D -1; - if (virgl_renderer_get_fd_for_texture(info.tex_id, &fd) < 0) { - g_critical("%s: failed to get fd for texture\n", __func__); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; - return; + int stride =3D info.stride; + int offset =3D 0; + bool exported =3D false; + +#if VIRGL_CHECK_VERSION(0, 7, 0) + exported =3D virgl_renderer_get_fd_for_texture2(info.tex_id, &fd, + &stride, &offset) = =3D=3D 0; +#endif + if (!exported) { + stride =3D info.stride; + offset =3D 0; + if (virgl_renderer_get_fd_for_texture(info.tex_id, &fd) < 0) { + g_critical("%s: failed to get fd for texture\n", __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } } assert(fd >=3D 0); + + if (offset) { + /* the scanout message has no field to carry the buffer offset= */ + g_critical("%s: unsupported dmabuf offset %d\n", __func__, off= set); + close(fd); + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + VhostUserGpuMsg msg =3D { .payload.dmabuf_scanout.scanout_id =3D ss.scanout_id, .payload.dmabuf_scanout.x =3D ss.r.x, @@ -423,7 +461,7 @@ virgl_cmd_set_scanout(VuGpu *g, .payload.dmabuf_scanout.height =3D ss.r.height, .payload.dmabuf_scanout.fd_width =3D info.width, .payload.dmabuf_scanout.fd_height =3D info.height, - .payload.dmabuf_scanout.fd_stride =3D info.stride, + .payload.dmabuf_scanout.fd_stride =3D stride, .payload.dmabuf_scanout.fd_flags =3D info.flags, .payload.dmabuf_scanout.fd_drm_fourcc =3D info.drm_fourcc }; --=20 2.56.0.116.g6de20f6092dc