From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833894; cv=none; d=zohomail.com; s=zohoarc; b=RkQRtkPjL4lgSqGakDJ5HBmlzZZeb5lE6140Gs4NccombjjBatAgiQYsvCgqeqyh1NhI0cMyGSvlRKQ482eJHNMghcN/q3ONwA+zBTg9ZwHcLcN5xojV44jyatvg8xQIRYLu7sa2WOLYS5/yG0QzobPps+4CZyfHsmgIYNv2Xg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833894; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2es2aBjZqT0ax3ThS164ydpYHqlvwID5B2Mml69M/Jk=; b=BFTIJAdiHegcg5AUDCu9isfvudyeduC4RoMInlNW7DDBgMEaQSqbtbcPU8vXX/vXvYO7GNcFk1seyHDxymDKROGGTGtXdgfmuBJdzYwgEIVNFUe/BSZhP0J3ZZBgDBvj3l3tHYsZ6yNKS4I1ZWauvJPsNmX0dCryESzdOdGBdKo= 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 1771833893987882.3836604163829; Mon, 23 Feb 2026 00:04:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvh-0002us-NF; Mon, 23 Feb 2026 03:04:33 -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 1vuQvb-0002uG-Bz for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:28 -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 1vuQvZ-0004Ki-7Q for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:27 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833865; x=1803369865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mSJwk8OL8GT7Kwlz7h7yRvXBaRvRP8lpklTQLrCYMRk=; b=D0Zp2KxAvvG/rSAFCDvqGs6XiG7IZds/ZyONn/5Uf3B+V0UeP2W4dZHS /iltuDBWIBlpvPafIALYzStnITGG7WVJ4TutNiKV+cdywX26cBkPA65uT ohLu6xT6yLi5/FIWbNIE07BXJczP7ZbeCEb5XfkRNKBHOi1A35UQ3l9Vo HmBFxbKNhhWEmBa0z+cXejF2M8G2Q9+xrh2fihTQvouQXQdZwexD+Bacc xa5RuvvDJtGuWBiKp2q25roqYLWOpw89w7w9hCJQpIFoaiWKFLcSe+FXv twVFWX21HStSP2fJX4rBZzZI1HwzQ6CQz3omXhBDn4To+gjdVKhosu1bU A==; X-CSE-ConnectionGUID: 42WC6CCFSqCVGwNFiGYdMw== X-CSE-MsgGUID: PadLuqXCTWyuUV2Yq5vGMw== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027099" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027099" X-CSE-ConnectionGUID: 1u165KsnTqm5IPNKHWk2dw== X-CSE-MsgGUID: kE62NodqRoG5aUzKRImlHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079150" 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 v7 01/10] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Mon, 23 Feb 2026 00:00:05 -0800 Message-ID: <20260223080200.468558-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833896651158500 There are cases when a blob resource's backing might get detached and re-attached again such as when the underlying object is getting migrated in the Guest. In these situations, we need to obtain a new dmabuf fd, which can be done by calling virtio_gpu_init_udmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 643e91ca2a..f20111fa57 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -937,6 +937,10 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; } + + if (res->blob_size) { + virtio_gpu_init_udmabuf(res); + } } =20 static void --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833893; cv=none; d=zohomail.com; s=zohoarc; b=aZ5jBFMZqKmdJTn43EqGrSPLYHj30H1kMIdTHX7IvWZMOPuZdDc63U0XUOg+LhXZ8rSH/sEsXv+4ajGPFP9lnwl6a5vkNEBxpVp+UIoQk/sbL+vthCUXdk2x50wnK8auCZIBnH3yTaQahV3cNNr30/o2+EU5ryktk+QMLkz5d6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833893; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IjQw6pPmuOXaZ5QI80xhzU0pxDQLXI1GCHD+y2io5Kg=; b=ijCLqSo3t7s0afeK0oaKoJGcJKfJ6a9soBeVfcbI53jnZL6vdPSkO6wadRs9VJqWTvqOJs3XfkzQAswuLZenUj8i6yEXNMsArtw11zUF2RxMlI6xgFBWhNKE/kvGe+ZmUeWZkiKbvs7wBY3hcr3tRHNNA2MM0hwvkAM/A54Nk9A= 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 17718338938361.8255378304177157; Mon, 23 Feb 2026 00:04:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvk-0002uu-92; Mon, 23 Feb 2026 03:04:36 -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 1vuQve-0002uU-8q for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:30 -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 1vuQvc-0004Ki-Kv for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:30 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833869; x=1803369869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lYWaP1kFmLOPTRi7iW/x1sxii0x816fC62gZjXLi8LA=; b=fN9HKFnXerqLop7GggFWnzYb2exWrM58OeGv1wxZEJJR1kHy1c8t2Kza vu3bFbhrGMiFV68pUwqYtpe9XuDG25gKpYVLuCnpSas2WzxmJI2bXUV2T g2C8jRDvq4bwkG2kKxT+YBvoNKRl2dVSrI32bxfqZ8vFLukv7cfouzYOI nZ49c8ZZGYm3YTioEQi8pcYUtVt+UopU6OtkzJqROJAhoSxqwAfu0Z7T0 v82VRetVLQdY9+HbBsrEFnQMLLXbwPWYI3LspboDEixvHXHCq5xpp+1du zcTc0FicrgVP0wukeH5pECNVS2EwV6e+0bR+kM24QfZEG6FmzyEmVp4s6 w==; X-CSE-ConnectionGUID: /atNZuuISbG+9TdZp+Puug== X-CSE-MsgGUID: jnhGTyb6RteQJgV1Z67csw== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027105" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027105" X-CSE-ConnectionGUID: 0Iobn4XFTKOChafZlFXNgw== X-CSE-MsgGUID: gevaZa8LTu6RvzFfsRY9vQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079155" 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 v7 02/10] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Mon, 23 Feb 2026 00:00:06 -0800 Message-ID: <20260223080200.468558-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833895475158500 If the Guest provides a DMA address that is associated with a ram device (such as a VFIO PCI device region and not its system memory), then we can obtain the hva (host virtual address) by invoking address_space_translate() followed by memory_region_get_ram_ptr(). We cannot use dma_memory_map() because for memory regions that do not support direct access, it would create bounce buffers instead of returning the actual hva, which is not desirable here. And, since VFIO device regions are not considered directly accessible (because they are mostly MMIO based), virtio-gpu cannot invoke dma_memory_map() to obtain the hva in this case. Therefore, in order to handle addresses associated with VFIO devices, we need to use the address_space_translate() API to first identify the right memory region and the appropriate offset within that region and then use memory_region_get_ram_ptr() to get the hva. This approach also works for addresses associated with the system memory region. Note that, although we take an explicit reference on the memory region, we would still rely on dma_memory_unmap() to drop that reference when the dma mapping is eventually unmapped. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f20111fa57..f5c6a7deb9 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -798,6 +798,23 @@ static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } =20 +static void *virtio_gpu_dma_memory_map(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd, + uint64_t a, hwaddr *len) +{ + MemoryRegion *mr; + hwaddr xlat; + + mr =3D address_space_translate(VIRTIO_DEVICE(g)->dma_as, a, &xlat, len, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); + if (memory_region_is_ram(mr)) { + memory_region_ref(mr); + return memory_region_get_ram_ptr(mr) + xlat; + } + return NULL; +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -839,9 +856,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, =20 do { len =3D l; - map =3D dma_memory_map(VIRTIO_DEVICE(g)->dma_as, a, &len, - DMA_DIRECTION_TO_DEVICE, - MEMTXATTRS_UNSPECIFIED); + map =3D virtio_gpu_dma_memory_map(g, cmd, a, &len); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" " element %d\n", __func__, e); --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833909; cv=none; d=zohomail.com; s=zohoarc; b=hybBg6cegDDpEhyOgakrBnnTF1efQep7Cjn1cZB4Pe3ONHqjjyy/6GgNfbx2M5fp8mPp3Wtj11HZ+tUc3Md+CERdGoPmVTece9OoUozBfBDD4sT7Nj1yrRr9JS/pjMeC2vXVdAWIZQD3s0mNwxa6vyReC6nMn6THL60u6MKThDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833909; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CjKc2dfaCZ8RDOAHkh1/HllNQZ5mWbZaYCP1KLlmuws=; b=JqUGADFy429ZSaXa5l1OgE69ZPnapYq2LtOwUUv1ixY3dDcz8pYHb96JO3LRlPjhUEMpMA9RnEUHzlxdAFOTsL3mAMbtUobhVGrx1F9toURxXiZBZFvjAc5gjQC9FxGR+/Y1t6LuoPzIZfDEitI0GoEJlBpZkXjkWZKH0SJiFcc= 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 17718339092951001.5314474572165; Mon, 23 Feb 2026 00:05:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvl-0002wR-O6; Mon, 23 Feb 2026 03:04:37 -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 1vuQvh-0002vB-T0 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:35 -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 1vuQve-0004Ki-Il for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:32 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833870; x=1803369870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WQUubMglOINXkPd3puxed1kwRdXppIaQlkqgg//+It0=; b=exGr5HP7+ah/9T1frnia5ocal/zQMBo0Bp2ZiE5l3OqtTe+S/B2jtZsj htm5Na6Di74MaF/dGQXZMs7szterLtJoZGbz5fqBTrZhAJPZ0SOex3ULA cdsRjPk5S6bYFTogpQRTEZKogzywfp/zJ6g2H/3RJrDHEtew4hz0o49ez Pv0B+6U1nOWSMAvToo1DtyMsHqhDM7GyuaA0RFInXDixIym+PsoSgwkOb AO4bISGbaStvguqlixg+lnWvO0U+6mm+BVVzqxZj1n3KHeZIKI2dERfk4 sERMyYXpQOK1ZjVk8Ep5kDdHxqdjQvnt/aJ2EE7MnQ4dQcNkGaMgyRy6m g==; X-CSE-ConnectionGUID: 57Ix4WyqTB+vgT2Y1OjMnA== X-CSE-MsgGUID: O/XCueF1QtK8Qyxclc6a/A== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027112" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027112" X-CSE-ConnectionGUID: dJNIlkYFQ5yBN3fJ8pwqMg== X-CSE-MsgGUID: odhsw2K1RHKnuszZgN0Wfg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079159" 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 v7 03/10] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Mon, 23 Feb 2026 00:00:07 -0800 Message-ID: <20260223080200.468558-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833910781158500 This is prep-work for adding the ability to create dmabuf fds from VFIO devices in addition to udmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/meson.build | 4 ++-- ...gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs.c} | 4 ++-- .../{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} | 12 ++++++------ hw/display/virtio-gpu.c | 8 ++++---- include/hw/virtio/virtio-gpu.h | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) rename hw/display/{virtio-gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs= .c} (79%) rename hw/display/{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} (94%) diff --git a/hw/display/meson.build b/hw/display/meson.build index 90e6c041bd..f5f92b1068 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -69,9 +69,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), = pixman]) if host_os =3D=3D 'linux' - virtio_gpu_ss.add(files('virtio-gpu-udmabuf.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf.c')) else - virtio_gpu_ss.add(files('virtio-gpu-udmabuf-stubs.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf-stubs.c')) endif virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} diff --git a/hw/display/virtio-gpu-udmabuf-stubs.c b/hw/display/virtio-gpu-= dmabuf-stubs.c similarity index 79% rename from hw/display/virtio-gpu-udmabuf-stubs.c rename to hw/display/virtio-gpu-dmabuf-stubs.c index f692e13510..01067e246d 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-dmabuf-stubs.c @@ -7,12 +7,12 @@ bool virtio_gpu_have_udmabuf(void) return false; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-dmabuf= .c similarity index 94% rename from hw/display/virtio-gpu-udmabuf.c rename to hw/display/virtio-gpu-dmabuf.c index d804f321aa..c34d4c85bc 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -68,7 +68,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) g_free(list); } =20 -static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *re= s) +static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) { res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_fd, 0); @@ -79,7 +79,7 @@ static void virtio_gpu_remap_udmabuf(struct virtio_gpu_si= mple_resource *res) } } =20 -static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res) +static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) { if (res->remapped) { munmap(res->remapped, res->blob_size); @@ -128,7 +128,7 @@ bool virtio_gpu_have_udmabuf(void) return memfd_backend; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { void *pdata =3D NULL; =20 @@ -141,7 +141,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd < 0) { return; } - virtio_gpu_remap_udmabuf(res); + virtio_gpu_remap_dmabuf(res); if (!res->remapped) { return; } @@ -151,10 +151,10 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) res->blob =3D pdata; } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { if (res->remapped) { - virtio_gpu_destroy_udmabuf(res); + virtio_gpu_destroy_dmabuf(res); } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f5c6a7deb9..72c7610664 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -360,7 +360,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, return; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 @@ -917,7 +917,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->addrs =3D NULL; =20 if (res->blob) { - virtio_gpu_fini_udmabuf(res); + virtio_gpu_fini_dmabuf(res); } } =20 @@ -954,7 +954,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, } =20 if (res->blob_size) { - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); } } =20 @@ -1440,7 +1440,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *op= aque, size_t size, return -EINVAL; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); =20 resource_id =3D qemu_get_be32(f); } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 58e0f91fda..e3d351a2d4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -354,10 +354,10 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_= framebuffer *fb, struct virtio_gpu_set_scanout_blob *ss, uint64_t blob_size); =20 -/* virtio-gpu-udmabuf.c */ +/* virtio-gpu-dmabuf.c */ bool virtio_gpu_have_udmabuf(void); -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res); int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833971; cv=none; d=zohomail.com; s=zohoarc; b=Nr2EwZmSav1drXR5frAfpdIq+UTdEVW8D0Y+MqXgSsx/dphAMf5XQ4tBBCRWupsOpEipZmrjlcXt9zwFhs9vsYH3V3+6BTTIo9pdY+vmuj2tw6UctjtknkFXK8XTyh1Mwxe0MGWUgJMgrVTDC3v1/bYUAlu4dtikcv3stmp8MIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833971; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fEylY4HeRrQg4z7pkuEupgOpmZpN1pRXlYvFVufBQPI=; b=QseiC9mCoMa2ZG49lxXgUeeFqD5sf7CdaNvhQTIulluGf1HUvI74Fm0j6+eSEYXx6PwedNrKaJVttTP3RzSsnRno1TkrMaN4FAYbBSNbP31rP85AToNap+oWCFwi5+rs+/SAv0ip5rspJmyxS+gjGHZsNJEylTv4IxKtuFPrekY= 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 1771833971139995.3429640299732; Mon, 23 Feb 2026 00:06:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvm-0002wV-5H; Mon, 23 Feb 2026 03:04:38 -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 1vuQvh-0002vC-T1 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:35 -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 1vuQvf-0004LL-6L for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:32 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833871; x=1803369871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8DjDopZg0XVik4k1ICxjRmt2mb1IxbLdY763BFKsh0Y=; b=JnDXe22qTWajwhkFla1oL5mJRYqM0q1X7ctdbo1H+6RzWazXNEBDyDIK HEhQ6kgj3/rX7bpeXoOYeMiEKuHscRUkSJ0pvB39t5S+Aq+75qwiDj+3f 63x/tpffZ52mMsa8+7YayCmO512U7EEz8JFsMcokAJ/WgBfRxlDGIVrbP HdP7jTxupjzfAD307fO/jk/uOGC2oWxje5BApc+6a0mMOgniHgpDU0aOu 8Tu8/n+eGSjl145CucQT2xQ8SVx6pb/78GCvFHCO/Jffz+PN1rYnG7L2c 456MPaPF5JM2r+8dsr/4L/yTPDJklRyLcdRZKxuKD8VS/gT1gVHKFh4gL g==; X-CSE-ConnectionGUID: 5ZWTkM9qTJush6ep+CRPPQ== X-CSE-MsgGUID: 8Z3EHu9aQ1ao7eh0yiFWiQ== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027119" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027119" X-CSE-ConnectionGUID: 0jUzzY1cQV6YXyjNuVx+YQ== X-CSE-MsgGUID: yWmMaaXZRqSc92C5hnXbYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079162" 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 v7 04/10] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Mon, 23 Feb 2026 00:00:08 -0800 Message-ID: <20260223080200.468558-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833972988158500 There is no need to wrap the call to qemu_ram_block_from_host() with rcu_read_lock/unlock as we already hold a reference to the memory region that owns the ram block. Note that, the reference was obtained via dma_memory_map() while creating the mapping. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index c34d4c85bc..0782bcf3a1 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -43,10 +43,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_resource *res) sizeof(struct udmabuf_create_item) * res->iov_cnt); =20 for (i =3D 0; i < res->iov_cnt; i++) { - rcu_read_lock(); rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); - rcu_read_unlock(); - if (!rb || rb->fd < 0) { g_free(list); return; --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833893; cv=none; d=zohomail.com; s=zohoarc; b=cmVd1ZCWM5T++2+wM+1jTVzoXvbJk/s+Vb9eS+mC/79vNi4eDTqfmW1ZeRlh5z/zegoc5DIbWdFEjQBCLC7A+D69PH5gMLQtZ9KkyjT7Rs4dIWMueYssvRrzoqWu87nN0SZyW9Q57X+CoVmJ7aY4/U5uyq9X6e0CRMlGcSzu+yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833893; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oQxKNqH7uchxjAw73psN2RqSTlA9DAJJrvqv34ryHVs=; b=WodEyQ6Kz4HhciyDwlikrL2/9vnqkWqJ89v7Gg5f0emscjRYe+yqmKKXl2MJtU1Y/FXSbTNAiD55NXSltaQlrFjHwS5HOs+fqA972XEn0etR1UYI3tfpMBWsdoC2dQRdTWFpQQqMaZKvnk8DnhMSK8glgogCxRlMovD7M+jmg9I= 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 1771833893090809.1359541702258; Mon, 23 Feb 2026 00:04:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvl-0002wP-HA; Mon, 23 Feb 2026 03:04:37 -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 1vuQvh-0002vD-Tx for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:36 -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 1vuQvf-0004L5-G5 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:32 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833871; x=1803369871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R+voCt8gQq6Y2SKx4ENrPxTbBWeBaPJn71IunQUW5Lg=; b=eBnmcimXLwU0gWp4fwH2+Uysrrp/hWU7JFzNaDlZkOxBjwdyp+o199Cv VckZwHXOgW7mc5lsRatwej0bCdzErCxFv4/BmOemDlyebvcYhdC8xd9PP ttJi/qR64SDAWojxx/Ep+RZQpS4TuABWIrR8ef74Q/JO5dbkVRgb59pow ZiB2yT+PiHzPgrvSdCES3Ds0CD0AtBmWXeWIqFLkKy8oB7PdUUggdS7MC 0he8QoBYop9h1TAmcGEyIcYbSXaMunNCccb85GCbfdTrpOF+YojuXdUKX Af1WBf/YEVW65v8zv/KbIDlh4yk6NWeqku1tO0r9pfcxuv2p/SHatXq4Z Q==; X-CSE-ConnectionGUID: FNO321T4SruAc7E44F24lg== X-CSE-MsgGUID: UQg5gxGlQqy6UoPynH7J0g== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027125" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027125" X-CSE-ConnectionGUID: FX8AKnfoT3GFwJoUb3gRJg== X-CSE-MsgGUID: 4lc9ounwRUuogFd7JK6biQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079166" 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 v7 05/10] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Mon, 23 Feb 2026 00:00:09 -0800 Message-ID: <20260223080200.468558-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833899822154100 Avoid the manual g_free() calls for the list pointer by using g_autofree in virtio_gpu_create_udmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 0782bcf3a1..8d67ef7c2a 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -29,7 +29,7 @@ =20 static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) { - struct udmabuf_create_list *list; + g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; ram_addr_t offset; int udmabuf, i; @@ -45,7 +45,6 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) for (i =3D 0; i < res->iov_cnt; i++) { rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); if (!rb || rb->fd < 0) { - g_free(list); return; } =20 @@ -62,7 +61,6 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, strerror(errno)); } - g_free(list); } =20 static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833981; cv=none; d=zohomail.com; s=zohoarc; b=N6pVbYSHqOEkbHIA1OiV0Th248tSfVBu38cSNlAOqEkZcKUwWa93b9VtpJlC+C98em6exxoJ0xAAm87k7P554TFwKR2gYIzdDe2gE3BjmffPd289AUv7IF4pVNIPR5HhM5La9dFE1TSJ2dJWVyJSUMC3dz/WTjifNaQYcAL1kQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833981; 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=MEVb3OBiyV4R6fHQ2fSdy2Rq8QGHST0YfvIFvHPTk6I=; b=C0ksWiR+bz+05GnGeUDuplHbAF8SbPxaaMy12EjaGdyk+QxaIG+gVExc3UIrl+bbAo47P+liG000X6qYxKv36Ru1mkiFhPGJRUafHwl5XnKyoiYfuqJFfAhvA7m+ng2aJ05fnsPt824M3N9cgmK6n4GfgJdx/xITxAGYDOdT2P0= 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 1771833981302294.95691385040845; Mon, 23 Feb 2026 00:06:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvm-0002x4-Py; Mon, 23 Feb 2026 03:04:38 -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 1vuQvk-0002vZ-08 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:36 -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 1vuQvi-0004Ki-6o for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:35 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833874; x=1803369874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rEN7gJG69z1iHbkpzNoQlYFgF+PtYJCFEZUSWY1s9U8=; b=ZH1Nr39GwCsXgEr9piKwwUSIly4gNwVpAH9oVBEjnlivZTtSA+Oa9tps dswrivRa7xwEnm+MznQvyNeCOzxQUAJuAFi6kYXvN9YvGka6/iVLEjUGz SLdXbed+R/61Y1+n68Nt5rnd6g9pXDRcQ7CBb21WJh2yp2iqUfgfux32Q 5Ohp8JIKr+B7vwC1tTxVjbywojMJ/J+Vr9RKgl8swidEVRwN1S1lf4gSc 3uk/0hv8z76bIFGccPXvCZ3p96D8Yk2jJAWxQvMKSTO7upDT3wfUNmdHk MbuAHEEP27bNdH5wQlLafPmXbrwYeBeTV+qwOqaSniaKLlylpaPJ8tYBW Q==; X-CSE-ConnectionGUID: w3UiYE+kQ2esYyx/NvZB1g== X-CSE-MsgGUID: r2dLbhTAQSK5LVALz9V6Gg== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027131" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027131" X-CSE-ConnectionGUID: DwWQjd3WQB6tlN0cIrGAJQ== X-CSE-MsgGUID: zLxSUqgHREmwbB/gLMWgUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079170" 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 v7 06/10] virtio-gpu-dmabuf: Improve error handling with 'Error **' and err enum Date: Mon, 23 Feb 2026 00:00:10 -0800 Message-ID: <20260223080200.468558-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833983275154100 Make the error handling more robust in virtio_gpu_init_udmabuf() by introducing 'Error **' parameter to capture errors and an enum to categorize Guest and Host errors. This allows for better error reporting and handling of errors from virtio_gpu_create_udmabuf() and virtio_gpu_remap_dmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 65 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 8d67ef7c2a..fdcf8e53a2 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -27,7 +27,17 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 -static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) +typedef enum VirtIOGPUErrorType { + VIRTIO_GPU_NO_ERROR =3D 0, + /* Guest is responsible for this error */ + VIRTIO_GPU_GUEST_ERROR =3D 1, + /* Host is at fault for this error */ + VIRTIO_GPU_HOST_ERROR =3D 2, +} VirtIOGPUErrorType; + +static VirtIOGPUErrorType +virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *res, int *fd, + Error **errp) { g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; @@ -36,7 +46,8 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) =20 udmabuf =3D udmabuf_fd(); if (udmabuf < 0) { - return; + error_setg(errp, "udmabuf device not available"); + return VIRTIO_GPU_HOST_ERROR; } =20 list =3D g_malloc0(sizeof(struct udmabuf_create_list) + @@ -45,7 +56,8 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) for (i =3D 0; i < res->iov_cnt; i++) { rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); if (!rb || rb->fd < 0) { - return; + error_setg(errp, "Could not find valid ramblock"); + return VIRTIO_GPU_GUEST_ERROR; } =20 list->list[i].memfd =3D rb->fd; @@ -56,22 +68,30 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res) list->count =3D res->iov_cnt; list->flags =3D UDMABUF_FLAGS_CLOEXEC; =20 - res->dmabuf_fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); - if (res->dmabuf_fd < 0) { - warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, - strerror(errno)); + *fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); + if (*fd < 0) { + error_setg_errno(errp, errno, "UDMABUF_CREATE_LIST: ioctl failed"); + if (errno =3D=3D EINVAL || errno =3D=3D EBADFD) { + return VIRTIO_GPU_GUEST_ERROR; + } + return VIRTIO_GPU_HOST_ERROR; } + return VIRTIO_GPU_NO_ERROR; } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, + Error **errp) { - res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, - MAP_SHARED, res->dmabuf_fd, 0); - if (res->remapped =3D=3D MAP_FAILED) { - warn_report("%s: dmabuf mmap failed: %s", __func__, - strerror(errno)); + void *map; + + map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, "dmabuf mmap failed"); res->remapped =3D NULL; + return false; } + res->remapped =3D map; + return true; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -125,19 +145,30 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + Error *local_err =3D NULL; + VirtIOGPUErrorType err; void *pdata =3D NULL; + int fd; =20 res->dmabuf_fd =3D -1; if (res->iov_cnt =3D=3D 1 && res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else { - virtio_gpu_create_udmabuf(res); - if (res->dmabuf_fd < 0) { + err =3D virtio_gpu_create_udmabuf(res, &fd, &local_err); + if (err !=3D VIRTIO_GPU_NO_ERROR) { + error_prepend(&local_err, "Cannot create dmabuf: "); + if (err =3D=3D VIRTIO_GPU_GUEST_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible mem\n"); + } + error_report_err(local_err); return; } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { + + res->dmabuf_fd =3D fd; + if (!virtio_gpu_remap_dmabuf(res, &local_err)) { + error_report_err(local_err); return; } pdata =3D res->remapped; --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833902; cv=none; d=zohomail.com; s=zohoarc; b=ev4hhnlOHsd684e7kbyALVn2Hh8sI/q8ChjO3hASQWxZSUpXDcQAWpe9JmZlRG6SlCsES1QIf5DuMGz35nQjJMMSt7iC8Gso5qQh1lYvfkbD+C4C/KXLDcMiGMDq0yrgoxPiuZjPpsK/v8CIwH1yD2KyvfnROEmxJS75Igu+6Hc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833902; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OvvXna9asyBYuGGCY/V62xry7x8KfmAwpbl4bxe8+oE=; b=D0YBjshSSufa968etOGzDY4cWDgHHMQWH3sDJLJpeHrRz13R8BkxI1la49qVYSwG0BfrW8Pb2RpH8EjLrE0X3YzA9imwUfhJ+Ezl9mF2qeEc7xNuTufJ8CyR4PQhDuvGzFyh+FQpHcVs6d2moGSkZq1e0BR5jWOs5tjMLLN0IBg= 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 1771833902691887.3023238587137; Mon, 23 Feb 2026 00:05:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvq-0002yT-Gw; Mon, 23 Feb 2026 03:04:42 -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 1vuQvj-0002vY-P1 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:36 -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 1vuQvi-0004LL-6A for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:35 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833874; x=1803369874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1TEvr2QnTOUFzPzfTMXk5IYYw/2XkOgNrkkXD+yNNs8=; b=MYLvGiEI2F4ppOTIiM8UC0lfRnRj1WcruiV6Nwo0fnKxWiHsvumis3kH A+2Pp0gD3KzN8x2HAZ6k8f0EMI1AQhi1m3Ufcde8+Ql1NM3T+27BtG3I2 M97hJJCuz1Cugf4xy0a1zMApkWfck7XjJyF3E4v+vHri4Dnhh+w2BCJ5n XjXC8688McLuuNyXYTF6OkwrLKARvRqS6Ue3m0MV8H7TtOkMF7F4LLtrW 3WT+BiK2F6jesqOE70Y5wHk/cyH9K4zxhaQYjcwMBHDWOcZ2y4XjYRgxl SHyIFAF0q/AiDpEmk/z476GQc+UVlhucq1UP2gEIAXk4rR87RpCtaPInj Q==; X-CSE-ConnectionGUID: 3DPbfbk+QWCQamGB3MrZQw== X-CSE-MsgGUID: c1naZWv9Rq2PXQ1VUq4TFA== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027136" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027136" X-CSE-ConnectionGUID: uwn5ezHcQRWeK5tlgOK/MQ== X-CSE-MsgGUID: ddtGgK5aRtuC3EZ07a2oug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079174" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v7 07/10] vfio/region: Add a helper to get region index from memory region Date: Mon, 23 Feb 2026 00:00:11 -0800 Message-ID: <20260223080200.468558-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833904217154100 Having a way to figure out the region index (or bar) associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info needed for mapping a part of a VFIO region or creating a dmabuf. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/region.c | 14 ++++++++++++++ include/hw/vfio/vfio-device.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 47fdc2df34..4cb92216ef 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -539,3 +539,17 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +int vfio_get_region_index_from_mr(MemoryRegion *mr) +{ + VFIORegion *region; + + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + region =3D mr->opaque; + return region->nr; + } + mr =3D mr->container; + } + return -1; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..596c7f5a10 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -308,6 +308,16 @@ bool vfio_device_has_region_cap(VFIODevice *vbasedev, = int region, uint16_t cap_t =20 int vfio_device_get_irq_info(VFIODevice *vbasedev, int index, struct vfio_irq_info *info); + +/** + * Return the region index associated with a given MemoryRegion. The index + * can be useful in retrieving region info. + * + * @mr: MemoryRegion to use + * + * Returns the region index or -1 on error. + */ +int vfio_get_region_index_from_mr(MemoryRegion *mr); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833994; cv=none; d=zohomail.com; s=zohoarc; b=g2SFlduJN30ApMRPB8nPH6ndqyK108qD7b/rPsC28EWjwAdcfaSfqCZ8S1rxgX9xIHBeRgb+gyGTVcfEysMDhxRtHvhHzHcPMlE8uNwBVo5EK2pyuJGLwD/PxUuA8Ew5PInNIv2FssGE559c2dtQrr5GJy3fDwEXnV9y/Hivuko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833994; 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=UA/hMbeB1WKwr/epJDNumFkzwNkAUeH/FolFZ2FsmAs=; b=KA/0dJuWts2h1pb73H6koL3MfXoiTSOKoSsdkGdBhspEAWGtdMGIcu+73wlxu9SsQLZLv5GJk9RI0evYcCLP/DqbenPi3ECk36vISNYfvGBSfLEmrrUQ5MW6sfHWGIJ2pYD7tr39C57wLrUIWGnxHYAko/WFgN2Af+W6vZkjpUQ= 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 1771833994341333.01035221173026; Mon, 23 Feb 2026 00:06:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvn-0002xE-Hd; Mon, 23 Feb 2026 03:04:39 -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 1vuQvl-0002wI-4Y for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:37 -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 1vuQvi-0004L5-85 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:36 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833874; x=1803369874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i+yz3W/13lozOSckUkgC09yg5zul8aQqUpaDK64jrDo=; b=cdVFGYqN80JZT0ktvHGgeOk3vvpAmOtR5u+bFTqgt1Th7mwnhVzxc4Mi tXazM78a6nzLjlHKkmuM9KDUbB79vjdKGDDM2AJVw4BtOu98y7fHvHnc/ mZfrShMEs/uHvS+MfnFNMir6O9+Zbx0mmuVYDc9mAyMaUzdAidjn1Hvv4 OmzzcZ90Q7ErJK1ZsN8Vdjp4Fv0iw4AO/9xKx7uqHTnQUvtNO4N6T454o 8nP+/Ab+cJlAvtkcOJSo5koMV4VQ685HTayTQRxoXAL1IFVXKE0L/cHQm T9Ki+JYvty1jl94G0dPZg+v9egLohjfIW22sZexgqLNDiDbj6x306agsX g==; X-CSE-ConnectionGUID: zXOKl5qKQ22GEViwos0lCg== X-CSE-MsgGUID: g4qasrZuRv+3uhoWXn1hng== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027140" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027140" X-CSE-ConnectionGUID: eK8cS/jVTHm9DaQ2VK6asg== X-CSE-MsgGUID: dSw6/VWqRKmG6z9e1pzwbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079178" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v7 08/10] vfio/device: Add support for creating dmabuf from multiple ranges Date: Mon, 23 Feb 2026 00:00:12 -0800 Message-ID: <20260223080200.468558-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833997514158500 In order to create a dmabuf associated with a buffer that spans multiple ranges, we first need to identify the VFIO region and index the buffer (represented by iovec) belongs to and then translate its addresses to offsets within that region. The qemu_ram_block_from_host() API gives us both the region and the offset info we need to populate the dma ranges so that we can invoke the VFIO_DEVICE_FEATURE_DMA_BUF feature to create the dmabuf. Also, instead of iterating over all QOM devices to find the VFIODevice associated with a memory region, introduce a helper to just use the vfio_device_list to lookup the VFIODevice. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 81 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 14 ++++++ 2 files changed, 95 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..a7603600f3 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include =20 +#include "system/ramblock.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" #include "hw/core/iommu.h" @@ -644,3 +645,83 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { .region_read =3D vfio_device_io_region_read, .region_write =3D vfio_device_io_region_write, }; + +static bool vfio_device_lookup(struct iovec *iov, VFIODevice **vbasedevp, + Error **errp) +{ + VFIODevice *vbasedev; + RAMBlock *first_rb; + ram_addr_t offset; + + first_rb =3D qemu_ram_block_from_host(iov[0].iov_base, false, &offset); + if (!first_rb) { + error_setg(errp, "Could not find first ramblock\n"); + return false; + } + + QLIST_FOREACH(vbasedev, &vfio_device_list, next) { + if (vbasedev->dev =3D=3D first_rb->mr->dev) { + *vbasedevp =3D vbasedev; + return true; + } + } + error_setg(errp, "No VFIO device found to create dmabuf from\n"); + return false; +} + +bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, + int *fd, Error **errp) +{ + g_autofree struct vfio_device_feature *feature =3D NULL; + struct vfio_device_feature_dma_buf *dma_buf; + RAMBlock *rb, *first_rb; + VFIODevice *vbasedev; + ram_addr_t offset; + int i, index; + size_t argsz; + + argsz =3D sizeof(*feature) + sizeof (*dma_buf) + + sizeof(struct vfio_region_dma_range) * iov_cnt; + feature =3D g_malloc0(argsz); + *feature =3D (struct vfio_device_feature) { + .argsz =3D argsz, + .flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF, + }; + dma_buf =3D (struct vfio_device_feature_dma_buf *)feature->data; + + if (!vfio_device_lookup(iov, &vbasedev, errp)) { + return false; + } + + for (i =3D 0; i < iov_cnt; i++) { + rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (i =3D=3D 0) { + first_rb =3D rb; + } + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Cannot create dmabuf with different regions\= n"); + return false; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + error_setg(errp, "Cannot find region index for dmabuf segment\= n"); + return false; + } + + dma_buf->region_index =3D index; + dma_buf->dma_ranges[i].offset =3D offset; + dma_buf->dma_ranges[i].length =3D iov[i].iov_len; + } + + dma_buf->nr_ranges =3D iov_cnt; + dma_buf->open_flags =3D O_RDONLY | O_CLOEXEC; + + *fd =3D vfio_device_get_feature(vbasedev, feature); + if (*fd < 0) { + error_setg_errno(errp, -(*fd), + "Could not create dmabuf fd via VFIO device"); + return false; + } + return true; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 596c7f5a10..003bac10b5 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -318,6 +318,20 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int= index, * Returns the region index or -1 on error. */ int vfio_get_region_index_from_mr(MemoryRegion *mr); + +/** + * Create a dmabuf fd by first translating the addresses in the + * iovec array into VFIO region offsets and then invoking the + * VFIO_DEVICE_FEATURE_DMA_BUF feature. + * + * @iov: array of iovec entries associated with a buffer + * @iov_cnt: number of entries in the iovec array + * @fd: pointer to store the resulting dmabuf fd + * + * Returns true on success and false in case of an error. + */ +bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, + int *fd, Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833914; cv=none; d=zohomail.com; s=zohoarc; b=QzhvarSndkh9KrvnhXVBShcR0vRBpeDBwXJukTsmPvb7zYJUKy3OTYQBAxW905ldSaSj4yAUgjg3YFRb6Oj/+THyb81Io9GQFhiTROU2+miP7+O7YvWqBqTsi5ZL5i90WSPNPrGjMHgDgZTBG4Wi1IbTGHHfNkJ6S6cnuJ0jQ3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833914; 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=Z1BjfAvFt2ushCzYURyH0xv+WQen4C21NOVDbKo7Aqs=; b=dM4WLsZbw1TdjpooYSBkVBG44NYAdg07UV36cmIwuQJa9beydG5KQfKd5tNSW3xdXlh13uufdBGWrUtaasefZejsNly/2AiRngca3zqi1Uj3QsFUt7HhCLWRiWVIpGlyx2IJWeve6a2Avg9DwaJzn7Sh/Yf+9KPK8m1Niqfhws8= 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 1771833914648815.9732845328252; Mon, 23 Feb 2026 00:05:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQvq-0002yU-Gi; Mon, 23 Feb 2026 03:04:42 -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 1vuQvm-0002wW-3x for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:38 -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 1vuQvk-0004LL-2E for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:37 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833876; x=1803369876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XdlPD2vAgZVn2p+n24qNT4tgujGy6mtlK5gYgH0LlWI=; b=gBuXzaxSjIapnXu1EZijmuMKBtW5VaE/EN7z3OpturdiLa4ETOR19lbZ 8cRM6uvGrGbX0b8NTaImLmtkGmiVpBZs4lTH57pBRWmupUTkWqUuepMaO WWVUYC/xRskSmVyi2zr30dqk/CWi/UF5ldoGFI58ul9oGn01KG/N6SdjC UDMUvRs+XGe2c4AxZCiHgaTsE/PQPGX0OboXuIZNvRK7hJCymnJnd0t9A 1nKwWRAoEGR0PhK+SjLeArzlQIlQaCi6bZYKgMnktcvZ43bp3GX3naebr eZZk8SRgfryJj1pLHza9vMLR9XPcgun16mpCIE0kWnB40Fm7x4+gW0PA/ Q==; X-CSE-ConnectionGUID: t2HzdaSnR4q+fhhqUDFbZw== X-CSE-MsgGUID: zEShHBUSTa6MZVQ5iwN9zg== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027144" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027144" X-CSE-ConnectionGUID: GWXIX8gOQdqkEqNAw5oUPw== X-CSE-MsgGUID: ECqZnjAaSd+iB4vADWscpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079183" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v7 09/10] vfio/device: Add a helper to mmap a dmabuf Date: Mon, 23 Feb 2026 00:00:13 -0800 Message-ID: <20260223080200.468558-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833916294154100 In order to mmap a dmabuf, we first need to create a placeholder mapping that would fit the entire size of the dmabuf. This mapping would then be replaced with smaller mappings of individual dmabuf segments. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 65 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 16 +++++++++ 2 files changed, 81 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index a7603600f3..91c9fa9eb1 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -725,3 +725,68 @@ bool vfio_device_create_dmabuf(struct iovec *iov, unsi= gned int iov_cnt, } return true; } + +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp) +{ + struct vfio_region_info *info =3D NULL; + VFIODevice *vbasedev =3D NULL; + ram_addr_t offset, len =3D 0; + RAMBlock *first_rb, *rb; + void *map, *submap; + int i, index; + + if (!vfio_device_lookup(iov, &vbasedev, errp)) { + return false; + } + + /* + * We first reserve a contiguous chunk of address space for the entire + * dmabuf, then replace it with smaller mappings that correspond to the + * individual segments of the dmabuf. + */ + map =3D mmap(NULL, total_size, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, = -1, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, "Could not reserve placeholder mappi= ng"); + return false; + } + + for (i =3D 0; i < iov_cnt; i++) { + rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (i =3D=3D 0) { + first_rb =3D rb; + } + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Cannot mmap dmabuf with different regions\n"= ); + goto err; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + error_setg(errp, "Cannot find region index for dmabuf segment\= n"); + goto err; + } + + if (vfio_device_get_region_info(vbasedev, index, &info)) { + error_setg(errp, "Cannot find region info for dmabuf segment\n= "); + goto err; + } + + submap =3D mmap(map + len, iov[i].iov_len, PROT_READ, + MAP_SHARED | MAP_FIXED, vbasedev->fd, + info->offset + offset); + if (submap =3D=3D MAP_FAILED) { + error_setg(errp, "Could not mmap dmabuf segment\n"); + goto err; + } + + len +=3D iov[i].iov_len; + } + *addr =3D map; + return true; +err: + munmap(map, total_size); + error_prepend(errp, "VFIO dmabuf mmap failed: "); + return false; +} + diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 003bac10b5..b8e0801b94 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -332,6 +332,22 @@ int vfio_get_region_index_from_mr(MemoryRegion *mr); */ bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, int *fd, Error **errp); + +/** + * Mmap a dmabuf by first translating the addresses in the iovec + * array into VFIO region offsets and then creating a placeholder + * mapping that would be replaced later with mappings that + * correspond to the dmabuf segments. + * + * @iov: array of iovec entries associated with the dmabuf + * @iov_cnt: number of entries in the iovec array + * @addr: pointer to store the resulting mmap address + * @total_size: total size of the dmabuf + * + * Returns true on success and false in case of an error. + */ +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.53.0 From nobody Sun Apr 12 00:55:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1771833919; cv=none; d=zohomail.com; s=zohoarc; b=l+aq3kctQabHMfvzBm42jMADUuKbi1baObDLiURMVohfwLvF5GFbwuCwsRpy5wWpMc/v1lf7Iwga7T+rvy49cQOXUOGbi46Gou1shDsyvtyb49K0Qs/9zm/A5vwKbvsw9P4PkQEdQR7wfTv312RkJOzMim6C9XDrGsIKVZM+Nxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771833919; 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=7b+xcsjOmcvTYtIMxDmkchHohhh7QGHErih14OjyCH8=; b=QVHh0EqT8xwMXYA1tvmwuus+sR7177ewmEox5TAP0Uh5FFV8Kh/8xPopIwyMNPn4gt7jh9O910jJQgtg9OPYhwoyXWeOCEj52H2xBpH9dQfhglIc8IUbW5M7EJzLE98krlm4J3ge7fMxanNkg5u8TEn+x4dUr/h+OEAtKaUrvg8= 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 1771833919563277.2293729686521; Mon, 23 Feb 2026 00:05:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuQw9-000349-8Y; Mon, 23 Feb 2026 03:05:01 -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 1vuQvw-0002z8-L3 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:49 -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 1vuQvu-0004Ki-9f for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:04:48 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2026 00:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771833886; x=1803369886; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zk6C2IUz7ZHX3FMtWcsagAH5rq1uf/P/063Si/p1gHc=; b=WQpD0FVW1+UJblJNDjaJWeF5ySPqpetWEaxkOt2TUbnTjtq+4xP5r+D1 RyFHjCbfMYLD8G5sVZ2XLg6s8XmCDNh1DAhbdu/SrzNNMr4fKkK7/oopY p3wjKfXIp2Q8k2nF+Fv45uB7jvrpmyUz8nIPomjr7a6rGowh2b8GhW3Wc ttJRQ+oBuHI2USmP/UaArLoE7BZefiTjdF3iiCwFxQnI6dhxlKE+f9MrF zDALNvgjLoC/iDUU885r75Hgd9Og+Z5jcacN5uOlZgXpHhH0kypWdj2R3 94T36cPxO1YJHiCAx8vu0qRcdXT+/aNuQDKAldoPvLBXmFfzzmYoXP4eW A==; X-CSE-ConnectionGUID: 42ZDeAX7Rw+jDrmF0pw/AQ== X-CSE-MsgGUID: n4gx5CQuTIu6adU3VfMgfg== X-IronPort-AV: E=McAfee;i="6800,10657,11709"; a="72027147" X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="72027147" X-CSE-ConnectionGUID: uGtcMhhyTwKvkcGDH2ZeDQ== X-CSE-MsgGUID: tTpSS3ZhRCmbqq5+cJOE9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,306,1763452800"; d="scan'208";a="246079187" 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 v7 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Mon, 23 Feb 2026 00:00:14 -0800 Message-ID: <20260223080200.468558-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223080200.468558-1-vivek.kasireddy@intel.com> References: <20260223080200.468558-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, 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: 1771833922661154100 In addition to memfd, a blob resource can also have its backing storage in a VFIO device region. Since, there is no effective way to determine where the backing storage is located, we first try to create a dmabuf assuming it is in memfd. If that fails, we try to create a dmabuf assuming it is in VFIO device region. So, we first call virtio_gpu_create_udmabuf() to check if the blob's backing storage is located in a memfd or not. If it is not, we invoke the vfio_device_create_dmabuf() API which identifies the right VFIO device and eventually creates a dmabuf fd. Note that in virtio_gpu_remap_dmabuf(), we first try to test if the VFIO dmabuf exporter supports mmap or not. If it doesn't, we fall back to the vfio_device_mmap_dmabuf() API to get a mapping created for the dmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/meson.build | 1 + hw/display/vfio-dmabuf-stubs.c | 23 +++++++++++++++++++++++ hw/display/virtio-gpu-dmabuf.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 hw/display/vfio-dmabuf-stubs.c diff --git a/hw/display/meson.build b/hw/display/meson.build index f5f92b1068..7d2bd839cc 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -70,6 +70,7 @@ if config_all_devices.has_key('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-dmabuf.c')) + virtio_gpu_ss.add(when: 'CONFIG_VFIO', if_false: files('vfio-dmabuf-st= ubs.c')) else virtio_gpu_ss.add(files('virtio-gpu-dmabuf-stubs.c')) endif diff --git a/hw/display/vfio-dmabuf-stubs.c b/hw/display/vfio-dmabuf-stubs.c new file mode 100644 index 0000000000..12f016f0c5 --- /dev/null +++ b/hw/display/vfio-dmabuf-stubs.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2026 Intel and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/iov.h" + +bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, + int *fd, Error **errp) +{ + error_setg(errp, "VFIO dmabuf support is not enabled"); + return false; +} + +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp) +{ + error_setg(errp, "VFIO mmap dmabuf support is not enabled"); + return false; +} diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index fdcf8e53a2..3f39371de1 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" @@ -82,13 +83,21 @@ virtio_gpu_create_udmabuf(struct virtio_gpu_simple_reso= urce *res, int *fd, static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, Error **errp) { + Error *mmap_err =3D NULL; void *map; =20 map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); if (map =3D=3D MAP_FAILED) { - error_setg_errno(errp, errno, "dmabuf mmap failed"); + error_setg_errno(&mmap_err, errno, "dmabuf mmap failed: "); res->remapped =3D NULL; - return false; + + if (!vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &map, + res->blob_size, errp)) { + error_report_err(mmap_err); + return false; + } + error_free(mmap_err); + mmap_err =3D NULL; } res->remapped =3D map; return true; @@ -145,7 +154,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { - Error *local_err =3D NULL; + Error *local_err =3D NULL, *vfio_err =3D NULL; VirtIOGPUErrorType err; void *pdata =3D NULL; int fd; @@ -158,12 +167,19 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) err =3D virtio_gpu_create_udmabuf(res, &fd, &local_err); if (err !=3D VIRTIO_GPU_NO_ERROR) { error_prepend(&local_err, "Cannot create dmabuf: "); - if (err =3D=3D VIRTIO_GPU_GUEST_ERROR) { - qemu_log_mask(LOG_GUEST_ERROR, - "Cannot create dmabuf: incompatible mem\n"); + + if (!vfio_device_create_dmabuf(res->iov, res->iov_cnt, &fd, + &vfio_err)) { + if (err =3D=3D VIRTIO_GPU_GUEST_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible mem\= n"); + } + error_report_err(local_err); + error_report_err(vfio_err); + return; } - error_report_err(local_err); - return; + error_free(local_err); + local_err =3D NULL; } =20 res->dmabuf_fd =3D fd; --=20 2.53.0