From nobody Sun Jan 25 10:15:21 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=1769149376; cv=none; d=zohomail.com; s=zohoarc; b=cUZfP2epOQHhONbEZcDkYyMf+2b7Iwc/qZwzbNZl9f4wNbdI7E+4L8emKjVbX6cFOp/PtA2MUmIpOhQbkiXTzev8qJ5VSe34hq/Yy1JITGSa5J01ycBEkerCWhFt3fqn8EpCk3N++WXkUElZwc+gXs4qI+W4Kktadnd1HfUbnwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149376; 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=hOmSKU3p2Q3vPlDWJ2rLLJoYtke4uHmKqjKc5ljjh3NJGXTzcXT1wpIbHqSEjQ1wsxBAtHAa/v6ogn48+sSrFT3yy/Br9G08fKjQAviO/7FDLjh5/ZWC2o7/k902woVs/sljR0TOCdP3W2A89AP7d2CPaN6+KGQeXHvP2/qzbsM= 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 1769149376140677.3117289895347; Thu, 22 Jan 2026 22:22:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYj-000398-67; Fri, 23 Jan 2026 01:22:17 -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 1vjAYg-00037w-QF for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:14 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYf-0000rq-9S for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:14 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:05 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149333; x=1800685333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BU+2P8UJQiCNZ6B+Dn1fq51GInHfsJ6cD01Wea2i1DY=; b=g7L88dEWwGYX9nLN0FUd4/lKTpqx4nW1rY/fa9Yflvsmg3JWioW275wG USXKxaDU5pSnG13OjE1c38n1D19/IY3FzXs3tiKDLep1PU2PIU7aXjmrs 4PVOcF6VBReYCv2zrmV4XpFasmxfusceWoakud9QzG3Ov/JRhAxVmYfD5 NXO8StAmbaX2AendAm6rA+CyG0yji33Ze84wyo3/xcCwnEEWdG+l803Ky IsfaLyNDnANh3kf7GMjhmMwilA3TQ63IVvEYNxljroW8/oqYny2eMtr92 LGzMpk3XMy23C+GddT/eUES6zR+F8fGSiJY35fYDXlwoDliwf/sFxeLDH w==; X-CSE-ConnectionGUID: YOVSj1+zR6WG0dEIgBnXFA== X-CSE-MsgGUID: G6qjtix6Qn+gofB05iFhOw== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254182" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254182" X-CSE-ConnectionGUID: Ijso7S6YTBWtypbx9ohbuQ== X-CSE-MsgGUID: ZpdkPEXZRxKvSTs83IKxmg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287399" 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 v4 1/8] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Thu, 22 Jan 2026 22:17:40 -0800 Message-ID: <20260123062042.568703-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149378074154100 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 Sun Jan 25 10:15:21 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=1769149377; cv=none; d=zohomail.com; s=zohoarc; b=W6dVhubaDwli3y4bN00suCy/2RX6V/+UAzGY8ZcpVHJ5IVfY9aajyntLdJR1+BooA/2iJyxih5gad1A4TFsf3PhBMIFjsbP/jwAFR6tMBx+GmpzJTbxwJ7p0h6cuOaFBauLX6PBDINu6j5XStOtRyhiclFfjO6OE3ZXPJ9Gr4dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149377; 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=n1QSzZcgmRSrWhuLS+mXYpgtMm/nEMAHjdWz05y3SFw=; b=FUCRN7c5wFIa3ZzSvAkprBV0M/Wap2x0wpXXCdnuuYoEeMFJtehs3u040y6Qv74SU18KSF9EXcA8nIwKk6Uu+dq7oqJHJMNLl0qcd5iK8cdk/Vo9MSYOc56PSSvGyUf0X9V7/FVRz8pC2DkNT3O/d1PWIi2I0IsAso/8IOFXIKE= 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 1769149377526405.01179098879584; Thu, 22 Jan 2026 22:22:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYj-00039a-Rm; Fri, 23 Jan 2026 01:22:17 -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 1vjAYi-00038Q-7I for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:16 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYg-0000sJ-JT for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:15 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149335; x=1800685335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NrMNznHBXX3uPZveNVk1de9YgIFmAWj4A/wgBBPFYng=; b=OKmE9/iSJYFRi3pGmmqTczzc9vBalrf00FDyqli1I1AJgGSf3BeXh7Ky RRNQm4RVWx9WGlzyahXhdl7TUzuP4W9NLEjqvfsk4IeOwyPWTxKE9848Q dYK93w+HxlE0TtTML9+Z8fzHFG+zYAHCCael3eL3wg816/t6kG0oU1s2P iJkq6jJhh9vyoO6vTPRNkavaOTohSUOapNqGsv/BAkY0VbxW6PiUF1qQn GGeGulPS5aNkwOxucDldzXoCmA/kJU4imuMvccoAhc9jeDVZQQ4cNqELd IeGy1og4NdmK/t5atd+iat8vYmgIgcFHca2ucRDAk93xYBXKhqH20qv14 Q==; X-CSE-ConnectionGUID: 4/oSv9P9TzWz2agJtOT5rg== X-CSE-MsgGUID: ungv5YWvRo+QkRq5BTVnOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254189" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254189" X-CSE-ConnectionGUID: lQ1fkWnRQ165DyMlAyaZIw== X-CSE-MsgGUID: p69W0Cm6TmCk9j7ETCgGgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287402" 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 v4 2/8] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Thu, 22 Jan 2026 22:17:41 -0800 Message-ID: <20260123062042.568703-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149380035154100 If the Guest provides a DMA address that is associated with a ram device (such as a 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(). This is because the ram device's address space is not accessible to virtio-gpu directly and hence dma_memory_map() cannot be used. Therefore, we first need to identify the memory region associated with the DMA address and add the offset to the pointer returned from memory_region_get_ram_ptr() to obtain the host address. Note that we take a reference on the memory region but we would still eventually call dma_memory_unmap() (to unref the mr). 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.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 Sun Jan 25 10:15:21 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=1769149379; cv=none; d=zohomail.com; s=zohoarc; b=kdhSiE5mSUWtAzAaconAok0CVhuhrUCC573VBnO6y5sQpHDbbvHfAItZDNEeY2Qs5H6hm88Hq9/6Cb0flYzLwNagpJzFi7GIYqtQ2tL3WoRCQfzq5+hs0DUjQ2vlUztLTljDBrfIHDdWc/zCOw9kXbpkhStrl7fp2HIgylk2Enc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149379; 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=HGnLkJXIaPZ2SlGk3KqwSWv5BCbpo8F8ZNOyt7sLmoU=; b=bHWeDyGBps6ovRQkdFz4qzViW0pgcJW0p1Zg9WLmK0Sgq0xKpYKX7XmeavhQFsFN7+NzexgL5r/BiCNarQFiV/SfSdONc8fJ0DF3fHhXcbLPTTzuQL3shj6bF8/HD4MZuzAe+D770sb0PS3I68rbEm2MTi3A2pby3cd4gpC1r+k= 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 1769149379664153.64313015241044; Thu, 22 Jan 2026 22:22:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYk-0003AG-QB; Fri, 23 Jan 2026 01:22:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYi-000397-V1 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:16 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYh-0000rq-5X for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:16 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149335; x=1800685335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=euo1uQzGYAUaN3wijSuUW/9xkovcGHGFmf0Ishxos5A=; b=IYkwDtfjyS0dszTdNZSUOa5hex5InaSMuxd3KygNcvbB/e73NwD/oo2j z6iKgogJ6C5OZ/IaJdqPILmNcOQDIc91B4H1ukVmUq0Dsf8wmugCKVmhm IH9TylQG47zEyNcJugJSG62WVBmcX192Agyy8qYNj9rnpc2M237sKpfff hQhdhB3u/BsDnqGkmAumGYtWZNf7wfZvgWCdLm8cZMVzEW+VwMUEsHqxp pEMDA7Fw/xOTNNFxuMQP8iuo779zb/DCHE9lrBbbpAciv7LIRgO7LlRyL 8S8K0NvGhwj3Ti5ahTsNjTOr4pU3ctxlwYxySisZe1B8lI+mho8I2ymHA A==; X-CSE-ConnectionGUID: YhhtwwHmQHOjnivZmy3Mxg== X-CSE-MsgGUID: UjC0aWzUTDmTmDb75WR4OQ== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254194" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254194" X-CSE-ConnectionGUID: ovjVwv9cQS6fQ83seOwfoA== X-CSE-MsgGUID: uy27e5PISHSqvZ0wKDP1Gg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287406" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v4 3/8] vfio: Document vfio_device_get_region_info() Date: Thu, 22 Jan 2026 22:17:42 -0800 Message-ID: <20260123062042.568703-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149408754158500 Add documentation for vfio_device_get_region_info() and clarify the expectations around its usage. Cc: Alex Williamson Cc: 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 Sun Jan 25 10:15:21 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=1769149386; cv=none; d=zohomail.com; s=zohoarc; b=YwfOjmoudbc5fngteplKwUK40oFELWAqza3D6YP0EBEwm7L7qTwfs/n4aPqPVTGCnH8HZLXJanKEFqsLmvlvAZsfM/X1yhpja8QGoZYKW826rPyA6KDsfkWPfeqw6TpjaLFrOJ3jTtzk3MJTBBgLzTx3R/eUYSnBGykWcxQMSEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149386; 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=bbnagiV+klXG4Zad75H6QKQHTEdiSc3txXC5WRZFnds=; b=SNRGdO3tyEu2Im0p9kShdXYJNKE3J2NGgywh1gVdZJ6XjYPYh8Km4Pa8iGmIz3hnVNzVZD/nWZiMdhNO0X73Bm1kZSSBB4M3EKO8BgwUbxFwE5cGP8st6Aj0SSZK72Vsd52zr2qfHVzlaZnTf/FSyTAk9sYh66q5cusguXkkcng= 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 1769149386746314.59328877631833; Thu, 22 Jan 2026 22:23:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYl-0003Ab-2a; Fri, 23 Jan 2026 01:22:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYj-00039O-JM for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:17 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYh-0000sW-QD for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:17 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149336; x=1800685336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3nm9C0FRlKNZfgdC1Q1cu9wRjqB68evlSDNuAHUY+D8=; b=irqHz6iggB8n8dsx3ZyLkk3R1lCMehx23Dbi3/FRiExe+dRWd1+4wRJA 25ho+0VBAk5A9j7pwlMWi2yxsllkD+aWoBF6n8SNRIKUmdLc458z+Moxx Nr1oTnqb1cOw0JOBdOBt8waT7QMavpQxO/IewiNl9SHpZkB70ckWnr/Cl ycBVBrHwM0LSQFhPV1ebVeRjaJCVg79OzM6MyT4e1J+4fbbwyyTw60OCR iQ1+pJxcNtEfZX51BbCDbR+uy5vh/lSNsgJ9RraDVC/BMA2Lko5zglbWf GrlDmIbCXaJNCj10szRIGduEtrs6IjuLshh5kvO3Cj9npHuGttNVVmoAE Q==; X-CSE-ConnectionGUID: oU9w7rOoRtGDS7/cmxwuMg== X-CSE-MsgGUID: bUfqidd/TVa0o4CdpJroqg== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254198" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254198" X-CSE-ConnectionGUID: 3UHgZYxVTdCeZUvTB8GK2w== X-CSE-MsgGUID: jDxXwqEaSOWnAOPyIuMeOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287408" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v4 4/8] vfio/region: Add a helper to get region index from memory region Date: Thu, 22 Jan 2026 22:17:43 -0800 Message-ID: <20260123062042.568703-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149388940158500 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..8943128dd2 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 Sun Jan 25 10:15:21 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=1769149413; cv=none; d=zohomail.com; s=zohoarc; b=PhrCOu3Ii4J8dNZTcSZ/Er3wgAZ2Tx9idIReQ9w0SOStPlTzuaTr1fO71Xq4iMIEADab1v/U7h9KeprCTPMUE64sVeK7hnjptD/yuzE50Ko82BAUVVTErS0D3IHCC5M69lUajb+bJxkRNkIppk9P2xuTu4v7tfx/z5+ydpU6AxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149413; 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=s0LfXKoXDPm1DBIxvO0IT+wJNoiEIrzgUAhyOG3/sUM=; b=VgfANo94eFdWojkhjbNypTAaaSg153+RS3J152Vmrlyi534Y3jevEMEKeVilGBKTAow9BYpzkdwPACm3L6CkYjs7LqZMutdrAzTCvNQjPq1IcCkYXZuEo5RpJNnlRLVCZptnfLJgJ/R4T28r2msFkOxVD1dx2gpjIBc5h9MoUzM= 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 176914941346532.574806535435414; Thu, 22 Jan 2026 22:23:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYm-0003Bm-GI; Fri, 23 Jan 2026 01:22:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYk-0003A5-Dp for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:18 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYi-0000sJ-Ja for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:18 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149337; x=1800685337; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yhdsCW0DFMHQGdzuiJxr5bsKYnwCstyI9SKEGqfdAQo=; b=RDnj4V86P6wTL6c9byp2xtN+jfP9jgJTcqieRjBMuh4t4uzbIdezHZgy bq2eQPQUel+649vUROJs/8Yhn9192VlNr/bxhTec2lcg3KaelR5FIQBi3 lvDAVItVJ0bJSJUtiX1RZpJLF1zufIq6G1vbAl5GKxFFwF940SsYmLfaz uynXaQ73Wk8ALwCMh6PCPVOTyDdHat5JesQpB8zlf1FCHrplU5BwArB0c HI+yiYJrcIT1m2RLcE5kjiinGpcDwR7tFsX7NgtQHDwZAmecw+N8cG/mQ HNneFYZGkOeiYqmD2AeZ3uYqV4ZIJJ60Lmrfbywbtb74w7maP4+DhWZFv g==; X-CSE-ConnectionGUID: RnH5IFwXTg+lAh4kyWjvFw== X-CSE-MsgGUID: eQN8ZLR/Roe1bUIA8EWSjg== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254204" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254204" X-CSE-ConnectionGUID: 43EOBY/fSMqt8SqXZDRQ2w== X-CSE-MsgGUID: +fE6sewrTKGxmZtjyIMePQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287411" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v4 5/8] vfio/device: Add a helper to lookup VFIODevice from memory region Date: Thu, 22 Jan 2026 22:17:44 -0800 Message-ID: <20260123062042.568703-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149414485158500 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 | 12 ++++++++++++ include/hw/vfio/vfio-device.h | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..afeff0f034 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -644,3 +644,15 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { .region_read =3D vfio_device_io_region_read, .region_write =3D vfio_device_io_region_write, }; + +VFIODevice *vfio_device_lookup(MemoryRegion *mr) +{ + VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &vfio_device_list, next) { + if (vbasedev->dev =3D=3D mr->dev) { + return vbasedev; + } + } + return NULL; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 596c7f5a10..ccf2fd887c 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -318,6 +318,15 @@ 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); + +/** + * Return the VFIO device associated with a given MemoryRegion. + * + * @mr: MemoryRegion to use + * + * Returns the VFIO device if found or NULL. + */ +VFIODevice *vfio_device_lookup(MemoryRegion *mr); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1 From nobody Sun Jan 25 10:15:21 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=1769149412; cv=none; d=zohomail.com; s=zohoarc; b=DFH0rR4BLw5pYx6oOrz3K+N31gSewV2waJzpBlLxalXwEDjd58eNcsf3oajH3aoAKJqFK/ZF7Eu9rLT8/aH+lmS7IrF+cqdyrxC8hrSvDHc91wNIqKxQbh+DzHzoI5R3QnH5feuXi7zc3lhowTVTrLa7pESB+yYBPIEWPAwXjVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149412; 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=GYn6HbcHJYhdAYEpyxkmqNdfzV1wASWBnLNtHnpxVl8=; b=TyFprLHhZN0itOFCI5jcIbBRJm6rLD0Uuvgo28M/5LB7xi4HD8AuOV2h4nxIUUzfZZLCoFiv8seLpph2FnrUyfgG8oVCb6SUXUb7dgJd2PjhS1H5QfGe/QsTFttJmw3sqETleDj7E/sd95WgMWmf2opVFLv04pNyQ2PB5u+n7Jw= 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 176914941278112.513508112405702; Thu, 22 Jan 2026 22:23:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYm-0003Bl-FG; Fri, 23 Jan 2026 01:22:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYl-0003Ak-4j for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:19 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYj-0000rq-AQ for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:18 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149337; x=1800685337; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9z4wt3h8g6G2FMrJhvHLEY2taO5XQrbNTl+7oirh0+8=; b=LmiSUKCVrtBFmThNzuMROr15WvMo54YmE59lruugEvEjJeG6KSsUM2GS 4b1s5vT21rPCMs64THo/0GTOGsewe/WJNxnkNGID6GjlkkZ9QjXvd663g 7I9CxsWKQTtUtqK/jJESjee9u6H5n7g1M6PgPuomyfdvdzVhqP7PeiYR4 ZiSKNTaWxLPKFdYPZ6CCYXDuSm/DXI5eZ9OJlvDd2xUL2V0GirZspCf3h ZH6XkRRHbykpwNOPhB7Cv6tHMm8il8EIZXEQ+Yo8SwDS+EQ3w8gSmxcXI Lrn4VkrELYfvcl7Gnb51ApdsbUcOCPMFbEmek/Avd65bN6btZhjBAibbV w==; X-CSE-ConnectionGUID: SQbDNshpRTu+io+vW17cQQ== X-CSE-MsgGUID: nZM3YcQeRtWHqtRz6qhYZQ== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254206" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254206" X-CSE-ConnectionGUID: V2H2UuOOQgSZ0Wt5SURKFw== X-CSE-MsgGUID: WhwcxvSqQ4i5cJQp3trm8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287414" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v4 6/8] vfio/device: Add support for creating dmabuf from multiple ranges Date: Thu, 22 Jan 2026 22:17:45 -0800 Message-ID: <20260123062042.568703-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149414511158500 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 | 44 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 14 +++++++++++ 2 files changed, 58 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index afeff0f034..90d7758d0d 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" @@ -656,3 +657,46 @@ VFIODevice *vfio_device_lookup(MemoryRegion *mr) } return NULL; } + +int vfio_device_create_dmabuf_fd(VFIODevice *vbasedev, + struct iovec *iov, unsigned int iov_cnt) +{ + g_autofree struct vfio_device_feature *feature =3D NULL; + struct vfio_device_feature_dma_buf *dma_buf; + RAMBlock *rb, *first_rb =3D NULL; + ram_addr_t offset; + size_t argsz; + int i, index; + + argsz =3D sizeof(*feature) + sizeof (*dma_buf) + + sizeof(struct vfio_region_dma_range) * iov_cnt; + feature =3D g_malloc0(argsz); + *feature =3D (struct vfio_device_feature) { + .argsz =3D argsz, + .flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF, + }; + dma_buf =3D (struct vfio_device_feature_dma_buf *)feature->data; + + for (i =3D 0; i < iov_cnt; i++) { + 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) { + return -1; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + return -1; + } + + 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; + return vfio_device_get_feature(vbasedev, feature); +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index ccf2fd887c..2f7e50f7ce 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -327,6 +327,20 @@ int vfio_get_region_index_from_mr(MemoryRegion *mr); * Returns the VFIO device if found or NULL. */ VFIODevice *vfio_device_lookup(MemoryRegion *mr); + +/** + * Create and return 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. + * + * @vbasedev: #VFIODevice to use + * @iov: array of iovec entries associated with a buffer + * @iov_cnt: number of entries in the iovec array + * + * Returns the newly created dmabuf fd or -1 on error. + */ +int vfio_device_create_dmabuf_fd(VFIODevice *vbasedev, + struct iovec *iov, unsigned int iov_cnt); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1 From nobody Sun Jan 25 10:15:21 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=1769149399; cv=none; d=zohomail.com; s=zohoarc; b=H2ZC0QatXGlEaFgecAmBbiRDhZp3yoh9sp20vZBT0vuYQ4u0sTWcSitgci4SQAJqilTOp3FAuIN5JrnD3V08IwC6p+QjvnJjEkajFyxGfNImxb0iWq64hbJkvYYE8QbpUa62UOwCaN9WAzKtcfs3en3txuM0O7fZp1mDTbMf/oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149399; 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=DNwiiNjZy1JC3azXWpka5ozoxHzvjBbzoMsaByRp8r2BElt4Xvkog4UMRmJ5LUURTdb1/uRgUmxJu+QkQ50PUNvgnqxBlYhO8TEhj2q1sSR2vbZM8fs7FMKhqp5najdlQf8KrHRFJn6Te6ulgs9+bgbD/L+4iNcDDgAiwcsLNCM= 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 1769149399710746.9580542570293; Thu, 22 Jan 2026 22:23:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYn-0003Ct-NM; Fri, 23 Jan 2026 01:22:21 -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 1vjAYm-0003BK-22 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:20 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYj-0000sW-Sp for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:19 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:06 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149338; x=1800685338; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ztabUCwYVEnXrUXpODUpIX/j6IsbTnuLW3gEfsQfQNk=; b=J/Ac/CLUraUdVEuVV5AeyZtfFhEo9BTbJkAJDG9UHZOjky+qUmcVLCPc JkgUFB4YzJbaotjp58EAqABG0Rg5fGSzp4ONAQxizDtvCRdnPayUhpLXD Lf0gSIeqs+AWa68SjED/ljpZFI6zht2lbDjWGm22dAUDKKMEyNm6RTESQ bLUsqStoHR+QqW8U2POqufxrZaMcaa8GamdcDhnfIx2d/udJGqE3ewMU8 gNfnB0MulH2fsLLMpO3ht0yv7ys2fqcwNksJIkBJqLwWDcypNBRO5sRc3 UbYsYCN/BLc7YjE1Yk/4HGXCdLdZx5hmRY5MOA+tT3YtRgG8WdOIpfjJm g==; X-CSE-ConnectionGUID: VcdbXkx0RTikpH/Rx5F/1A== X-CSE-MsgGUID: wrlz4oRxS6iXWZZyNYr4Sw== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254209" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254209" X-CSE-ConnectionGUID: 8Zy4+GJUTqu95Zx16zRLeA== X-CSE-MsgGUID: 1jWUsRuQTyCIw6ckSQmdWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287417" 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 v4 7/8] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Thu, 22 Jan 2026 22:17:46 -0800 Message-ID: <20260123062042.568703-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149400690158500 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 Sun Jan 25 10:15:21 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=1769149370; cv=none; d=zohomail.com; s=zohoarc; b=YWFN2McjzxVrqqNNusg5pZz3RPZ6kM3EQYPK9t6AzEQMWO3ukYuu8IVl4NFtrSitvFHFMIMu2NEe8wUUBPsLHZYcQhOcq5HhEX8PD0gmrSHG1gBnFVPTPnjBkKpbr5gqFml6dg/fLPm5gb5N2j9b6qpUDKqjLfQnZdWQrRKGEkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769149370; 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=nQiySHMcT41+ApZLmxzxE5vt4aC4yBiFn/UEl6w9380=; b=AcwaFPRk5ANqhWJu/9uKBe4ZRam8oKZ2qvUSDlZCGyS5QyElPpjdcHgIecPqYq99XkO54NuCrckTtYpe9RvcF1k412QtRkt8rCBpA1Yyay4pkK5o3jV1hp6g36uoUTZ3apbm09OF7x6+HUVT0KRrKt0Nadr2EKDnR/MoyamgirQ= 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 1769149370584805.7942422177733; Thu, 22 Jan 2026 22:22:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjAYo-0003DG-30; Fri, 23 Jan 2026 01:22:22 -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 1vjAYm-0003Bx-Lk for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:20 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjAYk-0000sJ-OT for qemu-devel@nongnu.org; Fri, 23 Jan 2026 01:22:20 -0500 Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:07 -0800 Received: from unknown (HELO vkasired-desk2.fm.intel.com) ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 22:22:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769149339; x=1800685339; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dOH/gF7JQzm/bUOolKZgzEjapwUscWN6HlBLSOMbf+Y=; b=NVA7BPq2aM6Mv0T+h6oNDdRrc88h1Y9heMbqA9acS1IWQve0CjiY6B5z mjFPyF3y82z3xv5eEWadDuqoX9XshpSQGE1C6JJqZiWhvUr0qO+u9A7bK 9+wuTtuSXHe6fA64fLivH1CHLY2IFetFYWkiglqH7LSyj4JWoVQR0zO7Y ghSOjfYjbt/ufMSDAinUzsKLKQlH8mLW0r0UejKrz5t0RCrYhgs2WT+GU aO6OUJDUn1SDeW32wURGSLveZwmuiAE6EZKPJSOKCn686FFkLH3uWXpql 4CDzPqgWlbMbOuFbx/Q7V+zh+x0DJ2EeymNRiBvLuVBHiHnZqmFjB55l/ Q==; X-CSE-ConnectionGUID: 4QeUSSb0Q/apgaxFyZ9n/A== X-CSE-MsgGUID: qSE17k1PTEmnmPKwhNjuBg== X-IronPort-AV: E=McAfee;i="6800,10657,11679"; a="74254211" X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="74254211" X-CSE-ConnectionGUID: w6msm5gySf+lcl0A4LBqHw== X-CSE-MsgGUID: xVV5IrQ6Rqek6V1wbXhFkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,247,1763452800"; d="scan'208";a="207287420" 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 v4 8/8] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Thu, 22 Jan 2026 22:17:47 -0800 Message-ID: <20260123062042.568703-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260123062042.568703-1-vivek.kasireddy@intel.com> References: <20260123062042.568703-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.14; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.07, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1769149374375154100 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 call vfio_create_dmabuf() which identifies the right VFIO device and eventually invokes the vfio_device_create_dmabuf_fd() API to have a dmabuf fd created. 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 use the VFIO device fd directly to create the CPU mapping. While at it, remove the unnecessary rcu_read_lock/rcu_read_unlock from virtio_gpu_create_udmabuf() and also replace warn_report() with qemu_log_mask(). 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 | 117 ++++++++++++++++++++++++++++++--- 2 files changed, 113 insertions(+), 9 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 c34d4c85bc..2dfe70d7eb 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,38 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 +static void vfio_create_dmabuf(struct virtio_gpu_simple_resource *res) +{ +#if defined(VIRTIO_GPU_VFIO_BLOB) + VFIODevice *vbasedev; + RAMBlock *first_rb; + ram_addr_t offset; + + first_rb =3D qemu_ram_block_from_host(res->iov[0].iov_base, false, &of= fset); + if (!first_rb) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not find ramblock\n", __func__); + return; + } + + vbasedev =3D vfio_device_lookup(first_rb->mr); + if (!vbasedev) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: No VFIO device found to create dmabuf from\n", + __func__); + return; + } + + res->dmabuf_fd =3D vfio_device_create_dmabuf_fd(vbasedev, + res->iov, res->iov_cnt); + if (res->dmabuf_fd < 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: VFIO_DEVICE_FEATURE_DMA_BUF: %s\n", + __func__, strerror(errno)); + } +#endif +} + static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) { struct udmabuf_create_list *list; @@ -43,10 +76,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; @@ -62,17 +92,84 @@ 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)); + qemu_log_mask(LOG_GUEST_ERROR, + "%s: UDMABUF_CREATE_LIST: %s\n", + __func__, strerror(errno)); } g_free(list); } =20 +static void *vfio_dmabuf_mmap(struct virtio_gpu_simple_resource *res) +{ + 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, ret =3D -1; + + first_rb =3D qemu_ram_block_from_host(res->iov[0].iov_base, false, &of= fset); + if (!first_rb) { + return MAP_FAILED; + } +#if defined(VIRTIO_GPU_VFIO_BLOB) + vbasedev =3D vfio_device_lookup(first_rb->mr); +#endif + if (!vbasedev) { + return MAP_FAILED; + } + + /* + * 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, res->blob_size, PROT_READ, MAP_SHARED, vbasedev->fd= , 0); + if (map =3D=3D MAP_FAILED) { + return map; + } + + 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 !=3D first_rb) { + goto err; + } +#if defined(VIRTIO_GPU_VFIO_BLOB) + ret =3D vfio_get_region_index_from_mr(rb->mr); + if (ret < 0) { + goto err; + } + + ret =3D vfio_device_get_region_info(vbasedev, ret, &info); +#endif + if (ret < 0 || !info) { + goto err; + } + + submap =3D mmap(map + len, res->iov[i].iov_len, PROT_READ, + MAP_SHARED | MAP_FIXED, vbasedev->fd, + info->offset + offset); + if (submap =3D=3D MAP_FAILED) { + goto err; + } + + len +=3D res->iov[i].iov_len; + } + return map; +err: + munmap(map, res->blob_size); + return MAP_FAILED; +} + 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); if (res->remapped =3D=3D MAP_FAILED) { + res->remapped =3D vfio_dmabuf_mmap(res); + if (res->remapped !=3D MAP_FAILED) { + return; + } warn_report("%s: dmabuf mmap failed: %s", __func__, strerror(errno)); res->remapped =3D NULL; @@ -139,8 +236,12 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_r= esource *res) } else { virtio_gpu_create_udmabuf(res); if (res->dmabuf_fd < 0) { - return; + vfio_create_dmabuf(res); + if (res->dmabuf_fd < 0) { + return; + } } + virtio_gpu_remap_dmabuf(res); if (!res->remapped) { return; @@ -153,9 +254,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