From nobody Fri Nov 14 22:21:15 2025 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=1762666791; cv=none; d=zohomail.com; s=zohoarc; b=VPcw+GRAfmTJuT+dSy1yZ1avhZMpijeeUkhpwWJvA0pCACn9ZkrS2I02E+cQpy+9NdveFER6aBW+bm+KK1uzMlUZu9GvI8LKIiuERiTHj+9WtS3SHiCmobtTDhdMv8qfgLhVCaYucQdsTNJsPz94KH8nC6P291r3tgSY1IKxavc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666791; 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=edNlf3z9LPgOvUZSf4tYSt6IyypSdufTFROUd6trEx8=; b=ON9/IAtDALnOj/jFzOemsYxC88lYylVxA2HqnW3tw6af4cknijzkb4wLCGjCFGH8FbZL3KntmD1NMS+uRYocrubBNgh+YHr3J/71qTafQril0Vl3TTKznRWAxEHg3LzsUbGfeIYyJUpm2tI1ug9SaCauyMZmM7jYSkWDz2r2Qyk= 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 1762666791823690.1904424674326; Sat, 8 Nov 2025 21:39:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8g-0005XD-KG; Sun, 09 Nov 2025 00:39:00 -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 1vHy8Y-0005Vz-JX for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:50 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8X-0007aH-2j for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:50 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666729; x=1794202729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4ssiyJyKb1dM2r+xpQ+t97aneJXk9s2pQd+SlFWTZtU=; b=CS5ulnVMh65QLEl4xumLvINxO5c5n0XIbb9Hvl3A/SQyYNfTNefV1khN 7DKQYFbCtp7IL/glrkbmToDRq3uHnYWLGzq3elAI9Ew4UvvHz/jERC1aI f1Tvckjb7mh1LkYSYvEBioQ27KZ6QYi7BbrL31kVQk53J1WcYXOZJOeMQ QwIHcv5jfcveNIhCo4KI44NLaeRJqHFnKEegH8SgGxBk2DhdpRgVxKuiE IJufW9XWS/qyp6Q+D3s2K4mQOPzHsGPtml/SwhsCl4MSdRGj6VRHvT8SS FH1L/RlgR2xCXzHmnWv4bu8qmcKPekDBcR6GfztdHOl/fwoaJYY64h0um A==; X-CSE-ConnectionGUID: /9jyfaL+QJm99YspZ2lg5Q== X-CSE-MsgGUID: dk29Cy8iQSm+yiDtbvCWAA== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965785" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965785" X-CSE-ConnectionGUID: fZHmqQ8rT92s6JuirOXLGA== X-CSE-MsgGUID: XeL1d4uGRZmeTtUX/KMpdw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129043" 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 v2 01/10] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Sat, 8 Nov 2025 21:33:44 -0800 Message-ID: <20251109053801.2267149-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666793705158500 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 Signed-off-by: Vivek Kasireddy Reviewed-by: Akihiko Odaki --- 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 43e88a4daf..199b18c746 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 Fri Nov 14 22:21:15 2025 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=1762666853; cv=none; d=zohomail.com; s=zohoarc; b=dnQkvwgPjGc6Xx3X186qIo5gixr5SZm8ia1OzmZcjOOM+5EXK4o7ZE0lURDQZqcxQLq7pFdJU4w0QcRh3CnNUsnOAMgdGgAOIIrXY/t6jR3xc//XwdQQcF3MR6bvhPAMaA2WG9nwoP9Z72aVs2lvY6BLshj19Ek+I9Vng+ALWnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666853; 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=jRFwMVDmiUnHdOqJIquMYNyl3RggBH7H0y5WCjFRLdw=; b=eg1FLCUmlm5X9Y34AUSrlOTG0CPS2XrPTSUPq0+AD/+olC52jXfD+BFjqIR8Ci1xsD7wv8RZ6OZyrGrCysJkmJZGUP8GICKWN6RL3yPveM2BD4+xmTleR1dKD1GOdGCq8Tz20xN1WX1wRnwy3KYhC+VDpRhZqOj0mqdYnvEdYeo= 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 1762666853626700.5803024424501; Sat, 8 Nov 2025 21:40:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8s-0005bR-4P; Sun, 09 Nov 2025 00:39:10 -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 1vHy8a-0005Wj-9e for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:53 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8Y-0007Zb-LT for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:52 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666731; x=1794202731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4n9hck6R0svxMbk2pUnGkjTH+5x2uBEAN0/Vtq1+Rrs=; b=kN0Ub7IZ1dRdcTaP21WL5Q+X4xtGG8VKNvnwZ038jq3QhyNst+mTWq/A GWOv68NelBrd6VmLK50512uOH724hQ8Qw2cTfyb/L00LomN03ymuhspqT 1sL8+ib498VUrDDu4mY1ruZ/T1G914kQ4voD15rC180Xsa+0tI7ENfh3T XuQfwwqlHX97mOeTZg7TdfOrtz3/j2BdIuC+JVOsGCYhRI17b0do+l0yU CdUoOAQc15Ggo9MkRwAQudMdbNGInYvq8ZwWlf0sKyKubWGFJhjL3Hy4l bhNahpZhXHRAHWid1BO7zRfIxrFZIcVqrSiNOFnq56E4I3yRMGhX0XDpa g==; X-CSE-ConnectionGUID: 6GGj3kuXTByXHDVg6wK28g== X-CSE-MsgGUID: re7dTfFmRDy8d1fbeOAbeA== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965786" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965786" X-CSE-ConnectionGUID: tKq7DucwRG6+ZycO2KqkTQ== X-CSE-MsgGUID: f4HjZ8aWQpaJA4T/dgdQRQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129046" 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 v2 02/10] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Sat, 8 Nov 2025 21:33:45 -0800 Message-ID: <20251109053801.2267149-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666855053158500 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 figure out if it belongs to a ram device or not and decide how to obtain the host address accordingly. Note that we take a reference on the memory region if it belongs to a ram device but we would still call dma_memory_unmap() later (to unref mr) regardless of how we obtained the hva. 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 199b18c746..d352b5afd6 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -798,6 +798,26 @@ 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 =3D NULL; + 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_device(mr)) { + memory_region_ref(mr); + return memory_region_get_ram_ptr(mr) + xlat; + } + + return dma_memory_map(VIRTIO_DEVICE(g)->dma_as, a, len, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -839,9 +859,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 Fri Nov 14 22:21:15 2025 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=1762666789; cv=none; d=zohomail.com; s=zohoarc; b=aODYN0SZp6BWbtcvd0bYSJl4rXOgiJhcsQW+DJiMqgiexLYnRQoEXon+SvuRomDDkjJHzDXpVbqKHInGOyh1w6QleYr7l5n/q/ybqRGmvyHk1zwpNE0DcJEo9sYIfxEddjIUug2KBA3Um+eXmHSYBWetWreelDQi8lnsGvJast8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666789; 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=3mFUSHo00QC6GQYcVLbxHXrviSlPeb3q5CMGM+onVI0=; b=ly7171JDFUia43EIw1G/qeCse/chHaX2txTX6VuYEVAAC+kFtD+yVK9fAm32JbpdT73gxu/69qTqNKeOAqLCHEJHO6ReQHIR7AjTFbKqnRARf9WHY9GaTWvNTDUcbp5U6pUAuYVwodamXTphefm4hb1T0vz/yKip4Yqym5GNhoc= 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 1762666789203769.047101064049; Sat, 8 Nov 2025 21:39:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8Y-0005VT-DC; Sun, 09 Nov 2025 00:38: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 1vHy8V-0005Uo-L4 for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:47 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8T-0007Zb-ET for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:47 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666726; x=1794202726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UEXmJpHXry9uVp0udXAUcXCrJOZasoHnLtLQA+q5aD8=; b=gJsJN5H2Ajb7yBV4m3uyIUlXS5xuBFewSoxYCOGNcVfVZ+7zGVm5idaT Ecz7QwF/CooX7lv08Nj7I6TuEvI0e5JJ81Bd38MmCt/+oiPINflLT3oxu QdgF3beDHK/UENRZPu/fStyae9nyQp6q4wWeOY0bN+PLZ1lkKtlE4yvzp pQ7YY8fFfs2sJsaq0kR2BfXF7oIAY0a3+LBWHNFAzNz65jb2c+mDrwM9G kWDpmhHf8scyL0cOIGOELOlgncbopNtYNeXgUG6GXDBbl6Rxr8lHQAH2Z j/9i+qyhGi2DPlXJ7fn8TEc3pk6CwFEvdzpRxf+SIDuqnz0VpPo0DIHVT A==; X-CSE-ConnectionGUID: fLjBmDaSTcK8v+bwFS4GEA== X-CSE-MsgGUID: 9jqWHm5+RwS0qlla1y8TEw== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965787" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965787" X-CSE-ConnectionGUID: 0ZOIRkr7ROWAIC+/oLTKWA== X-CSE-MsgGUID: EDTvSXURTBuNYhl1vXc/ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129049" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 03/10] vfio: Document vfio_device_get_region_info() Date: Sat, 8 Nov 2025 21:33:46 -0800 Message-ID: <20251109053801.2267149-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666792446158500 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 0fe6c60ba2..bb28123faf 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -257,6 +257,19 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCon= tainer *bcontainer, =20 void vfio_device_unprepare(VFIODevice *vbasedev); =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 Fri Nov 14 22:21:15 2025 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=1762666853; cv=none; d=zohomail.com; s=zohoarc; b=Y/x3wpPz4rcfVapBoiOjvStbgGhxHvh9KLF9/ykUo0Poj2R0AbhFxO7xe3Rthno+IegAj+MEJ/qQ+qpda/Uc1ntpS4/0ET+dDAKYCX7oOnGo3zzuo8kzK6hDFror7t2ClF8NiKMWq3mOoSfNxRZqfSNkNXqTnEXyZ5IGiaLyOeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666853; 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=NHARvQcGyqSCLX4MT8v8MImj6LpYlAK19YJHvyc2PzI=; b=I0aIDrrLXYAvIc3HDtvUEyvoSEETyXH5v9XIrAq95qSyfn1KTfExqDR48HlCPMhqHHZ2JaQHFgxSmYBoQeSPFr5oHzSkvw5Gh5nS8XmJ6IaB+6mBHIQ23mVoo6Pnf939L+RuFG2DUMfq+fg7i1vLahqPI1PKqOL6iGn1R3B3e5c= 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 1762666853945977.8144215650167; Sat, 8 Nov 2025 21:40:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8s-0005bp-CC; Sun, 09 Nov 2025 00:39:10 -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 1vHy8d-0005XK-Fb for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:58 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8b-0007ak-P5 for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:55 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666734; x=1794202734; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3djzRjzZE+tW6luIckijbzfq6imlE010PwpXSVzspAU=; b=MCK0d5/sx2m3bJIhrH5ofyIKbQm5/lGElJIBlLb+jhiozR5jg8XwoioR MIBghqo30yOyM6iG7fo9qESnZH4XD0tFTh0gAIJ59H7RTa04Zco/zCgDz jrKLiDG/N8aisuScO/da8Ng+/GYYIO1e4x56ryr9POC6VohNZkI4mglDH gvCTXn/G6wzIi6ER9Aqu+ouBMpT12hFHp/M/Sg45NZ9XKJlAIIX8oQE8T iiQcOXK1wBXbcvBWV8aOmG0gx6nPhcXIHgZXPvbmoIcDyaiefsZLKGeO/ vYzIsizSA16uJ+aJVV1vQNrHD2kg2boja1z9n116aeWFLilXxYPZ85ncp w==; X-CSE-ConnectionGUID: tUslf0KWT2iMnaQFdK5Hfg== X-CSE-MsgGUID: CFB8yuPfQmK9E+2vcEXI7w== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965788" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965788" X-CSE-ConnectionGUID: iICiCJjJSHaJdneDcGcfmg== X-CSE-MsgGUID: zEA3siaBSju0M4mZ9R0KbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129052" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 04/10] vfio/region: Add a helper to get region index from memory region Date: Sat, 8 Nov 2025 21:33:47 -0800 Message-ID: <20251109053801.2267149-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666854665158500 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 b165ab0b93..046adfaa2c 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -398,3 +398,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 bb28123faf..44cacd3728 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -290,6 +290,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 Fri Nov 14 22:21:15 2025 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=1762666808; cv=none; d=zohomail.com; s=zohoarc; b=RzANEmYo52n4nFL9ZSOSytgYNkIj4ONQohHeD+qZpH5bctU0FGj/m3or3tCSKC6f6MqVGWVcZR6dy6qVxSZI/et480zjG30W9phJUlBWdERzeJPhSkO4pdczpa1PGdYTt0ijZZSOMzPNmDVOTwW6N7vqJ5kkmCW8kSOtd6zCnK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666808; 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=aHgakfultMN2Nl/WjC98OkfqfEe3ALgwlXUYRCMy4CU=; b=bJS1aGq8fzJnJFH7jycMz+qEp5fWIljZp0572M0ptrt2JsedcVsS+v3zB+7hg3sLClzLVtNGY3XENYDYV3LzBxehlLxN/TFilkpxKRCJ5H/RPN3LaakqdxJMywlj9wt0LjPfu9OgyNEq+2Vpph3EOhYiXbn1XjEo9+9ywFzdTXc= 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 17626668089821010.9237669473256; Sat, 8 Nov 2025 21:40:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8p-0005ad-6Q; Sun, 09 Nov 2025 00:39:07 -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 1vHy8c-0005XI-Pa for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:58 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8b-0007aH-7r for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:54 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666733; x=1794202733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r9X27iFF9jmuT4eMQvcKCO4gQXvlIancgXdQF7u7ogs=; b=hdGqxaBHhhKg+eUWRcaHweeJI96SgHGeJ4Rb0NIR+jzzaepuvb4xZfv1 WTB8FgyzpfNpRMzmJhYU6mIaCgpqbuWY8bgQPfnMVOKS/P3mdwafmGjZE pJzbV404IzIKC5RKew6sevPb1LgOhAAEucmqU+MGiB/Jpa3nEASSvttML PSmDOqviKaPhzsTfgg0ESgxUj68eMgluGoHTZZ2veVInUorKmN14igg6K uV1yWMhTeHHy2tIIvxSVeXr7Qt9UKEc6D6SnuWJdED/w2kVSW5O2SSyuD FcP/VUi0Oa5M+LYwRaJo9wlhRifPUEieGoTzakWxWmMUNtpRxpRT4i1cd A==; X-CSE-ConnectionGUID: 5HGUlT1XREe549G+xEXuVw== X-CSE-MsgGUID: 5+w/aUSORX2md9689W5B/A== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965789" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965789" X-CSE-ConnectionGUID: Nfy3obEOS9WGqjFA0jfUlg== X-CSE-MsgGUID: mEb3d7JRSii1ihhAYJDJcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129057" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 05/10] vfio/device: Add a helper to lookup VFIODevice from memory region Date: Sat, 8 Nov 2025 21:33:48 -0800 Message-ID: <20251109053801.2267149-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666810219158500 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 76869828fc..9ff73f9941 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -603,3 +603,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 44cacd3728..2f8087f133 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -300,6 +300,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 Fri Nov 14 22:21:15 2025 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=1762666830; cv=none; d=zohomail.com; s=zohoarc; b=Twm7QApkvPOGLfm/GY6XK8xGRWcHVnGeSIseAAr+St9ERICSsycOMiuxBlh65GlgUhR+7ZZwsq7rYrp4i/8h9hI3+CeQ8R9q1/FYMxRPzg7F6alxk8cHHEIm3xz0VQbEwTjoQLqDPpRRHdZQ9bSgUgSLJcw/vxTtR0TtVHckhys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666830; 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=8GsiHqxk8a279c8+fQgeACCC+vjBv1kJEsav7DPjw/I=; b=I4A6fD2tw0YN6ozCmHaadqgNPiKc2NU8v9xWsFuc9PvwBNROk5mj7fNNIzhKZhhD8rMx8EwN2KYJ/Qa69Yy2BgLZ6i1lZ6l8aEym1k+VNyd3WCcwS8HuMIyD8F5nUgXOgUv/BXPq8XuTd/93xNF7BC1oKIXVxMXYxDHT45SoibM= 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 1762666830133407.6793016192024; Sat, 8 Nov 2025 21:40:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8o-0005aW-UE; Sun, 09 Nov 2025 00:39:06 -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 1vHy8b-0005Wv-Cp for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:53 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8Z-0007ak-J6 for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:53 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666732; x=1794202732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VuJToc00JExeRjtrvaBivKFB6Bcjdaq8Xje4Z9MGKu4=; b=LrVcT+Mtll7vw09cR9tnBmNe457gpxhU22dNp10Jk/oMEdtF7WMQ2eKu lJkpQ5KqEw9ROutQn92JGYBQhWzk97WMQ5CjnWIpmu1gXBfDpeOYldSFS dsHjxa26aaNkLP1Z+fd6gwohfCAoNCEb/pOQLgAR6vsrws2Ll5s67G8fA j7w3d+eLwAlRXf/17iM9ea/jR19aocs/vgYRA9X+NxwhIK7hvt3MfxQqA ONO7bMSw57jglsihBy+QvBonQqxWYL3Featgpu0mwF4zL2FacPW1y3HbD 7dbLzMcu6UmPedWMEy9+PyS+9WLZ54uo+hs96Isa+k3R6u4740EyBdJ7f Q==; X-CSE-ConnectionGUID: YHKrpMgTSY65kyfdwWB1ag== X-CSE-MsgGUID: nG/Zx5aQSIy05h1iylUr7g== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965790" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965790" X-CSE-ConnectionGUID: y4XITdonS8CMOahq/Pr0wQ== X-CSE-MsgGUID: SJfxkOC/TiGii4fvvRbQ8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129060" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 06/10] linux-headers: Update vfio.h to include VFIO_DEVICE_FEATURE_DMA_BUF Date: Sat, 8 Nov 2025 21:33:49 -0800 Message-ID: <20251109053801.2267149-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666832417158500 Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- linux-headers/linux/vfio.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 4d96d1fc12..bc11ca3663 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -1478,6 +1478,31 @@ struct vfio_device_feature_bus_master { }; #define VFIO_DEVICE_FEATURE_BUS_MASTER 10 =20 +/** + * Upon VFIO_DEVICE_FEATURE_GET create a dma_buf fd for the + * regions selected. + * + * open_flags are the typical flags passed to open(2), eg O_RDWR, O_CLOEXE= C, + * etc. offset/length specify a slice of the region to create the dmabuf f= rom. + * nr_ranges is the total number of (P2P DMA) ranges that comprise the dma= buf. + * + * Return: The fd number on success, -1 and errno is set on failure. + */ +#define VFIO_DEVICE_FEATURE_DMA_BUF 11 + +struct vfio_region_dma_range { + __u64 offset; + __u64 length; +}; + +struct vfio_device_feature_dma_buf { + __u32 region_index; + __u32 open_flags; + __u32 flags; + __u32 nr_ranges; + struct vfio_region_dma_range dma_ranges[]; +}; + /* -------- API for Type1 VFIO IOMMU -------- */ =20 /** --=20 2.50.1 From nobody Fri Nov 14 22:21:15 2025 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=1762666855; cv=none; d=zohomail.com; s=zohoarc; b=UxrwnWGToGGyIphGBv/wJjPF3Q9o1i9vhAxy07vv1fKtk7aPfmUAlyDizPWgbO9apxyvNIpYPWz5l4q5VGUB5T7fvfJBh84K5xh9juHXp1k3j7pI3NV0YPajmtE+KCYMl2pQKsMQRqY/g6oTL7m/ZGZNO2wmXvdhi4WK93sd32M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666855; 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=KDGO/Z8yk+Eo0bS7HvarOTWfa7HYCeNA9yMYh2Lcgw8=; b=KXpBYcrsWjNH2P419Sz+WkZKkSgNZnqkYjUbetnDgZvKttTvQLh7rHq6V1ADfb+HJJrjBT9UsTULsJJrjdWwbIky5qik9ke6gzZkLF8HsRkDcMgnT74HJ/mHa17d3srjHO2kpX2o1T+v+Mi1leyaUtDZCyxNmSHl4t4UeVS1ZFw= 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 1762666855679465.0250668655118; Sat, 8 Nov 2025 21:40:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8s-0005br-Jq; Sun, 09 Nov 2025 00:39:10 -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 1vHy8a-0005Wp-TL for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:53 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8Z-0007aH-4n for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:52 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666731; x=1794202731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z6qFGL5WE+eZg5Z8dvi+fn6ZmgEH4hUNJqCkhe0bpoo=; b=cVuYxiSjAFu7ejntj7M0Gd/HlAhXIiA22bMM7AVG3xRON4cd9wR7nB4d kU4A/XDAwSlgbyvt24jVIiM/Z5M5wGAsnElLKL6iuQJJcHV5LVNZDvUBi hpq28QYUor0gbSdANPMrxjuBCLBPwq8TAMyoTMWb1gVovsa0KVh34plcj cFoiw5DR49K9XYGTtk27tQVGspFzqcI24JN/ym46YeSlfTfwKCVq/lI6y CwKfFyacaWPf0e8F2Hr/DQsf0UvqTHFB+AzvxxZFsAM7PiXxAcj1/5Sbh 55AjljfKb6ZQuIKhjrT2xbaPtTpZ1bCZ/WLO7cB7E2kQ/Z+mEDQkfFkj5 g==; X-CSE-ConnectionGUID: gcUvZYHzQUaGAdUWCJt1lw== X-CSE-MsgGUID: 8gv3EkRtTfycmlZWbDpruw== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965791" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965791" X-CSE-ConnectionGUID: YYReIa0VReybm7NJnLUTTQ== X-CSE-MsgGUID: 9MqzAaCiSGqearlBRAb/xg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129063" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 07/10] vfio/device: Add support for VFIO_DEVICE_FEATURE_DMA_BUF Date: Sat, 8 Nov 2025 21:33:50 -0800 Message-ID: <20251109053801.2267149-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666856615158500 In order to implement VFIO_DEVICE_FEATURE_DMA_BUF, 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 in order to invoke this feature. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 40 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 14 ++++++++++++ 2 files changed, 54 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 9ff73f9941..5417142482 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/hw.h" @@ -615,3 +616,42 @@ 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; + ram_addr_t offset; + RAMBlock *rb; + 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); + 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 (!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; + feature->argsz =3D argsz; + feature->flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_B= UF; + + return vbasedev->io_ops->device_feature(vbasedev, feature); +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 2f8087f133..7fc2912f15 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -309,6 +309,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 Fri Nov 14 22:21:15 2025 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=1762666789; cv=none; d=zohomail.com; s=zohoarc; b=FwilccfWBWobpILhOUwYkntdS/C7Xcu7e8NGA5LELtRgaE6yC8RpNwRpF9IHbO284CMFZTRa2KQDsNsXwcvzT+B+CbBUcRwamxT67TAKYd+iyugEZrquU4M1hAQMlxNBYtQXRgMXUN2OIfcxyDH4pyfn89rMzHaf3nJB8JHaLB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666789; 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=51EEwsJwydj/7HZRuxFU6VI4yBb1+qMf5rQ2Fj+DheM=; b=X/NyJfHCR3zQJ+tnHkXDyFl0iQFM66elRiRMeVql/0EZEQiDns+jCaS3xitFpqgQ7snsecOzKxPG4AoWlHC7qZOVVY+qQqG3Bpnbk33Smy0v2csNTVnApgE+2qbq0U1nOtx3dN0QeQRMnAiyjfiPJU2JQskHCJVHGkWOesYVyR4= 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 1762666789471945.6324416411107; Sat, 8 Nov 2025 21:39:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8p-0005b6-OJ; Sun, 09 Nov 2025 00:39:07 -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 1vHy8e-0005XS-JE for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:58 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8c-0007Zb-Nt for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:56 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666735; x=1794202735; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZemXD745H4pR4Ij95HI9Ppx7XL8Kp4GBXYfiMEw3lZ8=; b=d994+oNMX6jqNunUpsd+TeEg4QdAj2pLUKWmOlaWaZzQvx5B8Tq02Z+1 mkaWbjhONXtaM07mfggMDlmZIZxwhLnFKx0PqdIw43RoNVHMs5k+x2Ppz zOsLZy3ovnL9HPaXEhkPhmXPSPgyVcxbbioM82RYrWDFdmJSEF62k4YYK Qc0JvGV33qAXU1OHDZAmJcLJPDRMaaZjP2opzvOxLm3v4hB8dKS6ejitR VbSkMaWsEsegCyBrY4/GvXiBvDWZH5gHtCmR/xUXOQaRUeheKbGHU3E+m Gmw6Ne/Ff4b/pzLaZqvQiSAxw1rRKKz2McEzS8URjxlSYZjUl2N/O50Fr A==; X-CSE-ConnectionGUID: NTG1c3q3Slawg4WZurcZXw== X-CSE-MsgGUID: 6Re0xFsDQmK7SFUlUMLUzg== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965792" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965792" X-CSE-ConnectionGUID: VatLgPz1Q8W6/B/MVjywuw== X-CSE-MsgGUID: 3yG+eg2VRqGFkV3D0xKiiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129066" 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 v2 08/10] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Sat, 8 Nov 2025 21:33:51 -0800 Message-ID: <20251109053801.2267149-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666792430158500 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 Signed-off-by: Vivek Kasireddy Reviewed-by: Akihiko Odaki --- 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 d352b5afd6..da005f2342 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 @@ -920,7 +920,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 @@ -957,7 +957,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, } =20 if (res->blob_size) { - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); } } =20 @@ -1443,7 +1443,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 Fri Nov 14 22:21:15 2025 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=1762666789; cv=none; d=zohomail.com; s=zohoarc; b=JM9jJu8bFN+JYEnIZqZrmqUTfIUo6tytTdvGoq7Hsf0LHlJu4Sz3p1QYpi9FjIya7ZItZg/hN+D88+OlghibZ52Ya5nHH8/pIXh2F+EMjyPFVEM2WKE+5Ib9UZA7EUJaBjtbJ+SaMRGXG5IoP7VtY7n5ffC2PMGxvmPnAF9lpLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666789; 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=pxn2bj0hLdoHax9612FuYdtKrLALFIiqv+Ua6TL2rLg=; b=CyIqk8YJJlMX251SDIGLi4tUHTIb4RlM/WHvoc2QGJQyDzMLMTLeAoHJT3Dz0q6nfo5TUz41xN4BFsuCGJu5xZBL1AwITnJB2RMXQeT4D+Awbsjsf4EhbcqF1i4nTo4s75KQYynmbGTvESNWWe3qX0beE7GPQ+I9y70ZBdLfTLk= 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 1762666789214475.6419026689181; Sat, 8 Nov 2025 21:39:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8t-0005bx-IW; Sun, 09 Nov 2025 00:39:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8c-0005XH-DL for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:58 -0500 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8a-0007Zb-O9 for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:54 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666733; x=1794202733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4MuIlqBaBvnfMbTuPCJMsBMQ1nurHwaBScGrpDh4BWI=; b=S8ok2TrXE/k6WqZ/PTmug6JUbdwrWGtFJ5caGtfg5F6JQMkK/Q+ZHu+3 f8ZkFcBnBUJKx6dkWXd5Bm3nLyM71I7jdCIk6kwTWoW6LA7UGcIqVD3to Fcbk+UwjGRpw00JczK6M4gECd5MM2PoTShO0tM/BDGhFDGaYC7gZeqt7F Vb+mJvka/H4lQb3aHkHnXmYp6vO34gY007SUIsEJqyytPbYEMWLyiCOnr 3wnPiADG6XfjNfQ7CSfNoKspas2VWPJxsDD0Q1ZTnAGKPhtoBgYTK4v2N DyDcbXujGqF3g7Ad+n+3Yzli2o1/vbmRWXwJJ8+zfYZyTGJiRpwZYbyNQ Q==; X-CSE-ConnectionGUID: r/20hd60SqO27BoNXfM2mQ== X-CSE-MsgGUID: Nb5gmpi0Rs2e2tq0LyH0KQ== X-IronPort-AV: E=McAfee;i="6800,10657,11607"; a="63965793" X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="63965793" X-CSE-ConnectionGUID: EguJ80UJQwqD0AnkSUjteA== X-CSE-MsgGUID: KfR4f3qaRiOynHV93I+xcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129069" 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 v2 09/10] virtio-gpu-dmabuf: Introduce qemu_iovec_same_memory_regions() Date: Sat, 8 Nov 2025 21:33:52 -0800 Message-ID: <20251109053801.2267149-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.18; 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_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: 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: 1762666792431158500 Add a helper to check whether the addresses in an iovec array belong to the same memory region or not. This is useful to verify before trying to create a dmabuf from an iovec array. 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index c34d4c85bc..80143034d4 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -27,6 +27,31 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 +static bool qemu_iovec_same_memory_regions(const struct iovec *iov, int io= v_cnt) +{ + RAMBlock *rb, *curr_rb; + ram_addr_t offset; + int i; + + rb =3D qemu_ram_block_from_host(iov[0].iov_base, false, &offset); + if (!rb) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not find ramblock/memory region\n", __fun= c__); + return false; + } + + for (i =3D 1; i < iov_cnt; i++) { + curr_rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (curr_rb !=3D rb) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: memory regions not same for iov entries\n", + __func__); + return false; + } + } + return true; +} + static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) { struct udmabuf_create_list *list; @@ -137,6 +162,10 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_r= esource *res) res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else { + if (!qemu_iovec_same_memory_regions(res->iov, res->iov_cnt)) { + return; + } + virtio_gpu_create_udmabuf(res); if (res->dmabuf_fd < 0) { return; --=20 2.50.1 From nobody Fri Nov 14 22:21:15 2025 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=1762666835; cv=none; d=zohomail.com; s=zohoarc; b=hottz18/L1rXTbY0rEpJWgtjXLQZ8ZU80Z3bEPTrQKLy6hwellHjaPxGy/2mkIakDPJUIVd222uNsmhjU0A/LE9nqrgfj7eX2A4+y8Pw6MsoE+JcfNY/2xCChK8soUmA5Fvg7FzI8GtUND8fZ/sFiH1P3zbnllhRlLcHeFkRTyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762666835; 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=5i+TG5RLMQCRoo9p4clchc+pLXvltGHAqRWyBaAJKEE=; b=KJJcqCIRK/Yad4wSzIO/xu81l2oF3s3XyK24mirUsYviPBkJw24ucTZTmsRR0ul1oALngroqP/IF0iiQgxEEDvTbWJ1h4/79KoK5UZgjwKgPbgqfKXzf/pm1UTmWGxkttlo45lvrQb4ZHbm51RIjCNwLn6XqCoFC8/AWUaSGlg8= 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 1762666835398729.9430968090052; Sat, 8 Nov 2025 21:40:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHy8l-0005ZM-L0; Sun, 09 Nov 2025 00:39: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 1vHy8W-0005VB-Pt for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:48 -0500 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHy8T-0007ZY-Bk for qemu-devel@nongnu.org; Sun, 09 Nov 2025 00:38:47 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:42 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2025 21:38:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762666726; x=1794202726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mqTCB0KZ3ENIGuzfE9e3tp7irG2sX0EMI9SKzQd7QWY=; b=Vp04mzjnyXnvX8EuqRMOKN+3j0s54SYqdqdLk1Wn8E0VP8+fxDoJbmSE QLDkA/VAz3aeQCXLMwbMzTzYUIsqd4aHxCWHufa0/ibGl+dkQSf4KpNv0 KfyRAsioj1FU2HprGgax3pYeDXJFxWamImbxfZ9IVQ3jE42/dh8tiPz8F VdmNF43/J6nLxIn7Ey50fwShVCA4kClWtndS9krZrVIQbhlu75bWgu2OO AznUOliNJxWHjQfm9yl40gsNEe7KOGl9mIwg/6xO77KkmbPsRQf0b5qpz zqvhj5/gkfKDEJIzQQo/kqZ4D1Exkgj8AU3tluR5rMubcfaJaDXoQ6jmK w==; X-CSE-ConnectionGUID: HI8DONHAT8ug9vlL4UfvLw== X-CSE-MsgGUID: 0oBpFQYuSH69JeiHxfcc7Q== X-IronPort-AV: E=McAfee;i="6800,10657,11531"; a="64685220" X-IronPort-AV: E=Sophos;i="6.17,312,1747724400"; d="scan'208";a="64685220" X-CSE-ConnectionGUID: XZx8DzGFRh2fe1CHggSopg== X-CSE-MsgGUID: QiS2WZVYTE2T0oLT5uugrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,291,1754982000"; d="scan'208";a="188129072" 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 v2 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Sat, 8 Nov 2025 21:33:53 -0800 Message-ID: <20251109053801.2267149-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com> References: <20251109053801.2267149-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.17; 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_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: 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: 1762666836440158500 In addition to memfd, a blob resource can also have its backing storage in a VFIO device region. Therefore, we first need to figure out if the blob is backed by a VFIO device region or a memfd before we can call the right API to get a dmabuf fd created. So, once we have the ramblock and the associated mr, we rely on memory_region_is_ram_device() to tell us where the backing storage is located. If the blob resource is VFIO backed, we try to find the right VFIO device that contains the blob and then invoke the API vfio_device_create_dmabuf(). Note that in virtio_gpu_remap_udmabuf(), 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. 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 | 114 +++++++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 7 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 80143034d4..940b0e0411 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" @@ -52,6 +53,19 @@ static bool qemu_iovec_same_memory_regions(const struct = iovec *iov, int iov_cnt) return true; } =20 +static void vfio_create_dmabuf(VFIODevice *vdev, + struct virtio_gpu_simple_resource *res) +{ +#if defined(VIRTIO_GPU_VFIO_BLOB) + res->dmabuf_fd =3D vfio_device_create_dmabuf_fd(vdev, res->iov, res->i= ov_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; @@ -93,11 +107,69 @@ static void virtio_gpu_create_udmabuf(struct virtio_gp= u_simple_resource *res) g_free(list); } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static void *vfio_dmabuf_mmap(struct virtio_gpu_simple_resource *res, + VFIODevice *vdev) +{ + struct vfio_region_info *info =3D NULL; + ram_addr_t offset, len =3D 0; + void *map, *submap; + int i, ret =3D -1; + RAMBlock *rb; + + /* + * 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, vdev->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) { + 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(vdev, 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, vdev->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, + VFIODevice *vdev) { res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_fd, 0); if (res->remapped =3D=3D MAP_FAILED) { + if (vdev) { + res->remapped =3D vfio_dmabuf_mmap(res, vdev); + if (res->remapped !=3D MAP_FAILED) { + return; + } + } warn_report("%s: dmabuf mmap failed: %s", __func__, strerror(errno)); res->remapped =3D NULL; @@ -155,7 +227,10 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + VFIODevice *vdev =3D NULL; void *pdata =3D NULL; + ram_addr_t offset; + RAMBlock *rb; =20 res->dmabuf_fd =3D -1; if (res->iov_cnt =3D=3D 1 && @@ -166,11 +241,38 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) return; } =20 - virtio_gpu_create_udmabuf(res); - if (res->dmabuf_fd < 0) { + rb =3D qemu_ram_block_from_host(res->iov[0].iov_base, false, &offs= et); + if (memory_region_is_ram_device(rb->mr)) { + vdev =3D vfio_device_lookup(rb->mr); + if (!vdev) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not find device to create dmabuf\= n", + __func__); + return; + } + + vfio_create_dmabuf(vdev, res); + if (res->dmabuf_fd < 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not create dmabuf from vfio devic= e\n", + __func__); + return; + } + } else if (memory_region_is_ram(rb->mr)) { + virtio_gpu_create_udmabuf(res); + if (res->dmabuf_fd < 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not create dmabuf from memfd\n", + __func__); + return; + } + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: memory region cannot be used to create dmab= uf\n", + __func__); return; } - virtio_gpu_remap_dmabuf(res); + virtio_gpu_remap_dmabuf(res, vdev); if (!res->remapped) { return; } @@ -182,9 +284,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