]> xenbits.xensource.com Git - xen.git/commitdiff
x86/iommu: introduce a cache sync hook
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 7 Jul 2020 13:11:18 +0000 (15:11 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 7 Jul 2020 13:11:18 +0000 (15:11 +0200)
The hook is only implemented for VT-d and it uses the already existing
iommu_sync_cache function present in VT-d code. The new hook is
added so that the cache can be flushed by code outside of VT-d when
using shared page tables.

Note that alloc_pgtable_maddr must use the now locally defined
sync_cache function, because IOMMU ops are not yet setup the first
time the function gets called during IOMMU initialization.

No functional change intended.

This is part of XSA-321.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: 91526b460e5009fc56edbd6809e66c327281faba
master date: 2020-07-07 14:38:34 +0200

xen/drivers/passthrough/vtd/extern.h
xen/drivers/passthrough/vtd/iommu.c
xen/include/asm-x86/iommu.h
xen/include/xen/iommu.h

index d6ffe804a4a6ada59f31df323dad76036a56c0b8..01d60a464427a87836dbcf0dfd84957c9bd38f79 100644 (file)
@@ -38,7 +38,6 @@ void disable_qinval(struct iommu *iommu);
 int enable_intremap(struct iommu *iommu, int eim);
 void disable_intremap(struct iommu *iommu);
 
-void iommu_sync_cache(const void *addr, unsigned int size);
 int iommu_alloc(struct acpi_drhd_unit *drhd);
 void iommu_free(struct acpi_drhd_unit *drhd);
 
index 274d035fb58aedb8b9fd93b4a0e0f8f73fece058..02a57a3da658f4a75603a64e51e0b4b4f2cc20be 100644 (file)
@@ -159,7 +159,7 @@ static void __init free_intel_iommu(struct intel_iommu *intel)
 
 static int iommus_incoherent;
 
-void iommu_sync_cache(const void *addr, unsigned int size)
+static void sync_cache(const void *addr, unsigned int size)
 {
     int i;
     static unsigned int clflush_size = 0;
@@ -198,7 +198,7 @@ u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages)
         vaddr = __map_domain_page(cur_pg);
         memset(vaddr, 0, PAGE_SIZE);
 
-        iommu_sync_cache(vaddr, PAGE_SIZE);
+        sync_cache(vaddr, PAGE_SIZE);
         unmap_domain_page(vaddr);
         cur_pg++;
     }
@@ -2813,6 +2813,7 @@ const struct iommu_ops __initconstrel intel_iommu_ops = {
     .iotlb_flush_all = iommu_flush_iotlb_all,
     .get_reserved_device_memory = intel_iommu_get_reserved_device_memory,
     .dump_p2m_table = vtd_dump_p2m_table,
+    .sync_cache = sync_cache,
 };
 
 /*
index 8dc392473d0980da7383a644016451c63ba793ef..f5cb04d03209dea2007166ecf1190282622b4441 100644 (file)
@@ -101,6 +101,13 @@ extern bool untrusted_msi;
 int pi_update_irte(const struct pi_desc *pi_desc, const struct pirq *pirq,
                    const uint8_t gvec);
 
+#define iommu_sync_cache(addr, size) ({                 \
+    const struct iommu_ops *ops = iommu_get_ops();      \
+                                                        \
+    if ( ops->sync_cache )                              \
+        ops->sync_cache(addr, size);                    \
+})
+
 #endif /* !__ARCH_X86_IOMMU_H__ */
 /*
  * Local variables:
index 617c993f50560fc5500f755a5998a1607f6d1c73..262679485d155ff848dc1a18823f5d087bb6a2c2 100644 (file)
@@ -221,6 +221,7 @@ struct iommu_ops {
     void (*update_ire_from_apic)(unsigned int apic, unsigned int reg, unsigned int value);
     unsigned int (*read_apic_from_ire)(unsigned int apic, unsigned int reg);
     int (*setup_hpet_msi)(struct msi_desc *);
+    void (*sync_cache)(const void *addr, unsigned int size);
 #endif /* CONFIG_X86 */
     int __must_check (*suspend)(void);
     void (*resume)(void);