From nobody Mon Apr 13 11:20:04 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=1772853139; cv=none; d=zohomail.com; s=zohoarc; b=HPQBVDJG0c3lgnuQVkKgcY4Nvt9/RBMew8jE99oGTYXa78gIR1okCEWlHk8sPXl75i+cP3X6kbbgqRGRl/efI7jC/iRQVY6bhFb9+AruXgn0BP0v18zcO1J0c0lTcs09WPnGZHnau6e7WmaI+CUjvupLzObAudq8WXOLwjw29r4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853139; 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=eujF32pFyCA04oR+peMUhz0eESY8tRGM53ZgqAyh9+A=; b=e5u4dlu9J07G2hqdqG+dH8oJol7fwRha5AGXaekddmii+6/6ISHaYtoeiLqtlWUEZOsWB4HvvAXaAKV/QN3d0gbLsPqZD2CJiozrh6YWIAKqJ8DUKY5njhTwk+zjoGda8JB1CyNQGip2VSm1BecU6KtZD1Q+6462J02fLdcSbIc= 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 1772853136013284.91989903479043; Fri, 6 Mar 2026 19:12:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4f-0004sP-Cy; Fri, 06 Mar 2026 22:11:29 -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 1vyi4d-0004s5-Ei for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:27 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4b-0000ol-UR for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:27 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853086; x=1804389086; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ndxcgores0l2qC+gItZqykbKhchBgLacTV55nno2J1c=; b=BadbmyPqGq3G8vWat2gnMaI3HgvVYw4tYrJ3/5ks6RTgcE0UuhWsNPkx njxAPNbOrLsZH8lroH3nOsKy7YvFE//XvLnKkzoM7ZC1KJSC/AWle1d7P DIJmWzkEDpvVeerTCggvpInNSzwHWjpp5nCPafj1cEb8w67+1m1WB8+W7 Lj2NHfwflsthRtgZ+tEk2j2vnBWXgadTJb+t0qJ48L1EIi6uFwLyTmg7m NXMndZrAeR8vt2Qk08zBC+rNAYE0n0i7/nzjphPFQwakRHLKbia29qeiu ysNdp2Dyxxoa6i9xq2Ui4KhnlhMWY6DFua28U7jJ2mfgJZ8xBwtqKlrT1 Q==; X-CSE-ConnectionGUID: c3IX8VxWRvWxiAfeJhOLRQ== X-CSE-MsgGUID: j4KNE3e3QnGyX74pDqhqag== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434046" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434046" X-CSE-ConnectionGUID: iMwvIcS8QKuxAkdpMYa6cw== X-CSE-MsgGUID: BKFhtA3IQfqR3HOQSDmcsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813786" 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 v10 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Date: Fri, 6 Mar 2026 19:05:59 -0800 Message-ID: <20260307030812.1224392-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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.7; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.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.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853143997154100 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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-dmabuf.c b/hw/display/virtio-gpu-dmabuf.c index 0a6b54fde5..55e3f60b60 100644 --- a/hw/display/virtio-gpu-dmabuf.c +++ b/hw/display/virtio-gpu-dmabuf.c @@ -148,9 +148,22 @@ void virtio_gpu_init_dmabuf(struct virtio_gpu_simple_r= esource *res) if (res->dmabuf_fd =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { error_free_or_abort(&local_err); =20 - qemu_log_mask(LOG_GUEST_ERROR, - "Cannot create dmabuf: incompatible memory\n"); - return; + res->dmabuf_fd =3D vfio_device_create_dmabuf_fd(res->iov, + res->iov_cnt, + &local_err); + if (res->dmabuf_fd =3D=3D VFIO_DMABUF_CREATE_ERR_INVALID_IOV) { + error_free_or_abort(&local_err); + qemu_log_mask(LOG_GUEST_ERROR, + "Cannot create dmabuf: incompatible memory\n= "); + return; + } + + if (res->dmabuf_fd < 0 || + !vfio_device_mmap_dmabuf(res->iov, res->iov_cnt, &pdata, + res->blob_size, &local_err)) { + virtio_gpu_destroy_dmabuf(res); + res->dmabuf_fd =3D -1; + } } else if (res->dmabuf_fd < 0 || !virtio_gpu_remap_dmabuf(res, &pdata, &local_err)) { virtio_gpu_destroy_dmabuf(res); --=20 2.53.0