File 20557-vtd-flush-proper-size.patch of Package xen

# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1259743716 0
# Node ID 04037c99b5f19bfffdda963c37b61a5f564371f0
# Parent  c3373757a5d6d9747379fa2ad575d7b8c12e25b7
VT-d: get rid of hardcode in iommu_flush_cache_entry

Currently iommu_flush_cache_entry uses a fixed size 8 bytes to flush
cache. But it also needs to flush caches with different sizes,
e.g. struct root_entry is 16 bytes. This patch fixes the hardcode by
using a parameter "size" to flush caches with different sizes.

Signed-off-by: Weidong Han <weidong.han@intel.com>

--- a/xen/drivers/passthrough/vtd/intremap.c
+++ b/xen/drivers/passthrough/vtd/intremap.c
@@ -231,7 +231,7 @@ static int ioapic_rte_to_remap_entry(str
     }
 
     memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry);
+    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
     invalidate_sync(iommu);
 
@@ -490,7 +490,7 @@ static int msi_msg_to_remap_entry(
     remap_rte->data = 0;
 
     memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry);
+    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
     invalidate_sync(iommu);
 
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -116,7 +116,7 @@ struct iommu_flush *iommu_get_flush(stru
 
 static unsigned int clflush_size;
 static int iommus_incoherent;
-static void __iommu_flush_cache(void *addr, int size)
+static void __iommu_flush_cache(void *addr, unsigned int size)
 {
     int i;
 
@@ -127,9 +127,9 @@ static void __iommu_flush_cache(void *ad
         clflush((char *)addr + i);
 }
 
-void iommu_flush_cache_entry(void *addr)
+void iommu_flush_cache_entry(void *addr, unsigned int size)
 {
-    __iommu_flush_cache(addr, 8);
+    __iommu_flush_cache(addr, size);
 }
 
 void iommu_flush_cache_page(void *addr)
@@ -159,7 +159,7 @@ static u64 bus_to_context_maddr(struct i
         }
         set_root_value(*root, maddr);
         set_root_present(*root);
-        iommu_flush_cache_entry(root);
+        iommu_flush_cache_entry(root, sizeof(struct root_entry));
     }
     maddr = (u64) get_context_addr(*root);
     unmap_vtd_domain_page(root_entries);
@@ -232,7 +232,7 @@ static u64 addr_to_dma_page_maddr(struct
              */
             dma_set_pte_readable(*pte);
             dma_set_pte_writable(*pte);
-            iommu_flush_cache_entry(pte);
+            iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
         }
         else
         {
@@ -551,8 +551,8 @@ static void dma_pte_clear_one(struct dom
         return;
     }
 
-    dma_clear_pte(*pte); 
-    iommu_flush_cache_entry(pte);
+    dma_clear_pte(*pte);
+    iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     for_each_drhd_unit ( drhd )
     {
@@ -607,7 +607,7 @@ static void iommu_free_pagetable(u64 pt_
             iommu_free_pagetable(dma_pte_addr(*pte), next_level);
 
         dma_clear_pte(*pte);
-        iommu_flush_cache_entry(pte);
+        iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
     }
 
     unmap_vtd_domain_page(pt_vaddr);
@@ -1127,7 +1127,7 @@ static int domain_context_mapping_one(
     context_set_address_width(*context, agaw);
     context_set_fault_enable(*context);
     context_set_present(*context);
-    iommu_flush_cache_entry(context);
+    iommu_flush_cache_entry(context, sizeof(struct context_entry));
 
     unmap_vtd_domain_page(context_entries);
 
@@ -1316,7 +1316,7 @@ static int domain_context_unmap_one(
     spin_lock_irqsave(&iommu->lock, flags);
     context_clear_present(*context);
     context_clear_entry(*context);
-    iommu_flush_cache_entry(context);
+    iommu_flush_cache_entry(context, sizeof(struct context_entry));
 
     if ( iommu_flush_context_device(iommu, domain_iommu_domid(domain),
                                     (((u16)bus) << 8) | devfn,
@@ -1491,7 +1491,7 @@ int intel_iommu_map_page(
     if ( iommu_snoop )
         dma_set_pte_snp(*pte);
 
-    iommu_flush_cache_entry(pte);
+    iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
     unmap_vtd_domain_page(page);
 
     for_each_drhd_unit ( drhd )
@@ -1548,7 +1548,7 @@ int iommu_page_mapping(struct domain *do
         pte = page + (start_pfn & LEVEL_MASK);
         dma_set_pte_addr(*pte, (paddr_t)start_pfn << PAGE_SHIFT_4K);
         dma_set_pte_prot(*pte, prot);
-        iommu_flush_cache_entry(pte);
+        iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
         unmap_vtd_domain_page(page);
         start_pfn++;
         index++;
--- a/xen/drivers/passthrough/vtd/vtd.h
+++ b/xen/drivers/passthrough/vtd/vtd.h
@@ -66,7 +66,7 @@ void free_pgtable_maddr(u64 maddr);
 void *map_vtd_domain_page(u64 maddr);
 void unmap_vtd_domain_page(void *va);
 
-void iommu_flush_cache_entry(void *addr);
+void iommu_flush_cache_entry(void *addr, unsigned int size);
 void iommu_flush_cache_page(void *addr);
 
 #endif // _VTD_H_
openSUSE Build Service is sponsored by