x86/vtd: fix IOMMU share PT destruction path
authorWei Liu <wei.liu2@citrix.com>
Tue, 9 Oct 2018 14:57:08 +0000 (15:57 +0100)
committerWei Liu <wei.liu2@citrix.com>
Thu, 11 Oct 2018 08:33:46 +0000 (09:33 +0100)
Commit 2916951c1 ("mm / iommu: include need_iommu() test in
iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and
91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and
need_iommu_pt_sync()") made things finer grain by spliting need_iommu
into three states.

The destruction path can't use iommu_use_hap_pt because at the point
platform op is called, IOMMU is either already switched to or has
always been in disabled state, and the shared PT test would always be
false.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
xen/drivers/passthrough/vtd/iommu.c

index f94b522c7314580798f6e64d3cb3d3e18783f0b4..4d1ff1081728278412fe77ba118530da0b432ed4 100644 (file)
@@ -1752,7 +1752,17 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(iommu_enabled);
+
+    /*
+     * We can't use iommu_use_hap_pt here because either IOMMU state
+     * is already changed to IOMMU_STATUS_disabled at this point or
+     * has always been IOMMU_STATUS_disabled.
+     *
+     * We also need to test if HAP is enabled because PV guests can
+     * enter this path too.
+     */
+    if ( hap_enabled(d) && iommu_hap_pt_share )
         return;
 
     spin_lock(&hd->arch.mapping_lock);