From nobody Mon Feb 9 09:34:47 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.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=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1585542473; cv=none; d=zohomail.com; s=zohoarc; b=AVYlbZntn7TBG6fhYh0j4E5c5d6X96UffeitK7RO/q9PzmFtUFgrEUWdyasufLvV3e/f8NHxOnb/+lGsD+Qtvau55sB8fozcWpkxIK1beLqVRN/57SZocLvwH6K0DdfDBUciqoXRHHtqZHv+vprhE8sIYg6WYOs0Dfe45hEGUBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585542473; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=XOkMs/Rn0nBUajfUtwXPJ7Nt0UmLe4RQ7DilVXdH4NE=; b=Da3hWcZ8xYwPEeDUDO/9++acMo5ENqWBBagOAC3yWue2P3pFH7Q8pbi929z5VHlGd4VYvnvtMHiAM4lrdWT3TVTYvQ0U/Py4fP17zeH4ObFqqARzvpLx5Zqk8MEsqPjSZ0BW6Gzn07ay1XDKxhBUk3yE0wTZ+kibHbSvli/lA8Y= ARC-Authentication-Results: i=1; mx.zohomail.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585542473491333.5220616230705; Sun, 29 Mar 2020 21:27:53 -0700 (PDT) Received: from localhost ([::1]:44756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIm1g-00084x-A3 for importer@patchew.org; Mon, 30 Mar 2020 00:27:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37827) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIltT-0000qq-9z for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIltR-0007rl-Vj for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:23 -0400 Received: from mga07.intel.com ([134.134.136.100]:12573) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIltR-0007o2-Ms for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:21 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2020 21:19:15 -0700 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga001.jf.intel.com with ESMTP; 29 Mar 2020 21:19:15 -0700 IronPort-SDR: 8/XBvJpv9bwcz+pHZSLdvTl42xLWtx8egm9XQ+k8yrGNcOt9f2RGbmYpUW+KwBG4gfw+hidW8+ dcVM2EnRzeMQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: qgNYyD69MoIiDphwOy365E8SrepQAAZKU4KDP1L17wz+CAzwFAlA8joiAPYPSP7bgSTbs7DeF3 d6fgsDdPh2Bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,322,1580803200"; d="scan'208";a="327632039" From: Liu Yi L To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Subject: [PATCH v2 10/22] vfio/pci: set host iommu context to vIOMMU Date: Sun, 29 Mar 2020 21:24:49 -0700 Message-Id: <1585542301-84087-11-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> References: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 134.134.136.100 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, kevin.tian@intel.com, yi.l.liu@intel.com, Yi Sun , kvm@vger.kernel.org, mst@redhat.com, jun.j.tian@intel.com, eric.auger@redhat.com, yi.y.sun@intel.com, Jacob Pan , pbonzini@redhat.com, hao.wu@intel.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For vfio-pci devices, it could use pci_device_set/unset_iommu() to expose host iommu context to vIOMMU emulators. vIOMMU emulators could make use the methods provided by host iommu context. e.g. propagate requests to host iommu. Cc: Kevin Tian Cc: Jacob Pan Cc: Peter Xu Cc: Eric Auger Cc: Yi Sun Cc: David Gibson Cc: Alex Williamson Signed-off-by: Liu Yi L --- hw/vfio/pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5e75a95..c140c88 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2717,6 +2717,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); VFIODevice *vbasedev_iter; VFIOGroup *group; + VFIOContainer *container; char *tmp, *subsys, group_path[PATH_MAX], *group_name; Error *err =3D NULL; ssize_t len; @@ -3028,6 +3029,11 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); =20 + container =3D vdev->vbasedev.group->container; + if (container->iommu_ctx.initialized) { + pci_device_set_iommu_context(pdev, &container->iommu_ctx); + } + return; =20 out_deregister: @@ -3072,9 +3078,16 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); + VFIOContainer *container; =20 vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); + + container =3D vdev->vbasedev.group->container; + if (container->iommu_ctx.initialized) { + pci_device_unset_iommu_context(pdev); + } + pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); if (vdev->irqchip_change_notifier.notify) { kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier); --=20 2.7.4