]> xenbits.xensource.com Git - xen.git/commitdiff
VT-d: refuse to use IOMMU with reserved CAP.ND value
authorJan Beulich <jbeulich@suse.com>
Wed, 20 Apr 2022 08:54:26 +0000 (10:54 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 20 Apr 2022 08:54:26 +0000 (10:54 +0200)
The field taking the value 7 (resulting in 18-bit DIDs when using the
calculation in cap_ndoms(), when the DID fields are only 16 bits wide)
is reserved. Instead of misbehaving in case we would encounter such an
IOMMU, refuse to use it.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
xen/drivers/passthrough/vtd/iommu.c

index 1e309dedf495a85c337afc9397b4ac68a070b30d..657e80598710fc19f1ac051e2f2968eac1ce9151 100644 (file)
@@ -1267,8 +1267,11 @@ int __init iommu_alloc(struct acpi_drhd_unit *drhd)
 
     quirk_iommu_caps(iommu);
 
+    nr_dom = cap_ndoms(iommu->cap);
+
     if ( cap_fault_reg_offset(iommu->cap) +
          cap_num_fault_regs(iommu->cap) * PRIMARY_FAULT_REG_LEN > PAGE_SIZE ||
+         ((nr_dom - 1) >> 16) /* I.e. cap.nd > 6 */ ||
          (has_register_based_invalidation(iommu) &&
           ecap_iotlb_offset(iommu->ecap) >= PAGE_SIZE) )
     {
@@ -1294,8 +1297,6 @@ int __init iommu_alloc(struct acpi_drhd_unit *drhd)
     if ( !ecap_coherent(iommu->ecap) )
         iommu_non_coherent = true;
 
-    nr_dom = cap_ndoms(iommu->cap);
-
     if ( nr_dom <= DOMID_MASK * 2 + cap_caching_mode(iommu->cap) )
     {
         /* Allocate domain id (bit) maps. */