[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3][4.16?] VT-d: per-domain IOMMU bitmap needs to have dynamic size


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 9 Nov 2021 15:57:07 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wMRh1TVmrnjdKeqysw7fuqZzraxYoHb4qRDEO2U2g34=; b=RLH5MC/29ts4v1Hx/OmWDpuxpd7KzNLCyVOkTirfjXfdY2z/efqySLuyHP7sMAsH1WNMLgYXX55tSrk9wHQnro7nGjvke/UQb26Z7Q779svAyIZcUu93W5edBcLN4dut+4Npw7jM3bIsimFKPHLOhOgx1hg/yuR8kLery3f72pk2YRrmeEoBFaze/QmU+fISFgWpzwylqWkHYaHNrmHzTXZuaOFkd4aRg1M2L0EX+8mcLkI3ofrWzK2S/PTpFx5n6ZAztJIn526/2glpYhSPy1g/UYTLJ4Q/1KaqXErNlO9N+eXWZNHfurrJGLZjTL/067cAAMgHAOMN1PjYjcmp0Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F4y2llAGDF+NN/rRbFd+U4CfA2AWmdu3KOxpp3Ai8f3xIVOoO7wO6Sv6F0cLT35uQywPIf5l4erO/KSDCqt6QYmAACxMYFu0Cop1vladohY/dcaHIpYrURfMQY/d0iefiGOwXbF2SBIv8r2ujJ/QRt2tVj/7eqSkQpbyY1D9vf93XKuGnWelWROF9tRj5Mgzo6a5yPN32OWV+RVtkUKs1Qn9CYX+MOyRuKWR3iHRwfNmIWBhku4G4cYS9JUQ0K448ml3GdCx7L17a4IoHRKVfNhpegHL/r34YWU/EkDdGi/OeEScG2kpQQyEZISedpMLlDMEssfJXqDhPps+pgrRkg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Kevin Tian <kevin.tian@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxx>
  • Delivery-date: Tue, 09 Nov 2021 14:57:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

With no upper bound (anymore) on the number of IOMMUs, a fixed-size
64-bit map may be insufficient (systems with 40 IOMMUs have already been
observed).

Fixes: 27713fa2aa21 ("VT-d: improve save/restore of registers across S3")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -54,7 +54,7 @@ bool __read_mostly iommu_qinval = true;
 bool __read_mostly iommu_snoop = true;
 #endif
 
-static unsigned int __initdata nr_iommus;
+static unsigned int __read_mostly nr_iommus;
 
 static struct iommu_ops vtd_ops;
 static struct tasklet vtd_fault_tasklet;
@@ -645,7 +645,7 @@ static int __must_check iommu_flush_iotl
 
         iommu = drhd->iommu;
 
-        if ( !test_bit(iommu->index, &hd->arch.vtd.iommu_bitmap) )
+        if ( !test_bit(iommu->index, hd->arch.vtd.iommu_bitmap) )
             continue;
 
         flush_dev_iotlb = !!find_ats_dev_drhd(iommu);
@@ -1308,6 +1308,11 @@ static int intel_iommu_domain_init(struc
 {
     struct domain_iommu *hd = dom_iommu(d);
 
+    hd->arch.vtd.iommu_bitmap = xzalloc_array(unsigned long,
+                                              BITS_TO_LONGS(nr_iommus));
+    if ( !hd->arch.vtd.iommu_bitmap )
+        return -ENOMEM;
+
     hd->arch.vtd.agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
 
     return 0;
@@ -1457,7 +1462,7 @@ int domain_context_mapping_one(
     if ( rc > 0 )
         rc = 0;
 
-    set_bit(iommu->index, &hd->arch.vtd.iommu_bitmap);
+    set_bit(iommu->index, hd->arch.vtd.iommu_bitmap);
 
     unmap_vtd_domain_page(context_entries);
 
@@ -1789,7 +1794,7 @@ static int domain_context_unmap(struct d
 
     if ( !found )
     {
-        clear_bit(iommu->index, &dom_iommu(domain)->arch.vtd.iommu_bitmap);
+        clear_bit(iommu->index, dom_iommu(domain)->arch.vtd.iommu_bitmap);
         cleanup_domid_map(domain, iommu);
     }
 
@@ -1819,6 +1824,8 @@ static void iommu_domain_teardown(struct
 
     for_each_drhd_unit ( drhd )
         cleanup_domid_map(d, drhd->iommu);
+
+    XFREE(hd->arch.vtd.iommu_bitmap);
 }
 
 static int __must_check intel_iommu_map_page(struct domain *d, dfn_t dfn,
--- a/xen/include/asm-x86/iommu.h
+++ b/xen/include/asm-x86/iommu.h
@@ -58,7 +58,7 @@ struct arch_iommu
         struct {
             uint64_t pgd_maddr; /* io page directory machine address */
             unsigned int agaw; /* adjusted guest address width, 0 is level 2 
30-bit */
-            uint64_t iommu_bitmap; /* bitmap of iommu(s) that the domain uses 
*/
+            unsigned long *iommu_bitmap; /* bitmap of iommu(s) that the domain 
uses */
         } vtd;
         /* AMD IOMMU */
         struct {




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.