From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230884165911.0393034459531; Fri, 27 Feb 2026 14:21:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bc-000645-M1; Fri, 27 Feb 2026 17:19:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Ba-00063n-P8 for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:51 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6BX-0007m5-OU for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:49 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230788; x=1803766788; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mSJwk8OL8GT7Kwlz7h7yRvXBaRvRP8lpklTQLrCYMRk=; b=NHDXAbw8+2HHCV+LIIA2Y8X3MAJvfWQOVE+NJjbZlY1xFmHu9Bt2ooO6 wI2UfFiVxXZ/dJ+8BdyMegpbIcCSHEKAYv/imhrZX1NQiDJLwYKYba6PD I+lV8xxq4NPMxaXVCz5H+7EuY2N81fGgNkQHNRZGligh/bKikF+yUoSIV cVjyBmf47sokAnC8ldxtxoOYX+dxGnaz8k5MLbCfowQuLre4t12N7TKlR vLvyuODMbW+FPVzL2W2QVnMb1AJtjhRHo7wybKHv4N+zrOpDh2RCtRlFO kQq4/uwajJs/pwFLFhJBydootTZloc8RGb0JOAbxCmN4so1D3GZU+CcEC w==; X-CSE-ConnectionGUID: kuX0m7i4S2ufACiQULnKdA== X-CSE-MsgGUID: Z3WvNqOHS8SQuFxN7YHh6Q== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509328" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509328" X-CSE-ConnectionGUID: x94JWGV/R5aHGWekbGvzMA== X-CSE-MsgGUID: UczGk8GaRF+E1JpRdmCCOw== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 01/10] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Fri, 27 Feb 2026 14:13:47 -0800 Message-ID: <20260227221632.827046-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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-ZM-MESSAGEID: 1772230939042158500 There are cases when a blob resource's backing might get detached and re-attached again such as when the underlying object is getting migrated in the Guest. In these situations, we need to obtain a new dmabuf fd, which can be done by calling virtio_gpu_init_udmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 643e91ca2a..f20111fa57 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -937,6 +937,10 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; } + + if (res->blob_size) { + virtio_gpu_init_udmabuf(res); + } } =20 static void --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230916906904.5099359649846; Fri, 27 Feb 2026 14:21:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bc-000643-ID; Fri, 27 Feb 2026 17:19:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Ba-00063m-P8 for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:51 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6BY-0007ml-Oe for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:50 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230789; x=1803766789; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lYWaP1kFmLOPTRi7iW/x1sxii0x816fC62gZjXLi8LA=; b=bxSWjjSzkSYA9RVpv4bDiglpYgJ1QB9TOkQDCmqEW2eHipFIl/txY/gk 29x+cQLYZztibDXH7KOMSJlXEwkR7MlsnkzUJHwnRQYHLsJyzUmC3wO6d 2P6jAtHpWwpPGiOo0vnbJsafVnH+32xUZqDnlTVdMy7/B3i3d/WUto4Uf IXhVwj6wxug6G5b8eCnO8ArQqN3y98/zibJfnq+aGRb0Y2PV0kKmjTU0u 6tdkuU1vdNYyG2/xMTBWz/gt1cO8SYj74TTDvlf+7XIksqHazgAE46rmk 1TAiWvWkjwqkX7hdPhGAhix/8TRyq/9ATymBku90RR0G+dSlrfHxm+Jpf Q==; X-CSE-ConnectionGUID: B8lLo1vORSG7NMPc+l6E7g== X-CSE-MsgGUID: izsXlQnOTDWxF2ZcOvm4NQ== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509333" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509333" X-CSE-ConnectionGUID: udaJMluJTZKqf5kGTm4e/Q== X-CSE-MsgGUID: HDsMqSXNR8SnSxS1J458Ww== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 02/10] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Fri, 27 Feb 2026 14:13:48 -0800 Message-ID: <20260227221632.827046-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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-ZM-MESSAGEID: 1772230932143158502 If the Guest provides a DMA address that is associated with a ram device (such as a VFIO PCI device region and not its system memory), then we can obtain the hva (host virtual address) by invoking address_space_translate() followed by memory_region_get_ram_ptr(). We cannot use dma_memory_map() because for memory regions that do not support direct access, it would create bounce buffers instead of returning the actual hva, which is not desirable here. And, since VFIO device regions are not considered directly accessible (because they are mostly MMIO based), virtio-gpu cannot invoke dma_memory_map() to obtain the hva in this case. Therefore, in order to handle addresses associated with VFIO devices, we need to use the address_space_translate() API to first identify the right memory region and the appropriate offset within that region and then use memory_region_get_ram_ptr() to get the hva. This approach also works for addresses associated with the system memory region. Note that, although we take an explicit reference on the memory region, we would still rely on dma_memory_unmap() to drop that reference when the dma mapping is eventually unmapped. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f20111fa57..f5c6a7deb9 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -798,6 +798,23 @@ static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } =20 +static void *virtio_gpu_dma_memory_map(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd, + uint64_t a, hwaddr *len) +{ + MemoryRegion *mr; + hwaddr xlat; + + mr =3D address_space_translate(VIRTIO_DEVICE(g)->dma_as, a, &xlat, len, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); + if (memory_region_is_ram(mr)) { + memory_region_ref(mr); + return memory_region_get_ram_ptr(mr) + xlat; + } + return NULL; +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -839,9 +856,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, =20 do { len =3D l; - map =3D dma_memory_map(VIRTIO_DEVICE(g)->dma_as, a, &len, - DMA_DIRECTION_TO_DEVICE, - MEMTXATTRS_UNSPECIFIED); + map =3D virtio_gpu_dma_memory_map(g, cmd, a, &len); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" " element %d\n", __func__, e); --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230910335530.1160496723265; Fri, 27 Feb 2026 14:21:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Be-00065A-Ea; Fri, 27 Feb 2026 17:19:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bc-00064F-Rv for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:52 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bb-0007ml-2T for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:52 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230791; x=1803766791; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WQUubMglOINXkPd3puxed1kwRdXppIaQlkqgg//+It0=; b=SorAm6BX3/62uxbI5BgZNcNmjTGxNZcWBmXEgWXfZrrsg+HT/rN9Uj+9 03tqljxg9B7eJiCANn+RPvTwv0f1CPc5znDogV7XQJAqjbK0lItk+eYD2 fHgrpAyWHSlqEUH8fdXazb/uOqNFCCEvhenwifZhJQsX6NeURdsX5SW5g OEXYMJeuGoFVahInzB+b2qiOEN5vkwFEfhtIqV057bLd2JD3BIh0io/c4 vOpqARQMNnTE0MkHA78qhgbjBO6+uI94jCT4bBA3qwlmHDYEDMR41yrH0 bXAoEVZMSCdjxpKjwiN+uakUc107uvajYqeF1h45UBruoYkCeOhxFtFP3 w==; X-CSE-ConnectionGUID: lEFJX+ooSBG4Y4CM3FAT+g== X-CSE-MsgGUID: yA4zuudBQlmR7qKK6Hpipg== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509338" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509338" X-CSE-ConnectionGUID: q8S1iHLyT12kEgP6vqHWxg== X-CSE-MsgGUID: CAcjL59pSUqaj4nLdgtz2Q== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 03/10] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Fri, 27 Feb 2026 14:13:49 -0800 Message-ID: <20260227221632.827046-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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-ZM-MESSAGEID: 1772230939026158500 This is prep-work for adding the ability to create dmabuf fds from VFIO devices in addition to udmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/meson.build | 4 ++-- ...gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs.c} | 4 ++-- .../{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} | 12 ++++++------ hw/display/virtio-gpu.c | 8 ++++---- include/hw/virtio/virtio-gpu.h | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) rename hw/display/{virtio-gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs= .c} (79%) rename hw/display/{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} (94%) diff --git a/hw/display/meson.build b/hw/display/meson.build index 90e6c041bd..f5f92b1068 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -69,9 +69,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), = pixman]) if host_os =3D=3D 'linux' - virtio_gpu_ss.add(files('virtio-gpu-udmabuf.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf.c')) else - virtio_gpu_ss.add(files('virtio-gpu-udmabuf-stubs.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf-stubs.c')) endif virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} diff --git a/hw/display/virtio-gpu-udmabuf-stubs.c b/hw/display/virtio-gpu-= dmabuf-stubs.c similarity index 79% rename from hw/display/virtio-gpu-udmabuf-stubs.c rename to hw/display/virtio-gpu-dmabuf-stubs.c index f692e13510..01067e246d 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-dmabuf-stubs.c @@ -7,12 +7,12 @@ bool virtio_gpu_have_udmabuf(void) return false; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-dmabuf= .c similarity index 94% rename from hw/display/virtio-gpu-udmabuf.c rename to hw/display/virtio-gpu-dmabuf.c index d804f321aa..c34d4c85bc 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -68,7 +68,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) g_free(list); } =20 -static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *re= s) +static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) { res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_fd, 0); @@ -79,7 +79,7 @@ static void virtio_gpu_remap_udmabuf(struct virtio_gpu_si= mple_resource *res) } } =20 -static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res) +static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) { if (res->remapped) { munmap(res->remapped, res->blob_size); @@ -128,7 +128,7 @@ bool virtio_gpu_have_udmabuf(void) return memfd_backend; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { void *pdata =3D NULL; =20 @@ -141,7 +141,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd < 0) { return; } - virtio_gpu_remap_udmabuf(res); + virtio_gpu_remap_dmabuf(res); if (!res->remapped) { return; } @@ -151,10 +151,10 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) res->blob =3D pdata; } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { if (res->remapped) { - virtio_gpu_destroy_udmabuf(res); + virtio_gpu_destroy_dmabuf(res); } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f5c6a7deb9..72c7610664 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -360,7 +360,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, return; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 @@ -917,7 +917,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->addrs =3D NULL; =20 if (res->blob) { - virtio_gpu_fini_udmabuf(res); + virtio_gpu_fini_dmabuf(res); } } =20 @@ -954,7 +954,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, } =20 if (res->blob_size) { - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); } } =20 @@ -1440,7 +1440,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *op= aque, size_t size, return -EINVAL; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); =20 resource_id =3D qemu_get_be32(f); } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 58e0f91fda..e3d351a2d4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -354,10 +354,10 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_= framebuffer *fb, struct virtio_gpu_set_scanout_blob *ss, uint64_t blob_size); =20 -/* virtio-gpu-udmabuf.c */ +/* virtio-gpu-dmabuf.c */ bool virtio_gpu_have_udmabuf(void); -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res); int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772230914; cv=none; d=zohomail.com; s=zohoarc; b=hYmfmFXk+9cwJjWZDZFfsN26U0A8fCtEw/jpvmfdPErCnavKBigVAtPS+Bcz1RtmBIW5rzW/s6sWEw8KEjd8oV+mpE2K1+MT0wmtdSOy75kllCTupYg0Tw5G6ssfoTsTfbg6RyPKxy+jVDqboGsTU5HVgHDLBIAcmoxzghp4lnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772230914; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fEylY4HeRrQg4z7pkuEupgOpmZpN1pRXlYvFVufBQPI=; b=mRF3/QZ0v0T1sylpW8T2DlW+fWWszRkP+DqHUDysY2q+J1ndTjZZtqWLqtwHfe0eG99TgE2Z4/tk4fX04UZy1bE0HsKJbIJcOmXpGOB4I+lSHyQF3aFe59ntGA4Lk8fTEIKRLDt2Xxijx8JR1fwlCYb98IQrdGhXsd6Zcs9E8Sc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230914942255.64390585377475; Fri, 27 Feb 2026 14:21:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Be-000651-3Q; Fri, 27 Feb 2026 17:19:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bc-000644-I3 for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:52 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bb-0007m5-2a for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:52 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230791; x=1803766791; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8DjDopZg0XVik4k1ICxjRmt2mb1IxbLdY763BFKsh0Y=; b=GFOvOX5t9ILhFmSCCEpAXG/UlE9zzX8xeW4mgtnXA+nhxii7bYV7pNVH 35ee4BN51NI7/vPEkpex1RIHYl9wfBwnFhhhuaX2D1NFLMirq/uw1vXJA U8eY7TI0Bbf9wib5e152Tzdcb8BTDGoWERRhAVnra2iYYSQmxG5E5OCoz Q2Z2ig4XEx9o4JQ+jRBLXmFFfjBe2i/E+ej3gq6QeE5BllarKyl6EelFB k4pfRykyZoGNTKvuvsBdR5Y2sV2i3m9mHkjl7uHRWEMlqaM8wo+Bf4+hC JxpwVEShv/Us3T1QNKRRK23J23bZBOS4gbxroPfwulbrvkjEaxqdAt78j w==; X-CSE-ConnectionGUID: xEZF07GpQaC6k20A+/lX5g== X-CSE-MsgGUID: WXjyDTtJSyaxz0Otfetrbw== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509344" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509344" X-CSE-ConnectionGUID: okJsn4+YToqCAgw12g/62A== X-CSE-MsgGUID: wpJ4YRuUSy+JL801cgQEbA== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 04/10] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Fri, 27 Feb 2026 14:13:50 -0800 Message-ID: <20260227221632.827046-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1772230916527158500 There is no need to wrap the call to qemu_ram_block_from_host() with rcu_read_lock/unlock as we already hold a reference to the memory region that owns the ram block. Note that, the reference was obtained via dma_memory_map() while creating the mapping. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index c34d4c85bc..0782bcf3a1 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -43,10 +43,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_resource *res) sizeof(struct udmabuf_create_item) * res->iov_cnt); =20 for (i =3D 0; i < res->iov_cnt; i++) { - rcu_read_lock(); rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); - rcu_read_unlock(); - if (!rb || rb->fd < 0) { g_free(list); return; --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772230805; cv=none; d=zohomail.com; s=zohoarc; b=fe4d327vv4CUDQu5ZaZxGBmEUvqeF0TdWUMBhTi819XhDLTwtzxTH1lQNk/IGDhh1FzQWXUbbUiI3inZb08KK81FUKHisRa6Fo/aEmRPtKKHc8GJiqni0cWETf2zOc0y4FQZNJIHhp1PjC1l5eidiCiEh+E2RBrQ5wq/0CfV3Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772230805; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oQxKNqH7uchxjAw73psN2RqSTlA9DAJJrvqv34ryHVs=; b=EJu6JB4KRVfF11H8aEjv7IP8aTzq7PMY0P0d8CYqhzStHQvcfL3RCHLLyyo/UkmISL1eMOMfUZFWpLUFLRUBM62KtlT3SdXftV4DExOp8bPKvspKQmw475NjyyUaOMGScE9NC4/Kf5Rs0xF7oppobdYNY4uQJ+Ky6Zyc99XmxtA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230805583302.9331429335026; Fri, 27 Feb 2026 14:20:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bf-00066G-TE; Fri, 27 Feb 2026 17:19:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bd-00064t-Ni for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:53 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bc-0007n5-7d for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:53 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230792; x=1803766792; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R+voCt8gQq6Y2SKx4ENrPxTbBWeBaPJn71IunQUW5Lg=; b=d2zVzNaReAqkyDBjeMxsK/Zu6TqvTRMumxYnBqGQdTzrh0wTB7j1D/lP +H7ZX1vrDzs9Z+Cc4rsbfg/SEVAJTLb99QUxnufHiPmq5lgkjCQeBr5SC mVu4ehjLp/zL4j2Nf6I3JA1p5taBWa4Bcu6xtW0v0DbscXJ5Z2y/yUbBC /twf1OgQKw9MxVJ9Gr1cGoff8RKrdwcaHqXLhRMt7infNGOSNMvjsNQ00 E+0bpkzMkYF/mVcJmuIQz/lPCFWbkEBcw8tmAJhQqmkrykpwBdUPlyI2W PxqSDcBWi6oxrtFtT50FF3YXYdS/ioEeYqxif8KTSno/gAVnK9e4syNtz Q==; X-CSE-ConnectionGUID: RCIQQWexTQ64SbI7k8EV5g== X-CSE-MsgGUID: W6Ru4ohORZmaM3Y32niBAA== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509349" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509349" X-CSE-ConnectionGUID: Xc9Wr7dwTHy/GDLau9WPDQ== X-CSE-MsgGUID: 2SdfoBdZSMiDQBtLy1NOYA== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 05/10] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Fri, 27 Feb 2026 14:13:51 -0800 Message-ID: <20260227221632.827046-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1772230807521158500 Avoid the manual g_free() calls for the list pointer by using g_autofree in virtio_gpu_create_udmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 0782bcf3a1..8d67ef7c2a 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -29,7 +29,7 @@ =20 static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) { - struct udmabuf_create_list *list; + g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; ram_addr_t offset; int udmabuf, i; @@ -45,7 +45,6 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) for (i =3D 0; i < res->iov_cnt; i++) { rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); if (!rb || rb->fd < 0) { - g_free(list); return; } =20 @@ -62,7 +61,6 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, strerror(errno)); } - g_free(list); } =20 static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772230896; cv=none; d=zohomail.com; s=zohoarc; b=OrEmG4p7SoJ5aPtd8TZWQOf3btaWooHwfxDw9rcUStFhxhODThXOz+/9Tq1g8hbtvEkqpfk16jAEklzU+G/vT/MNgkh66215Tg4j6YnclJWYByxDGohBZ6gGygH3nFbrgGOXsb0GE3mf1haUrhfYrZGVpfoDcO4EL/KjbzU+m0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772230896; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OvvXna9asyBYuGGCY/V62xry7x8KfmAwpbl4bxe8+oE=; b=Sd7/GNysNV7Lc9KsocXGxABJQeHNNUXVUEiryCXdkCyA/I8Ro9hSdf9U5tToWqLbB716pXDzxLaJrcIoRLlmWzXF7H+otjWqpE/sznFfQOVwoN1j/sDQIXKbAY/fvhegs12koqY5HdI2ayxIfbidesmqOJ585A0Ap+8RWKoniek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230896203609.5239726678046; Fri, 27 Feb 2026 14:21:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bg-00066Q-Kq; Fri, 27 Feb 2026 17:19:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Be-00065d-Rn for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:54 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bc-0007m5-Rs for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:54 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230793; x=1803766793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1TEvr2QnTOUFzPzfTMXk5IYYw/2XkOgNrkkXD+yNNs8=; b=jWX+YxZF9oZ0sHJU/ZZtQG3NrNVP45QQZgM4ujiZdEbUAQHohm+feQaj i5CEwgzjQ9kS3arVd157iJZKfOcBa8KhNGRoHedfPmdv5Dm77KPGEFceE pzRCieVPqSOfAUxanPQ7ier9Tof+kaVJkMxtfl3KCQTS3e9M+xsMNyr0Z SJgup/lHAWCeoLUtyiZ99LOgLEQ3sIKfzGnNvoGTag2R2f/ldapHvh7tF n/7LT/Z+VUDvBln5R4KZTKo6mMtXP7UntY4NnHVUURlroJfcFwTj1IDZA 0iQWb9FrXi2xv0VdDJfTVvqn1FGA3Z89IsmvzNGY/dQMwvVg3mHo/7yUe A==; X-CSE-ConnectionGUID: xPmSqLe+RFS5W/Lv02QaXw== X-CSE-MsgGUID: 1AZoSu+hQyqGNY5d9W8pUg== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509354" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509354" X-CSE-ConnectionGUID: ngiM56JrSku0IbSq7n/khA== X-CSE-MsgGUID: pIvaOOQPTnSlEQbyT42hqA== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 06/10] vfio/region: Add a helper to get region index from memory region Date: Fri, 27 Feb 2026 14:13:52 -0800 Message-ID: <20260227221632.827046-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1772230897975158501 Having a way to figure out the region index (or bar) associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info needed for mapping a part of a VFIO region or creating a dmabuf. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/region.c | 14 ++++++++++++++ include/hw/vfio/vfio-device.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 47fdc2df34..4cb92216ef 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -539,3 +539,17 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +int vfio_get_region_index_from_mr(MemoryRegion *mr) +{ + VFIORegion *region; + + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + region =3D mr->opaque; + return region->nr; + } + mr =3D mr->container; + } + return -1; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..596c7f5a10 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -308,6 +308,16 @@ bool vfio_device_has_region_cap(VFIODevice *vbasedev, = int region, uint16_t cap_t =20 int vfio_device_get_irq_info(VFIODevice *vbasedev, int index, struct vfio_irq_info *info); + +/** + * Return the region index associated with a given MemoryRegion. The index + * can be useful in retrieving region info. + * + * @mr: MemoryRegion to use + * + * Returns the region index or -1 on error. + */ +int vfio_get_region_index_from_mr(MemoryRegion *mr); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772230812; cv=none; d=zohomail.com; s=zohoarc; b=jHc7gIMZe5feJ3701hGq7snKZA7oSjJAXhHLPVFrDdu6Bh42p3VTxwaHRJx+ZmaMn0OQ5OP35kUDg7TyHP3b5YlW1zTfOdz+plddfgBJ7wfNNtnK686oJDYR+YuT/GhLB67M0L+VgGgSqNrL+VJwneD4gJDHYm1MPrBsDPJ1qB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772230812; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/VgarV1WVYmkOwg5zurWdWoMKh5t+3I8anwWgE/d6lY=; b=EtKhjB2tKqtO05x9IxWSFDgnGgbyrMkJDNvfCmmKQy2X0QBrUZp007Sd0iJQylcKhn6flrS9P89HzjKOiSiJXSFldqI6UUAHeFxF+XEE6eTtFY7SDGpgKt1G1KflUhRTY5iYCOuPVJHsLBiu2voxiczPjpPljeDJyIgKOBKn5gU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17722308120981022.7556542496899; Fri, 27 Feb 2026 14:20:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bh-000671-IP; Fri, 27 Feb 2026 17:19:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bf-000665-FD for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:55 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bd-0007ml-4m for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:55 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230793; x=1803766793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w3uTWrXd7VpeYAZj7l0t+FPlTl71pJf89qInb+jdvno=; b=PMD4w9whVnKdfhXufCfSIOO7+j9+UWaj7aw3QKiqTQOdpQ9hxQ4EQD25 i+3M+YPKercSQjL4yWSTZefV8JdpdFwIVGgR9pS7bCLbGBGYatb5X+tHH ZCFCUvhZUYNEPIKdHwuaKZ+ytWGmRw8We64de7C3DtC8R/brw/Htv8Rzh MSliEoL08uZqWhzih8IjdLEkhSZQykpOQNDowXrWzaIT72jYvNrA7LBnd y3LtgM0ZQk22Sw0eNJsXxslke8PHehv3TkJ3i7IqdGXItxunBQbd2v28P e7h+m8iP4mW24sgNFAm42toRC1FZz47WvVPslDQHX4ub91GiaQKc9In6J w==; X-CSE-ConnectionGUID: NtD6NHYJRHiCXxQh2fYHSw== X-CSE-MsgGUID: u70RVhsjRKGezR+cQczWcg== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509359" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509359" X-CSE-ConnectionGUID: UJmKq1egSZuBswMWk647Ag== X-CSE-MsgGUID: 1PhaXEl1SSK7ZQipksUNIA== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 07/10] vfio/device: Add support for creating dmabuf from multiple ranges Date: Fri, 27 Feb 2026 14:13:53 -0800 Message-ID: <20260227221632.827046-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1772230815663158502 In order to create a dmabuf associated with a buffer that spans multiple ranges, we first need to identify the VFIO region and index the buffer (represented by iovec) belongs to and then translate its addresses to offsets within that region. The qemu_ram_block_from_host() API gives us both the region and the offset info we need to populate the dma ranges so that we can invoke the VFIO_DEVICE_FEATURE_DMA_BUF feature to create the dmabuf. Also, instead of iterating over all QOM devices to find the VFIODevice associated with a memory region, introduce a helper to just use the vfio_device_list to lookup the VFIODevice. Lastly, introduce an enum to return the type of error encountered while creating the dmabuf fd. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 84 +++++++++++++++++++++++++++++++++++ hw/vfio/dmabuf-stubs.c | 17 +++++++ hw/vfio/meson.build | 1 + include/hw/vfio/vfio-device.h | 22 +++++++++ 4 files changed, 124 insertions(+) create mode 100644 hw/vfio/dmabuf-stubs.c diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..a25ecc3697 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include =20 +#include "system/ramblock.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" #include "hw/core/iommu.h" @@ -644,3 +645,86 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { .region_read =3D vfio_device_io_region_read, .region_write =3D vfio_device_io_region_write, }; + +static bool vfio_device_lookup(struct iovec *iov, VFIODevice **vbasedevp, + Error **errp) +{ + VFIODevice *vbasedev; + RAMBlock *first_rb; + ram_addr_t offset; + + first_rb =3D qemu_ram_block_from_host(iov[0].iov_base, false, &offset); + if (!first_rb) { + error_setg(errp, "Could not find first ramblock\n"); + return false; + } + + QLIST_FOREACH(vbasedev, &vfio_device_list, next) { + if (vbasedev->dev =3D=3D first_rb->mr->dev) { + *vbasedevp =3D vbasedev; + return true; + } + } + error_setg(errp, "No VFIO device found to create dmabuf from\n"); + return false; +} + +int vfio_device_create_dmabuf_fd(struct iovec *iov, unsigned int iov_cnt, + Error **errp) +{ + g_autofree struct vfio_device_feature *feature =3D NULL; + struct vfio_device_feature_dma_buf *dma_buf; + RAMBlock *rb, *first_rb; + VFIODevice *vbasedev; + ram_addr_t offset; + int i, index, ret; + size_t argsz; + + argsz =3D sizeof(*feature) + sizeof (*dma_buf) + + sizeof(struct vfio_region_dma_range) * iov_cnt; + feature =3D g_malloc0(argsz); + *feature =3D (struct vfio_device_feature) { + .argsz =3D argsz, + .flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF, + }; + dma_buf =3D (struct vfio_device_feature_dma_buf *)feature->data; + + if (!vfio_device_lookup(iov, &vbasedev, errp)) { + return VFIO_DMABUF_CREATE_GUEST_ERROR; + } + + for (i =3D 0; i < iov_cnt; i++) { + rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (i =3D=3D 0) { + first_rb =3D rb; + } + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Cannot create dmabuf with different regions\= n"); + return VFIO_DMABUF_CREATE_GUEST_ERROR; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + error_setg(errp, "Cannot find region index for dmabuf segment\= n"); + return VFIO_DMABUF_CREATE_GUEST_ERROR; + } + + dma_buf->region_index =3D index; + dma_buf->dma_ranges[i].offset =3D offset; + dma_buf->dma_ranges[i].length =3D iov[i].iov_len; + } + + dma_buf->nr_ranges =3D iov_cnt; + dma_buf->open_flags =3D O_RDONLY | O_CLOEXEC; + + ret =3D vfio_device_get_feature(vbasedev, feature); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Could not create dmabuf fd via VFIO device"); + if (ret =3D=3D -ENODEV || ret =3D=3D -EINVAL) { + return VFIO_DMABUF_CREATE_GUEST_ERROR; + } + return VFIO_DMABUF_CREATE_HOST_ERROR; + } + return ret; +} diff --git a/hw/vfio/dmabuf-stubs.c b/hw/vfio/dmabuf-stubs.c new file mode 100644 index 0000000000..e71e2b68dd --- /dev/null +++ b/hw/vfio/dmabuf-stubs.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2026 Intel and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/iov.h" +#include "hw/vfio/vfio-device.h" + +int vfio_device_create_dmabuf_fd(struct iovec *iov, unsigned int iov_cnt, + Error **errp) +{ + error_setg(errp, "VFIO dmabuf support is not enabled"); + return VFIO_DMABUF_CREATE_HOST_ERROR; +} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 82f68698fb..ac899d30a8 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -34,3 +34,4 @@ system_ss.add(when: 'CONFIG_IOMMUFD', if_false: files('io= mmufd-stubs.c')) system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c', )) +system_ss.add(when: 'CONFIG_VFIO', if_false: files('dmabuf-stubs.c')) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 596c7f5a10..9dcf3ea57d 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -41,6 +41,13 @@ enum { VFIO_DEVICE_TYPE_AP =3D 3, }; =20 +enum { + /* Guest is responsible for this error */ + VFIO_DMABUF_CREATE_GUEST_ERROR =3D -1, + /* Host is at fault for this error */ + VFIO_DMABUF_CREATE_HOST_ERROR =3D -2, +}; + typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIODeviceIOOps VFIODeviceIOOps; typedef struct VFIOMigration VFIOMigration; @@ -318,6 +325,21 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int= index, * Returns the region index or -1 on error. */ int vfio_get_region_index_from_mr(MemoryRegion *mr); + +/** + * Create a dmabuf fd by first translating the addresses in the + * iovec array into VFIO region offsets and then invoking the + * VFIO_DEVICE_FEATURE_DMA_BUF feature. + * + * @iov: array of iovec entries associated with a buffer + * @iov_cnt: number of entries in the iovec array + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns the created dmabuf fd or either VFIO_DMABUF_CREATE_GUEST_ERROR + * or VFIO_DMABUF_CREATE_HOST_ERROR on error. + */ +int vfio_device_create_dmabuf_fd(struct iovec *iov, unsigned int iov_cnt, + Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177223084577916.329530807812944; Fri, 27 Feb 2026 14:20:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bj-00067Q-Py; Fri, 27 Feb 2026 17:20:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bf-00066C-OV for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:55 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Be-0007n5-0w for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:55 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230794; x=1803766794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H/a/kqUYjQO2m0ZdrAJtD1lUIdP2SDzEYOBTYhsibeI=; b=iXYIjKG93YTCeHLRBrV9A+ocvEKTcRqZXGrYXnI6fXSZmx6RkUrhUtpF nfwvLZnJFB8mS9aLEyqBa4lTCqcOpLiIO5LEIkQ9DiZlOs/qvwh3JmFTO RNq3fWnTDfE2CvAn9GfOITK0W5+/UNHowYZAPz7z9Y9rUiAih0E6pgJqS Q/escd7P46kUAG5IG1Ym4E2tWLkyCi/E0nfwfEMPX/8MSgIjpx7K2nSup LpP7xcNB7dfZLDIEBK41MOzDDg5X2fjVwm3vD9Aam+l4vafIP+ODy4aB3 2vut9QD/D73JYqpcxKmhdXF6OHoDipWEGE10DvlmN5qyxrmoWMAKTqUuk Q==; X-CSE-ConnectionGUID: kS9UaHqdTg6FXO19lrxYQA== X-CSE-MsgGUID: 0waavMFtRiO63bOvPTF1LA== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509365" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509365" X-CSE-ConnectionGUID: 2d4HG9iqSiKiPWBofyEmtQ== X-CSE-MsgGUID: 3WcFRdvVRR+PhjZus5Zs8g== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 08/10] vfio/device: Add a helper to mmap a dmabuf Date: Fri, 27 Feb 2026 14:13:54 -0800 Message-ID: <20260227221632.827046-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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-ZM-MESSAGEID: 1772230865843158500 In order to mmap a dmabuf, we first need to create a placeholder mapping that would fit the entire size of the dmabuf. This mapping would then be replaced with smaller mappings of individual dmabuf segments. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 65 +++++++++++++++++++++++++++++++++++ hw/vfio/dmabuf-stubs.c | 7 ++++ include/hw/vfio/vfio-device.h | 17 +++++++++ 3 files changed, 89 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index a25ecc3697..596fbceb68 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -728,3 +728,68 @@ int vfio_device_create_dmabuf_fd(struct iovec *iov, un= signed int iov_cnt, } return ret; } + +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp) +{ + struct vfio_region_info *info =3D NULL; + VFIODevice *vbasedev =3D NULL; + ram_addr_t offset, len =3D 0; + RAMBlock *first_rb, *rb; + void *map, *submap; + int i, index; + + if (!vfio_device_lookup(iov, &vbasedev, errp)) { + return false; + } + + /* + * We first reserve a contiguous chunk of address space for the entire + * dmabuf, then replace it with smaller mappings that correspond to the + * individual segments of the dmabuf. + */ + map =3D mmap(NULL, total_size, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, = -1, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, "Could not reserve placeholder mappi= ng"); + return false; + } + + for (i =3D 0; i < iov_cnt; i++) { + rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (i =3D=3D 0) { + first_rb =3D rb; + } + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Cannot mmap dmabuf with different regions\n"= ); + goto err; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + error_setg(errp, "Cannot find region index for dmabuf segment\= n"); + goto err; + } + + if (vfio_device_get_region_info(vbasedev, index, &info)) { + error_setg(errp, "Cannot find region info for dmabuf segment\n= "); + goto err; + } + + submap =3D mmap(map + len, iov[i].iov_len, PROT_READ, + MAP_SHARED | MAP_FIXED, vbasedev->fd, + info->offset + offset); + if (submap =3D=3D MAP_FAILED) { + error_setg(errp, "Could not mmap dmabuf segment\n"); + goto err; + } + + len +=3D iov[i].iov_len; + } + *addr =3D map; + return true; +err: + munmap(map, total_size); + error_prepend(errp, "VFIO dmabuf mmap failed: "); + return false; +} + diff --git a/hw/vfio/dmabuf-stubs.c b/hw/vfio/dmabuf-stubs.c index e71e2b68dd..c3aa37233d 100644 --- a/hw/vfio/dmabuf-stubs.c +++ b/hw/vfio/dmabuf-stubs.c @@ -15,3 +15,10 @@ int vfio_device_create_dmabuf_fd(struct iovec *iov, unsi= gned int iov_cnt, error_setg(errp, "VFIO dmabuf support is not enabled"); return VFIO_DMABUF_CREATE_HOST_ERROR; } + +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp) +{ + error_setg(errp, "VFIO mmap dmabuf support is not enabled"); + return false; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 9dcf3ea57d..a1381f5f30 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -340,6 +340,23 @@ int vfio_get_region_index_from_mr(MemoryRegion *mr); */ int vfio_device_create_dmabuf_fd(struct iovec *iov, unsigned int iov_cnt, Error **errp); + +/** + * Mmap a dmabuf by first translating the addresses in the iovec + * array into VFIO region offsets and then creating a placeholder + * mapping that would be replaced later with mappings that + * correspond to the dmabuf segments. + * + * @iov: array of iovec entries associated with the dmabuf + * @iov_cnt: number of entries in the iovec array + * @addr: pointer to store the resulting mmap address + * @total_size: total size of the dmabuf + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns true on success and false in case of an error. + */ +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772230832811200.98745233785849; Fri, 27 Feb 2026 14:20:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bl-00067k-JJ; Fri, 27 Feb 2026 17:20:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bh-00067B-NR for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:57 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bf-0007m5-6R for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:19:56 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230795; x=1803766795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tvGLLWt/KVjrGwxv7KBoBI5nAuzCFdI/ypVr4mmfOqY=; b=dr2iPaaZRU2W5pTHBoUViAGuVoAf+HwS25WAxNeV5iQCL6GwIbymAAgQ 1kAt8+qvSg8lYZw66vEywuJdXBVITmL26rmEGKFSj95xZSL83wCfMWSOU JpX9vfm5KrsO4aV/DPxSGK2cIY5PFn5AIysa0NIAhxBmd6VvTVFFW/JsP YdDbk5i1J77tEnD+Fx0yYFbwnRsSHoAuAvbKxXfZLIJilf8TbuptAYDQD ZjIehxtAovu/hvgQnnL5ep2oTK0MrqgVWyTSEAvnrHka0IPw0fWEGOkvV c+ZGPTn9WF7iD6ohVnKMzqF9FQW8M+BcDwvwRRorNwY6TnOQNUHdT8AyI g==; X-CSE-ConnectionGUID: wvGPkJOQSyihfrJXenM9bg== X-CSE-MsgGUID: UHp+2VrbSTSfwD71sjBwzA== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509368" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509368" X-CSE-ConnectionGUID: SjVVzUI4TCmCae/aCs3JMQ== X-CSE-MsgGUID: NXkHtFmwSh6Gve+hqZlFmw== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 09/10] virtio-gpu-dmabuf: Improve error handling with 'Error **' and err enum Date: Fri, 27 Feb 2026 14:13:55 -0800 Message-ID: <20260227221632.827046-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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-ZM-MESSAGEID: 1772230851799158500 Make the error handling more robust in virtio_gpu_init_udmabuf() by introducing 'Error **' parameter to capture errors and using an enum from VFIO to categorize Guest and Host errors. This allows for better error reporting and handling of errors from virtio_gpu_create_udmabuf() and virtio_gpu_remap_dmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 61 ++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 8d67ef7c2a..b2badfc1bd 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -18,6 +18,7 @@ #include "ui/console.h" #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-gpu-pixman.h" +#include "hw/vfio/vfio-device.h" #include "trace.h" #include "system/ramblock.h" #include "system/hostmem.h" @@ -27,16 +28,18 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 -static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) +static int virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *re= s, + Error **errp) { g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; ram_addr_t offset; - int udmabuf, i; + int udmabuf, i, fd; =20 udmabuf =3D udmabuf_fd(); if (udmabuf < 0) { - return; + error_setg(errp, "udmabuf device not available or enabled"); + return VFIO_DMABUF_CREATE_HOST_ERROR; } =20 list =3D g_malloc0(sizeof(struct udmabuf_create_list) + @@ -45,7 +48,8 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) for (i =3D 0; i < res->iov_cnt; i++) { rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); if (!rb || rb->fd < 0) { - return; + error_setg(errp, "IOV memory address incompatible with udmabuf= "); + return VFIO_DMABUF_CREATE_GUEST_ERROR; } =20 list->list[i].memfd =3D rb->fd; @@ -56,22 +60,30 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res) list->count =3D res->iov_cnt; list->flags =3D UDMABUF_FLAGS_CLOEXEC; =20 - res->dmabuf_fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); - if (res->dmabuf_fd < 0) { - warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, - strerror(errno)); + fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); + if (fd < 0) { + error_setg_errno(errp, errno, "UDMABUF_CREATE_LIST: ioctl failed"); + if (errno =3D=3D EINVAL || errno =3D=3D EBADFD) { + return VFIO_DMABUF_CREATE_GUEST_ERROR; + } + return VFIO_DMABUF_CREATE_HOST_ERROR; } + return fd; } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, + Error **errp) { - res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, - MAP_SHARED, res->dmabuf_fd, 0); - if (res->remapped =3D=3D MAP_FAILED) { - warn_report("%s: dmabuf mmap failed: %s", __func__, - strerror(errno)); + void *map; + + map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, "dmabuf mmap failed"); res->remapped =3D NULL; + return false; } + res->remapped =3D map; + return true; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -125,19 +137,32 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + Error *local_err =3D NULL; void *pdata =3D NULL; + int ret; =20 res->dmabuf_fd =3D -1; if (res->iov_cnt =3D=3D 1 && res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else { - virtio_gpu_create_udmabuf(res); - if (res->dmabuf_fd < 0) { + ret =3D virtio_gpu_create_udmabuf(res, &local_err); + if (ret < 0) { + error_prepend(&local_err, "Cannot create dmabuf: "); + + if (ret =3D=3D VFIO_DMABUF_CREATE_GUEST_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memory\n= "); + error_free(local_err); + return; + } + error_report_err(local_err); return; } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { + + res->dmabuf_fd =3D ret; + if (!virtio_gpu_remap_dmabuf(res, &local_err)) { + error_report_err(local_err); return; } pdata =3D res->remapped; --=20 2.53.0 From nobody Mon Mar 2 08:46:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772230830; cv=none; d=zohomail.com; s=zohoarc; b=kZwMvgikb8kXHglhlFhxVkUXHKdi97EaTUk9X7j/dBFd1Sqv+nfSm3THYKF6YLGEJjftr8jKKUjHvuLoeNSpscaS7ssJ11ejpAduqCpA/S4fpx7Og3NwSOmRfIV3o3LaRXy83e4k6FGKpPxov5sd9z8TimHslzXU6hOnoGMHG4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772230830; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4cCbyFy5i1I5CqUa+AIt9i9KqNTte0llaqVybsv/X9k=; b=Ysq2PLYSKhIif1ZGeTRUgdPtZNobrClPJx+YIZJcrpAm3XIg4QiKeZaVTpzWwoi08c6uJAuJ+T+hKkFSTJ7l1DbCQG3XUZRgIK5kepP+Z0aaLGdhEi5gTTMKrf7CxhJonPhh2s+2KPaCLmdDuZrUmR6l4H0KxSLOOGNhl8FLg/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177223083097282.76528807873467; Fri, 27 Feb 2026 14:20:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vw6Bu-0006Kk-Jm; Fri, 27 Feb 2026 17:20:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bs-0006Jp-2F for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:20:08 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vw6Bp-0007ml-Qu for qemu-devel@nongnu.org; Fri, 27 Feb 2026 17:20:07 -0500 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2026 14:19:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772230806; x=1803766806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vEc4G49rjF034O9S3kVdRpVeSAKAdnxFYmbWIJROkr0=; b=i2YfuSvb9o7fZuajRMW8hjkppoTZTzwXKztZXDLCk4LKVmxo6oL1SGdj 3GvgXXC1gDRfGaIZtSLnFau233AwRshIXWLJm3A3dspcPP2qBzuXdQnj7 /wdkbkJjth3DLIiEz6izjoOVP39Hf+q/cTkeDGZv7fq/AMcJXSHJpV0UT HFSBt7BxOCBgn1Ql1O2ZkJKrkxWUULa01Qp6ZOgsMs0hFKnD21/GSywlr /Q0Z5zn5gn/vIxG4zNvqYNuL5GKcrNVrAPY2pDQ3y5Pc6NnGv4eSfk6LK grX81Mhzmo/12xpdSnyE34MHKm+v7X5hbIbHsryHQGbEhpgiOoBW3dWaG Q==; X-CSE-ConnectionGUID: b6H6vepSSBOpdo9qxq6oSQ== X-CSE-MsgGUID: E78l4Cd1QMSzrnWzAPpGYg== X-IronPort-AV: E=McAfee;i="6800,10657,11714"; a="73509370" X-IronPort-AV: E=Sophos;i="6.21,314,1763452800"; d="scan'208";a="73509370" X-CSE-ConnectionGUID: DJQDI38kTI+Pb01bV93Bdw== X-CSE-MsgGUID: PQaJmZo1SXKWXjn8N7hgyw== X-ExtLoop1: 1 From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v8 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Fri, 27 Feb 2026 14:13:56 -0800 Message-ID: <20260227221632.827046-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227221632.827046-1-vivek.kasireddy@intel.com> References: <20260227221632.827046-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.706, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.401, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1772230844712158500 In addition to memfd, a blob resource can also have its backing storage in a VFIO device region. Since, there is no effective way to determine where the backing storage is located, we first try to create a dmabuf assuming it is in memfd. If that fails, we try to create a dmabuf assuming it is in VFIO device region. So, we first call virtio_gpu_create_udmabuf() to check if the blob's backing storage is located in a memfd or not. If it is not, we invoke the vfio_device_create_dmabuf_fd() API which identifies the right VFIO device and eventually creates a dmabuf fd. Note that in virtio_gpu_remap_dmabuf(), we first try to test if the VFIO dmabuf exporter supports mmap or not. If it doesn't, we fall back to the vfio_device_mmap_dmabuf() API to get a mapping created for the dmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 35 +++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index b2badfc1bd..533d3d601c 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -74,13 +74,21 @@ static int virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_resource *res, static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, Error **errp) { + Error *mmap_err =3D NULL; void *map; =20 map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); if (map =3D=3D MAP_FAILED) { - error_setg_errno(errp, errno, "dmabuf mmap failed"); + error_setg_errno(&mmap_err, errno, "dmabuf mmap failed: "); res->remapped =3D NULL; - return false; + + if (!vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &map, + res->blob_size, errp)) { + error_report_err(mmap_err); + return false; + } + error_free(mmap_err); + mmap_err =3D NULL; } res->remapped =3D map; return true; @@ -137,7 +145,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { - Error *local_err =3D NULL; + Error *local_err =3D NULL, *vfio_err =3D NULL; void *pdata =3D NULL; int ret; =20 @@ -151,15 +159,28 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) error_prepend(&local_err, "Cannot create dmabuf: "); =20 if (ret =3D=3D VFIO_DMABUF_CREATE_GUEST_ERROR) { - qemu_log_mask(LOG_GUEST_ERROR, - "Cannot create dmabuf: incompatible memory\n= "); - error_free(local_err); - return; + ret =3D vfio_device_create_dmabuf_fd(res->iov, res->iov_cn= t, + &vfio_err); + if (ret > 0) { + error_free(local_err); + local_err =3D NULL; + goto out; + } + + if (ret =3D=3D VFIO_DMABUF_CREATE_GUEST_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memo= ry\n"); + error_free(vfio_err); + error_free(local_err); + return; + } + error_report_err(vfio_err); } error_report_err(local_err); return; } =20 +out: res->dmabuf_fd =3D ret; if (!virtio_gpu_remap_dmabuf(res, &local_err)) { error_report_err(local_err); --=20 2.53.0