# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# 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@xxxxxxxxx>
---
xen/drivers/passthrough/vtd/intremap.c | 6 ++--
xen/drivers/passthrough/vtd/iommu.c | 48 +++++++++++----------------------
2 files changed, 20 insertions(+), 34 deletions(-)
diff -r eeb0fce9aeaf -r fa51db0871e1 xen/drivers/passthrough/vtd/intremap.c
--- a/xen/drivers/passthrough/vtd/intremap.c Tue Jun 16 11:25:37 2009 +0100
+++ b/xen/drivers/passthrough/vtd/intremap.c Tue Jun 16 11:30:45 2009 +0100
@@ -568,6 +568,9 @@ int enable_intremap(struct iommu *iommu)
IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, dmar_readl,
(sts & DMA_GSTS_SIRTPS), sts);
+ /* 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);
@@ -582,9 +585,6 @@ int enable_intremap(struct iommu *iommu)
IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, dmar_readl,
(sts & DMA_GSTS_IRES), sts);
- /* After set SIRTP, we should do globally invalidate the IEC */
- iommu_flush_iec_global(iommu);
-
return init_apic_pin_2_ir_idx();
}
diff -r eeb0fce9aeaf -r fa51db0871e1 xen/drivers/passthrough/vtd/iommu.c
--- a/xen/drivers/passthrough/vtd/iommu.c Tue Jun 16 11:25:37 2009 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.c Tue Jun 16 11:30:45 2009 +0100
@@ -1639,13 +1639,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;
- }
-
if ( iommu->vector < 0 )
{
vector = iommu_set_interrupt(iommu);
@@ -1694,6 +1687,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;
}
@@ -1931,34 +1941,10 @@ void iommu_resume(void)
{
struct acpi_drhd_unit *drhd;
struct iommu *iommu;
- struct iommu_flush *flush;
u32 i;
if ( !iommu_enabled )
return;
-
- /* Re-initialize the register-based flush functions.
- * In iommu_flush_all(), we invoke iommu_flush_{context,iotlb}_global(),
- * but at this point, on hosts that support QI(Queued Invalidation), QI
- * hasn't been re-enabed yet, so for now let's use the register-based
- * invalidation method before invoking init_vtd_hw().
- */
- if ( iommu_qinval )
- {
- for_each_drhd_unit ( drhd )
- {
- iommu = drhd->iommu;
- flush = iommu_get_flush(iommu);
- flush->context = flush_context_reg;
- flush->iotlb = flush_iotlb_reg;
- }
- }
-
- /* 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.
- */
- iommu_flush_all();
if ( init_vtd_hw() != 0 && force_iommu )
panic("IOMMU setup failed, crash Xen for security purpose!\n");
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|