From nobody Mon Nov 23 05:00:11 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=1791404079; cv=none; d=zohomail.com; s=zohoarc; b=aFhi62cefcQw7nh2L72MjmPWp92hHe9NFVW5ZJpsvJw57QCEc+rhhLQ7m76CSTzWx18s+c7MwHSw/6/ZCOG9CvuqKfTGaqRhhY6d2Ol60sX3s12eCuKJmR7pw+WJiKysRyqVLzsssaJoo2Q1/sIin9PhonOGOy+uFs0kSzaAGbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404079; 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=qtaVicpV8bg45yh7zf92555XTxOiLBoZySvI1u/748I=; b=Ckj1ypTGWKpKYFJTef0N6EWjpu3Janb69z4sl3PSAu+ZzjSNgau3gXNx3n8D6IwJ2kde/s0Y8TaW73LrjRJ6dkikX22MscSuUxAhwPpSJw5Cdy/HH9AOIDGKG1ozyHe4+A5OOf4ptCg0qOt7w7Xw9cK9+LYcbmrGf+54+HbIKYc= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404079396498.08552756007805; Wed, 7 Oct 2026 13:14:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1X-0004Yp-Tc; Wed, 07 Oct 2026 16:13:59 -0400 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 1xEY1V-0004YL-DT for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:57 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1T-0002As-NJ for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:57 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:48 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404036; x=1822940036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+81JZluoc451K3C7qHfpgLDs8MKCDGZLiInKCTqM3aI=; b=D9irIDG02bYRmk+JdY73c8TdrdV0ZaD1Z24EJTwWwF7QMAMRsgOcHSBC z/y60hCsXz8aMpJ8QjyNyAyz8NVQNSarOrbWt0Ft/KfnP8t056cQj+4/J W/QI1ZUuwgkwd2FOrdQ40TG3zOv+YtzeQ2PQgDbJOBZF7M6lL3lOLFpIk 3dYRQk44pkJEZRQOtM5EU53BPSXq+U8zXub7jeucWd4UAHtDJpr5YCewY X3W6JtryYPA+3uruEMiXE5lgjOHEgSaH4RKG1X5MgpGKT6HaCDwx+B3ay P5T7izXiME0dqmYfX6bXg2PruIcjeuoyycnFUeEFrKnegxHpUu0gX+K7Q w==; X-CSE-ConnectionGUID: a1WeVPRUQWu5QleksG2ZSw== X-CSE-MsgGUID: 06rGN9lFSsKWh9hJLsvxlQ== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178454" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178454" X-CSE-ConnectionGUID: h0CgTnjiSR2N52HXIVMv9g== X-CSE-MsgGUID: Tdbl837hRuWFvDyC7fi8zA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564953" 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 v13 1/9] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Wed, 7 Oct 2026 13:09:20 -0700 Message-ID: <20261007201222.648687-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404083960158500 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 bb0f41bb1e..386db05e5b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -948,6 +948,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, @@ -993,9 +1010,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, /* TODO: a common DMA map SG helper */ 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 Nov 23 05:00:11 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=1791404136; cv=none; d=zohomail.com; s=zohoarc; b=G4ry8bxmiqk/x8ZKVmR6Aqz5xyIrEjbAYxnox0cBfp2Rhdkjc34i3TTMn426Tkg5XwHxtw4Dv+EBvTNtREx/wcFK8JePU+JYHJnNWjwJ9UhZHsVZeWgVAzEBGSoMP+8IhmpiGnUOfkRGyR5vvddx3Uqw1ujXRqS8ocwd1iFdaGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404136; 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=qcLQIk4G1SHpyA0aiEF3CRHd6t0h6eQuFugtyQTjP4w=; b=CX5AL/MHvHFfNHLMl0ItnyUqAGQeQn0MeYxK7B9iZsIfYv2sKbg1TV5bbLIYSIDPDVmiAzg3HBwcLAhJsWStzgKA3GPYMDAe5sBpCIcegdclBUQt9r+ouAgQpb4XFmOfSUcxrs2GUgR03NtAvUnPXN/qFuYKEYsd0TxOBySFKiw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404136936371.94302631467406; Wed, 7 Oct 2026 13:15:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1Z-0004Za-8P; Wed, 07 Oct 2026 16:14:01 -0400 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 1xEY1W-0004Ye-GO for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:58 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1U-0002B7-Dc for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:58 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:48 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404037; x=1822940037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rwyE6cR6hgEBINtf7YjYhXPvHcIR4ULy5pnzxbrkrzE=; b=WIRPFHeFE6Eav+zgokbAZhh0ohUKffslqL4lfFPewJnk4xFP5jec7XuT O+2xefERJheiPyQL2P05+mOK6873M7uxquOr/YvBSPR9a5LsokJKa1mon 8/TRWofyE2+brBLt5nVn3uKJBY8gWpNmi/0sKRSnU+swdxslPo6V8z+BK QQ1GeA1w7pC8RNRvg//g4cI3kXDYZDeWW9WJH9ZQ1L/uzOnBcYSeDm+fo B84scuWL02D2yuEtyW1lW97x87zD/H8F1G8bzqxom5nDH4snW83Otj2Na xu5o/w+K8VGT6YDxxKBvZrrAZ/Oww6xSftpc2hRfpZigcHbGwSsdBep5R A==; X-CSE-ConnectionGUID: XSJ9EPm6Q4q44gVMvFBGRg== X-CSE-MsgGUID: QEPDyHTaTWCunO787NJibQ== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178462" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178462" X-CSE-ConnectionGUID: 66DRKZLGQvihknpMiOEeFg== X-CSE-MsgGUID: XjdN4wjqRS6TQHAQN9EF/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564955" 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 v13 2/9] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Wed, 7 Oct 2026 13:09:21 -0700 Message-ID: <20261007201222.648687-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404140046158500 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 --- include/hw/virtio/virtio-gpu.h | 6 +++--- ...o-gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs.c} | 4 ++-- .../{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} | 10 +++++----- hw/display/virtio-gpu.c | 8 ++++---- hw/display/meson.build | 4 ++-- 5 files changed, 16 insertions(+), 16 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/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 631dfc63a4..4f3a5c6fb3 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -388,10 +388,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); -bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +bool 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, 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 1a9dfbdec1..83c3e16c23 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-dmabuf-stubs.c @@ -7,13 +7,13 @@ bool virtio_gpu_have_udmabuf(void) return false; } =20 -bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +bool virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ return false; } =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 6d2bc8d977..c537ec0a8c 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -71,7 +71,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); @@ -82,7 +82,7 @@ static void virtio_gpu_remap_udmabuf(struct virtio_gpu_si= mple_resource *res) } } =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) { munmap(res->remapped, res->blob_size); @@ -133,7 +133,7 @@ bool virtio_gpu_have_udmabuf(void) return memfd_backend; } =20 -bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +bool virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { void *pdata =3D NULL; =20 @@ -146,9 +146,9 @@ bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd < 0) { return false; } - virtio_gpu_remap_udmabuf(res); + virtio_gpu_remap_dmabuf(res); if (!res->remapped) { - virtio_gpu_fini_udmabuf(res); + virtio_gpu_fini_dmabuf(res); return false; } res->share_handle =3D res->dmabuf_fd; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 386db05e5b..c7346c8c68 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -407,7 +407,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, return; } =20 - if (!virtio_gpu_init_udmabuf(res)) { + if (!virtio_gpu_init_dmabuf(res)) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; virtio_gpu_cleanup_mapping(g, res); g_free(res); @@ -1091,7 +1091,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 @@ -1136,7 +1136,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, return; } =20 - if (!res->image && !virtio_gpu_init_udmabuf(res)) { + if (!res->image && !virtio_gpu_init_dmabuf(res)) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; virtio_gpu_cleanup_mapping(g, res); } @@ -1652,7 +1652,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *op= aque, size_t size, return -EINVAL; } =20 - if (!virtio_gpu_init_udmabuf(res)) { + if (!virtio_gpu_init_dmabuf(res)) { virtio_gpu_cleanup_mapping(g, res); g_free(res); return -EINVAL; diff --git a/hw/display/meson.build b/hw/display/meson.build index d8b4e121fe..89b8f74b7d 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -73,9 +73,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} --=20 2.53.0 From nobody Mon Nov 23 05:00:11 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=1791404114; cv=none; d=zohomail.com; s=zohoarc; b=eCJcnw6vJJjGtOhlii3pvI2CAElrNS2x2l4zS0j4R18mA5WfhRFYnYIXd/Mpn8dYaFAvkgzrama1NOXWwhMk6CWTCZE6b+6G/zCzN2oa36jGXLpCEmN9Bx36o0VEefUqjciNhgaVblJ0fZGV1fFlxgA10ipnpmkITZuSTExGzJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404114; 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=ISRi9l7HO32s2qk+BHXkL+xpzinQVZYUSoQGLXPMERk=; b=iRtRv1qRyY6EULwX7nC0v2HSA+Fo7ej9lczwnm+WWtpDEChUZ5Nkh/gFSlP0/wwiHTyqQ7OAYimNmaiTDRlB3HqfKwWqQV4CVuFYz10xp+1Kd5uN2ID4KmRHRAFRLPaMcbEekBtIw4y5qJCXH4qqYc68a5oew1TA7sJWPMp0qIc= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404114144786.6656813426223; Wed, 7 Oct 2026 13:15:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1e-0004b9-8i; Wed, 07 Oct 2026 16:14:07 -0400 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 1xEY1X-0004Yq-HT for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:59 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1V-0002As-Rw for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:13:59 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:48 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404038; x=1822940038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qwvzbthrv4eyjjFKjrm+AYp5t6YQnrZPU+/lpEpVBZY=; b=h3etag1VhqwiX7cqgs3DUVM4pSwUhp7fym1CJpN1UvIoyAV5IFRUEMXa SMqJVYTqCcTS4IVcWhgr8E97LMSLr0AZDuBRjcU0bYhniDdTIsmAQKPUv P97fVr9WzD0S6FGTJ0igpgsQRgz9kIDhqI1CKgQeGQIMp0ofd/nZ/Rku4 j48VK8omZtkHJzPR1zRmEVi3UdMi3QN8pQdMKRZfoGP3gPE040cPPPt2a gMpCdvCyHNtUww2p1X7m661yiJuSFzWAQKtccgBGNrg4o4bUKYOBar35Q afN5SX5bDeMXrGyJ+fQdGhKX1bCPyfzU+8wKcb/gMLWXuCg/CK/C6G2Hb w==; X-CSE-ConnectionGUID: ateZ2xktQ1O2in/g07HcTg== X-CSE-MsgGUID: jFli9LkCSLqXuOiUR6odBQ== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178469" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178469" X-CSE-ConnectionGUID: qAnNuemhRhyBs2qpwKzQMA== X-CSE-MsgGUID: ELlgsIlLQ+ix8QH6/mYBaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564958" 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 v13 3/9] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Wed, 7 Oct 2026 13:09:22 -0700 Message-ID: <20261007201222.648687-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404115205158500 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 c537ec0a8c..0ed8d9250e 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -46,10 +46,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_resource *res) } =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 Nov 23 05:00:11 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=1791404130; cv=none; d=zohomail.com; s=zohoarc; b=JU5IuHY72CgiB+eQLLozz/AYhyjVE1hwAbmf/uFeSdbQvWKYmA4kdS1Ju5Tq6//r9XRwN5cTjtr+0LI3AvBQeiZau3fNBBX2CvSBUpUto/kwUY+M7PldEnNBuuUKTy2a7Jv59b8Z07dEXYwa70WyUK6fmFwIxY5PZ+bnIieweYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404130; 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=DRl5SnYHCRwUJUD7Yto1VMXhsFpnro0YWv5VH6rMPww=; b=enRIDNKhJlZhUL09xiSizs6QUPi2bKzFXmXoeDOc+RWh1pTH9RVwo5EhzjPlEJiVF/kTFKlqT5TjOPFDqufUireGmjfVJsby/75HEN9z/N1RUof/aacptpKGYrnS0Q0U+oV8JBYrQL6vpazi4lIfE4tZOguvWGUz38/9JdR6yTE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404130167792.1193603791793; Wed, 7 Oct 2026 13:15:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1p-0004cS-3Z; Wed, 07 Oct 2026 16:14:17 -0400 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 1xEY1Y-0004ZS-EU for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:00 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1W-0002BI-R0 for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:00 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:48 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404039; x=1822940039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Eii/Ddy1nMhhF7TtcuT2NL6phsSZI+C3se2iHxozDAg=; b=mC2KjF/gmM26KGGwQQedWPeGFCkwBy0zOs8YvRkhZK+mGOCGtZdVjNWI taa9aB2sdkb1j4/EmFxS1J5e1ViaY9IWD1Aa1U/VNjAT+2zWjm2JrWsXV YFnDyyehfX341GjvIVnKFbeiD2yznl9igPAM795UIlc2cgIhynDipa0Zc GYxYFX2Ano2OXvnaW9kdxjYDMtI5iYvfL8/radLztiX+iVOZTWsGADU4S 89WimdhOqI6CowR1scBYzv6Q6CT1+PM4KecoQ0nU1u1BT+iMY3K+/dgPR pjcL0U0Xd8FClEsoexDrIGGIVPxca+tDQHN2+j2/TI8FFyGyQe1WcNc/o w==; X-CSE-ConnectionGUID: MHqSftJdQdiMJrtfOGDIrg== X-CSE-MsgGUID: +jrMmm/2TCS1VArzj+7sug== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178475" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178475" X-CSE-ConnectionGUID: C5+FqnIqSw2CGwcOl+7R6g== X-CSE-MsgGUID: ocuLD+ToQ0qX+Gsj4GCqIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564961" 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 v13 4/9] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Wed, 7 Oct 2026 13:09:23 -0700 Message-ID: <20261007201222.648687-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404131352158500 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 0ed8d9250e..6f05f367d0 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; @@ -48,7 +48,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 @@ -65,7 +64,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 Nov 23 05:00:11 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=1791404115; cv=none; d=zohomail.com; s=zohoarc; b=OF5zuGJUwuOlhxkPd5QFw1IrQHrOhr8QMyBrrATmeUrSBbyhS2DMTD+JHqoDszRSG3bJI4No9k+Dxj1XvUx+JmikI9LVsq/7aBaApVtnsWGUpJ/K+9F09efNcnfEn3dmtyV/SxGed+HoldB/HKNLCAqL0e4Hq9zjHrxzAly1GMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404115; 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=xvC3pGh7wduupVd67isixuJKvbVJ3lwwvnPvt1ocK1A=; b=axLGv+n2C47m54C+WobTW7A7N72UmXn/1+bnILvuPbnN19acT4CDjhnD7BKa2qp/GAftG+nN8KXFjJabnd7ekjVVlKpzS+Woc3YgC1FdZtfNKJOT3A7Ee9UinZr0R0dUwzop9568XtmSY1uZkNpTRioLu1z3cTMMqVbze63w6lA= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404115011417.29642426643784; Wed, 7 Oct 2026 13:15:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1c-0004a7-8k; Wed, 07 Oct 2026 16:14:06 -0400 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 1xEY1Y-0004ZU-Nq for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:00 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1W-0002B7-S1 for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:00 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:49 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404039; x=1822940039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=inwtww5NHwOAvlK6g7TuLU3xADf1XCgYBQ5nhrGk3Rk=; b=GoiBhghsxaU/pW2JLEzCdamFjsXI3ogeYYhWsxCOQNcnXgrdFVXw9WgP /cTP6ZOqN9esiF56LHmFR72WzICB5PFaC0b0v2TlCCHIX9efr6Y1G31DF Ou8eTgUpQgFttDaolBFaRFsC46rjJ2H/hBKvnv1mZdGy/X9EVgYqEpG0a o5GPR9p7u9tg2D7c+AQ0q3eJN9VCtikzJaasMkktNEWny0cAZ6TZTOibS pS8jlOvvrOFcshn2lKPkr3XewV0b/qq/FHduP+VmtH3iDXa+vuPIdVPk8 7TrpB2FTIuLkkTbONTzNm0fQ1Nfiw7t6BfNdXdeHsHNUVcxANcfRiIRdc A==; X-CSE-ConnectionGUID: y6fMb854Sf6E+ObFnlGwEg== X-CSE-MsgGUID: Z1xIHdSVQrq6X2/LTPsJ8w== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178480" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178480" X-CSE-ConnectionGUID: 3Wt+APqCTJ6ey32RBaCAKA== X-CSE-MsgGUID: SdEpRjlvQXSQ0Ya1OKIu3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564964" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v13 5/9] vfio/region: Add a helper to get VFIO region from memory region Date: Wed, 7 Oct 2026 13:09:24 -0700 Message-ID: <20261007201222.648687-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404117110158500 Having a way to get the VFIO region associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info such as index and offset 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/vfio-region.h | 10 ++++++++++ hw/vfio/region.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h index 58b236f113..004be67269 100644 --- a/hw/vfio/vfio-region.h +++ b/hw/vfio/vfio-region.h @@ -44,4 +44,14 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, b= ool enabled); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); =20 +/** + * Return the VFIO region associated with a given MemoryRegion. This can + * be useful in retrieving region info such as index and offset. + * + * @mr: MemoryRegion to use + * + * Returns the region or NULL on error. + */ +VFIORegion *vfio_get_region_from_mr(MemoryRegion *mr); + #endif /* HW_VFIO_REGION_H */ diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 54ad11a6c8..37678aeb2d 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -528,3 +528,14 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +VFIORegion *vfio_get_region_from_mr(MemoryRegion *mr) +{ + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + return mr->opaque; + } + mr =3D mr->container; + } + return NULL; +} --=20 2.53.0 From nobody Mon Nov 23 05:00:11 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=1791404130; cv=none; d=zohomail.com; s=zohoarc; b=GbIAkwacpLBoa2uobUUWSxqCAKekHI75YwxYDFo8szSfUjCbrkAjWIg44LRfAoZR2tb5Sbcr1aERprqtwn2KklGT1q39RtJeQhnTsMGJG76ev00nxa6pPVsYn0riHcXnp6F77wLI9NlzLYnm2w3HUsQabTPC3wArhDJZTOBxWV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404130; 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=BeA6XlE88ZQv9canoco8WjFTau6B5TNgEyZCM1oXgTE=; b=CmVxts3sRLM+v99GfcSTbBFDXm5lIOrxj52dEc/IErg6PqjWYB8lUkEuf/8qqZkk6FXOaGIAqTeDxP7Rptwsy22+wE5krjrRLY6XMzONU+bGmdvZVyAxynS3WSsO9BCisOunZggfPnnrwKVtCEy/9oQ0GPmXGl5DjfWPT7jXh+Q= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404130240881.3544333736601; Wed, 7 Oct 2026 13:15:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY2B-0004hJ-9J; Wed, 07 Oct 2026 16:14:39 -0400 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 1xEY1a-0004Zs-7q for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:02 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1X-0002As-SS for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:01 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:49 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404040; x=1822940040; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q/T8KyL74rPAV+HzFaQpjnSm0i0Y9CZb9x8uwhqsQuk=; b=RR/zsjPlxUB7ZtAolwoVi/6XEaCYV58OMqUUgZJKTjRf/LAvao0KPnqm d1E8E5i4ky2HXhy0UR+ZqfoOkuPPo2hAYQ8boeO/n//OGtGt1EcZVQU1w YyEyTGrFc0udlw0pTXraIahicttC285Rg/b7z/V24iYpbGv9JRYwcjYFV GuIPEQAd/9Xv5eMlEc67YqbEEEztGBuOmmkMyn5/McMFRV5TT7IJq5HmT wwlizhjMXWmlwHRtULyTblRGKnPKEpaR9LftsMqApP/LOpt0za70PhB8O 54cTWtSKIipySMjB1thAPlGVflPobZv1YJI0dXz2HxOrmxTKY8CnR7zV+ Q==; X-CSE-ConnectionGUID: /b/eA6qSRweTzIwMGp5dXA== X-CSE-MsgGUID: RngvFFxNT8mYlGBcbQj7uA== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178483" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178483" X-CSE-ConnectionGUID: qEbaFcaIQVilEIPyiVAsVA== X-CSE-MsgGUID: 990LLwhhSIek3/SJ/yEAiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564967" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v13 6/9] vfio/device: Add support for creating dmabuf from multiple ranges Date: Wed, 7 Oct 2026 13:09:25 -0700 Message-ID: <20261007201222.648687-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404131462158500 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. And, introduce another helper to lookup the VFIO region given an address. 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 --- include/hw/vfio/vfio-device.h | 22 +++++++ hw/vfio/device.c | 109 ++++++++++++++++++++++++++++++++++ hw/vfio/dmabuf-stubs.c | 17 ++++++ hw/vfio/meson.build | 1 + 4 files changed, 149 insertions(+) create mode 100644 hw/vfio/dmabuf-stubs.c diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 8472420d3f..c05430be8a 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 { + /* The Guest passed addresses stored in IOV are invalid */ + VFIO_DMABUF_CREATE_ERR_INVALID_IOV =3D -1, + /* Guest or Host may be at fault for this type of error */ + VFIO_DMABUF_CREATE_ERR_UNSPEC =3D -2, +}; + typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIODeviceIOOps VFIODeviceIOOps; typedef struct VFIOMigration VFIOMigration; @@ -323,6 +330,21 @@ 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); + +/** + * 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_ERR_UNSPEC + * or VFIO_DMABUF_CREATE_ERR_INVALID_IOV 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. */ diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 4f11959633..d95503a5f1 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -21,7 +21,9 @@ #include "qemu/osdep.h" #include =20 +#include "system/ramblock.h" #include "hw/vfio/vfio-device.h" +#include "hw/vfio/vfio-region.h" #include "hw/vfio/pci.h" #include "hw/core/iommu.h" #include "trace.h" @@ -667,3 +669,110 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { .region_read =3D vfio_device_io_region_read, .region_write =3D vfio_device_io_region_write, }; + +/* + * This helper looks up the VFIODevice corresponding to the given iov. It + * can be useful to determinine if a buffer (represented by the iov) belon= gs + * to a VFIO device or not. This is mainly invoked when external components + * such as virtio-gpu request creation of dmabuf fds for buffers that may + * belong to a VFIO device. + */ +static bool vfio_device_lookup(struct iovec *iov, VFIODevice **vbasedevp, + RAMBlock **first_rbp, 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; + } + + *first_rbp =3D first_rb; + 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; +} + +/* + * This helper looks up the VFIORegion corresponding to the given address. + * It also verifies that the RAMBlock associated with the address is the + * same as the first_rb passed in. This is to ensure that all addresses + * in the iov belong to the same region. + */ +static bool vfio_region_lookup(void *addr, VFIORegion **regionp, + RAMBlock *first_rb, ram_addr_t *offsetp, + Error **errp) +{ + VFIORegion *region; + RAMBlock *rb; + + rb =3D qemu_ram_block_from_host(addr, false, offsetp); + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Dmabuf segments must belong to the same region\n= "); + return false; + } + + region =3D vfio_get_region_from_mr(rb->mr); + if (region) { + *regionp =3D region; + return true; + } + error_setg(errp, "Could not find valid region for dmabuf segment\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 *first_rb =3D NULL; + VFIODevice *vbasedev; + VFIORegion *region; + ram_addr_t offset; + size_t argsz; + int i, ret; + + if (!vfio_device_lookup(iov, &vbasedev, &first_rb, errp)) { + return VFIO_DMABUF_CREATE_ERR_INVALID_IOV; + } + + 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; + + for (i =3D 0; i < iov_cnt; i++) { + if (!vfio_region_lookup(iov[i].iov_base, ®ion, + first_rb, &offset, errp)) { + return VFIO_DMABUF_CREATE_ERR_INVALID_IOV; + } + + dma_buf->region_index =3D region->nr; + 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"); + return VFIO_DMABUF_CREATE_ERR_UNSPEC; + } + return ret; +} diff --git a/hw/vfio/dmabuf-stubs.c b/hw/vfio/dmabuf-stubs.c new file mode 100644 index 0000000000..fb5318e929 --- /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_ERR_UNSPEC; +} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index c7c31b78f6..aa6f4bc1b4 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -38,3 +38,4 @@ stub_ss.add(files('iommufd-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')) --=20 2.53.0 From nobody Mon Nov 23 05:00:11 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=1791404133; cv=none; d=zohomail.com; s=zohoarc; b=bmU0Xre6McJLNjoSXLh6AREevmtI79ETa+zhVP23+v+1rSacR3jv5XiAk48PjylDoHE+ka2nz438uVg5vweO78ysPK8ABES31sy0OnyxhV5EWJXLnsWbnX0GHtgSeYg9BD6ALZpelkMVCEA0uzJSVQwOHuQ2NydFz5+EOUmGO0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404133; 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=1c8hHgc39tj4VFO2U2GUyG6a031n3kg4n63UaL1mTBs=; b=YsVEvv3GBqQKVdEl9vXyMj76WZmRnnZlwgE2qZKXJybDsas3dU38keMNWi5BKWSuPhlDd2K3+++OR+E/lrViHP/UifyBLEKOdnfb5UFk0Vvc5D/v0bQB/1bZNJlT925AKmcQxA/Wvykj4p0Q4NTVoRaBLWkfWrv/6/zZCEnMRZs= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404133647272.86006542266466; Wed, 7 Oct 2026 13:15:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY1n-0004cK-FG; Wed, 07 Oct 2026 16:14:15 -0400 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 1xEY1a-0004Zt-NC for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:02 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1Y-0002BI-Pi for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:02 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:49 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404041; x=1822940041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eewvSv5A7/D5spMXJzGxhfFCFSwhWuB7A5JmKaq8VG4=; b=MEexrU7lydf6LCUKb82ekuQ0hsP1RIbtdmKusQwcGRDlGj39Y23kaRFo EolT6HGT1K6UWhz3ick/T7MDFNydHppymztvodLO56iJKLuGVRTVL4VFw Cy/4NDu1db22nY0heAYTfGYAHpVFJUWNGnS4ZgqaS6mLCxoGtoI6r2LOb 8kReitefTHMNoZK+X7CZlyjnIFrefok6U4T0zpDpjXsbXHuB/kLnRNL0T l64qumxgoSEaL3eoB0Vt/ikJVIilZvkQiRSHthbHJqfNZWNN6IV0U4FFc 1Dw9OcpDwBLu8gnrUhVoOVDYAM0JkLdJqpubAJ7bzvxFvRqDuBPPsHjjx g==; X-CSE-ConnectionGUID: rRc7hSIWSD2r9JJvrpAXDg== X-CSE-MsgGUID: MeoxBeV+SYuBIC2BE2F+rw== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178486" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178486" X-CSE-ConnectionGUID: i3tHxe2jSr2sy4nLIC9/XA== X-CSE-MsgGUID: PRWoqnA5Txe1IemkAeqapQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564970" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v13 7/9] vfio/device: Add a helper to mmap a dmabuf Date: Wed, 7 Oct 2026 13:09:26 -0700 Message-ID: <20261007201222.648687-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404135217158500 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 --- include/hw/vfio/vfio-device.h | 15 ++++++++++ hw/vfio/device.c | 55 +++++++++++++++++++++++++++++++++++ hw/vfio/dmabuf-stubs.c | 7 +++++ 3 files changed, 77 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index c05430be8a..4b8fb62056 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -345,6 +345,21 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int= index, */ 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 + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns the mapped pointer on success and NULL on error. + */ +void *vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ diff --git a/hw/vfio/device.c b/hw/vfio/device.c index d95503a5f1..5bc0443764 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -776,3 +776,58 @@ int vfio_device_create_dmabuf_fd(struct iovec *iov, un= signed int iov_cnt, } return ret; } + +void *vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + Error **errp) +{ + size_t total_size =3D iov_size(iov, iov_cnt); + struct vfio_region_info *info =3D NULL; + ram_addr_t offset, len =3D 0; + VFIODevice *vbasedev; + VFIORegion *region; + RAMBlock *first_rb; + void *map, *submap; + int i; + + if (!vfio_device_lookup(iov, &vbasedev, &first_rb, errp)) { + return NULL; + } + + /* + * 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 NULL; + } + + for (i =3D 0; i < iov_cnt; i++) { + if (!vfio_region_lookup(iov[i].iov_base, ®ion, + first_rb, &offset, errp)) { + goto err; + } + + if (vfio_device_get_region_info(vbasedev, region->nr, &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_errno(errp, errno, "Could not mmap dmabuf segment\n= "); + goto err; + } + len +=3D iov[i].iov_len; + } + return map; +err: + munmap(map, total_size); + error_prepend(errp, "VFIO dmabuf mmap failed: "); + return NULL; +} + diff --git a/hw/vfio/dmabuf-stubs.c b/hw/vfio/dmabuf-stubs.c index fb5318e929..b9e03a162a 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_ERR_UNSPEC; } + +void *vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + Error **errp) +{ + error_setg(errp, "VFIO mmap dmabuf support is not enabled"); + return NULL; +} --=20 2.53.0 From nobody Mon Nov 23 05:00:11 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=1791404136; cv=none; d=zohomail.com; s=zohoarc; b=Uq1S+qPXdPZ4u4gWqS4rMhRCjp474JIH6T1nFTp7VFmlou1cW52Zjcp6FR2tpEB/s2h9JOg8djnnTgOvRsPr9iVnY/NeqIRrEeLuMLAEFDhflvj6811C3UZKLawZccZ8gs6Nv0JG8xvbjW/dn+EUQhgc0OldycgnXoWmh/ohlnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404136; 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=20BVwiWCGtIBLiVS5bURwhDC1u5F3MeE2fR9BBXYOYQ=; b=kADdG/g9zwZNTv91c80/FDjBSv2wMnWCx3MO8ywt0cIBV8bhlER95AuHIzexKyu9Gb4CC3GIsIBWEh8koZFeo9GhAW62eD/zbm5bWOXN6Qel5ojg8sAvCSIDR73nu5ow7lFL8TTJck8RJXUDlhqEUTzy244HEgzG5Lolg55Wenk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404136542178.17148202200235; Wed, 7 Oct 2026 13:15:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY26-0004dH-IQ; Wed, 07 Oct 2026 16:14:35 -0400 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 1xEY1b-0004aC-An for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:03 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1Z-0002B7-34 for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:03 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:49 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404041; x=1822940041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j5Y5Ol7gneFTBsVCADr0uA3bbbqU8zNP6j9n0Cubp4M=; b=D56R4wlnzW3gVT79Fd1hQqur15a13NHOfgQ3PnVbmKfJJowNps0JHVKZ GstDkdDzaceWXS/i9FxCTM6iW2dfaJCrL1fa5tU312p5i2ew0CI1SM5fo ilCUl1nyglJXumcBEQmsZVIXXiMGR888/E9UvqKSPZls+r6Qb9wl6cs6N LC58I0IKZ2qe0YUR3H7CH1Uqnnyc1DrLqDosoobiQOkBh+Jj1Vry5S2yI yfQBOJ48FGQA422iMwpPYHBwciR0uXb+GeKcu2zj7A4c4hZRmwGOZpUbJ q0ge5D7ea0hOt6prhPzoIjxRBA2sJbreoOSohIImYRvZhWDyH14XpTVFf w==; X-CSE-ConnectionGUID: VxdSNqJbTuWUBeCVSbgyig== X-CSE-MsgGUID: 2JyNYqdVT96sR0itdLULww== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178489" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178489" X-CSE-ConnectionGUID: mVA8jQE/S+CDjml634+J1Q== X-CSE-MsgGUID: NRnJrLvhQ4SLEFQ1BQdxaQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564974" 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 v13 8/9] virtio-gpu-dmabuf: Improve error handling with 'Error **' and err enum Date: Wed, 7 Oct 2026 13:09:27 -0700 Message-ID: <20261007201222.648687-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404137131158500 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 different errors. This allows for better error reporting and handling of errors from virtio_gpu_create_udmabuf() and virtio_gpu_remap_dmabuf(). Furtheremore, the main reason for using the VFIO enum is to handle the special INVALID_IOV case which can happen in two scenarios: 1) When the Blob resource's memory is backed by a VFIO region. This would cause INVALID_IOV error when we try to create a dmabuf via udmabuf driver but we can recover from this error by having the dmabuf be created by the VFIO driver instead. 2) When the Blob resource's memory is not backed by memfd or VFIO region. In this case, since the error can be attributed to the guest, we should use qemu_log_mask() instead of error_report_err() and emit a message that can be used to debug the guest error. Note that, to diagnose errors, a common pattern is to return -errno to enable the caller to implement specific error handling. However, in this case, since we want to distinguish the INVALID_IOV error from other errors, using the VFIO enum allows us to do so and is very convenient. 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 | 69 ++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 6f05f367d0..c9de8e9ba3 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,28 +28,32 @@ #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_ERR_UNSPEC; } =20 list =3D g_try_malloc0(sizeof(struct udmabuf_create_list) + sizeof(struct udmabuf_create_item) * res->iov_cnt= ); if (!list) { - return; + error_setg(errp, "failed to allocate udmabuf create list"); + return VFIO_DMABUF_CREATE_ERR_UNSPEC; } =20 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_ERR_INVALID_IOV; } =20 list->list[i].memfd =3D rb->fd; @@ -59,22 +64,28 @@ 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_ERR_INVALID_IOV; + } + return VFIO_DMABUF_CREATE_ERR_UNSPEC; } + return fd; } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static void *virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *re= s, + 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)); - res->remapped =3D NULL; + 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"); + return NULL; } + return map; } =20 void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) @@ -130,6 +141,7 @@ bool virtio_gpu_have_udmabuf(void) =20 bool virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + Error *local_err =3D NULL; void *pdata =3D NULL; =20 res->dmabuf_fd =3D -1; @@ -137,17 +149,28 @@ bool virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else if (res->blob_size) { - virtio_gpu_create_udmabuf(res); + res->dmabuf_fd =3D virtio_gpu_create_udmabuf(res, &local_err); + if (res->dmabuf_fd =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { + error_free_or_abort(&local_err); + + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memory\n"); + return false; + } else if (res->dmabuf_fd >=3D 0) { + pdata =3D virtio_gpu_remap_dmabuf(res, &local_err); + if (!pdata) { + virtio_gpu_fini_dmabuf(res); + } + } else { + res->dmabuf_fd =3D -1; + } + if (res->dmabuf_fd < 0) { - return false; - } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { - virtio_gpu_fini_dmabuf(res); + error_report_err(local_err); return false; } res->share_handle =3D res->dmabuf_fd; - pdata =3D res->remapped; + res->remapped =3D pdata; } =20 res->blob =3D pdata; --=20 2.53.0 From nobody Mon Nov 23 05:00:11 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=1791404127; cv=none; d=zohomail.com; s=zohoarc; b=i3vOKnoEaCTaEbM7TbTz+kITh4qXvuqXQoO7ahrijqCzR7HnIrqIblrmgfPFnH9tHdXZWTB7KwtUW4Gv+YwD+3n6LI9aC68Do4z55F2V3TDj/5sypmAUMsykbt9ehNUckHY+FOILeBukK4ceiNbqhsvWLHFAQtokcIwM5Z4N8VE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791404127; 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=61jOD4ix+570u8MXEWc0KtvDI9YPPXIwip3k1DQIiEY=; b=YOlHo/rtOqTUZZ7ZbHcgWD0b7i7l+a+lmBAK5z7rXaGzbQKb/ST6arkCXnsBGa0jmeB9K/Tr8kWDaS4YEcXIZ04NrCL5vIfOroH+zykIm7R2CNni8ugLy9e3eowganJRhyY6KUUx4B7jWSgztK/67fgCt9crq2PutZYWhQbCG3g= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791404127254262.5797235464371; Wed, 7 Oct 2026 13:15:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEY2C-0004ip-5J; Wed, 07 Oct 2026 16:14:40 -0400 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 1xEY1c-0004ac-Fe for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:06 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEY1a-0002As-Ky for qemu-devel@nongnu.org; Wed, 07 Oct 2026 16:14:04 -0400 Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:49 -0700 Received: from vkasired-desk1.fm.intel.com ([10.121.64.242]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2026 13:13:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791404043; x=1822940043; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z+oIk+G77ffAyvDt2gk8Rm+x+U8QdE6+d1lK3skZEJg=; b=d314cDy59YADPAcmh/iJ0MzGMIzlHMYBOQ5iZ6NrXDPRbLTa+TWuYhR3 ltbUdrzJj9Gmr/8Y9/sxXZjDn5qxM/Ij6JwduX1Z6vLib05TZfTh5mzjD 2fm+wtKr6MVzaJZb2lfQPUF0VrZgzO22V0XPpafV/PXd79sV5xTIxyFWr 6CSjBuvosOO8L18SNZIMFVOBeAtClTLz/uLX/hImb1GqgSw5F31gpShAE RKtK1Fk/+n4W04qiO6dHTZGdLx/ZkqvC6H8Nhy93BN2ear4v0/SxfW5Fn 4BSCucRV0P6B9PnJgO5qfqR2trM7NcTmC3BGB8drjRYyS0yrI6lZXmvcb w==; X-CSE-ConnectionGUID: gS6jm915SVeEVK3Sq9L3GA== X-CSE-MsgGUID: E2qwUCr4Qmy1m7i7eym2BA== X-IronPort-AV: E=McAfee;i="6800,10657,11928"; a="178492" X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="178492" X-CSE-ConnectionGUID: M6jGtRfrRyOJijW7ih1Kmg== X-CSE-MsgGUID: wa+m2lQaTuGS/KknShBJbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,144,1787036400"; d="scan'208";a="1564976" 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 v13 9/9] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Wed, 7 Oct 2026 13:09:28 -0700 Message-ID: <20261007201222.648687-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261007201222.648687-1-vivek.kasireddy@intel.com> References: <20261007201222.648687-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: 1791404129134158500 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, for mmapping the dmabuf, we directly call mmap() if the dmabuf fd was created via virtio_gpu_create_udmabuf() since we know that the udmabuf driver supports mmap(). However, if the dmabuf was created via vfio_device_create_dmabuf_fd(), we use the vfio_device_mmap_dmabuf() API to get a mapping 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 Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index c9de8e9ba3..f59a5e76ff 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -153,9 +153,25 @@ bool virtio_gpu_init_dmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { error_free_or_abort(&local_err); =20 - qemu_log_mask(LOG_GUEST_ERROR, - "Cannot create dmabuf: incompatible memory\n"); - return false; + res->dmabuf_fd =3D vfio_device_create_dmabuf_fd(res->iov, + res->iov_cnt, + &local_err); + if (res->dmabuf_fd =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { + error_free_or_abort(&local_err); + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memory\n= "); + return false; + } + + if (res->dmabuf_fd >=3D 0) { + pdata =3D vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, + &local_err); + if (!pdata) { + virtio_gpu_fini_dmabuf(res); + } + } else { + res->dmabuf_fd =3D -1; + } } else if (res->dmabuf_fd >=3D 0) { pdata =3D virtio_gpu_remap_dmabuf(res, &local_err); if (!pdata) { --=20 2.53.0