From nobody Sat Feb 7 05:48:51 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=1770103980; cv=none; d=zohomail.com; s=zohoarc; b=VQ5Kifkrx4h8yaqBz4w6kTIkrUXg7Tp8xJ/EFlIwENGvSkqWOh0+fRiBpT3oUWfnkrpgmiY8DL0Xm+TKtHGurZ9veCDBX86turE52ouLu8AK2+QO8zd0d710xa81m9Bwl5m42qtVXwlowRPAaOcr6WtgWrbQr1Oy+xOpFFWxkWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770103980; 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=Ft3LEhxsum4S5FvdDqC/n3QOiPW/l+92MGg1UY+nv8o=; b=hUV+d29+jtvcf+zuMebO6LuAin1aKRJLeYScNEg0k4FvLI1A1oSt6GpJMWbdq2pPcWn6r0TY8gkfnr6flbVch9rLOq4blxsE/88Vq7vuk5D3rNqgcxTobMWlL7Skf6InUnIsX0+hJTzUzagETII32CXixc+pBgSNVGhdEXeNHKY= 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 1770103980172558.0495041442856; Mon, 2 Feb 2026 23:33:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAtw-00076q-Ow; Tue, 03 Feb 2026 02:32:46 -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 1vnAts-00073Y-Tg for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:42 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtq-0006Ca-Q4 for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:40 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:33 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103958; x=1801639958; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BU+2P8UJQiCNZ6B+Dn1fq51GInHfsJ6cD01Wea2i1DY=; b=gXgXUqnv8Y9rkbTKKYratq9UYAkgFRUaexLgwLcwulMZJSmY84m43S4Y 1GYzlZejJwQ9S637SY2syYR0GHRnAMd9B3tgJWmIZa3pilshZ3z8ZKmcA RGVWvUbMUN1G/6OOJ1KDPfSsCH/OEbeO2tDeOJKjHVd4HablNqVHJCoYQ b7LhYqFb2xYjGNWh1sBA14FNLjwrftXp8NrhYPT6MmMwGLDjHLff+EZ2g uk3kXzloj16KqxCz7ntUeaBvrT7+Z8JaeBvHcf2L8xm5dAFubGONJ0ZQ5 B2PjDwF7XDKrSv88t8l/pqxqeRGCvTVWCJ8y5K17Tbk7aL4aSWznMlXEA g==; X-CSE-ConnectionGUID: 7mI9JMhIRDKv4O9XGB4rvQ== X-CSE-MsgGUID: ++d8TWCRS7amXLvPxomb3Q== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640871" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640871" X-CSE-ConnectionGUID: lN3gkNMYT3+jgMx/Meuwgg== X-CSE-MsgGUID: qAcldugCStu7xVutd0xujg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373067" 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 v5 01/12] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Mon, 2 Feb 2026 23:30:08 -0800 Message-ID: <20260203073200.848183-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104096697158500 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 f23eec6862..3d58cebf4b 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770103988; cv=none; d=zohomail.com; s=zohoarc; b=TyDAqalXE2IzhFCCm9OA2AThM4ZE6RIj6opAsh3DYJ1e8x0opJ2tqvW4dkSIi1FZV8ckJjgTHWI71ksUsie+M6HsA7FUZ5nwZk1mO2uMoilByCa6Fb2CA74I9By+AknMyL8tCq0QbgrqTjyqs9hjRLEmeJfTgGZOpW28iD6ycxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770103988; 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=ZQ5h3fovtAmT/s7zRc+x2h4gtFacnCbgl49mYfBWiuE=; b=DoI1kS+fJbGJuc87DnF2ZwjFb4gNxk1XU5BHT0d+F2NtXu0e4wh/xde0drHu8BMQcxCytkhSF11ZOsgGTziT6FZuppSrex5EmSTACwY9xr8ZYKFNt91V5Trs5szsRO6yR5yprOzD/BrZR5a3FKRclxQEhNXcPf9VplOxVxl8KQQ= 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 1770103988315195.20012631483223; Mon, 2 Feb 2026 23:33:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu1-0007Ch-LT; Tue, 03 Feb 2026 02:32:50 -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 1vnAtu-000742-Qf for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:43 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAts-0006DN-Rd for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:42 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:34 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103960; x=1801639960; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qyc4coqaiufmoCw8Ry4ts+yRMlI+dmRC0dY/6aPZKzg=; b=dN6QVAunP3H1rbLGQrro09gMPSd81e2F0vGjcBw3wWQdrnFzmWiYuzz3 0bvBJrAtKxYBot3sXj5oT6bVT3zEFZ1iJai2ZFlYc8tnpgG7bN2LVprrP //+XTi/Xvh1SmmPCveTGD/Jmrm+4NGLFL+D2x3cYIuKabC7fo8oIEJu+7 JrvgKFi+NNVtyOSrZnnlHyl2MB6MwY85+s+3Rs0F/ElJq8P5VvyhvZTFv fQabuAddcGHgk/OQZJlWLiB9uyE/TUlF+b8NDHSxccK+GNkapGAxXyf69 2kpWnuVYGZGUZXLGrXCUkuCTc2SChGz1qQKrTtMR2wqtIGm0b1+uyl9rw A==; X-CSE-ConnectionGUID: /PM+JGJpQci6XCee1xh8TQ== X-CSE-MsgGUID: 1RSOY8NGTACJb6f4nzVMmw== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640877" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640877" X-CSE-ConnectionGUID: 4EekjQ2gTl6wXbmIq9Tkkg== X-CSE-MsgGUID: 06/H0PrIQs2iKGq3EoXKcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373072" 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 v5 02/12] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Mon, 2 Feb 2026 23:30:09 -0800 Message-ID: <20260203073200.848183-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104397357158500 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 Signed-off-by: Vivek Kasireddy Reviewed-by: Akihiko Odaki --- 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 3d58cebf4b..9930a21317 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770103977; cv=none; d=zohomail.com; s=zohoarc; b=SPPwprLscx0+CP4l0gsQ2ys+lI86CBsL0tg1lz8CQ/E1KeMeE4mGsI1UebSh0TeV6TGmDmHZEC2lCIWIgJQVXmMp+i3k6A/J47wzfPws51nOO8nAyT36sBvstAnep+6oF5sXkKV3gz7EUV7ZlKZMgAMk/dDC2RrSWSmXILICYi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770103977; 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=Dw3l7wW5mpAxRjpvkoxbh0eaH5GEW1qSbBHDZpfjCCA=; b=Dpd53GpD9B/ZtlnVBdvbWhcoJ+OMX/f+DLQke7tGtPLcDQ8rToEcUEKGAWYAdtF7ZYHsF7S44nSmMzWL6VaSxmfrv7TfFFVzzr1DTff6mpbf8udeR9Tnt70xbgt34709NN6LAkwWIGiqa1Z6Z5nQs1w8nvGD46egGzDljosMYLI= 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 1770103976997291.47215798829336; Mon, 2 Feb 2026 23:32:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu2-0007Jq-OF; Tue, 03 Feb 2026 02:32:50 -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 1vnAtw-00077Q-OB for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:44 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtt-00067a-95 for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:43 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:34 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103961; x=1801639961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ztabUCwYVEnXrUXpODUpIX/j6IsbTnuLW3gEfsQfQNk=; b=i8sk22S6pnXJtIBR2UN5La0hF9dgziWAZQ9vsjmkoxqPW/HOqDL2XIqu kSZ8fNpgrb8I1JMKjfQOJxrULzRbgXsrajWck9Oy6AZ+jRjO1wgYRncMN hSEgWNmQjmPcayErIuUq6y2rpv2YmFWyiXSP5dKTKHOa4BS37eSW1wJYG xHpzxEV7zB1IvQnJcGmRAd0Q2m73YOfBK+tS+bMAOPchFi/zLCeZ/6CMl VOpIntuHu+Iy+C6bb+9zVdO5MECIg5f1+p3d8g1am2YAiSr/nV6SiiE3r BsSUNcOrH1lYjtvcRyOoPYmgW9ICIZHfwmvl6C8k/ppHYdJm9QN79vhFN w==; X-CSE-ConnectionGUID: R3ewMf6hRKe8pOBwhRlR2A== X-CSE-MsgGUID: VUiBpzp5QiqV5SWl1jOdiw== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640885" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640885" X-CSE-ConnectionGUID: m2MDBNH8TN+0R7IXY8t6ug== X-CSE-MsgGUID: Mpec0BsKSYa6MT/ufH4ETA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373084" 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 v5 03/12] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Mon, 2 Feb 2026 23:30:10 -0800 Message-ID: <20260203073200.848183-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770103978758154100 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 9930a21317..bc4d33c4dc 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770104003; cv=none; d=zohomail.com; s=zohoarc; b=QfqUcUFoLZCd9SAre9eZsHhlZZa4tq2E1CpNxBD04aT0lQ9tjO2RDzRvZZJqqFPZDTLG3rQPK7ZhFq6r3ZGk63n6zdgHQhYAgWC3r/ReFK7N7JN8Nl8Uqb4DpNCTLTedIg5NLgR9hv8WgWVZ2XOMu7gI5ZTZJoPm9yzqB7WEWw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104003; 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=SV1FQORoCkDEWJWgVkYNfAZGnP+Mxreq6xW1rYNVhQA=; b=XUTlTxTlu9ZVhGUeh2FpiPccB1YL8HjvCwyM0hD1GMF8qGoOEblJHAyBkm53/LGBLoCpk8zp49rYXlGBkvYLFOEEAqbDHn2YY15QXTubbt98COuX/aYQrgWB53zB/DuZmtlie5yV+FFW82iwcJtV3tuDykAqFbXBAmi1GNegZww= 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 1770104003621870.7282578164768; Mon, 2 Feb 2026 23:33:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu1-0007EF-LV; Tue, 03 Feb 2026 02:32:50 -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 1vnAtv-000766-62 for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:43 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtt-0006Ca-8s for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:42 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:34 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103961; x=1801639961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OkuB3kYF7xmHNv/+0X3gXdvyD6tejLSYKJjk9QF/6DQ=; b=gc194OJha/mJz+CGeIOnYglW0bc/AN+sASx5g+uU3+OK28J4wMFafsbE KHk+El2OErOxlRAHcU120hF3MC33Kc8pZp1siYc5le4d3SLj0FBgxHBqA f7gT0kSIh2dgJGjDQoQrWo/SPXRkXEauOLHhjA3OTHWIwH1p5GJoTI2Lf zuscH/OpNJ6oJOanFOaNORd5MtyabZferznxRRtzjsVDNeq/wCpIlqnX2 dL3MAWQHYq15/Pz8TLFQROm3X0UUnAjCiA1GikYs4/oE2gTyON9pRHefq /vFrqZCCqY6i0mAJfuczUa0CYan9VTGFLKarHAamdw0uSj1hkRQgoNiGB Q==; X-CSE-ConnectionGUID: OZ1KsSw3Tsu9YPGcyRj4fA== X-CSE-MsgGUID: SeoDQEfkSAyJ4+Z8nANI2A== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640893" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640893" X-CSE-ConnectionGUID: 65EfIQBISSaBPiSyaTdCcg== X-CSE-MsgGUID: 2a+98WRIRXOp6kZocX/9bA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373088" 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 v5 04/12] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Mon, 2 Feb 2026 23:30:11 -0800 Message-ID: <20260203073200.848183-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104116444158500 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 Signed-off-by: Vivek Kasireddy Reviewed-by: Akihiko Odaki --- 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770104046; cv=none; d=zohomail.com; s=zohoarc; b=nBtXB7gwLogyWcUOFqq3CWKISnOgfuzHswNANgvD07TgxSr0nMIDnF1pBX4zk5x2aAJ1bI9vVtJuGdC2FakVokmMJfWcBBrKhWddGZ0Q6jWH7in9YgIx7v0tVw8IV/DhUH0zCdhh/biuEereljsGxSstpE7uc+ffDMJeSz/hcGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104046; 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=d5xJXUA4HWH6QQoTfpemXzEkCfbNlokwhbuNGjIskyY=; b=IKccc5+cDZR6WKlzupvqJ/J0lStKwof95lxbVKZ5Pm78TFaSq4ZR0lkeHB3H4hmD65drg3No5y18FAL6hNToyJy6BvqGhrHxmzQO4KMKYrDAazqYq0ND9936JEvggRICzIge1Ja4ktbQXmk6luatfEcIvPNw6FpyCxiyVsPZwBQ= 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 1770104046331732.9199265315211; Mon, 2 Feb 2026 23:34:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu6-0007NV-Oi; Tue, 03 Feb 2026 02:32:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtw-000785-Qn for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:46 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtv-0006DN-5F for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:44 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:35 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103963; x=1801639963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sAIC02tFWxwAzWAC6ZXsDTdzNYZHqGEEMjqYME3SrNo=; b=VmhOuNUbYC4f4ShkbZxkwaR0QDX+h0m2nDWgpxfg3b/19GlGXvPk6HKK iY7ukT3i4wxgObVXaqebpK2HK/wFa4I/M2INWtL7N8pDLA+OaqwxFFqSM W6xdzVrxSwMGfVpL52L6Knjneug2xQF11vQVKlhGzZh93p0N0g0nnDzLx YRKM3ZqAf5hJIekTn/VZHKayOle0PSj581CnW/v6k2LeyZmSiGoUBEVLX FYS26L2EhkvoSg18exiBukZRmsQ6gahKAvJ2tfztp55gEUx4CXGk7r3j3 dK9LDlUtz+SHaH9yTFM2Gs2OowEpdqbyOSkdI9ugl+u5g4ZzC+iHh4rvs A==; X-CSE-ConnectionGUID: bq4EFVv+QGaTcN71JPGeqQ== X-CSE-MsgGUID: nJM/Dwt2T16aEde1H8IvHA== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640901" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640901" X-CSE-ConnectionGUID: 10xOvO7UTvSSKf2OCxumrQ== X-CSE-MsgGUID: 5NSPWgm5QlCV0OM4wlFufg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373095" 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 v5 05/12] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Mon, 2 Feb 2026 23:30:12 -0800 Message-ID: <20260203073200.848183-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104125017158500 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 Signed-off-by: Vivek Kasireddy Reviewed-by: Akihiko Odaki --- 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770104041; cv=none; d=zohomail.com; s=zohoarc; b=X+YhMgAXhJuYqfel2WMZ5bTJffZLRFARHSDymDfri7hysCj6pcYLjc5FIhYjLy5nN7UiSCKx7Nk8EcoFboEvbDoAWOiO5egv4JFYHg4oAhDXU5tW8BflraRTCeRGEdxb2uzNMqaACt2FZKkMMVbnBu+epMF0o3GU3dOlMRbITaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104041; 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=96kSSSlw+o0DwDKNNqrSGasAR9ZsmGtFBq+7cLRIreo=; b=j1DzBMlOe7TBXF9Fe9h39WA2Xt9LpGflNDS3G+6/l+pWYiNsjiT9XIzXLYNiCe9MCY5o1CKHjghN8dErn68dvaR9NG0GhthGPbW1Q6jp9GPqv+cCPLJ8i8ca25tJOOfDR9T0XlEAHjBIM/DOsrIQOJO7aLfpoOEexrYxk4UExLQ= 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 1770104041868681.7995820295778; Mon, 2 Feb 2026 23:34:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu7-0007Oz-9S; Tue, 03 Feb 2026 02:32:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAty-0007Bl-HL for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:46 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtv-0006Ca-Ig for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:45 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103963; x=1801639963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3QOpse0X65ajxJkuQD2k8UwfOB3vdSSNPt3BSqLJ1b0=; b=Wp4HkCApqwAhn4B0dMYwqeCLgw2RP7SIivQcX9kwcqxsHe7hxo6P1XuF X/+fqqe/JPOZboh/z6Jwuh9BAMvra9KDhHbYxwdyRqmmrxI7Sds0DDMGH Pve4VpYLDF0M3MjRkZAHgvGJfS0t7Q0DUKWoN4pUnIwCSKXlN/D6QUbG0 EkJzFIkYw5l+OIlP9P4XiOV46JyV3RRjOd6/gFFOhyVCx3UGkkznM2JN0 uhuMDyGTROTyNBLcScnM3EPO922Fe7S3GkiaJlmHTOxVivcGvvYx0tcR4 1yc2lh/fEq1XHjDWGuBxo9u5acebtnTcfcjCr5RFMOZkNJrODfGxqJV5B w==; X-CSE-ConnectionGUID: NYG6epV0TBGSIECSGJzOWg== X-CSE-MsgGUID: FgXNNAwOQw6o9hyQDN6yZQ== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640907" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640907" X-CSE-ConnectionGUID: T9VWdQBQQ1q5Dg22gF1mxA== X-CSE-MsgGUID: STQlY0VdRgajbNp9JdSAOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373102" 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 v5 06/12] virtio-gpu-dmabuf: Improve error handling by introducing 'Error **' Date: Mon, 2 Feb 2026 23:30:13 -0800 Message-ID: <20260203073200.848183-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104124815158500 Make the error handling more robust in virtio_gpu_init_udmabuf() by passing in 'Error **' parameter to capture errors from virtio_gpu_create_udmabuf() and virtio_gpu_remap_dmabuf(). And, since they now take in 'Error **' parameter, have them return a bool to adhere to best practices. 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 | 44 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 8d67ef7c2a..22e66fbb12 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -27,7 +27,8 @@ #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 bool virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es, + Error **errp) { g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; @@ -36,7 +37,8 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) =20 udmabuf =3D udmabuf_fd(); if (udmabuf < 0) { - return; + error_setg(errp, "udmabuf device not available"); + return false; } =20 list =3D g_malloc0(sizeof(struct udmabuf_create_list) + @@ -45,7 +47,11 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_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; + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not find valid ramblock\n", + __func__); + error_setg(errp, "Could not find ramblock for dmabuf segment"); + return false; } =20 list->list[i].memfd =3D rb->fd; @@ -58,20 +64,26 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res) =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)); + error_setg_errno(errp, -res->dmabuf_fd, + "Could not create dmabuf fd via udmabuf driver"); + return false; } + return true; } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, + Error **err1) { - res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, - MAP_SHARED, res->dmabuf_fd, 0); - if (res->remapped =3D=3D MAP_FAILED) { - warn_report("%s: dmabuf mmap failed: %s", __func__, - strerror(errno)); + void *map; + + map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(err1, errno, "dmabuf mmap failed"); res->remapped =3D NULL; + return false; } + res->remapped =3D map; + return true; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -125,6 +137,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + Error *err1 =3D NULL; void *pdata =3D NULL; =20 res->dmabuf_fd =3D -1; @@ -132,12 +145,13 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else { - virtio_gpu_create_udmabuf(res); - if (res->dmabuf_fd < 0) { + if (!virtio_gpu_create_udmabuf(res, &err1)) { + error_report_err(err1); return; } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { + + if (!virtio_gpu_remap_dmabuf(res, &err1)) { + error_report_err(err1); return; } pdata =3D res->remapped; --=20 2.50.1 From nobody Sat Feb 7 05:48:51 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=1770104029; cv=none; d=zohomail.com; s=zohoarc; b=XmYfjegF1gEs7qvc3ahjC4O32AcSohI1YvgDyl+wBhtOOgcnRWO/IkL9BBEmHQLgAYCxzyG0y/Dj0DRMZrxAcoE6mC9tUNPJt6I9MOKj5GumCwunRG1rWmzANF/PgJkmNh6qwV4OMjfIUL+rhULFwiHYsIA7uVLi6FTfFkHwV8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104029; 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=Sf79CiAG6SfHqkNGj75oFk3mJTt1TqAQVqnu+Y8ZqiE=; b=fveH1SWs+fHs7799XA4zLQCk4N3QbXj79ASDqfCCCU1+skLOHHz9X13qUuj0oCj3v2T1O3ztbLA+VOV7CTCsbPEJ3J1GcQHxFA1dvO+TanJXikgOIH7xyWC2Zjga3MKPncLFhwE931jVlInN3zrXZwg8iKad4UERaM7gptnsPPw= 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 1770104029309525.1013521593125; Mon, 2 Feb 2026 23:33:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu4-0007N0-VQ; Tue, 03 Feb 2026 02:32:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAu0-0007Eo-OM for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:49 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtx-00067a-2C for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:47 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103965; x=1801639965; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vLJ04mRE3eaGEiRhVGrnFwJ/UmQVbHxQHcqyM8xjArE=; b=Bg4bvUpuCOhoe1Iw085t2BPT35QzYaAeQGDBgYDd9lSaT10z60RotGE1 NnoSR+3o82K+/X2WhcPy93lfkSoVGWNSRpWjZbuZ+A8qSoutZBseKpCVe S/2UixW42VpV2XCWSffX7+f55GXbQexxa019w77aG5cShh20ukKy1D9NI HSdHgEPCt0KXsjHmLXxWvMCA2EcBOsozxWq3WA226hUMrbxidITK3kffk KYPrAE5bsBniYbiGmUnuDIn+5X7xdQTY0rddMZwqO0vxDkwkXt5qddHdL 45yXg0kQDqYxRMipsUwLOM8gzZ9baKM+/YONk0kmKx/w2zpPIbKfDHs5s A==; X-CSE-ConnectionGUID: 94DCVQo+Q063JSBoD/N/8A== X-CSE-MsgGUID: 2yBdS4rATKasqif0V6b1qA== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640910" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640910" X-CSE-ConnectionGUID: Dp2X0oMYS9qOiE4wKVfl4g== X-CSE-MsgGUID: Qxozh33DRWaJa4g+WNK8qA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373105" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 07/12] vfio: Document vfio_device_get_region_info() Date: Mon, 2 Feb 2026 23:30:14 -0800 Message-ID: <20260203073200.848183-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104121477158500 Add documentation for vfio_device_get_region_info() and clarify the expectations around its usage. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- include/hw/vfio/vfio-device.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 35a5ec6d92..828a31c006 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -275,6 +275,19 @@ bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODe= vice *vbasedev, int vfio_device_get_feature(VFIODevice *vbasedev, struct vfio_device_feature *feature); =20 +/** + * Return the region info for a given region index. The region info includ= es + * details such as size, offset, and capabilities. Note that the returned + * info pointer is either a cached copy or newly allocated by + * vfio_device_get_region_info(), so the caller is not expected to allocate + * or free it. + * + * @vbasedev: #VFIODevice to use + * @index: region index + * @info: pointer to store the region info + * + * Returns 0 on success or a negative value on error. + */ int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, --=20 2.50.1 From nobody Sat Feb 7 05:48:51 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=1770104053; cv=none; d=zohomail.com; s=zohoarc; b=HPYNM0rtLZEidU+NEC9ct3T+sFr/H684f0FT79mk7RcgaJ9tLssbFWBfd+cA5uojnB8vIw2qOidkwEwIaS4QhljnQ7TLX5nBFfnojNDD+8WeyH4WX2tdkmvcH4ivAYf9c+BMH9NUs/sT9Gacm5Hwrl1s2AIZj4d9EYika+SilTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104053; 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=oXkxCkb5yDecPBp87JpMAAg/WYB+TI0ipRNsgrCT188=; b=gSyV7lz9FP9I70O6gUfEskOkVhICjJuxr82ECcwkMwa6QJKBsNerZG7Ky5viomaHC9WuFsySGsbB3WokkGFEvEV+agvNl1a8eOn1WWa6jruF6tMkzKL2tpsR6xKb2nNrALV9KDIGs0qOODNokDPz9siWZ53mV59ictsnbmubWWY= 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 1770104053829444.75043218587234; Mon, 2 Feb 2026 23:34:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu3-0007Kz-9L; Tue, 03 Feb 2026 02:32:51 -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 1vnAu0-0007Em-O1 for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:49 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtx-0006DN-4k for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:47 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103965; x=1801639965; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6rfHFdfPdD8BjvFsHmnrTLtCCMNlWfo+Utny8DB0OFs=; b=D8q+t+K7SdrBVC0P6Hznysqfuv5yTa6ChOgjyHqu54HfO702OnCFjI7P VFwXJzXSS5XQWGMu00lNe/bxEPBUgOQOUUE1bUlJgIv2DPoQ8C9Oz9uHY NJx4NjMZb61JPlien9+2ZUJUYifn18y2/bWPUf45sdLKise59gC7c2vUR 0XdEXSxCWRTC7N0YBT4XoM+3BmMWnL54maoKNyB/Abi8YbyNjHPtsZhbD qaKACSIfCczj5vTjs8af9pjAkIPJmLwRCRL6I0cxgoMbJFfOVx7RdxS5l V6YPmiZdCKr/LcZNMXA5Yut9k0TIugU41XUZpItPAeRzHnL2gJPfU8Ggf w==; X-CSE-ConnectionGUID: fgE8vR3BQFS/nESFw5Z2Ug== X-CSE-MsgGUID: DPOmfZC4TWKL3UGJxqxTzQ== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640916" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640916" X-CSE-ConnectionGUID: fx77WMWSRl2AH532SxsqEw== X-CSE-MsgGUID: SHG5BDBKSSCyZrPJNtKNiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373108" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 08/12] vfio/region: Add a helper to get region index from memory region Date: Mon, 2 Feb 2026 23:30:15 -0800 Message-ID: <20260203073200.848183-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104126246158500 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 ab39d77574..9c3dc19ee1 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -461,3 +461,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.50.1 From nobody Sat Feb 7 05:48:51 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=1770104061; cv=none; d=zohomail.com; s=zohoarc; b=lCfONXsAMyN2wzuZWkGCr1Umk1n+Z1/0tZaATZC6AKc1QMHdVp4sXDqsiVootdDhqK/jK+iaiVQgnUCW/Zp+mbN4q3a6VOBPc4eZzSKe1uabpkWlsHuguCbRRuBu3Ios6KuNLyTQwT3xd4LoBV6wac7tN8bdcJi9ZFsZU5jw8vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104061; 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=bIHFuVGGKppfdG0zpoQ3hezI6XxIEr4+Bga+HAez8Jc=; b=LKBVGxHON6ihy1LFU5VkKeVm+ShJtivy5oZYw/RI7XljpC0NaJ55fN/w4WxyEGhSeCu9KAtj5Tvp78+QJKOzgdCC4AcXrYQqfY9M336UM0Ae+t6ody5Q1i8cctXFzmHi3Y2kqolbj7NmsiclfwxIUga2PvBO+iR9zDVO6Fi3Kc4= 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 1770104061087313.0046073824244; Mon, 2 Feb 2026 23:34:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu7-0007QD-VT; Tue, 03 Feb 2026 02:32:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAu3-0007LP-AD for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:51 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAu0-0006Ca-GL for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:51 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103968; x=1801639968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X8bbVuNMXC8vykTe65Rw/x/WDTflG92gptyM4eDsVm8=; b=FKwHIB16aKEisXEuH6hHA3P6KQ9S+9JaWF77sJaIiF8xd3NttUiCezxd upkyQ2OewHSPOipnhsBYFhaf5iK7+sHptl9WX0qDnVQeb1dqthyy3cbIk OqUsE+JapdfEnXjFbKLkONqw1ptWFtvwEtXlzthNYgC0+5FPwfJExdt6s VY9yvFhBkHlOF8sbx7IeZ9hwvdFhTecozEq2Za1YE8erh9w7ebMfOISgx P7HtrtzTvRQDSXtVxabQGWF62N0DGQeqHttApi5dfHZbPZtGOEvIHdznT UJNuFt7Mk3XzZvBEwYVc17qDgHVWqO2De3Br2vH9q7/0NqRD6BB/RrudD Q==; X-CSE-ConnectionGUID: wC+6mf9NSxSA0mjBapmqfA== X-CSE-MsgGUID: 8ABG7TwXSxKgaNWRbK7dgA== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640922" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640922" X-CSE-ConnectionGUID: j5BXF9GyTaG6fvxYV9hHNw== X-CSE-MsgGUID: qHlbABp0TRelZhCVvTN/Zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373111" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 09/12] vfio/device: Add a helper to lookup VFIODevice from memory region Date: Mon, 2 Feb 2026 23:30:16 -0800 Message-ID: <20260203073200.848183-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104063052154100 Instead of iterating over all QOM devices to find the VFIODevice associated with a memory region, it is faster to just use the vfio_device_list to lookup the VFIODevice. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..ecb3581fcc 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -644,3 +644,26 @@ 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; +} --=20 2.50.1 From nobody Sat Feb 7 05:48:51 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=1770104033; cv=none; d=zohomail.com; s=zohoarc; b=W5qvbei7em2Qo9m15n6d9OxunPTAWy7pEwEoGkzh1HcGlvzBG35W40d58oLDi5pwWBx5CL+TZJpfZVeb6fwjrZQ21621vjOoQuLo9a+QLomFKRa+M9p8nAPrOfyR4Nx3DMC3bN+LweorZUpwxql5/OMdjy120zWKMo2XFRBuqpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104033; 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=Za2qhe1y+HmtK8JUlxXFkybmLOSt8TA8eqoYAC3piks=; b=Cj0c7fY55lGSpk/jlmm8qu3+0CCf2Wy5TQk/16j3Wnt/jMlDR9lXqh7bLCHnr+YtyMUCXqy8DlXELcCvQKLAq4HY2ypvGL4gvpBT6/JkI1zFc4amRbwNoA9d7CiOTp0t1WeuJExv59bwZEAoLXX7bOVrSBuNaFVSDUUO2yDeJko= 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 1770104033390569.8155318957811; Mon, 2 Feb 2026 23:33:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAuF-0007VO-G3; Tue, 03 Feb 2026 02:33:03 -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 1vnAuD-0007Uz-UW for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:01 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAuC-0006DN-2U for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:01 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103980; x=1801639980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7KFkFFpt1PDG4pLWKDo1miZZKiFJdXxbhssCm6V///U=; b=BFtkVS9RILxehg+i9t0lMM6fUuTboNp+bSVzU9iuElPQ9D56bm8RzaCK zejgi5WFSPLBU2R4wvJrK3TlLmK3E9qbRlgKVMIZbeaHTqZqWWQkqFmi+ ayjJ6yKuw8MwhO1E1ntbrWI4mVdET1oFlqK9mOjQm38RBF39DQ4Ftnmnx NrazYFDItRo1wgjCys66KI4BIPvrsbG0bxZgJqVUNPQ5aIWCm+xB7IfNE DZdgCIaHXuNyiZgweq+bPXV4u5upe7UnKVs6hHXKkw1NbWpCjaMBlZa98 TWjVt33RJMjhxIt1Z2bBZm6KsBlgqg5GH6v2I1q9JVo5VjNGjaSckMBx1 Q==; X-CSE-ConnectionGUID: 2FoN7TGUT2a/qfetPNmeCw== X-CSE-MsgGUID: Aqn9MNt6RpWHzIYNSLp0SA== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640925" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640925" X-CSE-ConnectionGUID: i1kzHAZoQkqDWh8UP3W3rg== X-CSE-MsgGUID: U/1RTMMjQN+0fRQaGmc9yQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373116" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 10/12] vfio/device: Add support for creating dmabuf from multiple ranges Date: Mon, 2 Feb 2026 23:30:17 -0800 Message-ID: <20260203073200.848183-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104122833158501 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. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 58 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 14 +++++++++ 2 files changed, 72 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index ecb3581fcc..a7603600f3 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" @@ -667,3 +668,60 @@ static bool vfio_device_lookup(struct iovec *iov, VFIO= Device **vbasedevp, error_setg(errp, "No VFIO device found to create dmabuf from\n"); return false; } + +bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, + int *fd, 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; + 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 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 create dmabuf with different regions\= n"); + return false; + } + + 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 false; + } + + 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; + + *fd =3D vfio_device_get_feature(vbasedev, feature); + if (*fd < 0) { + error_setg_errno(errp, -(*fd), + "Could not create dmabuf fd via VFIO device"); + return false; + } + return true; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 596c7f5a10..003bac10b5 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -318,6 +318,20 @@ 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 + * @fd: pointer to store the resulting dmabuf fd + * + * Returns true on success and false in case of an error. + */ +bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, + int *fd, Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1 From nobody Sat Feb 7 05:48:51 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=1770103985; cv=none; d=zohomail.com; s=zohoarc; b=N9Riwh8MItmTaq/EIFwKmqyWPaha1nc5WwQz/AF6ai7vgNQFFtB/YpQBUc+2ThAcGs+bs+/jU7nVF2OvNczvVhIbC0RTX+5NMGSlfsCzEb00tr/WS4TYo5ywMebNM+eDpB+JCXKhtRQ6tmhnYVEvU6zFL/9eFJrcl7uBq96qn10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770103985; 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=ZGut6s3mT62Oa1fi/83mmWuDHvxfeI5JDg93PJ3y+w4=; b=PAUvnlDei8/7BE2o6FDgxRNfjbHKnrjL0/9XAnwUR9ZyV0xifwNllA13u+gtb25DFSKZRpLbiUD5CN9vI8Ri9fn0ZyFGKlivcty9XGiXG53ds1G6CamKWkU2tLO+YrK/ZRBG8CnGqBuNXyCXRbnI+gL7AEJJC1RcK8yxqUldOeg= 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 1770103984958127.90902711631361; Mon, 2 Feb 2026 23:33:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAuA-0007RX-8a; Tue, 03 Feb 2026 02:32:58 -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 1vnAu3-0007Ly-Mv for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:52 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAu2-00067a-1F for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:51 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103970; x=1801639970; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HkTr/zWEef0bVYlJ9JiAZY/xqp73/s2wMhr4ci6XAjI=; b=leSMY3nC89i6skgM3nGsRVIKOTAyFXn/mkKPxA8t008XwpneaxMcFDZr c/fTz5ODVohMSdt8HQUrU1AX3hl/YTiJdEiYJPqBY/EvEZ2UkSYtpYcZ3 VHVbtAHCnHyUiSiS/yjlnRVwyJtYfn1vRYVaRRcJHq3yYW/vz46TI/5vF Xvt9gFPOiYCnzlD6NlLWn7/bWPKervsPXi30ea/6X1BoJz35Z2x2lc1fL W3/i8aHXZTmfPilG7AYvV2g1w+rgDau9td5Js/Gj9dufoRcl9c7E7gybZ 9+0P4+oHGy+EGIu881OJM9RdPL0cueH4zMTEhpaDnizAVHHu0J7oqFWkH g==; X-CSE-ConnectionGUID: 64SdOJw6SxSJHhE6OsONyw== X-CSE-MsgGUID: yOlcWpYGSRW0JQDL6Q5LaA== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640926" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640926" X-CSE-ConnectionGUID: Se67nX2UQJqiILNONrL9WA== X-CSE-MsgGUID: 3S9XcfKPRNWl7kZ31VMsug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373119" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 11/12] vfio/device: Add a helper to mmap a dmabuf Date: Mon, 2 Feb 2026 23:30:18 -0800 Message-ID: <20260203073200.848183-12-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104105517158500 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 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 16 +++++++++ 2 files changed, 81 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index a7603600f3..ef05ec8ade 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -725,3 +725,68 @@ bool vfio_device_create_dmabuf(struct iovec *iov, unsi= gned int iov_cnt, } return true; } + +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/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 003bac10b5..b8e0801b94 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -332,6 +332,22 @@ int vfio_get_region_index_from_mr(MemoryRegion *mr); */ bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, int *fd, 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 + * + * 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.50.1 From nobody Sat Feb 7 05:48:51 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=1770104049; cv=none; d=zohomail.com; s=zohoarc; b=XJtOGA3HOAbSthGp1meE9YsuiQ+0u93vXB597KHoVqQ5QT25AQF+ooHKKBMutPLtJBBK6bkA9A/As/yb3OVQnO8bh7uqjINnM7UbBAluKylMGloIqAPRxXcERcjfQSGzyM11DuhhEQI8wDjB60zGSK1TqYsefJZj4H+oE9TCkL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104049; 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=DUSnKqbIaT3a7l8gOMHPWOhmYwZaqTUEkJWCP1H+p6o=; b=WbnoPO+OHwHH048Z/WmCGP3mFJ9L8y2NqPON0/+mfsl8pfwD5WSrSwSjqI0XOpQOjpMB/6jYrqlj8lPfh3Iew5dW/HvDpsCpJMJXrTNU4O/znWiD4hsb1arzdLXrXYsgv1TudCqD6A2aM7qn9HVspAGcmEMZLqTl1JpdyF1V+FM= 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 1770104049312369.7518775338473; Mon, 2 Feb 2026 23:34:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAuO-0007XV-TC; Tue, 03 Feb 2026 02:33: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 1vnAuF-0007VN-CD for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:03 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAuD-0006Ca-LQ for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:03 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103981; x=1801639981; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e7JZ6ZB3ohVIX+KOOS5rF5ICP/rXhFYhCok9J8P+Sqk=; b=Th1rInGxOAugGJpDOxSq+7BvCE+0d5FXgobl2rkGoky1jZIx7xvoZzpY ZuEdZu2BnqhbFPADmga/w+GmkLd+FMhislSYcwYzSaxnv2JCLXQnKhi8r DC67QFu9o9hLOS63ba05+no+dRGPpUwYExqhRlMvA44nnDe4iwun72Xpy QfKCsqm0g5jMQHisWEcKHxYZX20eYWk7fnhFaszfug+ml0TXVEIxoMjAV IfE8PMC13Q6HYHNv5UjmQDDp4qCS10OIiH9qkH5meal0i6fSsZv3xotIk hOq1ZQTrvVM2dzfzPz5aAKmDHsRLMLy+tSVX0KXFkOWlNHPmdZPy04S9O A==; X-CSE-ConnectionGUID: q7AN4ScISX27aNKWQZjr9A== X-CSE-MsgGUID: AA4weTh4TYSUoGBeM46Yuw== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640930" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640930" X-CSE-ConnectionGUID: utPQdkOZQ02axPngGNgALA== X-CSE-MsgGUID: Z5nMFG62TZS24OnKudrSog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373123" 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 v5 12/12] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Mon, 2 Feb 2026 23:30:19 -0800 Message-ID: <20260203073200.848183-13-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: 1770104054226154100 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() API which identifies the right VFIO device and eventually creates a dmabuf fd. Note that in virtio_gpu_remap_dmabuf(), we first try to test if the VFIO dmabuf exporter supports mmap or not. If it doesn't, we fall back to the vfio_device_mmap_dmabuf() API to get a mapping created for the dmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/Kconfig | 5 ++++ hw/display/virtio-gpu-dmabuf.c | 49 ++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/hw/display/Kconfig b/hw/display/Kconfig index 1e95ab28ef..0d090f25f5 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -106,6 +106,11 @@ config VIRTIO_VGA depends on VIRTIO_PCI select VGA =20 +config VIRTIO_GPU_VFIO_BLOB + bool + default y + depends on VFIO + config VHOST_USER_GPU bool default y diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 22e66fbb12..2e65f21dda 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,6 +28,23 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 +static bool virtio_gpu_create_vfio_dmabuf(struct virtio_gpu_simple_resourc= e *r, + Error **errp) +{ + bool ret =3D false; +#if defined(VIRTIO_GPU_VFIO_BLOB) + int fd; + + if (!vfio_device_create_dmabuf(r->iov, r->iov_cnt, &fd, errp)) { + return false; + } + + ret =3D true; + r->dmabuf_fd =3D fd; +#endif + return ret; +} + static bool virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es, Error **errp) { @@ -72,18 +90,25 @@ static bool virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res, } =20 static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, - Error **err1) + Error **err1, Error **err2) { + bool ret =3D true; void *map; =20 map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); if (map =3D=3D MAP_FAILED) { error_setg_errno(err1, errno, "dmabuf mmap failed"); - res->remapped =3D NULL; - return false; + map =3D NULL; + ret =3D false; +#if defined(VIRTIO_GPU_VFIO_BLOB) + if (vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &map, + res->blob_size, err2)) { + ret =3D true; + } +#endif } res->remapped =3D map; - return true; + return ret; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -137,7 +162,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { - Error *err1 =3D NULL; + Error *err1 =3D NULL, *err2 =3D NULL; void *pdata =3D NULL; =20 res->dmabuf_fd =3D -1; @@ -146,12 +171,16 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) pdata =3D res->iov[0].iov_base; } else { if (!virtio_gpu_create_udmabuf(res, &err1)) { - error_report_err(err1); - return; + if (!virtio_gpu_create_vfio_dmabuf(res, &err2)) { + error_report_err(err1); + error_report_err(err2); + return; + } } =20 - if (!virtio_gpu_remap_dmabuf(res, &err1)) { + if (!virtio_gpu_remap_dmabuf(res, &err1, &err2)) { error_report_err(err1); + error_report_err(err2); return; } pdata =3D res->remapped; @@ -162,9 +191,7 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_re= source *res) =20 void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { - if (res->remapped) { - virtio_gpu_destroy_dmabuf(res); - } + virtio_gpu_destroy_dmabuf(res); } =20 static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf) --=20 2.50.1