[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 2/2] arm/xen: don't use xen DMA ops when the device is protected by an IOMMU



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@xxxxxxxx>
---
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(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 4b61541853ea..73495f0b0a4d 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -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;
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 7619fbffcea2..0c2f0b77c8b9 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -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)
 {
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 6719f9efea09..2f2b5921bf68 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -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
 }
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e..f3d805f2246f 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -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);
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.