From nobody Tue Feb 10 20:48:27 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=1770706949; cv=none; d=zohomail.com; s=zohoarc; b=CddVLijwDQuicFMPlcKZH48GSMw+4cjND1CDvJZA9gctA54G38N0KTRFGW+ukhG7DOLD0ciICsSpLYU3tXo3IEAqv5JiOyIdGcLatxWGB/i3F8qDHnKi+KxD7Hl5g2C7ef8bu5qWolkYnaZbnw7W7FrWpeQJVVCL/mVWGa7a2yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706949; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ft3LEhxsum4S5FvdDqC/n3QOiPW/l+92MGg1UY+nv8o=; b=HrQyIOjez5mienxtDb/7+VxwV6I7pRZMj4linhKnAJKSTursH3nXbQH3wgzMtOFmKi6bJsPkh4tPlFc/v8pMN2pPE3G1/Uiz9ka5Tz4AqZJmzQVoWfojZF9P6yfLYBnaIAOwKsh6K5k+BzwuEo9sOvtNLKajDWTQvvt4PohcvGM= 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 1770706949453878.8614940465488; Mon, 9 Feb 2026 23:02:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlN-0004wz-1Q; Tue, 10 Feb 2026 02:02:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlL-0004wb-R4 for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:19 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlJ-0004oY-Oa for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:19 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706938; x=1802242938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BU+2P8UJQiCNZ6B+Dn1fq51GInHfsJ6cD01Wea2i1DY=; b=WqG9XwN1CKWi7qg8oweP+DiJPJWhrwg2DTwkLejTy2tpW6W36Bd/Bo9P Hm87cnci+jT7h8bkycZsPnyfOWxg0+jal0DwPG/OxfrnEvMDNRsBKfSOo YbRSXSRLIa7AeBBTb0bwCIj+hnmvOWAPkcLk8BIC0Pq9aq4WmEk4kchK0 4kb0x+96hSmKEO5C+euHLzAriFjzyOw4H6JPYOn/770bvW82+c+XC5Gjp Myml8rerFF9Cew5M61DPJXn7LxrUAMJyRQTnYHbHKfcge5HHe/cQZdH41 V8AICAAJRgsxv0hUW3XuScbEa2q7eQwpt1A2VddhPd0gRN4l09vey/Ru1 A==; X-CSE-ConnectionGUID: 50DCcgjqRk6ZEL9ptO7aZQ== X-CSE-MsgGUID: FGbDY1rSTvuVQpc3AgbMBg== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012138" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012138" X-CSE-ConnectionGUID: DsnPPYCRTIemF9e+t/ZsKQ== X-CSE-MsgGUID: tmzpdZanTBeHW2gOWwaqvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920532" 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 v6 01/11] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Date: Mon, 9 Feb 2026 22:59:41 -0800 Message-ID: <20260210070155.1176081-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706953652154100 There are cases when a blob resource's backing might get detached and re-attached again such as when the underlying object is getting migrated in the Guest. In these situations, we need to obtain a new dmabuf fd, which can be done by calling virtio_gpu_init_udmabuf(). Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f23eec6862..3d58cebf4b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -937,6 +937,10 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; } + + if (res->blob_size) { + virtio_gpu_init_udmabuf(res); + } } =20 static void --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770706958; cv=none; d=zohomail.com; s=zohoarc; b=eBZEwjy3SN6q/rnBkudM0esnqh8dqm69YhX7mlGiVNGGI1HKPYLhUJPJPpPHp4LVD7m4yQs5Rwicgm1vDcyLrimmpkBgmSGEk58fwGIDYtkroPpFCim399Too8ldgxVQsfEOwn9qa66FKQVXajAdbdMg/4As5v7UWnM+yXmwxpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706958; 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=7yQ3e7zbIclG9GtCCaLKlQLKwzuggCMzhi1T8dEkSQI=; b=Gql9JUnbvHMBxhIBBuIedvyOpeKMMzZFqZJomdsO0IdQ47l4gcVEJZMizJfd/DWi8Dr8kXB9v9RhrRk3oSlLU2vYGJbcWKs0UCw5m47d06LKfFRBjE/LtTtRpgonibfJiylkS9+Le8gZSu56MMSeHYYcaxBKP31nft1XmB6vHAo= 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 1770706958438625.2599133476533; Mon, 9 Feb 2026 23:02:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlP-0004xS-2f; Tue, 10 Feb 2026 02:02:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlN-0004x3-9O for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:21 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlL-0004oR-FG for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:20 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706939; x=1802242939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LuogRKHYhpk4yupWQQQxsAZlWl2tsNvD1m+TD2cKQWc=; b=I1SAq4Z3mNHswU3kRd93HTfEAl6TsGLmWn9xeFjxmLY3sW4AuEbGNh9Q 8hD4c1dibIiVzhGY8H85m4PEAR5PcNUYerE9nUh1/kCpA7PgrEcwkKdxn jJRXLX7Qk+GXfJraRk/OQlYbapv9fRTFp9MZ1Lp4DoTyyCC4K73ww+B2x XH++uQjmiWVB4qHnqVikm2+/GD5fDpcJnHjhQK5TvsQpaS5OwcRgAOvPr yHJwH0VGU//C7/HcD0Qs3HbuJSM2qt4u4QOPdGGqB0lq3mswQePUJpV+J ACxvELd2D7ZBrks5RpmleQ1Oak9R3Vf/ejDADMbz/BZhWVcIv+/qcDHHe w==; X-CSE-ConnectionGUID: z+BjVQmVTRSMivII3NkmXw== X-CSE-MsgGUID: 6+Oi12JmTe+s8kqMfW7RTg== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012144" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012144" X-CSE-ConnectionGUID: xu5jCr7JRhqIK2q9UfTDrg== X-CSE-MsgGUID: KSreCBpMTtu5L1s3NFTcKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920535" 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 v6 02/11] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Date: Mon, 9 Feb 2026 22:59:42 -0800 Message-ID: <20260210070155.1176081-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706961568154100 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 3d58cebf4b..9930a21317 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -798,6 +798,23 @@ static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } =20 +static void *virtio_gpu_dma_memory_map(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd, + uint64_t a, hwaddr *len) +{ + MemoryRegion *mr; + hwaddr xlat; + + mr =3D address_space_translate(VIRTIO_DEVICE(g)->dma_as, a, &xlat, len, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); + if (memory_region_is_ram(mr)) { + memory_region_ref(mr); + return memory_region_get_ram_ptr(mr) + xlat; + } + return NULL; +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -839,9 +856,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, =20 do { len =3D l; - map =3D dma_memory_map(VIRTIO_DEVICE(g)->dma_as, a, &len, - DMA_DIRECTION_TO_DEVICE, - MEMTXATTRS_UNSPECIFIED); + map =3D virtio_gpu_dma_memory_map(g, cmd, a, &len); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" " element %d\n", __func__, e); --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770707037; cv=none; d=zohomail.com; s=zohoarc; b=lakFmmIrECwToWjo07AGBpxt57qciu9uneJ8/32SjEGowuGIGftp5eTp+oiPgwoTehBRh6PF0+0XhmQepcBUL1kY2OCqn6gMAN1iTd6+wXZWjkwTmEBuX/+0a5gyXdBmU5k3OjZL5Mk8EwlS75kIiunDJmlSxtxxxw3EJBd7rvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770707037; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Dw3l7wW5mpAxRjpvkoxbh0eaH5GEW1qSbBHDZpfjCCA=; b=XUc7OviE3v56G4s16mcU5PrW7OseFkjDuGaIic/cTWWCOR2Ik37vZYj/hTo83eFydr0Iv8LWkZstPRmRRk6J2BNKJEKbof5ll7/GdaOq7XlL+gtWHGDQ+VDfvMWqZUMtPCtCYfx3n2uMhGB2sI2ErdU+cwWV1jnGbRKZ+1Crx20= 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 17707070374971020.5720577266992; Mon, 9 Feb 2026 23:03:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlT-0004zk-MY; Tue, 10 Feb 2026 02:02:27 -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 1vphlO-0004xW-Mx for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:23 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlM-0004p7-EP for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:22 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706940; x=1802242940; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ztabUCwYVEnXrUXpODUpIX/j6IsbTnuLW3gEfsQfQNk=; b=Y3mykoQ8x85BGbt4Ef9q30T3aqcc40hpezG9CZy2tEyH8o7Gp0ODXHjT p6QxZpScfIVsQVAgG+vQyN1LRHM9dWvEMuIgn+YhQhm0xeXms6Rz7JNGl QrlECosFxNLzpjGUsnQir4FdDHrgEcw5U/pdTVQkI3BJOpSO+x9Rfg0X2 VbDLOZfwqY3iNlkmN8ppHL8lN5aSgUSqgpDs8XxmCUyck17XtE3v9nTDF d37DOZWGZdG3QZfSHDQppSkqERmjBoPakF1tuway6Ry783wNSuvDTlKUg zxON0B8SWTUL9O+ORLd8WUQHsxTUogptL3DokSKHY4KVfreBoV3mLfbon w==; X-CSE-ConnectionGUID: QiC7RoCoSOqoGrqOL4OkFQ== X-CSE-MsgGUID: rINlG4pKQkqcgdilDshKow== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012150" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012150" X-CSE-ConnectionGUID: DJBiikBhTwWSj4fOc7gyUw== X-CSE-MsgGUID: grm4R24qQsOSjaw6Qe5oWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920538" 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 v6 03/11] virtio-gpu: Rename udmabuf files and helpers to dmabuf Date: Mon, 9 Feb 2026 22:59:43 -0800 Message-ID: <20260210070155.1176081-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770707038720158500 This is prep-work for adding the ability to create dmabuf fds from VFIO devices in addition to udmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: Akihiko Odaki Signed-off-by: Vivek Kasireddy --- hw/display/meson.build | 4 ++-- ...gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs.c} | 4 ++-- .../{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} | 12 ++++++------ hw/display/virtio-gpu.c | 8 ++++---- include/hw/virtio/virtio-gpu.h | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) rename hw/display/{virtio-gpu-udmabuf-stubs.c =3D> virtio-gpu-dmabuf-stubs= .c} (79%) rename hw/display/{virtio-gpu-udmabuf.c =3D> virtio-gpu-dmabuf.c} (94%) diff --git a/hw/display/meson.build b/hw/display/meson.build index 90e6c041bd..f5f92b1068 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -69,9 +69,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), = pixman]) if host_os =3D=3D 'linux' - virtio_gpu_ss.add(files('virtio-gpu-udmabuf.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf.c')) else - virtio_gpu_ss.add(files('virtio-gpu-udmabuf-stubs.c')) + virtio_gpu_ss.add(files('virtio-gpu-dmabuf-stubs.c')) endif virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} diff --git a/hw/display/virtio-gpu-udmabuf-stubs.c b/hw/display/virtio-gpu-= dmabuf-stubs.c similarity index 79% rename from hw/display/virtio-gpu-udmabuf-stubs.c rename to hw/display/virtio-gpu-dmabuf-stubs.c index f692e13510..01067e246d 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-dmabuf-stubs.c @@ -7,12 +7,12 @@ bool virtio_gpu_have_udmabuf(void) return false; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-dmabuf= .c similarity index 94% rename from hw/display/virtio-gpu-udmabuf.c rename to hw/display/virtio-gpu-dmabuf.c index d804f321aa..c34d4c85bc 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -68,7 +68,7 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) g_free(list); } =20 -static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *re= s) +static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) { res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_fd, 0); @@ -79,7 +79,7 @@ static void virtio_gpu_remap_udmabuf(struct virtio_gpu_si= mple_resource *res) } } =20 -static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res) +static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) { if (res->remapped) { munmap(res->remapped, res->blob_size); @@ -128,7 +128,7 @@ bool virtio_gpu_have_udmabuf(void) return memfd_backend; } =20 -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { void *pdata =3D NULL; =20 @@ -141,7 +141,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd < 0) { return; } - virtio_gpu_remap_udmabuf(res); + virtio_gpu_remap_dmabuf(res); if (!res->remapped) { return; } @@ -151,10 +151,10 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) res->blob =3D pdata; } =20 -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res) { if (res->remapped) { - virtio_gpu_destroy_udmabuf(res); + virtio_gpu_destroy_dmabuf(res); } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 9930a21317..bc4d33c4dc 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -360,7 +360,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, return; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 @@ -917,7 +917,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->addrs =3D NULL; =20 if (res->blob) { - virtio_gpu_fini_udmabuf(res); + virtio_gpu_fini_dmabuf(res); } } =20 @@ -954,7 +954,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, } =20 if (res->blob_size) { - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); } } =20 @@ -1440,7 +1440,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *op= aque, size_t size, return -EINVAL; } =20 - virtio_gpu_init_udmabuf(res); + virtio_gpu_init_dmabuf(res); =20 resource_id =3D qemu_get_be32(f); } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 58e0f91fda..e3d351a2d4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -354,10 +354,10 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_= framebuffer *fb, struct virtio_gpu_set_scanout_blob *ss, uint64_t blob_size); =20 -/* virtio-gpu-udmabuf.c */ +/* virtio-gpu-dmabuf.c */ bool virtio_gpu_have_udmabuf(void); -void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_dmabuf(struct virtio_gpu_simple_resource *res); int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770707006; cv=none; d=zohomail.com; s=zohoarc; b=ELjbRrziXVV3ZXv3bpHiI20cioF6++AjPgeLwcPOr7MTFk4G0/ZyjSpLXo1aFgORB+GPQDbF8pG7Jw9cZVV3fODzH4J9I8aB0uCTRNdgVeXJZZiTlAUOP+3nBU6iPrIZaH+93/0sfgFYzbBw0ZYbVrbGtSTqNUImMz+b3oxlqiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770707006; 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=UPl1Gj3iQrLQ+fe5a29ChtZpxhYfPG4mXCuPetu2vUs=; b=AUhl2jY5CQkPMHzzbtcoPSuvzxtKlDWoqTI+no6+7U4CCou/MyQ9WvBPkSoFM4fLw3sc3oFIv+cqUXJTvyvg2tZXLrNgUnb3qI7I9it0F5S6Fph/tHJRxC/F7WjT73njQeaNIQZNv2RZIwFKh7LMNYNeI17Eli1njI/gfoZFthU= 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 1770707006572409.91509560901216; Mon, 9 Feb 2026 23:03:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlQ-0004yE-Vb; Tue, 10 Feb 2026 02:02:24 -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 1vphlO-0004xT-98 for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:23 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlM-0004oY-CN for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:22 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706940; x=1802242940; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w/ldTTlumdmbb4uxQ7QvbLEY2tzOLXwNf75ZcOgzuno=; b=gBApb+TgECAFVN7dImw0uDosFg6FWgQlt8/tG58Q4AM908H+d8LAWgXy feJEwSvBEERSTT6gvpgWE1tSp+0asYEUkgse1ZgxGFYGyO/DPt+ZU6dBL dUWDurWySoWcYmaXnMSPwLC/5kiIFNif9f+Qd75Le2F7LYPcoHCIcCCZL JeU+lfX0FpqyqKEHU1ypk8+vUn4IX3ICzOiHtOxVboXF+PXqnl8lNzAy5 IjKv3JQGB6XQ/WIGNrcBnt0f2BbaFGD4Z0yFRC/tk+JlUSHb/p+6fY7Dx OjGXKfZBQFCB2CJXnfPtBuvfF8z/DHHfvh80LCkZFoxlJ6CO/mRvyUaoV w==; X-CSE-ConnectionGUID: 9VhaUsYhRl2SF1E2QUH5yw== X-CSE-MsgGUID: X9H20DWLSYWC/Su1YniBIA== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012156" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012156" X-CSE-ConnectionGUID: M91UMJxMSL+iQ6NuZ0tumg== X-CSE-MsgGUID: GrXvcaNuQM+UYtL8ntiNLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920541" 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 v6 04/11] virtio-gpu-dmabuf: Remove rcu_read_lock/unlock from virtio_gpu_create_udmabuf() Date: Mon, 9 Feb 2026 22:59:44 -0800 Message-ID: <20260210070155.1176081-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770707008133158500 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.50.1 From nobody Tue Feb 10 20:48:27 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=1770706983; cv=none; d=zohomail.com; s=zohoarc; b=fIIMYBC1YKBBoUyLgun1MX9f0ruHy2moRhw15A4qHYj50+mA0OsA6HsWfzxCi/yreUdhbyN07oJrApOFKIpQBgtWHYx7hQag+0K1zLIA3FRgLNi848k81yJssdNWcnvIR9YqUJc7xgvJD0/kqag5u/ypFp0IEm+EzI/m+ch4nHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706983; 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=8hXsfxCCbhJTaYUSUmRM4a3nsYuOMwYMsL6ByYfXyao=; b=kGnTIE1NsdBAK4Niq4XZ958msPF1p+i8Izynj9RMVZAAEA883NUDdTw5CadQieG6lZFuQaDi9ayUnYpfV4b38AT7ksv5sRvtOHRYBjbuGPstWJ6msvStFGzVzEt93aiZmhB0a0lFKD21yGtebNXIwWFpLeGzcVhzouteM8vucEA= 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 1770706983786857.8668647808674; Mon, 9 Feb 2026 23:03:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlR-0004yV-Ht; Tue, 10 Feb 2026 02:02:25 -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 1vphlP-0004xy-De for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:23 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlN-0004oR-LE for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:23 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706941; x=1802242941; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qXg+ylIgNJYyiez2ZWJ7vvZcreZYGOhcBt9sUvBPrjs=; b=Hsg7Jcb1kSeF0e/iVSPcBz4Lqrmmh6VZLTT+NyDbz7Z6mZTJdEqxo5xO h5j0ZV5yX3Rk8vKoazgYASkDQ8dcAdk2v4IR4MeohNsFuKPqw4bLN2wSG fUqu4gdWqOQD4SBgRa0Ycl5C1kUH2h3otoJn8BmkbXpG6bkJEHY/x68uD r4JgrM3MF99IVxG3u8EqZq7NYV72a7hDfgaUHpRDMegACTW9+irBx7oNO KKFGL/5IdsM1t/wE6KtgTrXzNb3JJShg9ujgHubzBqss2Psx4Rw9K4+gJ OWP0vDbI/CAOJ52ZYJnRT1ejUV34qISh9NdjIrziMXgArkYwsjDkMKG7t A==; X-CSE-ConnectionGUID: 7NBpzE6QSg2VrxCFKEH4/Q== X-CSE-MsgGUID: N5bKI6DISLKBhV3aHF1vNQ== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012163" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012163" X-CSE-ConnectionGUID: W2LcRSG9R6+OEpOJFixW+Q== X-CSE-MsgGUID: 84CAHjn/TMi1juvervwFSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920544" 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 v6 05/11] virtio-gpu-dmabuf: Use g_autofree for the list pointer Date: Mon, 9 Feb 2026 22:59:45 -0800 Message-ID: <20260210070155.1176081-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706985769154100 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.50.1 From nobody Tue Feb 10 20:48:27 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=1770707018; cv=none; d=zohomail.com; s=zohoarc; b=OEH4yWicvDPxsoO/RJd7ja9+HDbggro/b406Qa4o1KtWBnrDth1p5Hxigfa3CMRsYeP7m+3058uQZkfMhflyNMVVmI8TfuyFoPmU4R5rWW8Zrx4SrFqji8s4CSgdfIQh1dEY1h8W+SWpuMXvfcO0IzyCP3sshsHzKfYhUsknUjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770707018; 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=OQU4mJNfPlU0RTrZoliwWhNONrJ2KKAnWEuIN9nfMQs=; b=RTjUhcdcbsaaPOgy0d+o7hAWqV6u0SToymvSIk/Hc5+sfAA0jD13Ho+jWHxASs1xvjWbBjUr2EknIUGK6W0Q/JIJ8EKmoYveJciMlAOCyi/xeipFZiFglIYkqqjpPMUxIcznbPqjlKFdlQuwcutHn/cdtPNa9gHPZt4l1Aghuu0= 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 1770707018398858.6311960066197; Mon, 9 Feb 2026 23:03:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlT-0004zR-Dh; Tue, 10 Feb 2026 02:02:27 -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 1vphlR-0004yc-Oh for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:25 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlO-0004oY-NA for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:24 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706942; x=1802242942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oQRCKzfMfTFAgGPsOzk5OTOODedydtNxeQxzJaxB35U=; b=nvLbluS6R5bTpvt9+bRCL2cpzAVpV0yI/R5OlVDPxHRIdtNyUIBThwrD xpw4SbNqe9HehTq48Rc3bjPaPMp1GnYiW7DBN13Ln4kgrWpwX/bBNUlDZ WkaD0N9+cScKmYkbHcLHltIX2dQIXrhZsI9eZWMUayMLnemfgvT6/k6qv AsHAdDnUDNjJFO+/bjdRkpI5Fm/9MS/GcRliztYXxGirCE7XWnSA+5dtm FULnaOH4mKScMRSxQMguWeXnuGHjKFQx5XCvFlFYuwrTh+UkfV9DDUgNC aIdMfJ9FX/gLocsp1TuGGYHi+ZiC05CPGfwqATMu6yN5RJpDlOVpNc4w5 A==; X-CSE-ConnectionGUID: t3JFEOLLTn2eDgrA4LRtTg== X-CSE-MsgGUID: f7hVfzNrS/KMrefojQYUxA== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012169" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012169" X-CSE-ConnectionGUID: RKusPD1zTyiacbGCT8WMag== X-CSE-MsgGUID: +Zb4Q3djSeu3tZd//bg5tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920547" 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 v6 06/11] virtio-gpu-dmabuf: Improve error handling by introducing 'Error **' Date: Mon, 9 Feb 2026 22:59:46 -0800 Message-ID: <20260210070155.1176081-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770707019996154100 Make the error handling more robust in virtio_gpu_init_udmabuf() by passing in 'Error **' parameter to capture errors from virtio_gpu_create_udmabuf() and virtio_gpu_remap_dmabuf(). And, since they now take in 'Error **' parameter, have them return a bool to adhere to best practices. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-dmabuf.c | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 8d67ef7c2a..d9b2ecaf31 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -27,7 +27,8 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 -static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) +static bool virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es, + Error **errp) { g_autofree struct udmabuf_create_list *list =3D NULL; RAMBlock *rb; @@ -36,7 +37,8 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_s= imple_resource *res) =20 udmabuf =3D udmabuf_fd(); if (udmabuf < 0) { - return; + error_setg(errp, "udmabuf device not available"); + return false; } =20 list =3D g_malloc0(sizeof(struct udmabuf_create_list) + @@ -45,7 +47,10 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_= simple_resource *res) for (i =3D 0; i < res->iov_cnt; i++) { rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); if (!rb || rb->fd < 0) { - return; + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Could not find valid ramblock\n", + __func__); + return false; } =20 list->list[i].memfd =3D rb->fd; @@ -58,20 +63,26 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res) =20 res->dmabuf_fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); if (res->dmabuf_fd < 0) { - warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, - strerror(errno)); + error_setg_errno(errp, -res->dmabuf_fd, + "Could not create dmabuf fd via udmabuf driver"); + return false; } + return true; } =20 -static void virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res) +static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, + Error **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,6 +136,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { + Error *local_err =3D NULL; void *pdata =3D NULL; =20 res->dmabuf_fd =3D -1; @@ -132,12 +144,15 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; } else { - virtio_gpu_create_udmabuf(res); - if (res->dmabuf_fd < 0) { + if (!virtio_gpu_create_udmabuf(res, &local_err)) { + if (local_err) { + error_report_err(local_err); + } return; } - virtio_gpu_remap_dmabuf(res); - if (!res->remapped) { + + if (!virtio_gpu_remap_dmabuf(res, &local_err)) { + error_report_err(local_err); return; } pdata =3D res->remapped; --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770706977; cv=none; d=zohomail.com; s=zohoarc; b=EpJ/ofKQtuQQZwpI+INrA/amXViWnNDLWoh7n3XB/eTXBXqeye7L8pSgn/eE4ieWbRius3Loh9aS7UNuYXWi31eoexMQcuAyfyot85js+fowC17Y7a4+oN5YWTRrYvUIqn2+WannKNl7+5rCjL6oiMrPLeTl0/4E2EOI8eyL7A0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706977; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Sf79CiAG6SfHqkNGj75oFk3mJTt1TqAQVqnu+Y8ZqiE=; b=l35CkSR7xoz2NDQxSuCj9u1Wa6cvtlaVM5VDktig798NfEdyxrFVg0K2K+2LPt7te4tkJxmIM7HDF/QZ3Cg0LYObr4Y5ea9ZG287pRQgMzgE9r6azQaXl2zxCU5i9COw3zqLiYRwJlOgoyhmrUhjfD0lFdNe0II5VSCnhTlYK+g= 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 1770706977954327.97740069407587; Mon, 9 Feb 2026 23:02:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlT-0004zF-0W; Tue, 10 Feb 2026 02:02:27 -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 1vphlR-0004yb-On for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:25 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlP-0004p7-2x for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:24 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706943; x=1802242943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vLJ04mRE3eaGEiRhVGrnFwJ/UmQVbHxQHcqyM8xjArE=; b=KfteSpD8xW4YpB3Yaf1PnlYMF34fcgwTKk07abnSUMvJHoFPyMccnrf0 t2D/k3GVQLJRe4bhCzOYaF6E3JsrUum7ubR/Kup0HKYfx9ox5Luhxj37B vJ0xl4Z9XBOHM0YvWWd6AMQ1znP/tAzU/8rvrSUJsuO+dVOfOoYDf1RIz hhxGk+d9lZ2zY3e3eDvht2P1jI0PbYI9mtSKOPHrcWZXzjKPzMIivvlVp pMNhlWsDcK5K4Wtx0OKWn+SlW8iolJ862PyvXc/hLFw4iI9f1wL8iJeH6 RWQ3L7uHsa8mV+PS9ggdZyBav/FI9xmOpx11ddIFLFstqB9ryWExexJQA A==; X-CSE-ConnectionGUID: vQYmOREFRwGGluTsiiG0LQ== X-CSE-MsgGUID: XGpVyCSxR/O9COznWSa8rQ== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012175" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012175" X-CSE-ConnectionGUID: 2XenC3MfQ5+bD6UCTJsb2g== X-CSE-MsgGUID: Wto7QiFkT5C26FQDMpf+FQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920550" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 07/11] vfio: Document vfio_device_get_region_info() Date: Mon, 9 Feb 2026 22:59:47 -0800 Message-ID: <20260210070155.1176081-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706979950158500 Add documentation for vfio_device_get_region_info() and clarify the expectations around its usage. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- include/hw/vfio/vfio-device.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 35a5ec6d92..828a31c006 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -275,6 +275,19 @@ bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODe= vice *vbasedev, int vfio_device_get_feature(VFIODevice *vbasedev, struct vfio_device_feature *feature); =20 +/** + * Return the region info for a given region index. The region info includ= es + * details such as size, offset, and capabilities. Note that the returned + * info pointer is either a cached copy or newly allocated by + * vfio_device_get_region_info(), so the caller is not expected to allocate + * or free it. + * + * @vbasedev: #VFIODevice to use + * @index: region index + * @info: pointer to store the region info + * + * Returns 0 on success or a negative value on error. + */ int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770706968; cv=none; d=zohomail.com; s=zohoarc; b=lWK+IcFlpUIuHqWj8vRoThgbIFGRcWxSAazoNBgWVnL4M67V5T9P1JOOequfboj0xfRm7UuKsXW8F2aAWoYJnl37VA4RFtupPUP+V3VcPP9Pc44HNCnGgFr4s4wb0yPuhqXPRt+ZwNEayTMn9ztBrEFiil2QrI4ciQdY4bn3tV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706968; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oXkxCkb5yDecPBp87JpMAAg/WYB+TI0ipRNsgrCT188=; b=CCDMk1YzWwjCV+wlW6uc0nI40qZHu9fj8mAk64+kSDfzww0SgCqapNPR9Djw4Oa50YWhs+bJUl0HbQpLqEPdf9iOpmTXJtslFiaP3DEVOXByUo2a/i8kjCgMsKxLvPCj4obHcY3si5vUvpD8Kglf+nHYTUKm+kbD45GA63W3YTE= 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 17707069688581.125465398573283; Mon, 9 Feb 2026 23:02:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlU-00050A-KH; Tue, 10 Feb 2026 02:02:28 -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 1vphlT-0004zG-4s for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:27 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlP-0004oR-NR for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:26 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706943; x=1802242943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6rfHFdfPdD8BjvFsHmnrTLtCCMNlWfo+Utny8DB0OFs=; b=EcDLhtgQfCM3Yc8EVPNXzGA2A2zjhn3fGx/ltwAmQtXs3VJbpyogDNQE G4UhvT8LbRP1mV7FljL+/4641Pqyg3Uqi4oKz6fvffFip5jb1jUPjMz40 xf1Dw7BWGN5F7NSE5n04zY/iXo4K0V5GBs5AR0O3vbJEZ3RNg2/KsrOgg aCHpMlWE3cH6RHyEq+saHiMyb2zVZkvIyEG5ikH1DM3dVKlB5FxDVwB3e oWIh3NuWGLBf3RSkUpsT5dxVG9dQNV6nB7hcEGoAWg8pSbnk+wee+02Hr x2fool/uIyuFoosjKyumAlVfdGEPd8R3QEYM8QhmT8SIDE3JIa4Xvw3yJ Q==; X-CSE-ConnectionGUID: T04CfiGFS6WH2OsZszVOcw== X-CSE-MsgGUID: c/BXim4TTM6551twkzK1XQ== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012179" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012179" X-CSE-ConnectionGUID: FlnyOwycSvWlv9rNNzmCpA== X-CSE-MsgGUID: 2iogxenST/OeIdXrQfH/wA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920553" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 08/11] vfio/region: Add a helper to get region index from memory region Date: Mon, 9 Feb 2026 22:59:48 -0800 Message-ID: <20260210070155.1176081-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706971347154100 Having a way to figure out the region index (or bar) associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info needed for mapping a part of a VFIO region or creating a dmabuf. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/region.c | 14 ++++++++++++++ include/hw/vfio/vfio-device.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/vfio/region.c b/hw/vfio/region.c index ab39d77574..9c3dc19ee1 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -461,3 +461,17 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +int vfio_get_region_index_from_mr(MemoryRegion *mr) +{ + VFIORegion *region; + + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + region =3D mr->opaque; + return region->nr; + } + mr =3D mr->container; + } + return -1; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..596c7f5a10 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -308,6 +308,16 @@ bool vfio_device_has_region_cap(VFIODevice *vbasedev, = int region, uint16_t cap_t =20 int vfio_device_get_irq_info(VFIODevice *vbasedev, int index, struct vfio_irq_info *info); + +/** + * Return the region index associated with a given MemoryRegion. The index + * can be useful in retrieving region info. + * + * @mr: MemoryRegion to use + * + * Returns the region index or -1 on error. + */ +int vfio_get_region_index_from_mr(MemoryRegion *mr); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770706969; cv=none; d=zohomail.com; s=zohoarc; b=ho5yrFEA9BV/qotGvRlX3eKWvhXWNTl2nIibhzjmLbfXB4YtYUDvU8hmdu3RvzvbUyFfkUYNpHj8amjIX7TxPRAa1kCMQ9+GJquQTjqdyAaHwbjPpps0NYKGJU9LOcE0/wOonCUpz79UeJJflwz+k8jAs+GRyQ2Pc/f1rVHPHpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706969; 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=616TtSv/P4MB6kSQgTz7wqW1yzN8ko0967ixdUdDQCM=; b=SDSgr8yr5Q+1RSfMk4MDRKvMgZw9ZJc4hfqtmv2tMp4Dlak5EBW4UK7epu0fFxhzkpkoHr0ray66ShiRG+TtCEAY8lWNXo6HbjsbUeNGjmjN240MV/i7F4Pz6khg/1yqeTOG2CjHMbr1+eUz4wJaDfEYumXxmdJHv7798PiM8/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770706969712824.5830890685538; Mon, 9 Feb 2026 23:02:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlW-00053I-SQ; Tue, 10 Feb 2026 02:02:30 -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 1vphlT-0004zy-UO for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:27 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlS-0004oY-6m for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:27 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706946; x=1802242946; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V4N+nlGdAKKVvTdy20qKXzkyk59AwwC7IM9qRYhfmGE=; b=UZ+Q1Nt0J8WPk0f0RXzoxg+Eo8VR4lmmv/S1pXkfGGw+3ilVCm4SELoi VjU8jkxl5yZC+eSawgSU/rgtBe6JL9A/kHSzmdf1c8XF4zrnKJRdSu1Fe 34e0DZ8DOwSjZX9rq+kW0XHFtKZdxueug0ge10pPPT2LzhWcKMstE6KvH 5Q7o7ymISK+vI1b7PJfPqibMar3Fx0ZQUYbHAjig/P+OZsNYWsQLQWpkp bSYsxy33z1aftpy1dMPAX0Kw33ioubPCkjt2AIDnvU4gFQCRAdvm/cmqN gHBk29alwzpGseLcz5XBAlyuH8Yzg+W6UQMtFXci8Fki8fkZd3uCRk58f g==; X-CSE-ConnectionGUID: q7YniHrkT/KRsEq4pj45ag== X-CSE-MsgGUID: K8+1jhLiSe+eilwBzDs6GQ== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012182" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012182" X-CSE-ConnectionGUID: 8RiwMPZKRdSghMwASjEjQQ== X-CSE-MsgGUID: wAkmRUkJQkqpreTP+rpNuw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920556" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 09/11] vfio/device: Add support for creating dmabuf from multiple ranges Date: Mon, 9 Feb 2026 22:59:49 -0800 Message-ID: <20260210070155.1176081-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706972136158500 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.50.1 From nobody Tue Feb 10 20:48:27 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=1770706988; cv=none; d=zohomail.com; s=zohoarc; b=jneEG/teogFXdNWBxm2c2xOoePV+/URAt2lUXYRxkSIIWYXXLlsB/gt0NJKouq0UcqOsp32zMnqikrB4yIMwXeo+QdtAbxKKAxeHI176HBBwZH94rqjFnFXbbZdDGe0mOLifxsQWRZs6hRlAgEXD+PkBBdu6pTIHn7N2Gnfx1kM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706988; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZGut6s3mT62Oa1fi/83mmWuDHvxfeI5JDg93PJ3y+w4=; b=j+sfE/tE3Qhg6T4BXQ+oWSzP4HAvWZuvAFC8vU/lD5TsGe5UMzYF5OPsDMhJgzoA7lC2VpnkTcPyM8arSenUor+jLkmC0xOd6gPZQuFgyDbZX4dLlwNzShFsqDx1nYyOQ2wRPE1ElPodPM6V9JSMoEh9VTk59oqKoJRubKmGrAg= 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 1770706987994813.2576819769466; Mon, 9 Feb 2026 23:03:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphlf-00057Z-4z; Tue, 10 Feb 2026 02:02: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 1vphld-000550-TX for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:37 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphlc-0004p7-4d for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:37 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:15 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706956; x=1802242956; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HkTr/zWEef0bVYlJ9JiAZY/xqp73/s2wMhr4ci6XAjI=; b=Qo0RuurCaM7jv8uaTfci1OUMtkn4cqXXrZ2LmFlDDvIzGnG/uDQsXvwU 7o0QNmVgh9rlybwc0Wm0XpKX9If6HJvNR1G9YcKpM8M6frqshl6h4O1mI I77Ro3dCMMLIRsnFk3mRGmv9NfVIkq5DdcGk2V5A+mhHq4VSUeVCac2Fp zO/GDIuJI2nj/M19KyKdzcKanU8r4rkKA8XbuSva8sTHu4GEiMo4aV98M WE3LhRiO5EFUpcl4hdiI/T+BYiTf6mNGyWvx1PFMAyxp+6Zxe0mEfDIG5 6tiFN3SdLNf19PTnARxR2j7h4Avk+gohljILW98MGp6dKaN0B6vK3tzLx w==; X-CSE-ConnectionGUID: MPqFtYT7SYK4Y8uZTHr2Yw== X-CSE-MsgGUID: CcuDzGGHQqKqEcrY0FZf5w== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012185" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012185" X-CSE-ConnectionGUID: 9+7/NpY2TvOLGd4r5vlgyA== X-CSE-MsgGUID: VcrRWGSGTQi3WjnIBaj6dA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920559" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 10/11] vfio/device: Add a helper to mmap a dmabuf Date: Mon, 9 Feb 2026 22:59:50 -0800 Message-ID: <20260210070155.1176081-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706990177158500 In order to mmap a dmabuf, we first need to create a placeholder mapping that would fit the entire size of the dmabuf. This mapping would then be replaced with smaller mappings of individual dmabuf segments. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/device.c | 65 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-device.h | 16 +++++++++ 2 files changed, 81 insertions(+) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index a7603600f3..ef05ec8ade 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -725,3 +725,68 @@ bool vfio_device_create_dmabuf(struct iovec *iov, unsi= gned int iov_cnt, } return true; } + +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp) +{ + struct vfio_region_info *info =3D NULL; + VFIODevice *vbasedev =3D NULL; + ram_addr_t offset, len =3D 0; + RAMBlock *first_rb, *rb; + void *map, *submap; + int i, index; + + if (!vfio_device_lookup(iov, &vbasedev, errp)) { + return false; + } + + /* + * We first reserve a contiguous chunk of address space for the entire + * dmabuf, then replace it with smaller mappings that correspond to the + * individual segments of the dmabuf. + */ + map =3D mmap(NULL, total_size, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, = -1, 0); + if (map =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, "Could not reserve placeholder mappi= ng"); + return false; + } + + for (i =3D 0; i < iov_cnt; i++) { + rb =3D qemu_ram_block_from_host(iov[i].iov_base, false, &offset); + if (i =3D=3D 0) { + first_rb =3D rb; + } + if (!rb || rb !=3D first_rb) { + error_setg(errp, "Cannot mmap dmabuf with different regions\n"= ); + goto err; + } + + index =3D vfio_get_region_index_from_mr(rb->mr); + if (index < 0) { + error_setg(errp, "Cannot find region index for dmabuf segment\= n"); + goto err; + } + + if (!vfio_device_get_region_info(vbasedev, index, &info)) { + error_setg(errp, "Cannot find region info for dmabuf segment\n= "); + goto err; + } + + submap =3D mmap(map + len, iov[i].iov_len, PROT_READ, + MAP_SHARED | MAP_FIXED, vbasedev->fd, + info->offset + offset); + if (submap =3D=3D MAP_FAILED) { + error_setg(errp, "Could not mmap dmabuf segment\n"); + goto err; + } + + len +=3D iov[i].iov_len; + } + *addr =3D map; + return true; +err: + munmap(map, total_size); + error_prepend(errp, "VFIO dmabuf mmap failed: "); + return false; +} + diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 003bac10b5..b8e0801b94 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -332,6 +332,22 @@ int vfio_get_region_index_from_mr(MemoryRegion *mr); */ bool vfio_device_create_dmabuf(struct iovec *iov, unsigned int iov_cnt, int *fd, Error **errp); + +/** + * Mmap a dmabuf by first translating the addresses in the iovec + * array into VFIO region offsets and then creating a placeholder + * mapping that would be replaced later with mappings that + * correspond to the dmabuf segments. + * + * @iov: array of iovec entries associated with the dmabuf + * @iov_cnt: number of entries in the iovec array + * @addr: pointer to store the resulting mmap address + * @total_size: total size of the dmabuf + * + * Returns true on success and false in case of an error. + */ +bool vfio_device_mmap_dmabuf(struct iovec *iov, unsigned int iov_cnt, + void **addr, size_t total_size, Error **errp); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1 From nobody Tue Feb 10 20:48:27 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=1770706972; cv=none; d=zohomail.com; s=zohoarc; b=bZ8e1iHhJD5wJ56OAk4hnor4ev+VUp74qpy6RFeSa2ojcdjw8fnfHgTp7lq5pURrt8zovlvbnYaf8BfXE1Puvmp8ezOG53aVivffJrz9so8sBQuUQ18WbhGtPp8UiiCfjKGCBdWFJvH4z2u716xPopNiWmR3vv4NUT0obW4xyuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770706972; 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=dpKxxaOs5ocwfTWSF5gOsJC6g/thsbQmdMZAzNnuXmk=; b=LR9NwpmoO66tDAVW78RTT8rDSEMctKRb5TW+nqKlig9OZNn4vHWMqwOmcIu8FrhNEEluccaWkUkceWOTT4mynDb/KFWePDH4j5o7xRFa5C35hBwGorpzgCoh5c5PpqHi+dwQxw7C06PLJSHs5oITgheH6fcS/c1CHCGBkBE0pvk= 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 1770706972600961.5035871019873; Mon, 9 Feb 2026 23:02:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vphli-0005A9-43; Tue, 10 Feb 2026 02:02: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 1vphlf-00057m-JW for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:39 -0500 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vphld-0004oR-LL for qemu-devel@nongnu.org; Tue, 10 Feb 2026 02:02:39 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:15 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 23:02:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770706957; x=1802242957; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RDJw7SL5tnzcRtJqDrZV2wCnXuhljoWjheVY1G/e+fw=; b=ERJFw2TOoNsuMx6i0xlnAKufv9M4ytf32Tc3fQjMqxkwtWAUW6CCCL01 /H4uUS52mnGBwcteI7oQgLzC1CPKqD/9MZXDMEZ0NDxcMriABy/eHcW91 N81hwBi2uLnW1rMgx3WU6ePwLsVthlZadeUtqhXM5DrJAAPfySLGhDLFt tZIvbnRriEA9xoj6WojtP3c+tkZfhWVj1HE6wPujzd+LNqE1osGsYjYiC jtUYQiqU81NpcOeTzqBYn2Ms5TbMAn6bue2fv91DrwPtdYv63DRRHUbGH 5dWvME6ZRI3SpWvINlXG2C55NnRYUNe8GAmctPETR8Cc4o04XYXnQJAX/ A==; X-CSE-ConnectionGUID: i9sFoLA/TLqZtpkRK7FQ7g== X-CSE-MsgGUID: xdp4N3j5RJWPm5dk36krzw== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="72012188" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="72012188" X-CSE-ConnectionGUID: KY9oa0X/TdKL1TbsuCEfnw== X-CSE-MsgGUID: apD5OCfZTHqSHZZUt39teg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="210920562" 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 v6 11/11] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Mon, 9 Feb 2026 22:59:51 -0800 Message-ID: <20260210070155.1176081-12-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260210070155.1176081-1-vivek.kasireddy@intel.com> References: <20260210070155.1176081-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.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1770706975711154100 In addition to memfd, a blob resource can also have its backing storage in a VFIO device region. Since, there is no effective way to determine where the backing storage is located, we first try to create a dmabuf assuming it is in memfd. If that fails, we try to create a dmabuf assuming it is in VFIO device region. So, we first call virtio_gpu_create_udmabuf() to check if the blob's backing storage is located in a memfd or not. If it is not, we invoke the vfio_device_create_dmabuf() API which identifies the right VFIO device and eventually creates a dmabuf fd. Note that in virtio_gpu_remap_dmabuf(), we first try to test if the VFIO dmabuf exporter supports mmap or not. If it doesn't, we fall back to the vfio_device_mmap_dmabuf() API to get a mapping created for the dmabuf. Cc: Marc-Andr=C3=A9 Lureau Cc: Alex Benn=C3=A9e Cc: Akihiko Odaki Cc: Dmitry Osipenko Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/display/Kconfig | 5 ++++ hw/display/virtio-gpu-dmabuf.c | 50 ++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 8 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 d9b2ecaf31..54d010b995 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -18,6 +18,7 @@ #include "ui/console.h" #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-gpu-pixman.h" +#include "hw/vfio/vfio-device.h" #include "trace.h" #include "system/ramblock.h" #include "system/hostmem.h" @@ -27,6 +28,27 @@ #include "standard-headers/linux/udmabuf.h" #include "standard-headers/drm/drm_fourcc.h" =20 +static bool virtio_gpu_create_vfio_dmabuf(struct virtio_gpu_simple_resourc= e *r, + Error **errp) +{ + bool ret =3D false; +#if defined(CONFIG_VIRTIO_GPU_VFIO_BLOB) + Error *local_err =3D NULL; + int fd; + + if (!vfio_device_create_dmabuf(r->iov, r->iov_cnt, &fd, &local_err)) { + error_report_err(*errp); + *errp =3D NULL; + error_propagate(errp, local_err); + return false; + } + + ret =3D true; + r->dmabuf_fd =3D fd; +#endif + return ret; +} + static bool virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es, Error **errp) { @@ -73,16 +95,28 @@ static bool virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res, static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, Error **errp) { + Error *local_err =3D NULL; + bool ret =3D true; void *map; =20 map =3D mmap(NULL, res->blob_size, PROT_READ, MAP_SHARED, res->dmabuf_= fd, 0); if (map =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "dmabuf mmap failed"); - res->remapped =3D NULL; - return false; + map =3D NULL; + ret =3D false; +#if defined(CONFIG_VIRTIO_GPU_VFIO_BLOB) + if (vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &map, + res->blob_size, &local_err)) { + ret =3D true; + } else { + error_report_err(*errp); + *errp =3D NULL; + } +#endif + error_propagate(errp, local_err); } res->remapped =3D map; - return true; + return ret; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -145,8 +179,10 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_r= esource *res) pdata =3D res->iov[0].iov_base; } else { if (!virtio_gpu_create_udmabuf(res, &local_err)) { - if (local_err) { - error_report_err(local_err); + if (!virtio_gpu_create_vfio_dmabuf(res, &local_err)) { + if (local_err) { + error_report_err(local_err); + } } return; } @@ -163,9 +199,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