From nobody Sat Apr 11 23:08:45 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=1772694029; cv=none; d=zohomail.com; s=zohoarc; b=UggXF6H9k2RKyFTwMl+yF1HiHapHxkI6OiXgvPY/4jzAWA606ynCH4KbgSSHNEGlC4WD17CweEmYQDJC2/ZxuX5WcGjq2/fuveQMeuT9zNy5/G57pXF/zxn1ni5k5uJUQ8sohOhiCuBt+AyMHzzbQZHBFSTQWpyFwbvCpSxoxNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772694029; 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=agJIdr76cRbNtP1zV+sEPpstyq7p93DyNFS0tEw6XgA=; b=VEqylxBJHZwjc5NlcfHUj+Q0EbSwq4RtKEMtuQ4QZYqnkaM6XOJQxZc7JpsZYsrNGydnj0mRqcoO1zQDMmsrw93CcbjRs4Xh4Uady8WCg3Ae/Slpfe4UnrXo/royrYtuO1vwluMXb7UzI+LKd+QVhFGBzHez31yf+5Yi5YAKYkc= 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 1772694029978324.3104527028521; Wed, 4 Mar 2026 23:00:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vy2gl-0003Y9-BE; Thu, 05 Mar 2026 02:00:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vy2ga-0003XN-Qg for qemu-devel@nongnu.org; Thu, 05 Mar 2026 01:59:56 -0500 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vy2gZ-0007qy-49 for qemu-devel@nongnu.org; Thu, 05 Mar 2026 01:59:52 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2026 22:59:31 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2026 22:59:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772693991; x=1804229991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YUNbrp4edfd3cukBdHdjKpuhqQeo/bSB3kVXDpXzORs=; b=FV6XvX1CUqiI4TZEVo7ORLLrEfdOEreYdrto9glck7YarH6xJoyQBL6S W7dL43PHgE+N69AD6MKLM/vtFCyIwmTuzYj8VZD3JqhMQQcCspnUdDexP 7EjZDfMaJMIy+QeKZ+/uFrauoJwZ9XPziuVDF+1qQMPn5Lbnj+wLwqbfG xDlJCyfnTSS/FXd5Ftx054GJVsQ1f6/h7UywdpTSO79CjPnTgDAbz772S 0BV2SM8Y30994UI3j/SbUyoMfK8RXHy/e8qMVaoFEVhS6oN9VG0H9R2uD uSxBuA8pcPRCofEFPA6chfzy+g9i54sGXkYBOD5gOrVZbqCW2Tdb7Av07 A==; X-CSE-ConnectionGUID: C4DO4CS9Q36LkuioUa3cPQ== X-CSE-MsgGUID: s7fl8r8WTZ2JiqvD0k7keA== X-IronPort-AV: E=McAfee;i="6800,10657,11719"; a="91343534" X-IronPort-AV: E=Sophos;i="6.21,325,1763452800"; d="scan'208";a="91343534" X-CSE-ConnectionGUID: HWbDSD/iSSmgj15nBe49cQ== X-CSE-MsgGUID: bQ1+LUWzSNebDaM/tGvd2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,325,1763452800"; d="scan'208";a="218725688" 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 v9 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Wed, 4 Mar 2026 22:54:41 -0800 Message-ID: <20260305065700.1155146-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260305065700.1155146-1-vivek.kasireddy@intel.com> References: <20260305065700.1155146-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.8; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 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.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, 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: 1772694031591158500 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_fd() API which identifies the right VFIO device and eventually creates a dmabuf fd. Note that, for mmapping the dmabuf, we directly call mmap() if the dmabuf fd was created via virtio_gpu_create_udmabuf() since we know that the udmabuf driver supports mmap(). However, if the dmabuf was created via vfio_device_create_dmabuf_fd(), we use the vfio_device_mmap_dmabuf() API to get a mapping 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/virtio-gpu-dmabuf.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index dd64fbbc2d..7f4c399416 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -136,7 +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; + Error *local_err =3D NULL, *vfio_err =3D NULL; void *pdata =3D NULL; int ret; =20 @@ -155,10 +155,24 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) } =20 if (ret =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { - qemu_log_mask(LOG_GUEST_ERROR, - "Cannot create dmabuf: incompatible memory\n"); - error_free(local_err); - return; + ret =3D vfio_device_create_dmabuf_fd(res->iov, res->iov_cnt, + &vfio_err); + if (ret > 0) { + if (vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &pdata, + res->blob_size, &vfio_err)) { + error_free(local_err); + goto out; + } + } + + if (ret =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memory\n= "); + error_free(vfio_err); + error_free(local_err); + return; + } + error_report_err(vfio_err); } error_report_err(local_err); return; --=20 2.53.0