From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202300916346.47208154633665; Wed, 26 Apr 2017 03:25:00 -0700 (PDT) Received: from localhost ([::1]:54039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K83-00039Y-JU for importer@patchew.org; Wed, 26 Apr 2017 06:24:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K6Y-0002BP-NK for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K6T-0001vC-Qq for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:3709) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K6T-0001ur-DQ for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:21 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 26 Apr 2017 03:23:20 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066199" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:31 +0800 Message-Id: <1493201210-14357-2-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.43 Subject: [Qemu-devel] [RFC PATCH 01/20] intel_iommu: add "ecs" option 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" Report ecap.ECS=3D1 to guest by "-deivce intel-iommu, ecs=3Don" in QEMU Cmd Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 5 +++++ hw/i386/intel_iommu_internal.h | 1 + include/hw/i386/intel_iommu.h | 1 + 3 files changed, 7 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 4b7d90d..400d0d1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2409,6 +2409,7 @@ static Property vtd_properties[] =3D { ON_OFF_AUTO_AUTO), DEFINE_PROP_BOOL("x-buggy-eim", IntelIOMMUState, buggy_eim, false), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), + DEFINE_PROP_BOOL("ecs", IntelIOMMUState, ecs, FALSE), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2925,6 +2926,10 @@ static void vtd_init(IntelIOMMUState *s) s->ecap |=3D VTD_ECAP_PT; } =20 + if (s->ecs) { + s->ecap |=3D VTD_ECAP_ECS; + } + if (s->caching_mode) { s->cap |=3D VTD_CAP_CM; } diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index b96884e..ec1bd17 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -190,6 +190,7 @@ #define VTD_ECAP_EIM (1ULL << 4) #define VTD_ECAP_PT (1ULL << 6) #define VTD_ECAP_MHMV (15ULL << 20) +#define VTD_ECAP_ECS (1ULL << 24) =20 /* CAP_REG */ /* (offset >> 4) << 24 */ diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 3e51876..fa5963e 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -266,6 +266,7 @@ struct IntelIOMMUState { uint32_t version; =20 bool caching_mode; /* RO - is cap CM enabled? */ + bool ecs; /* Extended Context Support */ =20 dma_addr_t root; /* Current root table pointer */ bool root_extended; /* Type of root table (extended or not= ) */ --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202437523429.3692009702006; Wed, 26 Apr 2017 03:27:17 -0700 (PDT) Received: from localhost ([::1]:54050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KAG-0005Du-7L for importer@patchew.org; Wed, 26 Apr 2017 06:27:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K6f-0002FW-Aq for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K6a-0001wu-AT for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:41989) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K6Z-0001wP-Sc for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:28 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:23:26 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066220" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:32 +0800 Message-Id: <1493201210-14357-3-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.88 Subject: [Qemu-devel] [RFC PATCH 02/20] intel_iommu: exposed extended-context mode to guest 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" VT-d implementations reporting PASID or PRS fields as "Set", must also report ecap.ECS as "Set". Extended-Context is required for SVM. When ECS is reported, intel iommu driver would initiate extended root entry and extended context entry, and also PASID table if there is any SVM capable device. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 131 +++++++++++++++++++++++++++----------= ---- hw/i386/intel_iommu_internal.h | 9 +++ include/hw/i386/intel_iommu.h | 2 +- 3 files changed, 97 insertions(+), 45 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 400d0d1..bf98fa5 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -497,6 +497,11 @@ static inline bool vtd_root_entry_present(VTDRootEntry= *root) return root->val & VTD_ROOT_ENTRY_P; } =20 +static inline bool vtd_root_entry_upper_present(VTDRootEntry *root) +{ + return root->rsvd & VTD_ROOT_ENTRY_P; +} + static int vtd_get_root_entry(IntelIOMMUState *s, uint8_t index, VTDRootEntry *re) { @@ -509,6 +514,9 @@ static int vtd_get_root_entry(IntelIOMMUState *s, uint8= _t index, return -VTD_FR_ROOT_TABLE_INV; } re->val =3D le64_to_cpu(re->val); + if (s->ecs) { + re->rsvd =3D le64_to_cpu(re->rsvd); + } return 0; } =20 @@ -517,19 +525,30 @@ static inline bool vtd_context_entry_present(VTDConte= xtEntry *context) return context->lo & VTD_CONTEXT_ENTRY_P; } =20 -static int vtd_get_context_entry_from_root(VTDRootEntry *root, uint8_t ind= ex, - VTDContextEntry *ce) +static int vtd_get_context_entry_from_root(IntelIOMMUState *s, + VTDRootEntry *root, uint8_t index, VTDContextEntry *ce) { - dma_addr_t addr; + dma_addr_t addr, ce_size; =20 /* we have checked that root entry is present */ - addr =3D (root->val & VTD_ROOT_ENTRY_CTP) + index * sizeof(*ce); - if (dma_memory_read(&address_space_memory, addr, ce, sizeof(*ce))) { + ce_size =3D (s->ecs) ? (2 * sizeof(*ce)) : (sizeof(*ce)); + addr =3D (s->ecs && (index > 0x7f)) ? + ((root->rsvd & VTD_ROOT_ENTRY_CTP) + (index - 0x80) * ce_size) : + ((root->val & VTD_ROOT_ENTRY_CTP) + index * ce_size); + + if (dma_memory_read(&address_space_memory, addr, ce, ce_size)) { trace_vtd_re_invalid(root->rsvd, root->val); return -VTD_FR_CONTEXT_TABLE_INV; } - ce->lo =3D le64_to_cpu(ce->lo); - ce->hi =3D le64_to_cpu(ce->hi); + + ce[0].lo =3D le64_to_cpu(ce[0].lo); + ce[0].hi =3D le64_to_cpu(ce[0].hi); + + if (s->ecs) { + ce[1].lo =3D le64_to_cpu(ce[1].lo); + ce[1].hi =3D le64_to_cpu(ce[1].hi); + } + return 0; } =20 @@ -595,9 +614,11 @@ static inline uint32_t vtd_get_agaw_from_context_entry= (VTDContextEntry *ce) return 30 + (ce->hi & VTD_CONTEXT_ENTRY_AW) * 9; } =20 -static inline uint32_t vtd_ce_get_type(VTDContextEntry *ce) +static inline uint32_t vtd_ce_get_type(IntelIOMMUState *s, + VTDContextEntry *ce) { - return ce->lo & VTD_CONTEXT_ENTRY_TT; + return s->ecs ? (ce->lo & VTD_CONTEXT_ENTRY_TT) : + (ce->lo & VTD_EXT_CONTEXT_ENTRY_TT); } =20 static inline uint64_t vtd_iova_limit(VTDContextEntry *ce) @@ -842,16 +863,20 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, return ret_fr; } =20 - if (!vtd_root_entry_present(&re)) { + if (!vtd_root_entry_present(&re) || + (s->ecs && (devfn > 0x7f) && (!vtd_root_entry_upper_present(&re)))= ) { /* Not error - it's okay we don't have root entry. */ trace_vtd_re_not_present(bus_num); return -VTD_FR_ROOT_ENTRY_P; - } else if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD)) { - trace_vtd_re_invalid(re.rsvd, re.val); - return -VTD_FR_ROOT_ENTRY_RSVD; + } + if ((s->ecs && (devfn > 0x7f) && (re.rsvd & VTD_ROOT_ENTRY_RSVD)) || + (s->ecs && (devfn < 0x80) && (re.val & VTD_ROOT_ENTRY_RSVD)) || + ((!s->ecs) && (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD)))) { + trace_vtd_re_invalid(re.rsvd, re.val); + return -VTD_FR_ROOT_ENTRY_RSVD; } =20 - ret_fr =3D vtd_get_context_entry_from_root(&re, devfn, ce); + ret_fr =3D vtd_get_context_entry_from_root(s, &re, devfn, ce); if (ret_fr) { return ret_fr; } @@ -860,21 +885,36 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, /* Not error - it's okay we don't have context entry. */ trace_vtd_ce_not_present(bus_num, devfn); return -VTD_FR_CONTEXT_ENTRY_P; - } else if ((ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI) || - (ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO)) { + } + + /* Check Reserved bits in context-entry */ + if ((!s->ecs && (ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI)) || + (!s->ecs && (ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO)) || + (s->ecs && (ce[0].lo & VTD_EXT_CONTEXT_ENTRY_RSVD_LOW0)) || + (s->ecs && (ce[0].hi & VTD_EXT_CONTEXT_ENTRY_RSVD_HIGH0)) || + (s->ecs && (ce[1].lo & VTD_EXT_CONTEXT_ENTRY_RSVD_LOW1))) { trace_vtd_ce_invalid(ce->hi, ce->lo); return -VTD_FR_CONTEXT_ENTRY_RSVD; } + /* Check if the programming of context-entry is valid */ if (!vtd_is_level_supported(s, vtd_get_level_from_context_entry(ce))) { trace_vtd_ce_invalid(ce->hi, ce->lo); return -VTD_FR_CONTEXT_ENTRY_INV; } else { - switch (vtd_ce_get_type(ce)) { + switch (vtd_ce_get_type(s, ce)) { case VTD_CONTEXT_TT_MULTI_LEVEL: /* fall through */ case VTD_CONTEXT_TT_DEV_IOTLB: break; + case VTD_EXT_CONTEXT_TT_NO_DEV_IOTLB: + case VTD_EXT_CONTEXT_TT_DEV_IOTLB: + if (s->ecs) { + break; + } else { + trace_vtd_ce_invalid(ce->hi, ce->lo); + return -VTD_FR_CONTEXT_ENTRY_INV; + } case VTD_CONTEXT_TT_PASS_THROUGH: if (s->ecap & VTD_ECAP_PT) { break; @@ -894,18 +934,18 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, static int vtd_dev_get_trans_type(VTDAddressSpace *as) { IntelIOMMUState *s; - VTDContextEntry ce; + VTDContextEntry ce[2]; int ret; =20 s =3D as->iommu_state; =20 ret =3D vtd_dev_to_context_entry(s, pci_bus_num(as->bus), - as->devfn, &ce); + as->devfn, &ce[0]); if (ret) { return ret; } =20 - return vtd_ce_get_type(&ce); + return vtd_ce_get_type(s, &ce[0]); } =20 static bool vtd_dev_pt_enabled(VTDAddressSpace *as) @@ -1008,7 +1048,7 @@ static void vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, IOMMUTLBEntry *entry) { IntelIOMMUState *s =3D vtd_as->iommu_state; - VTDContextEntry ce; + VTDContextEntry ce[2]; uint8_t bus_num =3D pci_bus_num(bus); VTDContextCacheEntry *cc_entry =3D &vtd_as->context_cache_entry; uint64_t slpte, page_mask; @@ -1039,14 +1079,16 @@ static void vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, } /* Try to fetch context-entry from cache first */ if (cc_entry->context_cache_gen =3D=3D s->context_cache_gen) { - trace_vtd_iotlb_cc_hit(bus_num, devfn, cc_entry->context_entry.hi, - cc_entry->context_entry.lo, + trace_vtd_iotlb_cc_hit(bus_num, devfn, + cc_entry->context_entry[0].hi, + cc_entry->context_entry[0].lo, cc_entry->context_cache_gen); - ce =3D cc_entry->context_entry; - is_fpd_set =3D ce.lo & VTD_CONTEXT_ENTRY_FPD; + ce[0] =3D cc_entry->context_entry[0]; + ce[1] =3D cc_entry->context_entry[1]; + is_fpd_set =3D ce[0].lo & VTD_CONTEXT_ENTRY_FPD; } else { - ret_fr =3D vtd_dev_to_context_entry(s, bus_num, devfn, &ce); - is_fpd_set =3D ce.lo & VTD_CONTEXT_ENTRY_FPD; + ret_fr =3D vtd_dev_to_context_entry(s, bus_num, devfn, &ce[0]); + is_fpd_set =3D ce[0].lo & VTD_CONTEXT_ENTRY_FPD; if (ret_fr) { ret_fr =3D -ret_fr; if (is_fpd_set && vtd_is_qualified_fault(ret_fr)) { @@ -1057,10 +1099,11 @@ static void vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, return; } /* Update context-cache */ - trace_vtd_iotlb_cc_update(bus_num, devfn, ce.hi, ce.lo, + trace_vtd_iotlb_cc_update(bus_num, devfn, ce[0].hi, ce[0].lo, cc_entry->context_cache_gen, s->context_cache_gen); - cc_entry->context_entry =3D ce; + cc_entry->context_entry[0] =3D ce[0]; + cc_entry->context_entry[1] =3D ce[1]; cc_entry->context_cache_gen =3D s->context_cache_gen; } =20 @@ -1068,7 +1111,7 @@ static void vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, * We don't need to translate for pass-through context entries. * Also, let's ignore IOTLB caching as well for PT devices. */ - if (vtd_ce_get_type(&ce) =3D=3D VTD_CONTEXT_TT_PASS_THROUGH) { + if (vtd_ce_get_type(s, &ce[0]) =3D=3D VTD_CONTEXT_TT_PASS_THROUGH) { entry->translated_addr =3D entry->iova; entry->addr_mask =3D VTD_PAGE_SIZE - 1; entry->perm =3D IOMMU_RW; @@ -1076,7 +1119,7 @@ static void vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, return; } =20 - ret_fr =3D vtd_iova_to_slpte(&ce, addr, is_write, &slpte, &level, + ret_fr =3D vtd_iova_to_slpte(&ce[0], addr, is_write, &slpte, &level, &reads, &writes); if (ret_fr) { ret_fr =3D -ret_fr; @@ -1089,7 +1132,7 @@ static void vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, } =20 page_mask =3D vtd_slpt_level_page_mask(level); - vtd_update_iotlb(s, source_id, VTD_CONTEXT_ENTRY_DID(ce.hi), addr, slp= te, + vtd_update_iotlb(s, source_id, VTD_CONTEXT_ENTRY_DID(ce[0].hi), addr, = slpte, reads, writes, level); out: entry->iova =3D addr & page_mask; @@ -1283,7 +1326,7 @@ static void vtd_iotlb_global_invalidate(IntelIOMMUSta= te *s) static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domai= n_id) { IntelIOMMUNotifierNode *node; - VTDContextEntry ce; + VTDContextEntry ce[2]; VTDAddressSpace *vtd_as; =20 g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_domain, @@ -1292,8 +1335,8 @@ static void vtd_iotlb_domain_invalidate(IntelIOMMUSta= te *s, uint16_t domain_id) QLIST_FOREACH(node, &s->notifiers_list, next) { vtd_as =3D node->vtd_as; if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), - vtd_as->devfn, &ce) && - domain_id =3D=3D VTD_CONTEXT_ENTRY_DID(ce.hi)) { + vtd_as->devfn, &ce[0]) && + domain_id =3D=3D VTD_CONTEXT_ENTRY_DID(ce[0].hi)) { memory_region_iommu_replay_all(&vtd_as->iommu); } } @@ -1311,15 +1354,15 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, uint8_t am) { IntelIOMMUNotifierNode *node; - VTDContextEntry ce; + VTDContextEntry ce[2]; int ret; =20 QLIST_FOREACH(node, &(s->notifiers_list), next) { VTDAddressSpace *vtd_as =3D node->vtd_as; ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), - vtd_as->devfn, &ce); - if (!ret && domain_id =3D=3D VTD_CONTEXT_ENTRY_DID(ce.hi)) { - vtd_page_walk(&ce, addr, addr + (1 << am) * VTD_PAGE_SIZE, + vtd_as->devfn, &ce[0]); + if (!ret && domain_id =3D=3D VTD_CONTEXT_ENTRY_DID(ce[0].hi)) { + vtd_page_walk(&ce[0], addr, addr + (1 << am) * VTD_PAGE_SIZE, vtd_page_invalidate_notify_hook, (void *)&vtd_as->iommu, true); } @@ -2858,7 +2901,7 @@ static void vtd_iommu_replay(MemoryRegion *mr, IOMMUN= otifier *n) VTDAddressSpace *vtd_as =3D container_of(mr, VTDAddressSpace, iommu); IntelIOMMUState *s =3D vtd_as->iommu_state; uint8_t bus_n =3D pci_bus_num(vtd_as->bus); - VTDContextEntry ce; + VTDContextEntry ce[2]; =20 /* * The replay can be triggered by either a invalidation or a newly @@ -2867,12 +2910,12 @@ static void vtd_iommu_replay(MemoryRegion *mr, IOMM= UNotifier *n) */ vtd_address_space_unmap(vtd_as, n); =20 - if (vtd_dev_to_context_entry(s, bus_n, vtd_as->devfn, &ce) =3D=3D 0) { + if (vtd_dev_to_context_entry(s, bus_n, vtd_as->devfn, &ce[0]) =3D=3D 0= ) { trace_vtd_replay_ce_valid(bus_n, PCI_SLOT(vtd_as->devfn), PCI_FUNC(vtd_as->devfn), - VTD_CONTEXT_ENTRY_DID(ce.hi), - ce.hi, ce.lo); - vtd_page_walk(&ce, 0, ~0ULL, vtd_replay_hook, (void *)n, false); + VTD_CONTEXT_ENTRY_DID(ce[0].hi), + ce[0].hi, ce[0].lo); + vtd_page_walk(&ce[0], 0, ~0ULL, vtd_replay_hook, (void *)n, false); } else { trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn), PCI_FUNC(vtd_as->devfn)); diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index ec1bd17..71a1c1e 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -425,6 +425,15 @@ typedef struct VTDRootEntry VTDRootEntry; =20 #define VTD_CONTEXT_ENTRY_NR (VTD_PAGE_SIZE / sizeof(VTDContextEntr= y)) =20 +/* Definition for Extended Context */ +#define VTD_EXT_CONTEXT_ENTRY_RSVD_LOW0 (~(VTD_HAW_MASK)) +#define VTD_EXT_CONTEXT_ENTRY_RSVD_HIGH0 0xF0000000ULL +#define VTD_EXT_CONTEXT_ENTRY_RSVD_LOW1 ((~(VTD_HAW_MASK)) | 0xFF0ULL) +#define VTD_EXT_CONTEXT_ENTRY_RSVD_HIGH1 ((~(VTD_HAW_MASK)) | 0xFFFULL) +#define VTD_EXT_CONTEXT_ENTRY_TT (7ULL << 2) +#define VTD_EXT_CONTEXT_TT_NO_DEV_IOTLB (4ULL << 2) +#define VTD_EXT_CONTEXT_TT_DEV_IOTLB (5ULL << 2) + /* Paging Structure common */ #define VTD_SL_PT_PAGE_SIZE_MASK (1ULL << 7) /* Bits to decide the offset for each level */ diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index fa5963e..ae21fe5 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -76,7 +76,7 @@ struct VTDContextCacheEntry { * context_cache_gen!=3DIntelIOMMUState.context_cache_gen */ uint32_t context_cache_gen; - struct VTDContextEntry context_entry; + struct VTDContextEntry context_entry[2]; }; =20 struct VTDAddressSpace { --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202730803178.50406882610082; Wed, 26 Apr 2017 03:32:10 -0700 (PDT) Received: from localhost ([::1]:54077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KEz-0001Nn-DM for importer@patchew.org; Wed, 26 Apr 2017 06:32:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K6l-0002Jv-8M for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K6g-00020D-Ap for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:39 -0400 Received: from mga14.intel.com ([192.55.52.115]:34289) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K6g-0001zT-2N for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:34 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:23:32 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066272" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:33 +0800 Message-Id: <1493201210-14357-4-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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] [RFC PATCH 03/20] intel_iommu: add "svm" option 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" Expose "Shared Virtual Memory" to guest by using "svm" option. Also use "svm" to expose SVM related capabilities to guest. e.g. "-device intel-iommu, svm=3Don" Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 10 ++++++++++ hw/i386/intel_iommu_internal.h | 5 +++++ include/hw/i386/intel_iommu.h | 1 + 3 files changed, 16 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bf98fa5..ba1e7eb 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2453,6 +2453,7 @@ static Property vtd_properties[] =3D { DEFINE_PROP_BOOL("x-buggy-eim", IntelIOMMUState, buggy_eim, false), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), DEFINE_PROP_BOOL("ecs", IntelIOMMUState, ecs, FALSE), + DEFINE_PROP_BOOL("svm", IntelIOMMUState, svm, FALSE), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2973,6 +2974,15 @@ static void vtd_init(IntelIOMMUState *s) s->ecap |=3D VTD_ECAP_ECS; } =20 + if (s->svm) { + if (!s->ecs || !x86_iommu->pt_supported || !s->caching_mode) { + error_report("Need to set ecs, pt, caching-mode for svm"); + exit(1); + } + s->cap |=3D VTD_CAP_DWD | VTD_CAP_DRD; + s->ecap |=3D VTD_ECAP_PRS | VTD_ECAP_PTS | VTD_ECAP_PASID28; + } + if (s->caching_mode) { s->cap |=3D VTD_CAP_CM; } diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 71a1c1e..f2a7d12 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -191,6 +191,9 @@ #define VTD_ECAP_PT (1ULL << 6) #define VTD_ECAP_MHMV (15ULL << 20) #define VTD_ECAP_ECS (1ULL << 24) +#define VTD_ECAP_PASID28 (1ULL << 28) +#define VTD_ECAP_PRS (1ULL << 29) +#define VTD_ECAP_PTS (0xeULL << 35) =20 /* CAP_REG */ /* (offset >> 4) << 24 */ @@ -207,6 +210,8 @@ #define VTD_CAP_PSI (1ULL << 39) #define VTD_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) #define VTD_CAP_CM (1ULL << 7) +#define VTD_CAP_DWD (1ULL << 54) +#define VTD_CAP_DRD (1ULL << 55) =20 /* Supported Adjusted Guest Address Widths */ #define VTD_CAP_SAGAW_SHIFT 8 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index ae21fe5..8981615 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -267,6 +267,7 @@ struct IntelIOMMUState { =20 bool caching_mode; /* RO - is cap CM enabled? */ bool ecs; /* Extended Context Support */ + bool svm; /* Shared Virtual Memory */ =20 dma_addr_t root; /* Current root table pointer */ bool root_extended; /* Type of root table (extended or not= ) */ --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202578603383.0988126478901; Wed, 26 Apr 2017 03:29:38 -0700 (PDT) Received: from localhost ([::1]:54058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KCX-0007fq-Bz for importer@patchew.org; Wed, 26 Apr 2017 06:29:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K6l-0002Jw-8n for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K6j-00021n-2x for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:39 -0400 Received: from mga14.intel.com ([192.55.52.115]:34289) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K6i-0001zT-Pl for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:37 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:23:36 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066301" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:34 +0800 Message-Id: <1493201210-14357-5-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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] [RFC PATCH 04/20] Memory: modify parameter in IOMMUNotifier func 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 modifies parameter of IOMMUNotifier, use "void *data" instead of "IOMMUTLBEntry*". This is to extend it to support notifiers other than MAP/UNMAP. Signed-off-by: Liu, Yi L --- hw/vfio/common.c | 3 ++- hw/virtio/vhost.c | 3 ++- include/exec/memory.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 6b33b9f..14473f1 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -332,10 +332,11 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void= **vaddr, return true; } =20 -static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) +static void vfio_iommu_map_notify(IOMMUNotifier *n, void *data) { VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); VFIOContainer *container =3D giommu->container; + IOMMUTLBEntry *iotlb =3D (IOMMUTLBEntry *)data; hwaddr iova =3D iotlb->iova + giommu->iommu_offset; bool read_only; void *vaddr; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ccf8b2e..fd20fd0 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1161,9 +1161,10 @@ static void vhost_virtqueue_cleanup(struct vhost_vir= tqueue *vq) event_notifier_cleanup(&vq->masked_notifier); } =20 -static void vhost_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotl= b) +static void vhost_iommu_unmap_notify(IOMMUNotifier *n, void *data) { struct vhost_dev *hdev =3D container_of(n, struct vhost_dev, n); + IOMMUTLBEntry *iotlb =3D (IOMMUTLBEntry *)data; =20 if (hdev->vhost_ops->vhost_invalidate_device_iotlb(hdev, iotlb->iova, diff --git a/include/exec/memory.h b/include/exec/memory.h index 267f399..1faca3b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -81,7 +81,7 @@ typedef enum { =20 struct IOMMUNotifier; typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier, - IOMMUTLBEntry *data); + void *data); =20 struct IOMMUNotifier { IOMMUNotify notify; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202339057752.884641897914; Wed, 26 Apr 2017 03:25:39 -0700 (PDT) Received: from localhost ([::1]:54045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K8e-0003ls-3W for importer@patchew.org; Wed, 26 Apr 2017 06:25:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K70-0002WX-R9 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K6v-00029A-UC for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:12157) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K6v-000287-L4 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:49 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:23:48 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066337" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:35 +0800 Message-Id: <1493201210-14357-6-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.93 Subject: [Qemu-devel] [RFC PATCH 05/20] VFIO: add new IOCTL for svm bind tasks 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" Add a new IOCTL cmd VFIO_IOMMU_SVM_BIND_TASK attached on container->fd. On VT-d, this IOCTL cmd would be used to link the guest PASID page table to host. While for other vendors, it may also be used to support other kind of SVM bind request. Previously, there is a discussion on it with ARM engineer. It can be found by the link below. This IOCTL cmd may support SVM PASID bind request from userspace driver, or page table(cr3) bind request from guest. These SVM bind requests would be supported by adding different flags. e.g. VFIO_SVM_BIND_PASID is added to support PASID bind from userspace driver, VFIO_SVM_BIND_PGTABLE is added to support page table bind from guest. https://patchwork.kernel.org/patch/9594231/ Signed-off-by: Liu, Yi L --- linux-headers/linux/vfio.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 759b850..9848d63 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -537,6 +537,24 @@ struct vfio_iommu_type1_dma_unmap { #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) =20 +/* IOCTL for Shared Virtual Memory Bind */ +struct vfio_device_svm { + __u32 argsz; +#define VFIO_SVM_BIND_PASIDTBL (1 << 0) /* Bind PASID Table */ +#define VFIO_SVM_BIND_PASID (1 << 1) /* Bind PASID from userspace driver */ +#define VFIO_SVM_BIND_PGTABLE (1 << 2) /* Bind guest mmu page table */ + __u32 flags; + __u32 length; + __u8 data[]; +}; + +#define VFIO_SVM_TYPE_MASK (VFIO_SVM_BIND_PASIDTBL | \ + VFIO_SVM_BIND_PASID | \ + VFIO_SVM_BIND_PGTABLE ) + +#define VFIO_IOMMU_SVM_BIND_TASK _IO(VFIO_TYPE, VFIO_BASE + 22) + + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ =20 /* --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202380263101.40472087311673; Wed, 26 Apr 2017 03:26:20 -0700 (PDT) Received: from localhost ([::1]:54048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K9K-0004Oh-VP for importer@patchew.org; Wed, 26 Apr 2017 06:26:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K76-0002c9-5U for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K71-0002D1-3z for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:00 -0400 Received: from mga05.intel.com ([192.55.52.43]:18203) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K70-0002Bs-Pm for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:23:55 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 26 Apr 2017 03:23:53 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066349" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:36 +0800 Message-Id: <1493201210-14357-7-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.43 Subject: [Qemu-devel] [RFC PATCH 06/20] VFIO: add new notifier for binding PASID table 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 includes the following items: * add vfio_register_notifier() for vfio notifier initialization * add new notifier flag IOMMU_NOTIFIER_SVM_PASIDT_BIND =3D 0x4 * add vfio_iommu_bind_pasid_tbl_notify() to link guest pasid table to host This patch doesn't register new notifier in vfio memory region listener region_add callback. The reason is as below: On VT-d, when virtual intel_iommu is exposed to guest, the vfio memory listener listens to address_space_memory. When guest Intel IOMMU driver enables address translation, vfio memory listener may switch to listen to vtd_address_space. But there is special case. If virtual intel_iommu reports ecap.PT=3D1 to guest and meanwhile guest Intel IOMMU driver sets "pt" mode for the assigned, vfio memory listener would keep listen to address_space_memory to make sure there is GPA->HPA mapping in pIOMMU. Thus region_add would not be triggered. While for the newly added notifier, it requires to be registered once virtual intel_iommu is exposed to guest. Signed-off-by: Liu, Yi L --- hw/vfio/common.c | 37 +++++++++++++++++++++++------- hw/vfio/pci.c | 53 +++++++++++++++++++++++++++++++++++++++= +++- include/exec/memory.h | 8 +++++++ include/hw/vfio/vfio-common.h | 5 ++++ 4 files changed, 94 insertions(+), 9 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 14473f1..e270255 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -294,6 +294,25 @@ static bool vfio_listener_skipped_section(MemoryRegion= Section *section) section->offset_within_address_space & (1ULL << 63); } =20 +VFIOGuestIOMMU *vfio_register_notifier(VFIOContainer *container, + MemoryRegion *mr, + hwaddr offset, + IOMMUNotifier *n) +{ + VFIOGuestIOMMU *giommu; + + giommu =3D g_malloc0(sizeof(*giommu)); + giommu->iommu =3D mr; + giommu->iommu_offset =3D offset; + giommu->container =3D container; + giommu->n =3D *n; + + QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); + memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); + + return giommu; +} + /* Called with rcu_read_lock held. */ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr, bool *read_only) @@ -466,6 +485,8 @@ static void vfio_listener_region_add(MemoryListener *li= stener, =20 if (memory_region_is_iommu(section->mr)) { VFIOGuestIOMMU *giommu; + IOMMUNotifier n; + hwaddr iommu_offset; =20 trace_vfio_listener_region_add_iommu(iova, end); /* @@ -474,21 +495,21 @@ static void vfio_listener_region_add(MemoryListener *= listener, * would be the right place to wire that up (tell the KVM * device emulation the VFIO iommu handles to use). */ - giommu =3D g_malloc0(sizeof(*giommu)); - giommu->iommu =3D section->mr; - giommu->iommu_offset =3D section->offset_within_address_space - - section->offset_within_region; - giommu->container =3D container; + iommu_offset =3D section->offset_within_address_space - + section->offset_within_region; llend =3D int128_add(int128_make64(section->offset_within_region), section->size); llend =3D int128_sub(llend, int128_one()); - iommu_notifier_init(&giommu->n, vfio_iommu_map_notify, + iommu_notifier_init(&n, vfio_iommu_map_notify, IOMMU_NOTIFIER_ALL, section->offset_within_region, int128_get64(llend)); - QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); =20 - memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); + giommu =3D vfio_register_notifier(container, + section->mr, + iommu_offset, + &n); + memory_region_iommu_replay(giommu->iommu, &giommu->n, false); =20 return; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 332f41d..9e13472 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2594,11 +2594,38 @@ static void vfio_unregister_req_notifier(VFIOPCIDev= ice *vdev) vdev->req_enabled =3D false; } =20 +static void vfio_iommu_bind_pasid_tbl_notify(IOMMUNotifier *n, void *data) +{ + VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); + VFIOContainer *container =3D giommu->container; + IOMMUNotifierData *iommu_data =3D (IOMMUNotifierData *) data; + struct vfio_device_svm *vfio_svm; + int argsz; + + argsz =3D sizeof(*vfio_svm) + iommu_data->payload_size; + vfio_svm =3D g_malloc0(argsz); + vfio_svm->argsz =3D argsz; + vfio_svm->flags =3D VFIO_SVM_BIND_PASIDTBL; + vfio_svm->length =3D iommu_data->payload_size; + memcpy(&vfio_svm->data, iommu_data->payload, + iommu_data->payload_size); + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_SVM_BIND_TASK, vfio_svm) !=3D 0) { + error_report("vfio_iommu_bind_pasid_tbl_notify:" + " bind failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(vfio_svm); +} + static void vfio_realize(PCIDevice *pdev, Error **errp) { VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); VFIODevice *vbasedev_iter; VFIOGroup *group; + AddressSpace *as; + MemoryRegion *subregion; char *tmp, group_path[PATH_MAX], *group_name; Error *err =3D NULL; ssize_t len; @@ -2650,7 +2677,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 trace_vfio_realize(vdev->vbasedev.name, groupid); =20 - group =3D vfio_get_group(groupid, pci_device_iommu_address_space(pdev)= , errp); + as =3D pci_device_iommu_address_space(pdev); + group =3D vfio_get_group(groupid, as, errp); if (!group) { goto error; } @@ -2833,6 +2861,29 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); =20 + /* Check if vIOMMU exists */ + QTAILQ_FOREACH(subregion, &as->root->subregions, subregions_link) { + if (memory_region_is_iommu(subregion)) { + IOMMUNotifier n1; + + /* + FIXME: current iommu notifier is actually designed for + IOMMUTLB MAP/UNMAP. However, vIOMMU emulator may need + notifiers other than MAP/UNMAP, so it'll be better to + split the non-IOMMUTLB notifier from the current IOMMUTLB + notifier framewrok. + */ + iommu_notifier_init(&n1, vfio_iommu_bind_pasid_tbl_notify, + IOMMU_NOTIFIER_SVM_PASIDT_BIND, + 0, + 0); + vfio_register_notifier(group->container, + subregion, + 0, + &n1); + } + } + return; =20 out_teardown: diff --git a/include/exec/memory.h b/include/exec/memory.h index 1faca3b..d2f24cc 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -65,6 +65,12 @@ struct IOMMUTLBEntry { IOMMUAccessFlags perm; }; =20 +struct IOMMUNotifierData { + uint64_t payload_size; + uint8_t *payload; +}; +typedef struct IOMMUNotifierData IOMMUNotifierData; + /* * Bitmap for different IOMMUNotifier capabilities. Each notifier can * register with one or multiple IOMMU Notifier capability bit(s). @@ -75,6 +81,8 @@ typedef enum { IOMMU_NOTIFIER_UNMAP =3D 0x1, /* Notify entry changes (newly created entries) */ IOMMU_NOTIFIER_MAP =3D 0x2, + /* Notify PASID Table Binding */ + IOMMU_NOTIFIER_SVM_PASIDT_BIND =3D 0x4, } IOMMUNotifierFlag; =20 #define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index c582de1..195795c 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -160,6 +160,11 @@ void vfio_put_group(VFIOGroup *group); int vfio_get_device(VFIOGroup *group, const char *name, VFIODevice *vbasedev, Error **errp); =20 +VFIOGuestIOMMU *vfio_register_notifier(VFIOContainer *container, + MemoryRegion *mr, + hwaddr offset, + IOMMUNotifier *n); + extern const MemoryRegionOps vfio_region_ops; extern QLIST_HEAD(vfio_group_head, VFIOGroup) vfio_group_list; extern QLIST_HEAD(vfio_as_head, VFIOAddressSpace) vfio_address_spaces; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202443411775.8479192607798; Wed, 26 Apr 2017 03:27:23 -0700 (PDT) Received: from localhost ([::1]:54051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KAM-0005Mi-9v for importer@patchew.org; Wed, 26 Apr 2017 06:27:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7A-0002g6-Qs for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K76-0002JK-Eq for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:04 -0400 Received: from mga06.intel.com ([134.134.136.31]:52653) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K76-0002I6-4f for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:00 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP; 26 Apr 2017 03:23:58 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066360" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:37 +0800 Message-Id: <1493201210-14357-8-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.31 Subject: [Qemu-devel] [RFC PATCH 07/20] VFIO: check notifier flag in region_del() 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 adds flag check when unregistering MAP/UNMAP notifier in region_del. MAP/UNMAP notifier would be unregistered when iommu memory region is deleted. This is to avoid unregistering other notifiers. Peter Xu's intel_iommu enhancement series has introduced dynamic switch of IOMMU region. If an assigned device switches to use "pt", the IOMMU region would be deleted, thus the MAP/UNMAP notifier would be unregistered. While for some cases, the other notifiers may still wanted. e.g. if a user decides to use vSVM for the assigned device after the switch, then the pasid table bind notifier is needed. The newly added pasid table bind notifier would be unregistered in the vfio_disconnect_container(). The link below would direct you to Peter's dynamic switch patch. https://www.mail-archive.com/qemu-devel@nongnu.org/msg444462.html Signed-off-by: Liu, Yi L --- hw/vfio/common.c | 5 +++-- include/exec/memory.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e270255..719de61 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -501,7 +501,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, section->size); llend =3D int128_sub(llend, int128_one()); iommu_notifier_init(&n, vfio_iommu_map_notify, - IOMMU_NOTIFIER_ALL, + IOMMU_NOTIFIER_MAP_UNMAP, section->offset_within_region, int128_get64(llend)); =20 @@ -578,7 +578,8 @@ static void vfio_listener_region_del(MemoryListener *li= stener, =20 QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { if (giommu->iommu =3D=3D section->mr && - giommu->n.start =3D=3D section->offset_within_region) { + giommu->n.start =3D=3D section->offset_within_region && + giommu->n.notifier_flags & IOMMU_NOTIFIER_MAP_UNMAP) { memory_region_unregister_iommu_notifier(giommu->iommu, &giommu->n); QLIST_REMOVE(giommu, giommu_next); diff --git a/include/exec/memory.h b/include/exec/memory.h index d2f24cc..7bd13ab 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -85,7 +85,7 @@ typedef enum { IOMMU_NOTIFIER_SVM_PASIDT_BIND =3D 0x4, } IOMMUNotifierFlag; =20 -#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) +#define IOMMU_NOTIFIER_MAP_UNMAP (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMA= P) =20 struct IOMMUNotifier; typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier, --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202478533618.8843759462876; Wed, 26 Apr 2017 03:27:58 -0700 (PDT) Received: from localhost ([::1]:54053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KAv-00065U-Cc for importer@patchew.org; Wed, 26 Apr 2017 06:27:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7G-0002kW-DJ for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7B-0002NQ-HH for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:10 -0400 Received: from mga03.intel.com ([134.134.136.65]:30501) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7B-0002MA-7h for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:05 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:03 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066381" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:38 +0800 Message-Id: <1493201210-14357-9-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.65 Subject: [Qemu-devel] [RFC PATCH 08/20] Memory: add notifier flag check in memory_replay() 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" memory_region_iommu_replay is used to do replay with MAP/UNMAP notifier. However, other notifiers may be passed in, so add a check against notifier flag to avoid potential error. e.g. memory_region_iommu_replay_all loops all registered notifiers, may just pass in wrong notifier. Signed-off-by: Liu, Yi L --- memory.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/memory.c b/memory.c index 9c253cc..0728e62 100644 --- a/memory.c +++ b/memory.c @@ -1630,6 +1630,14 @@ void memory_region_iommu_replay(MemoryRegion *mr, IO= MMUNotifier *n, hwaddr addr, granularity; IOMMUTLBEntry iotlb; =20 + if (!(n->notifier_flags & IOMMU_NOTIFIER_MAP_UNMAP)) { + /* If notifier flag is not IOMMU_NOTIFIER_UNMAP or + * IOMMU_NOTIFIER_MAP, return. This check is necessary + * as there is notifier other than MAP/UNMAP + */ + return; + } + /* If the IOMMU has its own replay callback, override */ if (mr->iommu_ops->replay) { mr->iommu_ops->replay(mr, n); --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202893916848.9850283339499; Wed, 26 Apr 2017 03:34:53 -0700 (PDT) Received: from localhost ([::1]:54085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KHc-0003nd-IY for importer@patchew.org; Wed, 26 Apr 2017 06:34:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7G-0002kY-Ds for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7F-0002QX-0O for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:10 -0400 Received: from mga03.intel.com ([134.134.136.65]:30501) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7E-0002MA-M4 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:08 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:08 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066392" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:39 +0800 Message-Id: <1493201210-14357-10-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.65 Subject: [Qemu-devel] [RFC PATCH 09/20] Memory: introduce iommu_ops->record_device 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" With vIOMMU exposed to guest, vIOMMU emulator needs to do translation between host and guest. e.g. a device-selective TLB flush, vIOMMU emulator needs to replace guest SID with host SID so that to limit the invalidation. This patch introduces a new callback iommu_ops->record_device() to notify vIOMMU emulator to record necessary information about the assigned device. Signed-off-by: Liu, Yi L --- include/exec/memory.h | 11 +++++++++++ memory.c | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 7bd13ab..49087ef 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -203,6 +203,8 @@ struct MemoryRegionIOMMUOps { IOMMUNotifierFlag new_flags); /* Set this up to provide customized IOMMU replay function */ void (*replay)(MemoryRegion *iommu, IOMMUNotifier *notifier); + void (*record_device)(MemoryRegion *iommu, + void *device_info); }; =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -708,6 +710,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, void memory_region_notify_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry); =20 +/* + * memory_region_notify_device_record: notify IOMMU to record assign + * device. + * @mr: the memory region to notify + * @ device_info: device information + */ +void memory_region_notify_device_record(MemoryRegion *mr, + void *info); + /** * memory_region_register_iommu_notifier: register a notifier for changes = to * IOMMU translation entries. diff --git a/memory.c b/memory.c index 0728e62..45ef069 100644 --- a/memory.c +++ b/memory.c @@ -1600,6 +1600,18 @@ static void memory_region_update_iommu_notify_flags(= MemoryRegion *mr) mr->iommu_notify_flags =3D flags; } =20 +void memory_region_notify_device_record(MemoryRegion *mr, + void *info) +{ + assert(memory_region_is_iommu(mr)); + + if (mr->iommu_ops->record_device) { + mr->iommu_ops->record_device(mr, info); + } + + return; +} + void memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n) { --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493203047693588.2405865585321; Wed, 26 Apr 2017 03:37:27 -0700 (PDT) Received: from localhost ([::1]:54108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KK6-0005v6-Aw for importer@patchew.org; Wed, 26 Apr 2017 06:37:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7Q-0002tf-NL for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7L-0002U7-P4 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:20 -0400 Received: from mga11.intel.com ([192.55.52.93]:23414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7L-0002Tv-Gs for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:15 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:14 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066404" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:40 +0800 Message-Id: <1493201210-14357-11-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.93 Subject: [Qemu-devel] [RFC PATCH 10/20] VFIO: notify vIOMMU emulator when device is assigned 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" With vIOMMU exposed to guest, notify vIOMMU emulator to record information of this assigned device. This patch adds iommu_ops->record_device to record the host bus/slot/function for this device. In future, it can be extended to other info which is needed. Signed-off-by: Liu, Yi L --- hw/vfio/pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 9e13472..a1e6942 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2881,6 +2881,10 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) subregion, 0, &n1); + + memory_region_notify_device_record(subregion, + &vdev->host); + } } =20 --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202585045853.1955156954639; Wed, 26 Apr 2017 03:29:45 -0700 (PDT) Received: from localhost ([::1]:54059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KCe-0007lY-0k for importer@patchew.org; Wed, 26 Apr 2017 06:29:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7W-0002yx-Di for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7R-0002Va-GW for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:26 -0400 Received: from mga03.intel.com ([134.134.136.65]:25915) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7R-0002V7-5E for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:21 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:19 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066421" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:41 +0800 Message-Id: <1493201210-14357-12-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.65 Subject: [Qemu-devel] [RFC PATCH 11/20] intel_iommu: provide iommu_ops->record_device 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 provides iommu_ops->record_device implementation for intel_iommu. It records the host sid in the IntelIOMMUNotifierNode for further virtualization usage. e.g. guest sid -> host sid translation during propagating 1st level cache invalidation from guest to host. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 19 +++++++++++++++++++ include/hw/i386/intel_iommu.h | 1 + 2 files changed, 20 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index ba1e7eb..0c412d2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2407,6 +2407,24 @@ static void vtd_iommu_notify_flag_changed(MemoryRegi= on *iommu, } } =20 +static void vtd_iommu_record_device(MemoryRegion *iommu, + void *device_info) +{ + VTDAddressSpace *vtd_as =3D container_of(iommu, VTDAddressSpace, iommu= ); + IntelIOMMUState *s =3D vtd_as->iommu_state; + IntelIOMMUNotifierNode *node =3D NULL; + IntelIOMMUNotifierNode *next_node =3D NULL; + PCIHostDeviceAddress *host =3D (PCIHostDeviceAddress *) device_info; + + QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) { + if (node->vtd_as =3D=3D vtd_as) { + node->host_sid =3D ((host->bus & 0xffUL) << 8) + | ((host->slot & 0x1f) << 3) + | (host->function & 0x7); + } + } +} + static const VMStateDescription vtd_vmstate =3D { .name =3D "iommu-intel", .version_id =3D 1, @@ -2940,6 +2958,7 @@ static void vtd_init(IntelIOMMUState *s) s->iommu_ops.translate =3D vtd_iommu_translate; s->iommu_ops.notify_flag_changed =3D vtd_iommu_notify_flag_changed; s->iommu_ops.replay =3D vtd_iommu_replay; + s->iommu_ops.record_device =3D vtd_iommu_record_device; s->root =3D 0; s->root_extended =3D false; s->dmar_enabled =3D false; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 8981615..a4ce5c3 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -252,6 +252,7 @@ struct VTD_MSIMessage { =20 struct IntelIOMMUNotifierNode { VTDAddressSpace *vtd_as; + uint16_t host_sid; QLIST_ENTRY(IntelIOMMUNotifierNode) next; }; =20 --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202623787739.7394145388523; Wed, 26 Apr 2017 03:30:23 -0700 (PDT) Received: from localhost ([::1]:54061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KDG-0008Jq-0a for importer@patchew.org; Wed, 26 Apr 2017 06:30:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7W-0002yz-Ec for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7V-0002X1-4o for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:26 -0400 Received: from mga03.intel.com ([134.134.136.65]:25915) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7U-0002V7-Qc for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:25 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:24 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066462" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:42 +0800 Message-Id: <1493201210-14357-13-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.65 Subject: [Qemu-devel] [RFC PATCH 12/20] Memory: Add func to fire pasidt_bind notifier 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" Add a separate function to fire pasid table bind notifier. In future there may be more pasid bind type with different granularity. e.g. binding pasid entry instead of binding pasid table. It can be supported by adding bind_type, check bind_type in fire func and trigger correct notifier. Signed-off-by: Liu, Yi L --- include/exec/memory.h | 11 +++++++++++ memory.c | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 49087ef..3b8f487 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -695,6 +695,17 @@ uint64_t memory_region_iommu_get_min_page_size(MemoryR= egion *mr); void memory_region_notify_iommu(MemoryRegion *mr, IOMMUTLBEntry entry); =20 +/* + * memory_region_notify_iommu_svm_bind notify SVM bind + * request from vIOMMU emulator. + * + * @mr: the memory region of IOMMU + * @data: IOMMU SVM data + */ +void memory_region_notify_iommu_svm_bind(MemoryRegion *mr, + void *data); + + /** * memory_region_notify_one: notify a change in an IOMMU translation * entry to a single notifier diff --git a/memory.c b/memory.c index 45ef069..ce0b0ff 100644 --- a/memory.c +++ b/memory.c @@ -1729,6 +1729,27 @@ void memory_region_notify_iommu(MemoryRegion *mr, } } =20 +void memory_region_notify_iommu_svm_bind(MemoryRegion *mr, + void *data) +{ + IOMMUNotifier *iommu_notifier; + IOMMUNotifierFlag request_flags; + + assert(memory_region_is_iommu(mr)); + + /*TODO: support other bind requests with smaller gran, + * e.g. bind signle pasid entry + */ + request_flags =3D IOMMU_NOTIFIER_SVM_PASIDT_BIND; + + QLIST_FOREACH(iommu_notifier, &mr->iommu_notify, node) { + if (iommu_notifier->notifier_flags & request_flags) { + iommu_notifier->notify(iommu_notifier, data); + break; + } + } +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask =3D 1 << client; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493203190624362.0285127646591; Wed, 26 Apr 2017 03:39:50 -0700 (PDT) Received: from localhost ([::1]:54129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KMP-0008K3-Ek for importer@patchew.org; Wed, 26 Apr 2017 06:39:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7g-00037D-FN for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7b-0002ZH-Gs for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:36 -0400 Received: from mga07.intel.com ([134.134.136.100]:30840) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7b-0002Z6-6t for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:31 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP; 26 Apr 2017 03:24:30 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066499" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:43 +0800 Message-Id: <1493201210-14357-14-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.100 Subject: [Qemu-devel] [RFC PATCH 13/20] IOMMU: add pasid_table_info for guest pasid table 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 adds iommu.h to define some generic definition for IOMMU. Here defines "struct pasid_table_info" for guest pasid table bind. Signed-off-by: Liu, Yi L --- linux-headers/linux/iommu.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 linux-headers/linux/iommu.h diff --git a/linux-headers/linux/iommu.h b/linux-headers/linux/iommu.h new file mode 100644 index 0000000..4519dcf --- /dev/null +++ b/linux-headers/linux/iommu.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2017 Intel Corporation. + * Author: Yi Liu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + */ + +#ifndef __LINUX_IOMMU_H +#define __LINUX_IOMMU_H + +#include + +struct pasid_table_info { + __u64 ptr; /* PASID table ptr */ + __u64 size; /* PASID table size*/ + __u32 model; /* magic number */ +#define INTEL_IOMMU (1 << 0) +#define ARM_SMMU (1 << 1) + __u8 opaque[];/* IOMMU-specific details */ +}; + +#endif /* __LINUX_IOMMU_H */ --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202522031706.7296375967983; Wed, 26 Apr 2017 03:28:42 -0700 (PDT) Received: from localhost ([::1]:54056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KBc-0006oq-Pk for importer@patchew.org; Wed, 26 Apr 2017 06:28:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7g-00037C-F4 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7e-0002a8-VZ for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:36 -0400 Received: from mga07.intel.com ([134.134.136.100]:30840) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7e-0002Z6-Lp for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:34 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP; 26 Apr 2017 03:24:34 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066513" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:44 +0800 Message-Id: <1493201210-14357-15-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.100 Subject: [Qemu-devel] [RFC PATCH 14/20] intel_iommu: add FOR_EACH_ASSIGN_DEVICE macro 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" Add FOR_EACH_ASSIGN_DEVICE. It would be used to loop all assigned devices when processing guest pasid table linking and iommu cache invalidate propagation. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 32 ++++++++++++++++++++++++++++++++ hw/i386/intel_iommu_internal.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 0c412d2..f291995 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -55,6 +55,38 @@ static int vtd_dbgflags =3D VTD_DBGBIT(GENERAL) | VTD_DB= GBIT(CSR); #define VTD_DPRINTF(what, fmt, ...) do {} while (0) #endif =20 +#define FOR_EACH_ASSIGN_DEVICE(__notify_info_type, \ + __opaque_type, \ + __hook_info, \ + __hook_fn) \ +do { \ + IntelIOMMUNotifierNode *node; \ + VTDNotifierIterator iterator; \ + int ret =3D 0; \ + __notify_info_type *notify_info; \ + __opaque_type *opaq; \ + int argsz; \ + argsz =3D sizeof(*notify_info) + sizeof(*opaq); \ + notify_info =3D g_malloc0(argsz); \ + QLIST_FOREACH(node, &(s->notifiers_list), next) { \ + VTDAddressSpace *vtd_as =3D node->vtd_as; \ + VTDContextEntry ce[2]; \ + iterator.bus =3D pci_bus_num(vtd_as->bus); \ + ret =3D vtd_dev_to_context_entry(s, iterator.bus, \ + vtd_as->devfn, &ce[0]); \ + if (ret !=3D 0) { \ + continue; \ + } \ + iterator.sid =3D vtd_make_source_id(iterator.bus, vtd_as->devfn); \ + iterator.did =3D VTD_CONTEXT_ENTRY_DID(ce[0].hi); \ + iterator.host_sid =3D node->host_sid; \ + iterator.vtd_as =3D vtd_as; \ + iterator.ce =3D &ce[0]; \ + __hook_fn(&iterator, __hook_info, notify_info); \ + } \ + g_free(notify_info); \ +} while (0) + static void vtd_define_quad(IntelIOMMUState *s, hwaddr addr, uint64_t val, uint64_t wmask, uint64_t w1cmask) { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index f2a7d12..5178398 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -439,6 +439,17 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_EXT_CONTEXT_TT_NO_DEV_IOTLB (4ULL << 2) #define VTD_EXT_CONTEXT_TT_DEV_IOTLB (5ULL << 2) =20 +struct VTDNotifierIterator { + VTDAddressSpace *vtd_as; + VTDContextEntry *ce; + uint16_t host_sid; + uint16_t sid; + uint16_t did; + uint8_t bus; +}; + +typedef struct VTDNotifierIterator VTDNotifierIterator; + /* Paging Structure common */ #define VTD_SL_PT_PAGE_SIZE_MASK (1ULL << 7) /* Bits to decide the offset for each level */ --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202782425128.364094106087; Wed, 26 Apr 2017 03:33:02 -0700 (PDT) Received: from localhost ([::1]:54079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KFp-0002Mk-6a for importer@patchew.org; Wed, 26 Apr 2017 06:33:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7l-0003BP-6V for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7j-0002cs-PK for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:41 -0400 Received: from mga07.intel.com ([134.134.136.100]:30840) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7j-0002Z6-An for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:39 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP; 26 Apr 2017 03:24:39 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066528" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:45 +0800 Message-Id: <1493201210-14357-16-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.100 Subject: [Qemu-devel] [RFC PATCH 15/20] intel_iommu: link whole 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" VT-d has a nested mode which allows SVM virtualization. Link the whole guest PASID table to host context entry and enable nested mode, pIOMMU would do nested translation for DMA request. Thus achieve GVA->HPA translation. When extended-context-entry is modified in guest, intel_iommu emulator should capture it, then link the whole guest PASID table to host and enable nested mode for the assigned device. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 121 +++++++++++++++++++++++++++++++++++++= ++-- hw/i386/intel_iommu_internal.h | 11 ++++ 2 files changed, 127 insertions(+), 5 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f291995..cd6db65 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -36,6 +36,7 @@ #include "hw/i386/apic_internal.h" #include "kvm_i386.h" #include "trace.h" +#include =20 /*#define DEBUG_INTEL_IOMMU*/ #ifdef DEBUG_INTEL_IOMMU @@ -55,6 +56,14 @@ static int vtd_dbgflags =3D VTD_DBGBIT(GENERAL) | VTD_DB= GBIT(CSR); #define VTD_DPRINTF(what, fmt, ...) do {} while (0) #endif =20 +typedef void (*vtd_device_hook)(VTDNotifierIterator *iter, + void *hook_info, + void *notify_info); + +static void vtd_context_inv_notify_hook(VTDNotifierIterator *iter, + void *hook_info, + void *notify_info); + #define FOR_EACH_ASSIGN_DEVICE(__notify_info_type, \ __opaque_type, \ __hook_info, \ @@ -1213,6 +1222,66 @@ static void vtd_iommu_replay_all(IntelIOMMUState *s) } } =20 +void vtd_context_inv_notify_hook(VTDNotifierIterator *iter, + void *hook_info, + void *notify_info) +{ + struct pasid_table_info *pasidt_info; + IOMMUNotifierData iommu_data; + VTDContextHookInfo *context_hook_info; + uint16_t *host_sid; + pasidt_info =3D (struct pasid_table_info *) notify_info; + context_hook_info =3D (VTDContextHookInfo *) hook_info; + switch (context_hook_info->gran) { + case VTD_INV_DESC_CC_GLOBAL: + /* Fall through */ + case VTD_INV_DESC_CC_DOMAIN: + if (iter->did =3D=3D *context_hook_info->did) { + break; + } + /* Fall through */ + case VTD_INV_DESC_CC_DEVICE: + if ((iter->did =3D=3D *context_hook_info->did) && + (iter->sid =3D=3D *context_hook_info->sid)) { + break; + } + /* Fall through */ + default: + return; + } + + pasidt_info->model =3D INTEL_IOMMU; + host_sid =3D (uint16_t *)&pasidt_info->opaque; + + pasidt_info->ptr =3D iter->ce[1].lo; + pasidt_info->size =3D iter->ce[1].lo & VTD_PASID_TABLE_SIZE_MASK; + *host_sid =3D iter->host_sid; + iommu_data.payload =3D (uint8_t *) pasidt_info; + iommu_data.payload_size =3D sizeof(*pasidt_info) + sizeof(*host_sid); + memory_region_notify_iommu_svm_bind(&iter->vtd_as->iommu, + &iommu_data); + return; +} + +static void vtd_context_cache_invalidate_notify(IntelIOMMUState *s, + uint16_t *did, + uint16_t *sid, + uint8_t gran, + vtd_device_hook hook_fn) +{ + VTDContextHookInfo context_hook_info =3D { + .did =3D did, + .sid =3D sid, + .gran =3D gran, + }; + + FOR_EACH_ASSIGN_DEVICE(struct pasid_table_info, + uint16_t, + &context_hook_info, + hook_fn); + return; +} + static void vtd_context_global_invalidate(IntelIOMMUState *s) { trace_vtd_inv_desc_cc_global(); @@ -1228,8 +1297,35 @@ static void vtd_context_global_invalidate(IntelIOMMU= State *s) * VT-d emulation codes. */ vtd_iommu_replay_all(s); + + if (s->svm) { + vtd_context_cache_invalidate_notify(s, NULL, NULL, + VTD_INV_DESC_CC_GLOBAL, vtd_context_inv_notify_hook); + } } =20 +static void vtd_context_domain_selective_invalidate(IntelIOMMUState *s, + uint16_t did) +{ + trace_vtd_inv_desc_cc_global(); + s->context_cache_gen++; + if (s->context_cache_gen =3D=3D VTD_CONTEXT_CACHE_GEN_MAX) { + vtd_reset_context_cache(s); + } + /* + * From VT-d spec 6.5.2.1, a global context entry invalidation + * should be followed by a IOTLB global invalidation, so we should + * be safe even without this. Hoewever, let's replay the region as + * well to be safer, and go back here when we need finer tunes for + * VT-d emulation codes. + */ + vtd_iommu_replay_all(s); + + if (s->svm) { + vtd_context_cache_invalidate_notify(s, &did, NULL, + VTD_INV_DESC_CC_DOMAIN, vtd_context_inv_notify_hook); + } +} =20 /* Find the VTD address space currently associated with a given bus number, */ @@ -1258,13 +1354,14 @@ static VTDBus *vtd_find_as_from_bus_num(IntelIOMMUS= tate *s, uint8_t bus_num) */ static void vtd_context_device_invalidate(IntelIOMMUState *s, uint16_t source_id, + uint16_t did, uint16_t func_mask) { uint16_t mask; VTDBus *vtd_bus; VTDAddressSpace *vtd_as; uint8_t bus_n, devfn; - uint16_t devfn_it; + uint16_t devfn_it, sid_it; =20 trace_vtd_inv_desc_cc_devices(source_id, func_mask); =20 @@ -1311,6 +1408,12 @@ static void vtd_context_device_invalidate(IntelIOMMU= State *s, * happened. */ memory_region_iommu_replay_all(&vtd_as->iommu); + if (s->svm) { + sid_it =3D vtd_make_source_id(pci_bus_num(vtd_bus->bus= ), + devfn_it); + vtd_context_cache_invalidate_notify(s, &did, &sid_it, + VTD_INV_DESC_CC_DEVICE, vtd_context_inv_notify_hoo= k); + } } } } @@ -1324,6 +1427,7 @@ static uint64_t vtd_context_cache_invalidate(IntelIOM= MUState *s, uint64_t val) { uint64_t caig; uint64_t type =3D val & VTD_CCMD_CIRG_MASK; + uint16_t did; =20 switch (type) { case VTD_CCMD_DOMAIN_INVL: @@ -1338,7 +1442,9 @@ static uint64_t vtd_context_cache_invalidate(IntelIOM= MUState *s, uint64_t val) =20 case VTD_CCMD_DEVICE_INVL: caig =3D VTD_CCMD_DEVICE_INVL_A; - vtd_context_device_invalidate(s, VTD_CCMD_SID(val), VTD_CCMD_FM(va= l)); + did =3D VTD_CCMD_DID(val); + vtd_context_device_invalidate(s, VTD_CCMD_SID(val), + did, VTD_CCMD_FM(val)); break; =20 default: @@ -1720,7 +1826,7 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s,= VTDInvDesc *inv_desc) static bool vtd_process_context_cache_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { - uint16_t sid, fmask; + uint16_t sid, fmask, did; =20 if ((inv_desc->lo & VTD_INV_DESC_CC_RSVD) || inv_desc->hi) { trace_vtd_inv_desc_cc_invalid(inv_desc->hi, inv_desc->lo); @@ -1728,17 +1834,22 @@ static bool vtd_process_context_cache_desc(IntelIOM= MUState *s, } switch (inv_desc->lo & VTD_INV_DESC_CC_G) { case VTD_INV_DESC_CC_DOMAIN: + did =3D VTD_INV_DESC_CC_DID(inv_desc->lo); + vtd_context_domain_selective_invalidate(s, did); trace_vtd_inv_desc_cc_domain( (uint16_t)VTD_INV_DESC_CC_DID(inv_desc->lo)); - /* Fall through */ + break; case VTD_INV_DESC_CC_GLOBAL: + trace_vtd_inv_desc_cc_domain( + (uint16_t)VTD_INV_DESC_CC_DID(inv_desc->lo)); vtd_context_global_invalidate(s); break; =20 case VTD_INV_DESC_CC_DEVICE: sid =3D VTD_INV_DESC_CC_SID(inv_desc->lo); fmask =3D VTD_INV_DESC_CC_FM(inv_desc->lo); - vtd_context_device_invalidate(s, sid, fmask); + did =3D VTD_INV_DESC_CC_DID(inv_desc->lo); + vtd_context_device_invalidate(s, sid, did, fmask); break; =20 default: diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 5178398..5ab7d77 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -439,6 +439,14 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_EXT_CONTEXT_TT_NO_DEV_IOTLB (4ULL << 2) #define VTD_EXT_CONTEXT_TT_DEV_IOTLB (5ULL << 2) =20 +struct VTDContextHookInfo { + uint16_t *did; + uint16_t *sid; + uint8_t gran; +}; + +typedef struct VTDContextHookInfo VTDContextHookInfo; + struct VTDNotifierIterator { VTDAddressSpace *vtd_as; VTDContextEntry *ce; @@ -450,6 +458,9 @@ struct VTDNotifierIterator { =20 typedef struct VTDNotifierIterator VTDNotifierIterator; =20 +/* Masks for struct VTDContextEntry - Extended Context */ +#define VTD_PASID_TABLE_SIZE_MASK 0xf + /* Paging Structure common */ #define VTD_SL_PT_PAGE_SIZE_MASK (1ULL << 7) /* Bits to decide the offset for each level */ --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202942310797.8468386505535; Wed, 26 Apr 2017 03:35:42 -0700 (PDT) Received: from localhost ([::1]:54096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KIO-0004Ug-Qs for importer@patchew.org; Wed, 26 Apr 2017 06:35:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7u-0003JF-JI for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7p-0002eO-L7 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:50 -0400 Received: from mga06.intel.com ([134.134.136.31]:61221) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7p-0002e2-9X for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:45 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP; 26 Apr 2017 03:24:44 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066543" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:46 +0800 Message-Id: <1493201210-14357-17-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.31 Subject: [Qemu-devel] [RFC PATCH 16/20] VFIO: Add notifier for propagating IOMMU TLB invalidate 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 adds the following items: * add new notifier flag IOMMU_NOTIFIER_IOMMU_TLB_INV =3D 0x8 * add new IOCTL cmd VFIO_IOMMU_TLB_INVALIDATE attached on container->fd * add vfio_iommu_tlb_invalidate_notify() to propagate IOMMU TLB invalidate to host This new notifier is originated from the requirement of SVM virtualization on VT-d. It is for invalidation of first-level and nested mappings from the IOTLB and the paging-structure-caches. Since the existed MAP/UNMAP notifier is designed for second-level related mappings, it is not suitable for the new requirement. So it is necessary to introduce this new notifier to meet the SVM virtualization requirement. Further detail would be included in the patch below: "intel_iommu: propagate Extended-IOTLB invalidate to host" Signed-off-by: Liu, Yi L --- hw/vfio/pci.c | 37 +++++++++++++++++++++++++++++++++++++ include/exec/memory.h | 2 ++ linux-headers/linux/iommu.h | 5 +++++ linux-headers/linux/vfio.h | 8 ++++++++ 4 files changed, 52 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a1e6942..afcefd6 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2619,6 +2619,33 @@ static void vfio_iommu_bind_pasid_tbl_notify(IOMMUNo= tifier *n, void *data) g_free(vfio_svm); } =20 +static void vfio_iommu_tlb_invalidate_notify(IOMMUNotifier *n, + void *data) +{ + VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); + VFIOContainer *container =3D giommu->container; + IOMMUNotifierData *iommu_data =3D (IOMMUNotifierData *) data; + struct vfio_iommu_tlb_invalidate *vfio_tlb_inv; + int argsz; + + argsz =3D sizeof(*vfio_tlb_inv) + iommu_data->payload_size; + vfio_tlb_inv =3D g_malloc0(argsz); + vfio_tlb_inv->argsz =3D argsz; + vfio_tlb_inv->length =3D iommu_data->payload_size; + + memcpy(&vfio_tlb_inv->data, iommu_data->payload, + iommu_data->payload_size); + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_TLB_INVALIDATE, + vfio_tlb_inv) !=3D 0) { + error_report("vfio_iommu_tlb_invalidate_notify:" + " failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(vfio_tlb_inv); +} + static void vfio_realize(PCIDevice *pdev, Error **errp) { VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); @@ -2865,6 +2892,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) QTAILQ_FOREACH(subregion, &as->root->subregions, subregions_link) { if (memory_region_is_iommu(subregion)) { IOMMUNotifier n1; + IOMMUNotifier n2; =20 /* FIXME: current iommu notifier is actually designed for @@ -2882,6 +2910,15 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) 0, &n1); =20 + iommu_notifier_init(&n2, vfio_iommu_tlb_invalidate_notify, + IOMMU_NOTIFIER_IOMMU_TLB_INV, + 0, + 0); + vfio_register_notifier(group->container, + subregion, + 0, + &n2); + memory_region_notify_device_record(subregion, &vdev->host); =20 diff --git a/include/exec/memory.h b/include/exec/memory.h index 3b8f487..af15351 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -83,6 +83,8 @@ typedef enum { IOMMU_NOTIFIER_MAP =3D 0x2, /* Notify PASID Table Binding */ IOMMU_NOTIFIER_SVM_PASIDT_BIND =3D 0x4, + /* Notify IOMMU TLB Invalidation */ + IOMMU_NOTIFIER_IOMMU_TLB_INV =3D 0x8, } IOMMUNotifierFlag; =20 #define IOMMU_NOTIFIER_MAP_UNMAP (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMA= P) diff --git a/linux-headers/linux/iommu.h b/linux-headers/linux/iommu.h index 4519dcf..c2742ba 100644 --- a/linux-headers/linux/iommu.h +++ b/linux-headers/linux/iommu.h @@ -27,4 +27,9 @@ struct pasid_table_info { __u8 opaque[];/* IOMMU-specific details */ }; =20 +struct tlb_invalidate_info { + __u32 model; + __u8 opaque[]; +}; + #endif /* __LINUX_IOMMU_H */ diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 9848d63..6c71c4a 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -554,6 +554,14 @@ struct vfio_device_svm { =20 #define VFIO_IOMMU_SVM_BIND_TASK _IO(VFIO_TYPE, VFIO_BASE + 22) =20 +/* For IOMMU Invalidation Passdwon */ +struct vfio_iommu_tlb_invalidate { + __u32 argsz; + __u32 length; + __u8 data[]; +}; + +#define VFIO_IOMMU_TLB_INVALIDATE _IO(VFIO_TYPE, VFIO_BASE + 23) =20 /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ =20 --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202668399978.4745030458972; Wed, 26 Apr 2017 03:31:08 -0700 (PDT) Received: from localhost ([::1]:54069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KDy-0000a2-U0 for importer@patchew.org; Wed, 26 Apr 2017 06:31:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K81-0003Qw-CU for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K7w-0002gA-F7 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:57 -0400 Received: from mga01.intel.com ([192.55.52.88]:4834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K7w-0002fi-4v for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:52 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:51 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066571" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:47 +0800 Message-Id: <1493201210-14357-18-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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.88 Subject: [Qemu-devel] [RFC PATCH 17/20] Memory: Add func to fire TLB invalidate notifier 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 adds a separate function to fire IOMMU TLB invalidate notifier. Signed-off-by: Liu, Yi L --- include/exec/memory.h | 9 +++++++++ memory.c | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index af15351..0155bad 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -707,6 +707,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, void memory_region_notify_iommu_svm_bind(MemoryRegion *mr, void *data); =20 +/* + * memory_region_notify_iommu_invalidate: notify IOMMU + * TLB invalidation passdown. + * + * @mr: the memory region of IOMMU + * @data: IOMMU SVM data + */ +void memory_region_notify_iommu_invalidate(MemoryRegion *mr, + void *data); =20 /** * memory_region_notify_one: notify a change in an IOMMU translation diff --git a/memory.c b/memory.c index ce0b0ff..8c572d5 100644 --- a/memory.c +++ b/memory.c @@ -1750,6 +1750,24 @@ void memory_region_notify_iommu_svm_bind(MemoryRegio= n *mr, } } =20 +void memory_region_notify_iommu_invalidate(MemoryRegion *mr, + void *data) +{ + IOMMUNotifier *iommu_notifier; + IOMMUNotifierFlag request_flags; + + assert(memory_region_is_iommu(mr)); + + request_flags =3D IOMMU_NOTIFIER_IOMMU_TLB_INV; + + QLIST_FOREACH(iommu_notifier, &mr->iommu_notify, node) { + if (iommu_notifier->notifier_flags & request_flags) { + iommu_notifier->notify(iommu_notifier, data); + break; + } + } +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask =3D 1 << client; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493203093167566.1289003948406; Wed, 26 Apr 2017 03:38:13 -0700 (PDT) Received: from localhost ([::1]:54110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KKp-0006bO-EI for importer@patchew.org; Wed, 26 Apr 2017 06:38:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K87-0003Wp-04 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K82-0002jQ-14 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:03 -0400 Received: from mga09.intel.com ([134.134.136.24]:7861) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K81-0002j3-KT for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:57 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:24:56 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066586" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:48 +0800 Message-Id: <1493201210-14357-19-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.24 Subject: [Qemu-devel] [RFC PATCH 18/20] intel_iommu: propagate Extended-IOTLB invalidate 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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" The invalidation of Extended-IOTLB invalidates first-level and nested mappings from the IOTLB and the paging-structure-caches. For SVM virtualization, iommu tlb invalidate notifier is added. The reason is as below: * On VT-d, MAP/UNMAP notifier would be used to shadow the changes of the guest second-level page table. While for the 1st-level page table, is not shadowed like the way of second-level page table. Actually, the guest 1st-level page table is linked to host after the whole guest PASID table is linked to host. 1st-level page table is owned by guest in this SVM virtualization solution for VT-d. Guest should have modified the 1st-level page table in memory before it issues the invalidate request for 1st-level mappings, so MAP/UNMAP notifier is not suitable for the invalidation of guest 1st-level mappings. * Since guest owns the 1st-level page table, host have no knowledge about the invalidations to 1st-level related mappings. So intel_iommu emulator needs to propagate the invalidate request to host, then host invalidates the 1st-level and nested mapping in IOTLB and paging-structure-caches on host. So a new notifier is added to meet such requirement. Before passing the invalidate request to host, intel_iommu emulator needs to do specific translation to the invalidation request. e.g. granularity translation, needs to limit the scope of the invalidate. This patchset proposes passing raw data from guest to host when propagating the guest IOMMU TLB invalidation. As the cover letter mentioned, there is both pros and cons for passing raw data. Would be pleased to see comments on the way how to pass the invalidate request to host. For Extended-IOTLB invalidation, intel_iommu emulator would check all the assigned devices to see if the device is affected by the invalidate request, also intel_iommu emulator needs to do sanity check to the invalidate request and then pass it to host. Host would replace some fields in the raw data before submitting to pIOMMU. e.g. guest domain ID must be replaced with the real domain ID in host. In future PASID may also need to be replaced. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 126 +++++++++++++++++++++++++++++++++++++= ++++ hw/i386/intel_iommu_internal.h | 33 +++++++++++ 2 files changed, 159 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index cd6db65..5fbb7f1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -64,6 +64,10 @@ static void vtd_context_inv_notify_hook(VTDNotifierItera= tor *iter, void *hook_info, void *notify_info); =20 +static void vtd_tlb_inv_notify_hook(VTDNotifierIterator *iter, + void *hook_info, + void *notify_info); + #define FOR_EACH_ASSIGN_DEVICE(__notify_info_type, \ __opaque_type, \ __hook_info, \ @@ -1979,6 +1983,121 @@ done: return true; } =20 +static void vtd_tlb_inv_passdown_notify(IntelIOMMUState *s, + VTDIOTLBInvHookInfo *hook_info, + vtd_device_hook hook_fn) +{ + FOR_EACH_ASSIGN_DEVICE(struct tlb_invalidate_info, + VTDInvalidateData, + hook_info, + hook_fn); + return; +} + +static void vtd_tlb_inv_notify_hook(VTDNotifierIterator *iter, + void *hook_info, + void *notify_info) +{ + struct tlb_invalidate_info *tlb_inv_info; + IOMMUNotifierData iommu_data; + VTDIOTLBInvHookInfo *tlb_hook_info; + VTDInvalidateData *inv_data; + tlb_inv_info =3D (struct tlb_invalidate_info *) notify_info; + tlb_hook_info =3D (VTDIOTLBInvHookInfo *) hook_info; + switch (tlb_hook_info->inv_desc->lo & VTD_INV_DESC_TYPE) { + case VTD_INV_DESC_EXT_IOTLB: + if (iter->did =3D=3D *tlb_hook_info->did) { + break; + } else { + return; + } + default: + return; + } + + tlb_inv_info->model =3D INTEL_IOMMU; + + inv_data =3D (VTDInvalidateData *)&tlb_inv_info->opaque; + inv_data->pasid =3D *tlb_hook_info->pasid; + inv_data->sid =3D iter->host_sid; + inv_data->inv_desc =3D *tlb_hook_info->inv_desc; + + iommu_data.payload =3D (uint8_t *) tlb_inv_info; + iommu_data.payload_size =3D sizeof(*tlb_inv_info) + sizeof(*inv_data); + + memory_region_notify_iommu_invalidate(&iter->vtd_as->iommu, + &iommu_data); +} + +static bool vtd_process_exiotlb_desc(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint16_t domain_id; + uint32_t pasid; + uint8_t am; + VTDIOTLBInvHookInfo tlb_hook_info; + + if ((inv_desc->lo & VTD_INV_DESC_EXIOTLB_RSVD_LO) || + (inv_desc->hi & VTD_INV_DESC_EXIOTLB_RSVD_HI)) { + VTD_DPRINTF(GENERAL, "error: non-zero reserved field in" + "EXIOTLB Invalidate Descriptor hi 0x%"PRIx64 + " lo 0x%"PRIx64, inv_desc->hi, inv_desc->lo); + return false; + } + + domain_id =3D VTD_INV_DESC_EXIOTLB_DID(inv_desc->lo); + switch (inv_desc->lo & VTD_INV_DESC_IOTLB_G) { + case VTD_INV_DESC_EXIOTLB_ALL_ALL: + VTD_DPRINTF(INV, "Invalidate all within ALL PASID"); + inv_desc->lo &=3D ~VTD_INV_DESC_IOTLB_G; + inv_desc->lo |=3D VTD_INV_DESC_EXIOTLB_NONG_PASID; + break; + + case VTD_INV_DESC_EXIOTLB_NONG_ALL: + VTD_DPRINTF(INV, "Invalidate non-global within ALL PASID"); + break; + + case VTD_INV_DESC_EXIOTLB_NONG_PASID: + VTD_DPRINTF(INV, "Invalidate non-global within slective-PASID," + "domain 0x%"PRIx16, domain_id); + + break; + + case VTD_INV_DESC_EXIOTLB_PSI_PASID: + am =3D VTD_INV_DESC_EXIOTLB_AM(inv_desc->hi); + VTD_DPRINTF(INV, "Invalidate selective-page within selective-" + "PASID, domain 0x%"PRIx16 " addr 0x%"PRIx64 + " mask %"PRIu8, domain_id, + (hwaddr) VTD_INV_DESC_EXIOTLB_ADDR(inv_desc->hi), + am); + if (am > VTD_MAMV) { + VTD_DPRINTF(GENERAL, "error: supported max address mask value" + "is %"PRIu8, (uint8_t)VTD_MAMV); + return false; + } + + break; + + default: + VTD_DPRINTF(GENERAL, "error: invalid granularity in Ex-IOTLB" + "Invalidate Descriptor hi 0x%"PRIx64 " lo 0x%"PRIx64, + inv_desc->hi, inv_desc->lo); + return false; + } + + pasid =3D VTD_INV_DESC_EXIOTLB_PASID(inv_desc->lo); + + tlb_hook_info.did =3D &domain_id; + tlb_hook_info.sid =3D NULL; + tlb_hook_info.pasid =3D &pasid; + tlb_hook_info.inv_desc =3D inv_desc; + vtd_tlb_inv_passdown_notify(s, + &tlb_hook_info, + vtd_tlb_inv_notify_hook); + + return true; +} + static bool vtd_process_inv_desc(IntelIOMMUState *s) { VTDInvDesc inv_desc; @@ -2008,6 +2127,13 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 + case VTD_INV_DESC_EXT_IOTLB: + trace_vtd_inv_desc("extended-iotlb", inv_desc.hi, inv_desc.lo); + if (!vtd_process_exiotlb_desc(s, &inv_desc)) { + return false; + } + break; + case VTD_INV_DESC_WAIT: trace_vtd_inv_desc("wait", inv_desc.hi, inv_desc.lo); if (!vtd_process_wait_desc(s, &inv_desc)) { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 5ab7d77..9f89751 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -341,6 +341,7 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_IEC 0x4 /* Interrupt Entry Cache Invalidate Descriptor */ #define VTD_INV_DESC_WAIT 0x5 /* Invalidation Wait Descripto= r */ +#define VTD_INV_DESC_EXT_IOTLB 0x6 /* Ext-IOTLB Invalidate Desc */ #define VTD_INV_DESC_NONE 0 /* Not an Invalidate Descripto= r */ =20 /* Masks for Invalidation Wait Descriptor*/ @@ -380,6 +381,22 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_HI 0xffeULL #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8 =20 +#define VTD_INV_DESC_EXIOTLB_ALL_ALL (0ULL << 4) +#define VTD_INV_DESC_EXIOTLB_NONG_ALL (1ULL << 4) +#define VTD_INV_DESC_EXIOTLB_NONG_PASID (2ULL << 4) +#define VTD_INV_DESC_EXIOTLB_PSI_PASID (3ULL << 4) + +#define VTD_INV_DESC_EXIOTLB_RSVD_LO 0xfff000000000ffc0ULL +#define VTD_INV_DESC_EXIOTLB_RSVD_HI 0xf00ULL + +#define VTD_INV_DESC_EXIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_EXIOTLB_DID(val) (((val) >> 16) & \ + VTD_DOMAIN_ID_MASK) +#define VTD_INV_DESC_EXIOTLB_ADDR(val) ((val) & ~0xfffULL) +#define VTD_INV_DESC_EXIOTLB_AM(val) ((val) & 0x3fULL) +#define VTD_INV_DESC_EXIOTLB_IH(val) (((val) >> 6) & 0x1) +#define VTD_INV_DESC_EXIOTLB_GL(val) (((val) >> 7) & 0x1) + /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { uint16_t domain_id; @@ -388,6 +405,13 @@ struct VTDIOTLBPageInvInfo { }; typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo; =20 +struct VTDInvalidateData { + uint16_t sid; /* it is a physical SID instead of guest SID */ + uint32_t pasid; + VTDInvDesc inv_desc; +}; +typedef struct VTDInvalidateData VTDInvalidateData; + /* Pagesize of VTD paging structures, including root and context tables */ #define VTD_PAGE_SHIFT 12 #define VTD_PAGE_SIZE (1ULL << VTD_PAGE_SHIFT) @@ -447,6 +471,15 @@ struct VTDContextHookInfo { =20 typedef struct VTDContextHookInfo VTDContextHookInfo; =20 +struct VTDIOTLBInvHookInfo { + uint16_t *did; + uint32_t *pasid; + uint16_t *sid; + VTDInvDesc *inv_desc; +}; + +typedef struct VTDIOTLBInvHookInfo VTDIOTLBInvHookInfo; + struct VTDNotifierIterator { VTDAddressSpace *vtd_as; VTDContextEntry *ce; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493202831389606.9335118601609; Wed, 26 Apr 2017 03:33:51 -0700 (PDT) Received: from localhost ([::1]:54082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KGc-00030I-7E for importer@patchew.org; Wed, 26 Apr 2017 06:33:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K87-0003Wq-0c for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K84-0002jx-RP for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:03 -0400 Received: from mga09.intel.com ([134.134.136.24]:7861) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K84-0002j3-DA for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:00 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:25:00 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:24:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066599" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:49 +0800 Message-Id: <1493201210-14357-20-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.24 Subject: [Qemu-devel] [RFC PATCH 19/20] intel_iommu: propagate PASID-Cache invalidate 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 adds support for propagating PASID-Cache invalidation to host. Similar with Extended-IOTLB invalidation, intel_iommu emulator would also check all the assigned devices and do sanity check, then pass it to host. Host pIOMMU driver would replace some fields in the raw data before submitting to pIOMMU. e.g. guest domain ID must be replaced with the real domain ID in host. In future PASID may need to be replaced. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 56 ++++++++++++++++++++++++++++++++++++++= ++++ hw/i386/intel_iommu_internal.h | 10 ++++++++ 2 files changed, 66 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 5fbb7f1..c5e9170 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2006,6 +2006,7 @@ static void vtd_tlb_inv_notify_hook(VTDNotifierIterat= or *iter, tlb_hook_info =3D (VTDIOTLBInvHookInfo *) hook_info; switch (tlb_hook_info->inv_desc->lo & VTD_INV_DESC_TYPE) { case VTD_INV_DESC_EXT_IOTLB: + case VTD_INV_DESC_PC: if (iter->did =3D=3D *tlb_hook_info->did) { break; } else { @@ -2098,6 +2099,54 @@ static bool vtd_process_exiotlb_desc(IntelIOMMUState= *s, return true; } =20 +static bool vtd_process_pasid_desc(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint16_t domain_id; + uint32_t pasid; + VTDIOTLBInvHookInfo tlb_hook_info; + + if ((inv_desc->lo & VTD_INV_DESC_PASIDC_RSVD_LO) || + (inv_desc->hi & VTD_INV_DESC_PASIDC_RSVD_HI)) { + VTD_DPRINTF(GENERAL, "error: non-zero reserved field" + " in PASID desc, hi 0x%"PRIx64 " lo 0x%"PRIx64, + inv_desc->hi, inv_desc->lo); + return false; + } + + domain_id =3D VTD_INV_DESC_PASIDC_DID(inv_desc->lo); + + switch (inv_desc->lo & VTD_INV_DESC_PASIDC_G) { + case VTD_INV_DESC_PASIDC_ALL_ALL: + VTD_DPRINTF(INV, "Invalidate all PASID"); + break; + + case VTD_INV_DESC_PASIDC_PASID_SI: + VTD_DPRINTF(INV, "pasid-selective invalidation" + " domain 0x%"PRIx16, domain_id); + break; + + default: + VTD_DPRINTF(GENERAL, "error: invalid granularity" + " in PASID-Cache Invalidate Descriptor" + " hi 0x%"PRIx64 " lo 0x%"PRIx64, + inv_desc->hi, inv_desc->lo); + return false; + } + + pasid =3D VTD_INV_DESC_PASIDC_PASID(inv_desc->lo); + + tlb_hook_info.did =3D &domain_id; + tlb_hook_info.sid =3D NULL; + tlb_hook_info.pasid =3D &pasid; + tlb_hook_info.inv_desc =3D inv_desc; + vtd_tlb_inv_passdown_notify(s, + &tlb_hook_info, + vtd_tlb_inv_notify_hook); + + return true; +} + static bool vtd_process_inv_desc(IntelIOMMUState *s) { VTDInvDesc inv_desc; @@ -2134,6 +2183,13 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 + case VTD_INV_DESC_PC: + trace_vtd_inv_desc("pasid-cache", inv_desc.hi, inv_desc.lo); + if (!vtd_process_pasid_desc(s, &inv_desc)) { + return false; + } + break; + case VTD_INV_DESC_WAIT: trace_vtd_inv_desc("wait", inv_desc.hi, inv_desc.lo); if (!vtd_process_wait_desc(s, &inv_desc)) { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 9f89751..a6b9350 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -342,6 +342,7 @@ typedef union VTDInvDesc VTDInvDesc; Invalidate Descriptor */ #define VTD_INV_DESC_WAIT 0x5 /* Invalidation Wait Descripto= r */ #define VTD_INV_DESC_EXT_IOTLB 0x6 /* Ext-IOTLB Invalidate Desc */ +#define VTD_INV_DESC_PC 0x7 /* PASID-cache Invalidate Desc= */ #define VTD_INV_DESC_NONE 0 /* Not an Invalidate Descripto= r */ =20 /* Masks for Invalidation Wait Descriptor*/ @@ -397,6 +398,15 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_EXIOTLB_IH(val) (((val) >> 6) & 0x1) #define VTD_INV_DESC_EXIOTLB_GL(val) (((val) >> 7) & 0x1) =20 +#define VTD_INV_DESC_PASIDC_G (3ULL << 4) +#define VTD_INV_DESC_PASIDC_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_PASIDC_DID(val) (((val) >> 16) & VTD_DOMAIN_ID_MASK) +#define VTD_INV_DESC_PASIDC_RSVD_LO 0xfff000000000ffc0ULL +#define VTD_INV_DESC_PASIDC_RSVD_HI 0xffffffffffffffffULL + +#define VTD_INV_DESC_PASIDC_ALL_ALL (0ULL << 4) +#define VTD_INV_DESC_PASIDC_PASID_SI (1ULL << 4) + /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { uint16_t domain_id; --=20 1.9.1 From nobody Sat May 4 20:11:19 2024 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.zoho.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 1493203332109289.7399411011602; Wed, 26 Apr 2017 03:42:12 -0700 (PDT) Received: from localhost ([::1]:54149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3KOg-0001yL-Ud for importer@patchew.org; Wed, 26 Apr 2017 06:42:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K89-0003ZT-Vt for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K88-0002lW-W5 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:06 -0400 Received: from mga09.intel.com ([134.134.136.24]:7861) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K88-0002j3-Hs for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:25:04 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2017 03:25:04 -0700 Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:25:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066635" From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:50 +0800 Message-Id: <1493201210-14357-21-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-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: 134.134.136.24 Subject: [Qemu-devel] [RFC PATCH 20/20] intel_iommu: propagate Ext-Device-TLB invalidate 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.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 Extended-Device-TLB invalidation, intel_iommu emulator needs to check all the assigned device and find the affected device. Replace the guest SID with the host SID in the invalidate descriptor and pass the request to host. Host may just submit the request to corresponding invalidation queue in pIOMMU. In future maybe PASID needs to be replaced. Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 43 ++++++++++++++++++++++++++++++++++++++= ++++ hw/i386/intel_iommu_internal.h | 7 +++++++ 2 files changed, 50 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index c5e9170..4370790 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2012,6 +2012,13 @@ static void vtd_tlb_inv_notify_hook(VTDNotifierItera= tor *iter, } else { return; } + case VTD_INV_DESC_EXT_DIOTLB: + if (iter->sid !=3D *tlb_hook_info->sid) { + return; + } + tlb_hook_info->inv_desc->lo &=3D ~VTD_INV_DESC_EXT_DIOTLB_SID_MASK; + tlb_hook_info->inv_desc->lo |=3D (iter->host_sid << 16); + break; default: return; } @@ -2147,6 +2154,34 @@ static bool vtd_process_pasid_desc(IntelIOMMUState *= s, return true; } =20 +static bool vtd_process_ext_device_iotlb(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint32_t pasid; + uint16_t sid; + VTDIOTLBInvHookInfo tlb_hook_info; + + if ((inv_desc->lo & VTD_INV_DESC_EXT_DIOTLB_RSVD_LO) || + (inv_desc->hi & VTD_INV_DESC_EXT_DIOTLB_RSVD_HI)) { + VTD_DPRINTF(GENERAL, "error: non-zero reserved field in" + " Device ExIOTLB desc, hi 0x%"PRIx64 " lo 0x%"PRIx64, + inv_desc->hi, inv_desc->lo); + return false; + } + + pasid =3D VTD_INV_DESC_EXT_DIOTLB_PASID(inv_desc->lo); + sid =3D VTD_INV_DESC_EXT_DIOTLB_SID(inv_desc->lo); + + tlb_hook_info.did =3D NULL; + tlb_hook_info.sid =3D &sid; + tlb_hook_info.pasid =3D &pasid; + tlb_hook_info.inv_desc =3D inv_desc; + vtd_tlb_inv_passdown_notify(s, + &tlb_hook_info, + vtd_tlb_inv_notify_hook); + return true; +} + static bool vtd_process_inv_desc(IntelIOMMUState *s) { VTDInvDesc inv_desc; @@ -2190,6 +2225,14 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 + case VTD_INV_DESC_EXT_DIOTLB: + trace_vtd_inv_desc("device-extended-iotlb", + inv_desc.hi, inv_desc.lo); + if (!vtd_process_ext_device_iotlb(s, &inv_desc)) { + return false; + } + break; + case VTD_INV_DESC_WAIT: trace_vtd_inv_desc("wait", inv_desc.hi, inv_desc.lo); if (!vtd_process_wait_desc(s, &inv_desc)) { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index a6b9350..3cb2361 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -343,6 +343,7 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_WAIT 0x5 /* Invalidation Wait Descripto= r */ #define VTD_INV_DESC_EXT_IOTLB 0x6 /* Ext-IOTLB Invalidate Desc */ #define VTD_INV_DESC_PC 0x7 /* PASID-cache Invalidate Desc= */ +#define VTD_INV_DESC_EXT_DIOTLB 0x8 /* Ext-DIOTLB Invalidate Desc = */ #define VTD_INV_DESC_NONE 0 /* Not an Invalidate Descripto= r */ =20 /* Masks for Invalidation Wait Descriptor*/ @@ -407,6 +408,12 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_PASIDC_ALL_ALL (0ULL << 4) #define VTD_INV_DESC_PASIDC_PASID_SI (1ULL << 4) =20 +#define VTD_INV_DESC_EXT_DIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_EXT_DIOTLB_SID(val) (((val) >> 16) & 0xffff) +#define VTD_INV_DESC_EXT_DIOTLB_RSVD_LO 0xe00ULL +#define VTD_INV_DESC_EXT_DIOTLB_RSVD_HI 0x7feULL +#define VTD_INV_DESC_EXT_DIOTLB_SID_MASK 0xFFFF0000ULL + /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { uint16_t domain_id; --=20 1.9.1