From nobody Sun Feb 8 22:43:39 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=1770104049; cv=none; d=zohomail.com; s=zohoarc; b=XJtOGA3HOAbSthGp1meE9YsuiQ+0u93vXB597KHoVqQ5QT25AQF+ooHKKBMutPLtJBBK6bkA9A/As/yb3OVQnO8bh7uqjINnM7UbBAluKylMGloIqAPRxXcERcjfQSGzyM11DuhhEQI8wDjB60zGSK1TqYsefJZj4H+oE9TCkL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104049; 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=DUSnKqbIaT3a7l8gOMHPWOhmYwZaqTUEkJWCP1H+p6o=; b=WbnoPO+OHwHH048Z/WmCGP3mFJ9L8y2NqPON0/+mfsl8pfwD5WSrSwSjqI0XOpQOjpMB/6jYrqlj8lPfh3Iew5dW/HvDpsCpJMJXrTNU4O/znWiD4hsb1arzdLXrXYsgv1TudCqD6A2aM7qn9HVspAGcmEMZLqTl1JpdyF1V+FM= 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 1770104049312369.7518775338473; Mon, 2 Feb 2026 23:34:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAuO-0007XV-TC; Tue, 03 Feb 2026 02:33:13 -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 1vnAuF-0007VN-CD for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:03 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAuD-0006Ca-LQ for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:33:03 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103981; x=1801639981; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e7JZ6ZB3ohVIX+KOOS5rF5ICP/rXhFYhCok9J8P+Sqk=; b=Th1rInGxOAugGJpDOxSq+7BvCE+0d5FXgobl2rkGoky1jZIx7xvoZzpY ZuEdZu2BnqhbFPADmga/w+GmkLd+FMhislSYcwYzSaxnv2JCLXQnKhi8r DC67QFu9o9hLOS63ba05+no+dRGPpUwYExqhRlMvA44nnDe4iwun72Xpy QfKCsqm0g5jMQHisWEcKHxYZX20eYWk7fnhFaszfug+ml0TXVEIxoMjAV IfE8PMC13Q6HYHNv5UjmQDDp4qCS10OIiH9qkH5meal0i6fSsZv3xotIk hOq1ZQTrvVM2dzfzPz5aAKmDHsRLMLy+tSVX0KXFkOWlNHPmdZPy04S9O A==; X-CSE-ConnectionGUID: q7AN4ScISX27aNKWQZjr9A== X-CSE-MsgGUID: AA4weTh4TYSUoGBeM46Yuw== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640930" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640930" X-CSE-ConnectionGUID: utPQdkOZQ02axPngGNgALA== X-CSE-MsgGUID: Z5nMFG62TZS24OnKudrSog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373123" 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 v5 12/12] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Mon, 2 Feb 2026 23:30:19 -0800 Message-ID: <20260203073200.848183-13-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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.10; 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: 1770104054226154100 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 | 49 ++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 11 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 22e66fbb12..2e65f21dda 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,23 @@ #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(VIRTIO_GPU_VFIO_BLOB) + int fd; + + if (!vfio_device_create_dmabuf(r->iov, r->iov_cnt, &fd, errp)) { + 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) { @@ -72,18 +90,25 @@ static bool virtio_gpu_create_udmabuf(struct virtio_gpu= _simple_resource *res, } =20 static bool virtio_gpu_remap_dmabuf(struct virtio_gpu_simple_resource *res, - Error **err1) + Error **err1, Error **err2) { + 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(err1, errno, "dmabuf mmap failed"); - res->remapped =3D NULL; - return false; + map =3D NULL; + ret =3D false; +#if defined(VIRTIO_GPU_VFIO_BLOB) + if (vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &map, + res->blob_size, err2)) { + ret =3D true; + } +#endif } res->remapped =3D map; - return true; + return ret; } =20 static void virtio_gpu_destroy_dmabuf(struct virtio_gpu_simple_resource *r= es) @@ -137,7 +162,7 @@ bool virtio_gpu_have_udmabuf(void) =20 void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_resource *res) { - Error *err1 =3D NULL; + Error *err1 =3D NULL, *err2 =3D NULL; void *pdata =3D NULL; =20 res->dmabuf_fd =3D -1; @@ -146,12 +171,16 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_= resource *res) pdata =3D res->iov[0].iov_base; } else { if (!virtio_gpu_create_udmabuf(res, &err1)) { - error_report_err(err1); - return; + if (!virtio_gpu_create_vfio_dmabuf(res, &err2)) { + error_report_err(err1); + error_report_err(err2); + return; + } } =20 - if (!virtio_gpu_remap_dmabuf(res, &err1)) { + if (!virtio_gpu_remap_dmabuf(res, &err1, &err2)) { error_report_err(err1); + error_report_err(err2); return; } pdata =3D res->remapped; @@ -162,9 +191,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