Skip to contentSkip to conversation

VT-d: IOTLB flush fixups

PATCH Yang, Xiaowei 2 participants 3 messages May 28, 2008 – May 29, 2008 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1211950777.17461.0.camel@ip6-localhost

#1 lore raw
Quoted 9 lines

On map: only flush when old PTE was valid or invalid PTE may be cached. On unmap: always flush old entry, but skip flush for unaffected IOMMUs.

--

 iommu.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

--

Seems my last mail sent to the xen-devel is lost and I have no local copy so I have to write again...

Espen,
Thanks for the patch! I also noticed context/iotlb flush need a cleanup. As flush of present/non-present entry are different, your change to iommu_intel_map_page are not that correct. So I made up anther patch. iommu_flush is also removed, as VTd table is not shared with p2m any more.

Thanks,
Xiaowei

xen/arch/x86/mm/hap/p2m-ept.c +0 -6
diff -r c93a913c221f xen/arch/x86/mm/hap/p2m-ept.c
@@ -266,12 +266,6 @@ out:
                 iommu_unmap_page(d, gfn);
         }
     }
-
-#ifdef P2M_SHARE_WITH_VTD_PAGE_TABLE
-    /* If p2m table is shared with vtd page-table. */
-    if ( iommu_enabled && is_hvm_domain(d) && (p2mt == p2m_mmio_direct) )
-        iommu_flush(d, gfn, (u64*)ept_entry);
-#endif
 
     return rv;
 }
xen/drivers/passthrough/vtd/iommu.c +32 -71

177 lines not on this page · raw message

xen/include/xen/iommu.h +0 -1
diff -r c93a913c221f xen/include/xen/iommu.h
@@ -65,7 +65,6 @@ void reassign_device_ownership(struct do
                                u8 bus, u8 devfn);
 int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn);
 int iommu_unmap_page(struct domain *d, unsigned long gfn);
-void iommu_flush(struct domain *d, unsigned long gfn, u64 *p2m_entry);
 void iommu_set_pgd(struct domain *d);
 void iommu_free_pgd(struct domain *d);
 void iommu_domain_teardown(struct domain *d);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

A message that is not in the archive (sent off-list or not yet received): 1211965013.16052.16.camel@ip6-localhost

#3 lore raw

[Xiaowei Yang]

Quoted 13 lines
Quoted 9 lines

On map: only flush when old PTE was valid or invalid PTE may be cached. On unmap: always flush old entry, but skip flush for unaffected IOMMUs.

--

 iommu.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

--

Seems my last mail sent to the xen-devel is lost and I have no local copy so I have to write again...

Quoted 8 lines

Espen,
Thanks for the patch! I also noticed context/iotlb flush need a cleanup. As flush of present/non-present entry are different, your change to iommu_intel_map_page are not that correct. So I made up anther patch. iommu_flush is also removed, as VTd table is not shared with p2m any more.

Oh, right. When flushing a non-present cached entry domid 0 must be used. Here's a modification of your patch:

- Made the non-present flush testing a bit simpler.
- Removed dma_addr_level_page_maddr(). Use a modified addr_to_dma_page_maddr() instead.
- Upon mapping new context entry: flush old entry using domid 0 and always flush iotlb.

--

 arch/x86/mm/hap/p2m-ept.c       |    6 -
 drivers/passthrough/vtd/iommu.c |  150 ++++++++++------------------------------
 include/xen/iommu.h             |    1 
 3 files changed, 38 insertions(+), 119 deletions(-)
xen/arch/x86/mm/hap/p2m-ept.c +0 -6
diff -r c93a913c221f xen/arch/x86/mm/hap/p2m-ept.c
@@ -267,12 +267,6 @@
         }
     }
 
-#ifdef P2M_SHARE_WITH_VTD_PAGE_TABLE
-    /* If p2m table is shared with vtd page-table. */
-    if ( iommu_enabled && is_hvm_domain(d) && (p2mt == p2m_mmio_direct) )
-        iommu_flush(d, gfn, (u64*)ept_entry);
-#endif
-
     return rv;
 }
 
xen/drivers/passthrough/vtd/iommu.c +38 -112

263 lines not on this page · raw message

xen/include/xen/iommu.h +0 -1
diff -r c93a913c221f xen/include/xen/iommu.h
@@ -65,7 +65,6 @@
                                u8 bus, u8 devfn);
 int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn);
 int iommu_unmap_page(struct domain *d, unsigned long gfn);
-void iommu_flush(struct domain *d, unsigned long gfn, u64 *p2m_entry);
 void iommu_set_pgd(struct domain *d);
 void iommu_free_pgd(struct domain *d);
 void iommu_domain_teardown(struct domain *d);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 6 lines · Espen Skoglund

Oh, right. When flushing a non-present cached entry domid 0 must be used. Here's a modification of your patch:

- Made the non-present flush testing a bit simpler.
- Removed dma_addr_level_page_maddr(). Use a modified addr_to_dma_page_maddr() instead.

Yes, it's simpler. Thanks! However, you forgot spin_unlock before return. so it leads to deadlock. Here's a small fix.

Quoted 2 lines

- Upon mapping new context entry: flush old entry using domid 0 and always flush iotlb.

Actually, you may find before/after your modification, the code are the same functionally. We can pass domid=0 or non_present_entry_flush=1 to flush non present tlb.

Thanks,
Xiaowei

Quoted 1 line
xen/drivers/passthrough/vtd/iommu.c +3 -2
diff -r f681c4de91fc xen/drivers/passthrough/vtd/iommu.c
@@ -212,10 +212,10 @@ static u64 addr_to_dma_page_maddr(struct
     if ( hd->pgd_maddr == 0 )
     {
         if ( !alloc )
-            return 0;
+            goto out;
         hd->pgd_maddr = alloc_pgtable_maddr();
         if ( hd->pgd_maddr == 0 )
-            return 0;
+            goto out;
     }
 
     parent = (struct dma_pte *)map_vtd_domain_page(hd->pgd_maddr);
@@ -263,6 +263,7 @@ static u64 addr_to_dma_page_maddr(struct
     }
 
     unmap_vtd_domain_page(parent);
+ out:
     spin_unlock_irqrestore(&hd->mapping_lock, flags);
     return pte_maddr;
 }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel