From nobody Fri Dec 19 13:24:54 2025 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=1689147804; cv=none; d=zohomail.com; s=zohoarc; b=J+1Qcv3F7PIX+Azv9fNz7VPSs5lQ+N7YRAUSJy2aUGciRfDzgDgZQbjQFoDjJfUb1HmoC04S74mHzn/Sw5HUrOQNdPuKYz1mz3TqTbAm+wYgH8UBt5wPqYjiAnMS1/0lOJxCo5AjCC4lKFVEUq87zl9kQsX9FWXDwEbqjK6c99c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689147804; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m75EM+Fq28lGRhJOmoAE0Cbp1aiaYE7RJ0P5Kw0TT9A=; b=V4ohv4FJQOnE0t48uE+HYh50lwC2uAufZ9UvTH9kaiIWgSzyOC/PP1VYkTkQCzHNx7kHmFxDuwlGfYp68xkEYkNMtB3gcjsXjujeamfhu2Ah4ZijmPOSFlTzW4SRnVL50wRP4CFuqtyTftBNZj7QuVowv7Z7vN7IB8dM16QNu/4= 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 1689147804739669.1824849555215; Wed, 12 Jul 2023 00:43:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJUTD-0007gA-NL; Wed, 12 Jul 2023 03:41:07 -0400 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 1qJUT3-0006xA-1V for qemu-devel@nongnu.org; Wed, 12 Jul 2023 03:40:59 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJUT0-0006oM-VZ for qemu-devel@nongnu.org; Wed, 12 Jul 2023 03:40:56 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:40:23 -0700 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.147]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:40:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689147654; x=1720683654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=apMBFuT5bB9quYcKUjAClkvNLolYixzVgGegQnDwoMA=; b=LYuzbswIrjB93YxrINzKSQVi7yOL2/wMTsqMo+8/EAUVilf0DJR90UZK lJ3JOoKkfaAZ+XMMJg/g/ybgHwQCCA15n9ca6ovsQ0e7xsWkAvjgAaiYh xJDaq0jByXTvcusgIGf+RiHaSlZklxmDu6HWNZ+Du9fmAI+hchtcp4bv8 cxA7IGYCupAZ7/n0Mrrn1VrZaOmnfXuWYXqF5ti44xoBpuFWkX6deoY7G UnS8cpMQvg0HIPN0z5nqFxI9EkScCZUTpe8bEALCTRrTBAhboHUmCnbeI mVodTT1sPGH/dMpQyeCaaWBh5/QMLtyHssDlSvkzkXRqf/7ViSSrD/246 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="430953877" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="430953877" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="835024175" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="835024175" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, eric.auger@redhat.com, peterx@redhat.com, jasonwang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [RFC PATCH v4 23/24] vfio/as: Allow the selection of a given iommu backend Date: Wed, 12 Jul 2023 15:25:27 +0800 Message-Id: <20230712072528.275577-24-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712072528.275577-1-zhenzhong.duan@intel.com> References: <20230712072528.275577-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 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=134.134.136.100; envelope-from=zhenzhong.duan@intel.com; helo=mga07.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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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: 1689147806076100001 Content-Type: text/plain; charset="utf-8" From: Eric Auger Now we support two types of iommu backends, let's add the capability to select one of them. This depends on whether an iommufd object has been linked with the vfio-pci device: if the user wants to use the legacy backend, it shall not link the vfio-pci device with any iommufd object: -device vfio-pci,host=3D0000:02:00.0 This is called the legacy mode/backend. If the user wants to use the iommufd backend (/dev/iommu) it shall pass an iommufd object id in the vfio-pci device options: -object iommufd,id=3Diommufd0 -device vfio-pci,host=3D0000:02:00.0,iommufd=3Diommufd0 Note the /dev/iommu device may have been pre-opened by a management tool such as libvirt. This mode is no more considered for the legacy backend. So let's remove the "TODO" comment. Suggested-by: Alex Williamson Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/vfio/pci.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6e49ac5ee9..9aa6c21200 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -43,6 +43,7 @@ #include "migration/blocker.h" #include "migration/qemu-file.h" #include "linux/iommufd.h" +#include "sysemu/iommufd.h" =20 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" =20 @@ -3175,6 +3176,15 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) char uuid[UUID_FMT_LEN]; char *name; =20 +#ifdef CONFIG_IOMMUFD + if (vbasedev->iommufd) { + iommufd_backend_connect(vbasedev->iommufd, errp); + if (*errp) { + return; + } + } +#endif + if (!vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || ~vdev->host.slot || ~vdev->host.function)) { @@ -3470,6 +3480,9 @@ error: static void vfio_instance_finalize(Object *obj) { VFIOPCIDevice *vdev =3D VFIO_PCI(obj); +#ifdef CONFIG_IOMMUFD + VFIODevice *vbasedev =3D &vdev->vbasedev; +#endif =20 vfio_display_finalize(vdev); vfio_bars_finalize(vdev); @@ -3483,6 +3496,11 @@ static void vfio_instance_finalize(Object *obj) * g_free(vdev->igd_opregion); */ vfio_put_device(vdev); +#ifdef CONFIG_IOMMUFD + if (vbasedev->iommufd) { + iommufd_backend_disconnect(vbasedev->iommufd); + } +#endif } =20 static void vfio_exitfn(PCIDevice *pdev) @@ -3609,11 +3627,10 @@ static Property vfio_pci_dev_properties[] =3D { qdev_prop_nv_gpudirect_clique, uint8_t), DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_r= elo, OFF_AUTOPCIBAR_OFF), - /* - * TODO - support passed fds... is this necessary? - * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name), - * DEFINE_PROP_STRING("vfiogroupfd, VFIOPCIDevice, vfiogroupfd_name), - */ +#ifdef CONFIG_IOMMUFD + DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd, + TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), +#endif DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1