From nobody Fri Oct 24 13:14:02 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519902465101663.5787891618052; Thu, 1 Mar 2018 03:07:45 -0800 (PST) Received: from localhost ([::1]:55616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erM3l-0002nP-0k for importer@patchew.org; Thu, 01 Mar 2018 06:07:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erLnS-0005gk-I8 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:50:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erLnR-0000E1-I9 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:50:46 -0500 Received: from mga14.intel.com ([192.55.52.115]:7359) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erLnR-00006Y-9Y for qemu-devel@nongnu.org; Thu, 01 Mar 2018 05:50:45 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2018 02:50:44 -0800 Received: from sky-dev.bj.intel.com ([10.238.144.105]) by fmsmga006.fm.intel.com with ESMTP; 01 Mar 2018 02:50:42 -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="208048717" From: "Liu, Yi L" To: qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au Date: Thu, 1 Mar 2018 18:33:32 +0800 Message-Id: <1519900415-30314-10-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519900415-30314-1-git-send-email-yi.l.liu@linux.intel.com> References: <1519900415-30314-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 09/12] intel_iommu: record assigned devices in a list 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: "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, jasowang@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, pbonzini@redhat.com, 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" This patch records assigned devices in a list within Intel vIOMMU emulator. The recorded info can be used to filter out affect assigned devices when Qemu captured guest's cache invalidate request. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 31 ++++++++++++++++++++++++++----- include/hw/i386/intel_iommu.h | 11 ++++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 2fd0a6d..978f47a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2685,7 +2685,10 @@ static const MemoryRegionOps vtd_mem_ir_ops =3D { }, }; =20 -VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devf= n) +VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, + PCIBus *bus, + int devfn, + bool allocate) { uintptr_t key =3D (uintptr_t)bus; VTDBus *vtd_bus =3D g_hash_table_lookup(s->vtd_as_by_busptr, &key); @@ -2704,7 +2707,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, = PCIBus *bus, int devfn) =20 vtd_dev_as =3D vtd_bus->dev_as[devfn]; =20 - if (!vtd_dev_as) { + if (!vtd_dev_as && allocate) { snprintf(name, sizeof(name), "intel_iommu_devfn_%d", devfn); vtd_bus->dev_as[devfn] =3D vtd_dev_as =3D g_malloc0(sizeof(VTDAddr= essSpace)); =20 @@ -3001,7 +3004,7 @@ static AddressSpace *vtd_host_dma_iommu(PCIBus *bus, = void *opaque, int devfn) =20 assert(0 <=3D devfn && devfn < PCI_DEVFN_MAX); =20 - vtd_as =3D vtd_find_add_as(s, bus, devfn); + vtd_as =3D vtd_find_add_as(s, bus, devfn, true); return &vtd_as->as; } =20 @@ -3012,16 +3015,34 @@ static int vtd_device_notify(PCIBus *bus, { IntelIOMMUState *s =3D opaque; VTDAddressSpace *vtd_as; + IntelIOMMUAssignedDeviceNode *node =3D NULL; + IntelIOMMUAssignedDeviceNode *next_node =3D NULL; =20 assert(0 <=3D devfn && devfn < PCI_DEVFN_MAX); =20 - vtd_as =3D vtd_find_add_as(s, bus, devfn); + vtd_as =3D vtd_find_add_as(s, bus, devfn, false); =20 if (vtd_as =3D=3D NULL) { return -1; } =20 - /* TODO: record assigned device in IOMMU Emulator */ + if (type =3D=3D PCI_NTY_DEV_ADD) { + node =3D g_malloc0(sizeof(*node)); + node->vtd_as =3D vtd_as; + QLIST_INSERT_HEAD(&s->assigned_device_list, node, next); + return 0; + } + + QLIST_FOREACH_SAFE(node, &s->assigned_device_list, next, next_node) { + if (node->vtd_as =3D=3D vtd_as) { + if (type =3D=3D PCI_NTY_DEV_DEL) { + QLIST_REMOVE(node, next); + g_free(node); + } + break; + } + } + return 0; } =20 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 1df6fa9..0b6dc32 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -68,6 +68,7 @@ typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress; typedef struct VTDIrq VTDIrq; typedef struct VTD_MSIMessage VTD_MSIMessage; typedef struct IntelIOMMUMRNotifierNode IntelIOMMUMRNotifierNode; +typedef struct IntelIOMMUAssignedDeviceNode IntelIOMMUAssignedDeviceNode; =20 /* Context-Entry */ struct VTDContextEntry { @@ -258,6 +259,11 @@ struct IntelIOMMUMRNotifierNode { QLIST_ENTRY(IntelIOMMUMRNotifierNode) next; }; =20 +struct IntelIOMMUAssignedDeviceNode { + VTDAddressSpace *vtd_as; + QLIST_ENTRY(IntelIOMMUAssignedDeviceNode) next; +}; + /* The iommu (DMAR) device state struct */ struct IntelIOMMUState { X86IOMMUState x86_iommu; @@ -296,6 +302,8 @@ struct IntelIOMMUState { VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed = by bus number */ /* list of registered notifiers */ QLIST_HEAD(, IntelIOMMUMRNotifierNode) notifiers_list; + /* list of assigned devices */ + QLIST_HEAD(, IntelIOMMUAssignedDeviceNode) assigned_device_list; =20 /* interrupt remapping */ bool intr_enabled; /* Whether guest enabled IR */ @@ -310,6 +318,7 @@ struct IntelIOMMUState { /* Find the VTD Address space associated with the given bus pointer, * create a new one if none exists */ -VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devf= n); +VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, + int devfn, bool allocate); =20 #endif --=20 1.9.1