xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
authorStefano Stabellini <stefano.stabellini@xilinx.com>
Fri, 19 Mar 2021 20:01:40 +0000 (13:01 -0700)
committerJuergen Gross <jgross@suse.com>
Fri, 23 Apr 2021 09:33:50 +0000 (11:33 +0200)
Newer Xen versions expose two Xen feature flags to tell us if the domain
is directly mapped or not. Only when a domain is directly mapped it
makes sense to enable swiotlb-xen on ARM.

Introduce a function on ARM to check the new Xen feature flags and also
to deal with the legacy case. Call the function xen_swiotlb_detect.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210319200140.12512-1-sstabellini@kernel.org
Signed-off-by: Juergen Gross <jgross@suse.com>
arch/arm/include/asm/xen/swiotlb-xen.h [new file with mode: 0644]
arch/arm/xen/mm.c
arch/arm64/include/asm/xen/swiotlb-xen.h [new file with mode: 0644]
arch/arm64/mm/dma-mapping.c
include/xen/arm/swiotlb-xen.h [new file with mode: 0644]
include/xen/interface/features.h
include/xen/swiotlb-xen.h

diff --git a/arch/arm/include/asm/xen/swiotlb-xen.h b/arch/arm/include/asm/xen/swiotlb-xen.h
new file mode 100644 (file)
index 0000000..455ade5
--- /dev/null
@@ -0,0 +1 @@
+#include <xen/arm/swiotlb-xen.h>
index 467fa225c3d0ed5c9793107f583c2be74d7a88c9..e1b12b242a3204751c05ea99e620df869eeddc01 100644 (file)
@@ -135,10 +135,22 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
        return;
 }
 
+int xen_swiotlb_detect(void)
+{
+       if (!xen_domain())
+               return 0;
+       if (xen_feature(XENFEAT_direct_mapped))
+               return 1;
+       /* legacy case */
+       if (!xen_feature(XENFEAT_not_direct_mapped) && xen_initial_domain())
+               return 1;
+       return 0;
+}
+
 static int __init xen_mm_init(void)
 {
        struct gnttab_cache_flush cflush;
-       if (!xen_initial_domain())
+       if (!xen_swiotlb_detect())
                return 0;
        xen_swiotlb_init(1, false);
 
diff --git a/arch/arm64/include/asm/xen/swiotlb-xen.h b/arch/arm64/include/asm/xen/swiotlb-xen.h
new file mode 100644 (file)
index 0000000..455ade5
--- /dev/null
@@ -0,0 +1 @@
+#include <xen/arm/swiotlb-xen.h>
index 93e87b2875567e09427b4d5e60a947a0e33be77c..4bf1dd3eb041912f8cad240fa606eb9efb5df2a1 100644 (file)
@@ -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_swiotlb_detect())
                dev->dma_ops = &xen_swiotlb_dma_ops;
 #endif
 }
diff --git a/include/xen/arm/swiotlb-xen.h b/include/xen/arm/swiotlb-xen.h
new file mode 100644 (file)
index 0000000..2994fe6
--- /dev/null
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ARM_SWIOTLB_XEN_H
+#define _ASM_ARM_SWIOTLB_XEN_H
+
+extern int xen_swiotlb_detect(void);
+
+#endif /* _ASM_ARM_SWIOTLB_XEN_H */
index 6d1384abfbdf96edf21665022b9ef1eb9a5fe7d1..5a7bdefa06a8654919826adcf1637afa7fc8f18d 100644 (file)
  */
 #define XENFEAT_linux_rsdp_unrestricted   15
 
+/*
+ * A direct-mapped (or 1:1 mapped) domain is a domain for which its
+ * local pages have gfn == mfn. If a domain is direct-mapped,
+ * XENFEAT_direct_mapped is set; otherwise XENFEAT_not_direct_mapped
+ * is set.
+ *
+ * If neither flag is set (e.g. older Xen releases) the assumptions are:
+ * - not auto_translated domains (x86 only) are always direct-mapped
+ * - on x86, auto_translated domains are not direct-mapped
+ * - on ARM, Dom0 is direct-mapped, DomUs are not
+ */
+#define XENFEAT_not_direct_mapped         16
+#define XENFEAT_direct_mapped             17
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
index d5eaf9d682b804be2d563e2a284ae292436e9980..dbc4a4b785f68d999f977b3f5ddaa6a058297a14 100644 (file)
@@ -3,6 +3,7 @@
 #define __LINUX_SWIOTLB_XEN_H
 
 #include <linux/swiotlb.h>
+#include <asm/xen/swiotlb-xen.h>
 
 void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
                          size_t size, enum dma_data_direction dir);