* [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
@ 2021-03-19 20:01 Stefano Stabellini
2021-03-19 23:00 ` Boris Ostrovsky
2021-04-23 9:36 ` Juergen Gross
0 siblings, 2 replies; 3+ messages in thread
From: Stefano Stabellini @ 2021-03-19 20:01 UTC (permalink / raw)
To: boris.ostrovsky; +Cc: jgross, sstabellini, xen-devel, Stefano Stabellini
From: Stefano Stabellini <stefano.stabellini@xilinx.com>
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>
---
Changes in v3:
- remove any x86 changes
- introduce asm/xen/swiotlb-xen.h for arm
---
arch/arm/include/asm/xen/swiotlb-xen.h | 1 +
arch/arm/xen/mm.c | 14 +++++++++++++-
arch/arm64/include/asm/xen/swiotlb-xen.h | 1 +
arch/arm64/mm/dma-mapping.c | 2 +-
include/xen/arm/swiotlb-xen.h | 7 +++++++
include/xen/interface/features.h | 14 ++++++++++++++
include/xen/swiotlb-xen.h | 1 +
7 files changed, 38 insertions(+), 2 deletions(-)
create mode 100644 arch/arm/include/asm/xen/swiotlb-xen.h
create mode 100644 arch/arm64/include/asm/xen/swiotlb-xen.h
create mode 100644 include/xen/arm/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
index 000000000000..455ade5d5320
--- /dev/null
+++ b/arch/arm/include/asm/xen/swiotlb-xen.h
@@ -0,0 +1 @@
+#include <xen/arm/swiotlb-xen.h>
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 467fa225c3d0..e1b12b242a32 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -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
index 000000000000..455ade5d5320
--- /dev/null
+++ b/arch/arm64/include/asm/xen/swiotlb-xen.h
@@ -0,0 +1 @@
+#include <xen/arm/swiotlb-xen.h>
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 93e87b287556..4bf1dd3eb041 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_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
index 000000000000..2994fe6031a0
--- /dev/null
+++ b/include/xen/arm/swiotlb-xen.h
@@ -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 */
diff --git a/include/xen/interface/features.h b/include/xen/interface/features.h
index 6d1384abfbdf..5a7bdefa06a8 100644
--- a/include/xen/interface/features.h
+++ b/include/xen/interface/features.h
@@ -83,6 +83,20 @@
*/
#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__ */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index d5eaf9d682b8..dbc4a4b785f6 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
2021-03-19 20:01 [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
@ 2021-03-19 23:00 ` Boris Ostrovsky
2021-04-23 9:36 ` Juergen Gross
1 sibling, 0 replies; 3+ messages in thread
From: Boris Ostrovsky @ 2021-03-19 23:00 UTC (permalink / raw)
To: Stefano Stabellini; +Cc: jgross, xen-devel, Stefano Stabellini
On 3/19/21 4:01 PM, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@xilinx.com>
>
> 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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
2021-03-19 20:01 [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
2021-03-19 23:00 ` Boris Ostrovsky
@ 2021-04-23 9:36 ` Juergen Gross
1 sibling, 0 replies; 3+ messages in thread
From: Juergen Gross @ 2021-04-23 9:36 UTC (permalink / raw)
To: Stefano Stabellini, boris.ostrovsky; +Cc: xen-devel, Stefano Stabellini
[-- Attachment #1.1.1: Type: text/plain, Size: 578 bytes --]
On 19.03.21 21:01, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@xilinx.com>
>
> 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>
Pushed to xen/tip.git for-linus-5.13
Juergen
[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-23 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 20:01 [PATCH v3] xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
2021-03-19 23:00 ` Boris Ostrovsky
2021-04-23 9:36 ` Juergen Gross
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).