From nobody Mon Apr 13 09:25:02 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=1772853139; cv=none; d=zohomail.com; s=zohoarc; b=KIlJG7rnLxb7Yvvov5KXoHJNv6qgJyUgUxJipVk7iItni4oWkHVLRgTxlMVXMTUjFyOMOsulXJF2vdX75YIF5gF7PyRcMYX5GjG7UIDHWg661TLCNM1sMvIpkeoBzH30j3Gl2IXxwShR+bdJ6xRk0odBcFH1SM0sZTBJs7/9YLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853139; 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=2es2aBjZqT0ax3ThS164ydpYHqlvwID5B2Mml69M/Jk=; b=XCWdPwv6ZXprNbsxntBSXMsNI2V6AN5Jvcz/Bhzrgz16gyYmfkBMshSmA1rGD1LsEws4CcfB+nM8vqTNZQ0xPQBE2A5M9OIsY80qgoq39/LR7VY8wasZWdrOct7O5Mk5AjhobnAh0NbeEWLKp+pFqmsRTgdQK/04rforvPJXyX4= 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 1772853139461320.57471550635944; Fri, 6 Mar 2026 19:12:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4P-0004l0-CI; Fri, 06 Mar 2026 22:11:13 -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 1vyi4N-0004kY-H7 for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:11 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4L-0000oY-PK for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:11 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853070; x=1804389070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mSJwk8OL8GT7Kwlz7h7yRvXBaRvRP8lpklTQLrCYMRk=; b=Ag26J0+K+knYfig50A6DTMwwO8ZKbYq8bT+Nsf9xBvYrIf1aJ7bdq/zw NPmIoYHhq00lZ5w6KAPD3EBPnr6pSymoKp5jMWw2OOX8mwF/syHvF34v+ mXAuXB0dhyz04pgjoB2mt0W1/NaCq74B3LMBLjUUVqs7Ay2Ridpq+U5BD uWs2QC3XLU8FPc759KM+3Xet7/2xuR19ObdmZ+5lmRvcXquFrqjGaPWKR fZoRgDr1TUcRLflSp/8AKMXDJZGdhViygsL7tH5y3zs+qAlQwW5H9UL67 3I3Zb+3DiGijOdxnyzebHAfvUmEeEK8miWvHVgeOWBE0DR0lSuLJQwy95 w==; X-CSE-ConnectionGUID: z8qd3GqIQUui0fUFei1vjQ== X-CSE-MsgGUID: IuYHfzShTm6nFbv1WpkjWw== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434000" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434000" X-CSE-ConnectionGUID: Kcs+ZqsWT2iSmKQP5XBITA== X-CSE-MsgGUID: 42mCRZaMTuucO+C6lKDjHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813758" 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 v10 01/10] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Fri, 6 Mar 2026 19:05:50 -0800 Message-ID: <20260307030812.1224392-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853141410158500 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 Apr 13 09:25:02 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=1772853121; cv=none; d=zohomail.com; s=zohoarc; b=ay7/d+OBnxmvGyTFeiPJZyDQtU8bguKfJWj+y/qpDR6d6aL7gBh0GI7EVDGJYENaBXSkXnE+84+V52EM4VmumGaVfFLirt6H7zaFIh2DfR+1Kmwga1WG8bu5IXoj/t+WsnGnIR9UATBnRF+vzKM9IxKmTWzj3BRXonZBwCiWbdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853121; 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=IjQw6pPmuOXaZ5QI80xhzU0pxDQLXI1GCHD+y2io5Kg=; b=Kzq/UPtJdrrbQBhslSwwRFKvD1anL2i7DMoKW+gEYViX4FBKAyxvyoV+4UYLEbbhD4MvxSVK1gP1mGnY88G8vTZvN2ZxdywKroPfRdokhKRzmAHTyZR0q+UsgZ/OqXlyItUwkwCQPBDJ624uRzVSc1ui9dw5RlaPOTAhBJN6Y7Y= 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 1772853121144778.272209460945; Fri, 6 Mar 2026 19:12:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4O-0004ki-CX; Fri, 06 Mar 2026 22:11:12 -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 1vyi4M-0004kP-R2 for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:10 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4L-0000oK-0T for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:10 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853069; x=1804389069; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lYWaP1kFmLOPTRi7iW/x1sxii0x816fC62gZjXLi8LA=; b=TfKHhizR6lbM5w5d3ncLAHp0p05UOwUlybpQ1vl5316m26NjIzhZuEq1 Nr2rrFRuXmhzzz2ehuHGjpQyPMQ3a2o4pVKnSJUZ00e1Zpkt4adDSDKMK yzit+N6agblzPP4PCom2da09Anuw0KHO4DQ+JSIaO+73s9m4fDnL6gd7v oVadcipP7/2x+EfcazRcUn85AtPqkG8Uh7cfeybvJ3Y+ir8chhBh1USlu lq8Dgz9FrCnbo8+l15no59wEsijFHl/ZIKAGOuigHI+gnzMPDI3LweWnD 9vqpFXliCdNsgVF9BhMxj6uE4w4MibaARkHxC79EY4oiXqaWvvvkoSZ9K g==; X-CSE-ConnectionGUID: /QmGwQilSYK/8wKY6OV05A== X-CSE-MsgGUID: hbUQe6rUQCuApWDLB/bSFA== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434006" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434006" X-CSE-ConnectionGUID: TuAfv0T7SpuORSVUxmYh0g== X-CSE-MsgGUID: C7q0Vf6ETNG84msgqhyPeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813762" 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 v10 02/10] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Fri, 6 Mar 2026 19:05:51 -0800 Message-ID: <20260307030812.1224392-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853123624154100 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 Apr 13 09:25:02 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=1772853090; cv=none; d=zohomail.com; s=zohoarc; b=TKgOZ55cB7N7W8kfRbvVT2diunyTMTonoFF2S0lX9pu0UAaKYqxB7L8c0KHbWUywODPY9r+ZsEYm8CNa258+bQ+BiuKiuNV6AuNnqsHnHfFiaMZQfbxfQC/2BXHVVkRi0GwZF7QRCm29Gv3dMZ2siJvf/4X+JCE9DcS/zocl8RI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853090; 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=CjKc2dfaCZ8RDOAHkh1/HllNQZ5mWbZaYCP1KLlmuws=; b=CaXdTdiw+rNLHc3ht9p4iRNHrRrrVJ91kIOqS6L0NUEz1GWQPpAw/AhCRmfsPR0I3MshYFXIgdk7QQZJGmxGH7z4I/FqCzzGTgPZwzcSI/RHhc3KxZ809LAS3fER/EmliPHjyuc54e/gfhRlPzQ10W19l8DU+4ZtPVMojTF1TYY= 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 1772853090905506.48517753906935; Fri, 6 Mar 2026 19:11:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4S-0004m2-EE; Fri, 06 Mar 2026 22:11:16 -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 1vyi4P-0004l1-0p for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:13 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4N-0000oK-5K for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:12 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853071; x=1804389071; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WQUubMglOINXkPd3puxed1kwRdXppIaQlkqgg//+It0=; b=h/kgrJlmyb01Y4vtDrgRoMNJNiz/rvYpRH0R7N74TM7sSNqorJocDKV3 tyEDhPE1GueJ6LPQo9STBKCBueFiqerc1Gi9R0TzEU+nquWUSpNavSKzB Q9tXw/3pTLfj3tynHRXmDn12cKQYgk79VqO7xvP+Ux0lIgKXpdgxOBAU2 ca+4i9gnTtaNmaNtEoHcyDaNtcQBtL5W7ibf6d3xVZ6fE9nQ7NSExl194 m/84sKrHxAOOl2rndBsahFVgvLRTBz9629WA3LqEaIos+yOaWu0DzDDFY WJiMxenXyXfd68VkT5L25mbIpZc41vAOjmGm0QStoSP0K0goa/ltdSXM2 w==; X-CSE-ConnectionGUID: bFqp37g1TZ+G7siy02T2Ug== X-CSE-MsgGUID: bx3R4Z7aTyOz9wZThpBftw== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434012" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434012" X-CSE-ConnectionGUID: kdtqaIWaSCmQxkcd30TbIw== X-CSE-MsgGUID: o74JDwo0S8e8VKRrDpXe/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813765" 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 v10 03/10] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Fri, 6 Mar 2026 19:05:52 -0800 Message-ID: <20260307030812.1224392-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853095032158500 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 Apr 13 09:25:02 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=1772853168; cv=none; d=zohomail.com; s=zohoarc; b=X+wPwG6dhS6N2EoImp3eXArF4q5SR37U1mbzmoQ8vd2z56E1y5HwmZPZ5feozGKUwhMISUExfnqaYg7yY3Z7RMWii1pjGo3/GhUQ1azrzT+mVrxjiFne+e2vGr23rut/4EVk2p6XuHUlROnXFLFnSU5SumPT7cO4dJls9YDZQew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853168; 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=O757psUzrLOk7D5GbwxVXa8G8dto6wK8L8QMqAHVRFHMwSzP4jHHsGUIE3iMrDK5Y5BA+jalJNdo/Dr6XJnq38K8siwB6XcPSH7fEzr6MWVgFNEyHSr86eE9/5nO2xgchywyiUBm4AivX1hOBUlNaXnf527pqMLte9ye5VI9blQ= 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 1772853168211780.2124546788979; Fri, 6 Mar 2026 19:12:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4Z-0004rA-4o; Fri, 06 Mar 2026 22:11:23 -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 1vyi4P-0004l2-DX for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:14 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4N-0000ol-Pu for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:13 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853072; x=1804389072; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8DjDopZg0XVik4k1ICxjRmt2mb1IxbLdY763BFKsh0Y=; b=nJU5n4KOiHduq9phni1lYu5bRLPsiskALxAQa3w2ONcqNmXdzGWYZxC7 Ca/pCFYL7kGuy+CZsd2hXPvYGCp6/CAAnMu8oXF0rs0Y19yq/VD2cpYWh 0QNk6BJEr6reNqoulAtyUlCYbuF28iY9hoZiptKbEl7QEu+satNLamhO6 O0tmMi/YqmdOz1Sd7uBGBhzhA++uBJf+/ONWmH5Q9AttYkUrXc+Ws+roX KQbMKqrl5pLSaA4gZpthTdyxDAGh5Hpvs88J2JlAJtxBx9Po75UK8pof+ G5kERtT48nfbon6NYGBxTEQH4E6lCg5zQFYpgNg+PGKSQ9ifGD08QggfZ g==; X-CSE-ConnectionGUID: ud+kD78fRjqmpigP4KZ6TQ== X-CSE-MsgGUID: p/6v9nLiQguRBiXBPAZv4w== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434018" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434018" X-CSE-ConnectionGUID: TAPcllkAQdu5UVdjrtdd4g== X-CSE-MsgGUID: VH6tO3iyQ3ilgq0dZIZsCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813768" 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 v10 04/10] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Fri, 6 Mar 2026 19:05:53 -0800 Message-ID: <20260307030812.1224392-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853169784158500 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 Apr 13 09:25:02 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=1772853109; cv=none; d=zohomail.com; s=zohoarc; b=HZAl1ppZGfJwiwqspG+jbRgWT6rc4fmRxFQ8cSopaSXkM6AR7rWyDaDLqhnPXXqRr4iYMwrK+9h+bPH/BSKjqb0Fjx90rjODskyWYtx5nOSsMTOabE2z0rVjBKHytl+kewhXcu5hRSMECbIeJfdAoAupHDy4C2tDfCqcmZMSIP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853109; 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=Sji0JwzR9qZCKWYE2zJPxBe2z9gkVpvDXTRTVvNWlt8sU/CmClY71pzwHv7NPXHiLhkO8T4CpaoL0C4lkIxwIkW3d7H3m9OFuW4du2OlNG200HPZNq9aPSUEUUhbK2tlmi54UagO+XVfOKghVUGN61RhDpm9bUQ+OpqvKygrEqE= 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 1772853109901429.88425376386704; Fri, 6 Mar 2026 19:11:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4U-0004mB-Bi; Fri, 06 Mar 2026 22:11:18 -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 1vyi4Q-0004lD-89 for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:14 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4N-0000oY-Sr for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:14 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853072; x=1804389072; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R+voCt8gQq6Y2SKx4ENrPxTbBWeBaPJn71IunQUW5Lg=; b=npPKcAd8R6wusNcVlbQUwjBy+gjU29ERu3DVKvC6QWgY1IadvNR/I/7r t0S9N7FUIkxX/8ZJfOUddDB0bId3SiB58LBuT2YZxtjLP7TcLXCpEuOl9 tzjGjFq7hoH/KkFehdbHIrnnxxbP+TQB05y0+OrqQhTxhaXrPoMx2aBdG 6/dRo6lAts0pLO6j/ADHe0XAVFWVGAS2ZS0c7iBbK2kSNkyl30rrPf/5A y1gBXTa6hUMXCega/JgFDnf+PUd9h5Uqrj0P2SanZELwGRMGniBSMCEt4 j1WJ1lWIrgVqwegQde/lPQcwU4N/ExJRW31fKOeCA41FbgixgAcGOK34H Q==; X-CSE-ConnectionGUID: ARxgGzNcTa66CYTdvvV+3g== X-CSE-MsgGUID: gb/AixdCQ+azgfCdv/8GrQ== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434023" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434023" X-CSE-ConnectionGUID: rIC9dFyKRr2Ua87KNTjKig== X-CSE-MsgGUID: +EegjvOyRhGZsMEcWzFlVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813771" 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 v10 05/10] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Fri, 6 Mar 2026 19:05:54 -0800 Message-ID: <20260307030812.1224392-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853113844158500 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 Apr 13 09:25:02 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=1772853167; cv=none; d=zohomail.com; s=zohoarc; b=WCEBSOlivbEWVEjj+jO5CRbGN3l+KgsgLEk4cDIMlILwKEznoEaNzShJ3F71GIzJkwtwMn9z9x91CDQM/p0zsouG7WaiLFAbAT7FcoLG1OmO5/fuz71gb5byUUDOKYbTVEmDteANH5PCig6Fu5XivFaUSakvHgz/aFbx65LviE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853167; 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=S3UH7MRpdi/2u1cdCgKrlnXK2z+zf1WrhkflsMX9dBNbEXoaz3rLx8rb9yZvYuKsTwht10pU67zRLRpdigoigSqC8AlO0yaXrcdgBfe8USU+lSWBqVjbPv/Li/S8zXMsTaOeeEQLwc/SR57mn2iBo+QFXEuF7B8BvfUhcZD5z3c= 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 1772853167410329.8760312496132; Fri, 6 Mar 2026 19:12:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4V-0004nf-So; Fri, 06 Mar 2026 22:11:19 -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 1vyi4R-0004lg-2n for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:15 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4P-0000oK-BK for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:14 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853073; x=1804389073; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1TEvr2QnTOUFzPzfTMXk5IYYw/2XkOgNrkkXD+yNNs8=; b=Bi4V6+pwYc91lJji3ycMp5qW2bh3IgiHFugBd5gRVfp2z2CJRzLcsD8Q n78Sn1+L29CFzQ4rhAbcYud/UcuURz44yu7AGPGMvtspoLdyHAJrLQ20I ziSmdsB3dkQ4Rjs1WH6sjfuuNy9HcMSRxzKu6klz6TWfuOhfqAdPZ8T3M IUdsi3Bd8dKq279oKUxLIpD+b/YlqZl6XbUMMq4ZzV08yGuuhl7+0NNH2 1v9dvx9YEyAiNPA7m0e3IzasKIQYh2LT63BbU/LymeWpDQRzvluCKiybA nP+gUil03IpLKPf3qX/ZEb6vXSAQUulZI09/56nZPGZ4cPgWUGrmuqJxX A==; X-CSE-ConnectionGUID: 4f/Bpr1mSlyvhKZjYvs66w== X-CSE-MsgGUID: UbOl8diNTcC+qZKDttRPcQ== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434029" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434029" X-CSE-ConnectionGUID: zHPNlRYwTa+0um0pZfA80w== X-CSE-MsgGUID: qbiYDQdmS6qywCqWvIcb9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813774" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v10 06/10] vfio/region: Add a helper to get region index from memory region Date: Fri, 6 Mar 2026 19:05:55 -0800 Message-ID: <20260307030812.1224392-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853172139154100 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 Apr 13 09:25:02 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=1772853156; cv=none; d=zohomail.com; s=zohoarc; b=CL/8XnPLiRMSba/pPzuPFpj235SwCTrdkymxo9N57D6X9I/oitkkMTNgUps6mGJTqqqjCjSfAwxoX7T0ubQnVynySytHxoFknGQNJG5uwlVZ+XrucrqUGlrdEaYeKjzWS6hnX/NngxxIjA3/IWPFsY4rP3juj4BzPw9OfHr8Ync= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853156; 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=VOnbMoLWDMvkA0U8mrp+cB/Yeuu0x8irWI5zenbfzWA=; b=ZA0v7DBpSiX63di5liwAMEmt3pacDbfex/RqaNq3HcM1xIYmAvKDPd28DQhplx1VsUlbsw4vjj69LDl2VCRvgACeNgm1MKe6U0S9Io8OguBMdhANJt+0B7bLmySYcQ5IW5Ac4MYMH+PgM15adg5UtsxqPdSJzxtyxB4jQlPvj50= 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 1772853156356889.470665103836; Fri, 6 Mar 2026 19:12:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4V-0004nT-LW; Fri, 06 Mar 2026 22:11:19 -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 1vyi4R-0004lo-K0 for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:15 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4P-0000ol-O4 for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:15 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853074; x=1804389074; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UItcbupB/uwZcfp4UNEcPNYUFQcpUcNo+S9Ep6gGUiM=; b=cGp/wTRcr9B8/Jf0PxZdds6KIz/fZ+HQp25EkUKsDsWgmX6m8GG7HOQs g0bGqkmRi7vbltEV2yuq+B7vckLk0LB72OFgSr5WRoL1/x2n4uTBMN7sc y3KvEvi+MKQyUvqFk6e5t4/scSIDgpEKS4PBfzIkNMjzXBXuAxcFUTHJY vofOIargtoQdyKRdlbr5HjLwzPmGFUsUIjvjVGZgQ7l7oyKcwBUTFE/XD HpchoR3kamXupdjKeEh+SqrunVt4qRvb2zubn3P+ISkp3xfDpEnAy/247 Zsdvv3ZHWvLt58PPmUdn3aSuCEEnuOKau40EY3Vo/FK/YNRyeaxZpGMks g==; X-CSE-ConnectionGUID: MFejFkQETTyO8RRyFktB6g== X-CSE-MsgGUID: FQUJ1R/ATKmgx+Fv4y8+XQ== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434035" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434035" X-CSE-ConnectionGUID: XW8XJuR4Tz6XN/X0Vh8HvQ== X-CSE-MsgGUID: BWGIxuwVS5eCXWxAi4ZTNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813777" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v10 07/10] vfio/device: Add support for creating dmabuf from multiple ranges Date: Fri, 6 Mar 2026 19:05:56 -0800 Message-ID: <20260307030812.1224392-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853157443158500 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 | 81 +++++++++++++++++++++++++++++++++++ hw/vfio/dmabuf-stubs.c | 17 ++++++++ hw/vfio/meson.build | 1 + include/hw/vfio/vfio-device.h | 22 ++++++++++ 4 files changed, 121 insertions(+) create mode 100644 hw/vfio/dmabuf-stubs.c diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..2d01059be0 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,83 @@ 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_ERR_INVALID_IOV; + } + + 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_ERR_INVALID_IOV; + } + + 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_ERR_INVALID_IOV; + } + + 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"); + 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..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..566e5d8bc0 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; @@ -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_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. */ --=20 2.53.0 From nobody Mon Apr 13 09:25:02 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=1772853156; cv=none; d=zohomail.com; s=zohoarc; b=Gos6LDe8W5LHEqalutrBknaqhk4xtiPY88Wno0sKar8LpsjUqgFWuOa+t9CDTQQlpP6U95JoSyFSrSY1f9XMFI49T245Xpg07y279tf9rpU9nEee+D5NepbzwCRqLYEl3ifFvNFuXx5GmpdFqlWjjkek6YRqMZYW7qw+/Flta4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853156; 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=25A+y7ap2R6Nq4CWTqZp4faqqZSKyYra0hzvjJ8fQo8=; b=NrKHearjUGKyPGXnRsEn5zbIQKTN05NnCcA+zNE9Z3Itazn+529VDvvrdqX+IL60w08tTADB5XBq6XywO+RSUH9YYJFVnKeDC/OvHSluxOnpip8IUIOraWTwx8AUOrbEy2ccgPbmEpqDiErwPDvFju8HHCy6ZULPFUceZ9yJVCo= 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 177285315613219.40131849895363; Fri, 6 Mar 2026 19:12:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4W-0004ni-3z; Fri, 06 Mar 2026 22:11:20 -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 1vyi4T-0004mD-BV for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:18 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4R-0000oK-Cs for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:17 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853075; x=1804389075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hhz5My/Nci4MkLLcv1gOxQ5MgaITXA44LkA+ZiKWCXU=; b=Fo+JwFxi/52HJx57F1SeAJ5dmlYrMjZ/ohY5L+d6UXMTVGvXVDx9DefC iBxsR80Z/dWGa+tCrA6bZJMw6GaiemLCDpR4zy8Ih7vfMgcN9KCjgoZkx uRjSAA7piRHVrIc5OXh0IVnXO4rnAzIBVuJAuAJU7G7Z7WojFo/3SWc18 4C0hYEhJ6WFg3Rj9aH+QNAOxvWsu8AkLDBknTF+u9R1x+Qb299oZcavu1 e1yrOvbryn3okGSJUw7IlgrrRZmA4+dpFfXVS/q2OpI+iuLEb/TkPd/W/ WkfpSdOhKKGqL2pvZnPfAs5KW/8Vw76L8InDURwzNmNtVucfjXQAFyRCa g==; X-CSE-ConnectionGUID: B+ec/WoqQuGXiaO0Nrw28w== X-CSE-MsgGUID: UMi8XxiLT+mb/Oi2i0FRNA== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434040" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434040" X-CSE-ConnectionGUID: q9DVSK8HTMSy63lX1FYqsA== X-CSE-MsgGUID: xJUNaIDtR4ObOPmwmjHykA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813780" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v10 08/10] vfio/device: Add a helper to mmap a dmabuf Date: Fri, 6 Mar 2026 19:05:57 -0800 Message-ID: <20260307030812.1224392-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853181664158500 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 2d01059be0..592d901c77 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -725,3 +725,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 566e5d8bc0..2de21a3047 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 Apr 13 09:25:02 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=1772853186; cv=none; d=zohomail.com; s=zohoarc; b=Z7BXWoyQ7unbDPcwFq6RIW9lKbcpO5Pi+1oOe8eIawSLs+FD8ICytwaf6ajL31cV2dWu9kQmxK3RpCY4IZQihYkhOadqbJiCxZO04ipPd/xCFboC1c5hhrvmiByKIHfV3dL5xg3TGLWeQQ4RqkWVxe1OmI42aMwfUv7UPtG75s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853186; 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=s3EedhsVgREn34CDSmnY5JB0WsZmDAETf6J8OkkLBsU=; b=dmKAZVoBdqFmpnZoPdwELj7jXRinXy/J4Esxzb4Dd8Kkozf7gRHeWnRt6YssvaHpHjqoDNoLjWX4/Tem7/tpR5CBP/7JB08fB3G6gtkSFjxRRzIxkqdagXwDjLwrW7CXRFb2ExZbJHCDnm3/v4+A+/21DSHnpwH983gEa3Ldcqg= 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 17728531867581006.4164480956764; Fri, 6 Mar 2026 19:13:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4Z-0004rZ-Ki; Fri, 06 Mar 2026 22:11:23 -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 1vyi4S-0004m7-GZ for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:17 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4Q-0000oY-Ir for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:16 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853075; x=1804389075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cBfqLVebTnC1FcLyB6BaOptJmlKXBwR43AHeVZEx9rU=; b=NE2EJhJwepXhFL5J+8hbnG2TDr8BHvV2s9CC5Cr8w1b+R3SKDySBSK4K vkkTTMIn/D30qkrlLs27gfNmuXnin04XXGmR8S9x3nYTWFAbeO/KYnHNA UElHsLVlhTyRMkw5tiXyqBjoxLpDIWamI0WrP0PyN0ME4XvR3pQCC1EFf 2rmB2WB8eL+pl2/IoJ9z5vtwZitHEfWAfnxPt8sI1c/37CcRbRF2VxmrA EdBpwxIvLY3PcKfJvKY4M8OpZS+XGs0b6PtgN3qZIKu8LvZQNaKKLuLxz zcw8GJoNRD18a1uiCUBeIycfDU5LM3FVG55P1qkZ4PX87z5ax1w2qzr9O w==; X-CSE-ConnectionGUID: UVwfwbkgSd6Vp4sgd73+Nw== X-CSE-MsgGUID: efZ89qQpTmmE3yj9P8NFEg== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434043" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434043" X-CSE-ConnectionGUID: mwdbBoOWQ1OlSzQJWfbuAA== X-CSE-MsgGUID: bKLMNmJtSyCiZhWMlBWQFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813784" 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 v10 09/10] virtio-gpu-dmabuf: Improve error handling with 'Error **' and err enum Date: Fri, 6 Mar 2026 19:05:58 -0800 Message-ID: <20260307030812.1224392-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853187245158500 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 | 65 ++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 8d67ef7c2a..0a6b54fde5 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_ERR_UNSPEC; } =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_ERR_INVALID_IOV; } =20 list->list[i].memfd =3D rb->fd; @@ -56,22 +60,29 @@ 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 bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, + void **addr, 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 false; } + *addr =3D map; + return true; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -125,22 +136,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; =20 - res->dmabuf_fd =3D -1; if (res->iov_cnt =3D=3D 1 && res->iov[0].iov_len < 4096) { + res->dmabuf_fd =3D -1; pdata =3D res->iov[0].iov_base; } else { - 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; + } else if (res->dmabuf_fd < 0 || + !virtio_gpu_remap_dmabuf(res, &pdata, &local_err)) { + virtio_gpu_destroy_dmabuf(res); + res->dmabuf_fd =3D -1; + } + if (res->dmabuf_fd < 0) { + error_report_err(local_err); return; } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { - return; - } - pdata =3D res->remapped; + res->remapped =3D pdata; } =20 res->blob =3D pdata; --=20 2.53.0 From nobody Mon Apr 13 09:25:02 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=1772853139; cv=none; d=zohomail.com; s=zohoarc; b=HPQBVDJG0c3lgnuQVkKgcY4Nvt9/RBMew8jE99oGTYXa78gIR1okCEWlHk8sPXl75i+cP3X6kbbgqRGRl/efI7jC/iRQVY6bhFb9+AruXgn0BP0v18zcO1J0c0lTcs09WPnGZHnau6e7WmaI+CUjvupLzObAudq8WXOLwjw29r4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853139; 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=eujF32pFyCA04oR+peMUhz0eESY8tRGM53ZgqAyh9+A=; b=e5u4dlu9J07G2hqdqG+dH8oJol7fwRha5AGXaekddmii+6/6ISHaYtoeiLqtlWUEZOsWB4HvvAXaAKV/QN3d0gbLsPqZD2CJiozrh6YWIAKqJ8DUKY5njhTwk+zjoGda8JB1CyNQGip2VSm1BecU6KtZD1Q+6462J02fLdcSbIc= 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 1772853136013284.91989903479043; Fri, 6 Mar 2026 19:12:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4f-0004sP-Cy; Fri, 06 Mar 2026 22:11:29 -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 1vyi4d-0004s5-Ei for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:27 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4b-0000ol-UR for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:27 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853086; x=1804389086; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ndxcgores0l2qC+gItZqykbKhchBgLacTV55nno2J1c=; b=BadbmyPqGq3G8vWat2gnMaI3HgvVYw4tYrJ3/5ks6RTgcE0UuhWsNPkx njxAPNbOrLsZH8lroH3nOsKy7YvFE//XvLnKkzoM7ZC1KJSC/AWle1d7P DIJmWzkEDpvVeerTCggvpInNSzwHWjpp5nCPafj1cEb8w67+1m1WB8+W7 Lj2NHfwflsthRtgZ+tEk2j2vnBWXgadTJb+t0qJ48L1EIi6uFwLyTmg7m NXMndZrAeR8vt2Qk08zBC+rNAYE0n0i7/nzjphPFQwakRHLKbia29qeiu ysNdp2Dyxxoa6i9xq2Ui4KhnlhMWY6DFua28U7jJ2mfgJZ8xBwtqKlrT1 Q==; X-CSE-ConnectionGUID: c3IX8VxWRvWxiAfeJhOLRQ== X-CSE-MsgGUID: j4KNE3e3QnGyX74pDqhqag== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434046" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434046" X-CSE-ConnectionGUID: iMwvIcS8QKuxAkdpMYa6cw== X-CSE-MsgGUID: BKFhtA3IQfqR3HOQSDmcsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813786" 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 v10 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Fri, 6 Mar 2026 19:05:59 -0800 Message-ID: <20260307030812.1224392-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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=192.198.163.7; 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_RPBL_BLOCKED=0.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853143997154100 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 Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 0a6b54fde5..55e3f60b60 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -148,9 +148,22 @@ void 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; + 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; + } + + if (res->dmabuf_fd < 0 || + !vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &pdata, + res->blob_size, &local_err)) { + virtio_gpu_destroy_dmabuf(res); + res->dmabuf_fd =3D -1; + } } else if (res->dmabuf_fd < 0 || !virtio_gpu_remap_dmabuf(res, &pdata, &local_err)) { virtio_gpu_destroy_dmabuf(res); --=20 2.53.0