@@ -2286,7 +2286,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
set_dma_ops(dev, dma_ops);
#ifdef CONFIG_XEN
- if (xen_initial_domain())
+ if (xen_initial_domain() && !xen_is_protected_device(dev))
dev->dma_ops = &xen_swiotlb_dma_ops;
#endif
dev->archdata.dma_ops_setup = true;
@@ -63,6 +63,15 @@ static __read_mostly unsigned int xen_events_irq;
uint32_t xen_start_flags;
EXPORT_SYMBOL(xen_start_flags);
+bool xen_is_protected_device(struct device *dev)
+{
+ struct fwnode_handle *fwnode =
+ fwnode_find_reference(dev_fwnode(dev), "iommus", 0) ;
+ if (IS_ERR(fwnode))
+ return false;
+ return of_device_is_compatible(to_of_node(fwnode), "xen,iommu-el2-v1");
+}
+
int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
int nr, struct page **pages)
{
@@ -53,7 +53,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
iommu_setup_dma_ops(dev, dma_base, dma_base + size - 1);
#ifdef CONFIG_XEN
- if (xen_swiotlb_detect())
+ if (xen_swiotlb_detect() && !xen_is_protected_device(dev))
dev->dma_ops = &xen_swiotlb_dma_ops;
#endif
}
@@ -9,6 +9,7 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir);
void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir);
+bool xen_is_protected_device(struct device *dev);
int xen_swiotlb_init(void);
void __init xen_swiotlb_init_early(void);
Only Xen is able to know if a device can safely avoid to use xen-swiotlb. However since Xen links FDT nodes of protected devices to special dummy xen-iommu node we can use that information to decide whether xen-swiotlb is needed. Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com> --- Changelog: v3: rebased over master & documented DT binding https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01755.html v2: re-use common iommu dt bindings to let guests know which devices are protected: https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html arch/arm/mm/dma-mapping.c | 2 +- arch/arm/xen/enlighten.c | 9 +++++++++ arch/arm64/mm/dma-mapping.c | 2 +- include/xen/swiotlb-xen.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-)