File 19752-vtd-srtp-sirtp-flush.patch of Package xen
# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1245148245 -3600
# Node ID fa51db0871e1c4d8eca9913c6fc36c299be4e8d4
# Parent eeb0fce9aeafc704419886e654c37799f94ac5a2
vtd: Fix flush for SRTP and SIRTP set
SRTP (Set Root Table Pointer) operation must be set before enable or
re-enable DMA remapping. And after set it, software must globally
invalidate the context-cache and then globally invalidate the
IOTLB. This is required to ensure hardware uses only the remapping
structures referenced by the new root-table pointer, and not stale
cached entries. Similarly, SIRTP (Set Interrupt Remap Table Pointer)
operation must be set before enable or re-enable Interrupt
remapping, and after set it, software must globally invalidate the
interrupt entry cache. This patch adds global context and iotlb
flush after set root entry, and globally flushs interrupt entry
cache before enabling Interrupt remapping. And remove the
iommu_flush_all in iommu_resume becuase it becomes redundant after
adds flush for SRTP in init_vtd_hw.
Signed-off-by: Weidong Han <weidong.han@intel.com>
--- a/xen/drivers/passthrough/vtd/intremap.c
+++ b/xen/drivers/passthrough/vtd/intremap.c
@@ -579,6 +579,9 @@ int enable_intremap(struct iommu *iommu)
cpu_relax();
}
+ /* After set SIRTP, must globally invalidate the interrupt entry cache */
+ iommu_flush_iec_global(iommu);
+
/* enable comaptiblity format interrupt pass through */
gcmd |= DMA_GCMD_CFI;
dmar_writel(iommu->reg, DMAR_GCMD_REG, gcmd);
@@ -603,9 +606,6 @@ int enable_intremap(struct iommu *iommu)
cpu_relax();
}
- /* After set SIRTP, we should do globally invalidate the IEC */
- iommu_flush_iec_global(iommu);
-
init_ioapic_pin_intremap_index();
return 0;
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1727,13 +1727,6 @@ static int init_vtd_hw(void)
for_each_drhd_unit ( drhd )
{
iommu = drhd->iommu;
- ret = iommu_set_root_entry(iommu);
- if ( ret )
- {
- gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: set root entry failed\n");
- return -EIO;
- }
-
vector = iommu_set_interrupt(iommu);
dma_msi_data_init(iommu, vector);
dma_msi_addr_init(iommu, cpu_physical_id(first_cpu(cpu_online_map)));
@@ -1775,6 +1768,23 @@ static int init_vtd_hw(void)
}
}
+ for_each_drhd_unit ( drhd )
+ {
+ iommu = drhd->iommu;
+ ret = iommu_set_root_entry(iommu);
+ if ( ret )
+ {
+ gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: set root entry failed\n");
+ return -EIO;
+ }
+ }
+
+ /*
+ * After set root entry, must globally invalidate context cache, and
+ * then globally invalidate IOTLB
+ */
+ iommu_flush_all();
+
return 0;
}
@@ -1988,12 +1998,6 @@ int iommu_resume(void)
if ( !vtd_enabled )
return 0;
- /* Not sure whether the flush operation is required to meet iommu
- * specification. Note that BIOS also executes in S3 resume and iommu may
- * be touched again, so let us do the flush operation for safety.
- */
- wbinvd();
-
if ( init_vtd_hw() != 0 && force_iommu )
panic("IOMMU setup failed, crash Xen for security purpose!\n");