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

[RFC PATCH] dma-mapping: don't set swiotlb-xen fops for IOMMU-protected devices



Prior to this patch swiotlb-xen fops are set for all devices when
we are booting as as Dom0 or direct-mapped DomU.

Since Xen now marks devices which are IOMMU-protected by
adding additional property to the relevant device, we can
check for this property and don't set swiotlb-xen fops for
any IOMMU-protected device.

Signed-off-by: Roman Skakun <Roman_Skakun@xxxxxxxx>
---
 arch/arm/mm/dma-mapping.c   | 2 +-
 arch/arm/xen/enlighten.c    | 4 ++++
 arch/arm64/mm/dma-mapping.c | 2 +-
 include/xen/xen.h           | 2 ++
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c4b8df2ad328..c3e5841d871e 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -2280,7 +2280,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_device_protected(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 49f566ad9acb..6ddef3233095 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -425,6 +425,10 @@ static int __init xen_pm_init(void)
 }
 late_initcall(xen_pm_init);
 
+bool xen_is_device_protected(void *obj) {
+       struct device *dev = obj;
+       return of_property_read_bool(dev->of_node, "xen,behind-iommu");
+}
 
 /* empty stubs */
 void xen_arch_pre_suspend(void) { }
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 93e87b287556..0af5f7a63124 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, size);
 
 #ifdef CONFIG_XEN
-       if (xen_initial_domain())
+       if (xen_initial_domain() && !xen_is_device_protected(dev))
                dev->dma_ops = &xen_swiotlb_dma_ops;
 #endif
 }
diff --git a/include/xen/xen.h b/include/xen/xen.h
index 43efba045acc..3725d69de6f9 100644
--- a/include/xen/xen.h
+++ b/include/xen/xen.h
@@ -61,4 +61,6 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct 
page **pages);
 #include <xen/balloon.h>
 #endif
 
+bool xen_is_device_protected(void *obj);
+
 #endif /* _XEN_XEN_H */
-- 
2.27.0




 


Rackspace

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