From nobody Fri Oct 24 13:10:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151990193354827.746821305128492; Thu, 1 Mar 2018 02:58:53 -0800 (PST) Received: from localhost ([::1]:55553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erLvE-00042m-En for importer@patchew.org; Thu, 01 Mar 2018 05:58:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erLlu-0004HY-Jg for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:49:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erLlt-0007zC-MP for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:49:10 -0500 Received: from mga14.intel.com ([192.55.52.115]:7314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erLls-0007fT-W1 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:49:09 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2018 02:49:08 -0800 Received: from sky-dev.bj.intel.com ([10.238.144.105]) by orsmga003.jf.intel.com with ESMTP; 01 Mar 2018 02:49:06 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,408,1515484800"; d="scan'208";a="31611642" From: "Liu, Yi L" To: qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au Date: Thu, 1 Mar 2018 18:32:00 +0800 Message-Id: <1519900322-30263-11-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519900322-30263-1-git-send-email-yi.l.liu@linux.intel.com> References: <1519900322-30263-1-git-send-email-yi.l.liu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [PATCH v3 10/12] intel_iommu: bind guest pasid table to host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, alex.williamson@redhat.com, "Liu, Yi L" , eric.auger.pro@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For assigned SVA capable devices, needs to bind guest pasid table to host. Intel vIOMMU emulator captures device selective context cache flush, and propagate the guest pasid table pointer to host, in host iommu driver configs the guest pasid table pointer in its translation structure. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 69 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 978f47a..d92a66d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -37,6 +37,10 @@ #include "kvm_i386.h" #include "trace.h" =20 +static bool vtd_device_is_assigned(IntelIOMMUState *s, + PCIBus *bus, + uint16_t devfn); + static void vtd_define_quad(IntelIOMMUState *s, hwaddr addr, uint64_t val, uint64_t wmask, uint64_t w1cmask) { @@ -1255,6 +1259,20 @@ static void vtd_context_global_invalidate(IntelIOMMU= State *s) vtd_iommu_replay_all(s); } =20 +static uint64_t vtd_get_pasid_table_from_context(VTDContextEntry *ce) +{ + uint64_t pasidt_addr =3D ce->hi; + /* TODO: TBD */ + return pasidt_addr; +} + +static uint32_t vtd_get_pasidt_size_from_context(VTDContextEntry *ce) +{ + uint32_t pasidt_size =3D ce->hi; + /* TODO: TBD */ + return pasidt_size; +} + /* Do a context-cache device-selective invalidation. * @func_mask: FM field after shifting */ @@ -1291,6 +1309,11 @@ static void vtd_context_device_invalidate(IntelIOMMU= State *s, if (vtd_bus) { devfn =3D VTD_SID_TO_DEVFN(source_id); for (devfn_it =3D 0; devfn_it < PCI_DEVFN_MAX; ++devfn_it) { + VTDContextEntry ce; + int ret =3D 0; + uint64_t pasidt_addr; + uint32_t size; + vtd_as =3D vtd_bus->dev_as[devfn_it]; if (vtd_as && ((devfn_it & mask) =3D=3D (devfn & mask))) { trace_vtd_inv_desc_cc_device(bus_n, VTD_PCI_SLOT(devfn_it), @@ -1311,6 +1334,26 @@ static void vtd_context_device_invalidate(IntelIOMMU= State *s, * happened. */ memory_region_iommu_replay_all(&vtd_as->iommu); + + /* + * If device is SVA capable assigned device, needs + * to bind guest pasid table to host + * + */ + if (!vtd_device_is_assigned(s, vtd_as->bus, devfn_it)) { + continue; + } + + ret =3D vtd_dev_to_context_entry(s, bus_n, + vtd_as->devfn, &ce); + if (ret) { + continue; + } + + pasidt_addr =3D vtd_get_pasid_table_from_context(&ce); + size =3D vtd_get_pasidt_size_from_context(&ce); + pci_device_sva_bind_pasid_table(vtd_as->bus, devfn_it, + pasidt_addr, size); } } } @@ -3046,6 +3089,32 @@ static int vtd_device_notify(PCIBus *bus, return 0; } =20 +static bool vtd_device_is_assigned(IntelIOMMUState *s, + PCIBus *bus, + uint16_t devfn) +{ + VTDAddressSpace *vtd_as; + IntelIOMMUAssignedDeviceNode *node =3D NULL; + IntelIOMMUAssignedDeviceNode *next_node =3D NULL; + + vtd_as =3D vtd_find_add_as(s, bus, devfn, false); + + if (vtd_as =3D=3D NULL) { + /* + * If vtd_as is NULL, return false for safe + */ + return false; + } + + QLIST_FOREACH_SAFE(node, &s->assigned_device_list, next, next_node) { + if (node->vtd_as =3D=3D vtd_as) { + return true; + } + } + + return false; +} + static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) { X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); --=20 1.9.1