xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Subsystems (7)
Stefano Stabellini
maintainerPATCH 1/1 xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
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.
Also rename the existing pci_xen_swiotlb_detect on x86 to xen_swiotlb_detect so that we can share a common function declaration.
---
This is the corresponding Xen patch under review:
https://marc.info/?l=xen-devel&m=161421618217686
We don't *have to* make the x86 function and the ARM function exactly the same, but I thought it would be much nicer if we did. However, we can't really call it pci_* on ARM as there is no PCI necessarily.
--- arch/arm/xen/mm.c | 14 +++++++++++++- arch/arm64/mm/dma-mapping.c | 2 +- arch/x86/include/asm/xen/swiotlb-xen.h | 4 ++-- arch/x86/kernel/pci-swiotlb.c | 2 +- arch/x86/xen/pci-swiotlb-xen.c | 6 +++--- include/xen/interface/features.h | 7 +++++++ include/xen/swiotlb-xen.h | 6 ++++++ 7 files changed, 33 insertions(+), 8 deletions(-)
arch/arm/xen/mm.c +13 -1
@@ -135,10 +135,22 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)return ; } +int __init 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);
arch/arm64/mm/dma-mapping.c +1 -1
@@ -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 }
arch/x86/include/asm/xen/swiotlb-xen.h +2 -2
@@ -2,14 +2,14 @@#ifndef _ASM_X86_SWIOTLB_XEN_H#define _ASM_X86_SWIOTLB_XEN_H +#include <xen/swiotlb-xen.h> +#ifdef CONFIG_SWIOTLB_XEN extern int xen_swiotlb; -extern int __init pci_xen_swiotlb_detect (void );extern void __init pci_xen_swiotlb_init (void );extern int pci_xen_swiotlb_init_late (void );#else #define xen_swiotlb (0) -static inline int __init pci_xen_swiotlb_detect (void ) {return 0 ; }static inline void __init pci_xen_swiotlb_init (void ) { }static inline int pci_xen_swiotlb_init_late (void ) {return -ENXIO ; }#endif
arch/x86/kernel/pci-swiotlb.c +1 -1
@@ -30,7 +30,7 @@ int __init pci_swiotlb_detect_override(void)return swiotlb; }IOMMU_INIT_FINISH (pci_swiotlb_detect_override, - pci_xen_swiotlb_detect, + xen_swiotlb_detect, pci_swiotlb_init, pci_swiotlb_late_init);
arch/x86/xen/pci-swiotlb-xen.c +3 -3
@@ -21,12 +21,12 @@int xen_swiotlb__read_mostly ;/* -* pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary +* xen_swiotlb_detect - set xen_swiotlb to 1 if necessary * * This returns non-zero if we are forced to use xen_swiotlb (by the boot * option). */ -int __init pci_xen_swiotlb_detect (void ) +int __init xen_swiotlb_detect (void ) {if (!xen_pv_domain ())
@@ -90,7 +90,7 @@ int pci_xen_swiotlb_init_late(void) }EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late); -IOMMU_INIT_FINISH (pci_xen_swiotlb_detect, +IOMMU_INIT_FINISH (xen_swiotlb_detect,NULL , pci_xen_swiotlb_init,NULL );
include/xen/interface/features.h +7 -0
@@ -83,6 +83,13 @@*/ #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. +*/ +#define XENFEAT_not_direct_mapped 16 +#define XENFEAT_direct_mapped 17 +#define XENFEAT_NR_SUBMAPS 1#endif /* __XEN_PUBLIC_FEATURES_H__ */
include/xen/swiotlb-xen.h +6 -0
@@ -12,4 +12,10 @@ void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,extern int xen_swiotlb_init (int verbose,bool early);extern const struct dma_map_ops xen_swiotlb_dma_ops; +#ifdef CONFIG_SWIOTLB_XEN +extern int __init xen_swiotlb_detect (void ); +#else +static inline int __init xen_swiotlb_detect (void ) {return 0 ; } +#endif +#endif /* __LINUX_SWIOTLB_XEN_H */
Signature · 1 line
2.17.1
Stefano Stabellini
maintainerGentle ping, now that the Xen side is acked (not committed due to the imminent release):
https://marc.info/?l=xen-devel&m=161559099506456
Quoted 169 lines · Stefano Stabellini
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.Also rename the existing
pci_xen_swiotlb_detecton x86 toxen_swiotlb_detectso that we can share a common function declaration.Signed-off-by Stefano Stabellini <[email protected]>---
This is the corresponding Xen patch under review:
https://marc.info/?l=xen-devel&m=161421618217686We don't *have to* make the x86 function and the ARM function exactly the same, but I thought it would be much nicer if we did. However, we can't really call it pci_* on ARM as there is no PCI necessarily.
--- arch/arm/xen/mm.c | 14 +++++++++++++- arch/arm64/mm/dma-mapping.c | 2 +- arch/x86/include/asm/xen/swiotlb-xen.h | 4 ++-- arch/x86/kernel/pci-swiotlb.c | 2 +- arch/x86/xen/pci-swiotlb-xen.c | 6 +++--- include/xen/interface/features.h | 7 +++++++ include/xen/swiotlb-xen.h | 6 ++++++ 7 files changed, 33 insertions(+), 8 deletions(-)arch/arm/xen/mm.c +13
-1@@ -135,10 +135,22 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)return ; } +int __init 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);arch/arm64/mm/dma-mapping.c +1
-1@@ -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 }arch/x86/include/asm/xen/swiotlb-xen.h +2
-2@@ -2,14 +2,14 @@#ifndef _ASM_X86_SWIOTLB_XEN_H#define _ASM_X86_SWIOTLB_XEN_H +#include <xen/swiotlb-xen.h> +#ifdef CONFIG_SWIOTLB_XEN extern int xen_swiotlb; -extern int __init pci_xen_swiotlb_detect (void );extern void __init pci_xen_swiotlb_init (void );extern int pci_xen_swiotlb_init_late (void );#else #define xen_swiotlb (0) -static inline int __init pci_xen_swiotlb_detect (void ) {return 0 ; }static inline void __init pci_xen_swiotlb_init (void ) { }static inline int pci_xen_swiotlb_init_late (void ) {return -ENXIO ; }#endif arch/x86/kernel/pci-swiotlb.c +1
-1@@ -30,7 +30,7 @@ int __init pci_swiotlb_detect_override(void)return swiotlb; }IOMMU_INIT_FINISH (pci_swiotlb_detect_override, - pci_xen_swiotlb_detect, + xen_swiotlb_detect, pci_swiotlb_init, pci_swiotlb_late_init);arch/x86/xen/pci-swiotlb-xen.c +3
-3@@ -21,12 +21,12 @@int xen_swiotlb__read_mostly ;/* -* pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary +* xen_swiotlb_detect - set xen_swiotlb to 1 if necessary * * This returns non-zero if we are forced to use xen_swiotlb (by the boot * option). */ -int __init pci_xen_swiotlb_detect (void ) +int __init xen_swiotlb_detect (void ) {if (!xen_pv_domain ())@@ -90,7 +90,7 @@ int pci_xen_swiotlb_init_late(void) }EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late); -IOMMU_INIT_FINISH (pci_xen_swiotlb_detect, +IOMMU_INIT_FINISH (xen_swiotlb_detect,NULL , pci_xen_swiotlb_init,NULL );include/xen/interface/features.h +7
-0@@ -83,6 +83,13 @@*/ #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. +*/ +#define XENFEAT_not_direct_mapped 16 +#define XENFEAT_direct_mapped 17 +#define XENFEAT_NR_SUBMAPS 1#endif /* __XEN_PUBLIC_FEATURES_H__ */ include/xen/swiotlb-xen.h +6
-0@@ -12,4 +12,10 @@ void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,extern int xen_swiotlb_init (int verbose,bool early);extern const struct dma_map_ops xen_swiotlb_dma_ops; +#ifdef CONFIG_SWIOTLB_XEN +extern int __init xen_swiotlb_detect (void ); +#else +static inline int __init xen_swiotlb_detect (void ) {return 0 ; } +#endif +#endif /* __LINUX_SWIOTLB_XEN_H */ Signature · 1 line
2.17.1
Boris Ostrovsky
reviewerQuoted 11 lines · Stefano Stabellini
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.Also rename the existing
pci_xen_swiotlb_detecton x86 toxen_swiotlb_detectso that we can share a common function declaration.Signed-off-by Stefano Stabellini <[email protected]>
Quoted 8 lines
---
This is the corresponding Xen patch under review:
https://marc.info/?l=xen-devel&m=161421618217686We don't *have to* make the x86 function and the ARM function exactly the same, but I thought it would be much nicer if we did. However, we can't really call it pci_* on ARM as there is no PCI necessarily.
I would prefer to keep existing names for consistency on x86 side (but making that inconsistent with ARM, as you point out). But if you feel strongly about making the change you would have to have x86 maintainers agree to this (arch/x86/kernel/pci-swiotlb.c).
-boris
Stefano Stabellini
maintainerQuoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Stefano Stabellini
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.Also rename the existing
pci_xen_swiotlb_detecton x86 toxen_swiotlb_detectso that we can share a common function declaration.Signed-off-by Stefano Stabellini <[email protected]>---
This is the corresponding Xen patch under review:
https://marc.info/?l=xen-devel&m=161421618217686
Quoted 6 lines
Quoted 3 lines
We don't *have to* make the x86 function and the ARM function exactly the same, but I thought it would be much nicer if we did. However, we can't really call it pci_* on ARM as there is no PCI necessarily.
I would prefer to keep existing names for consistency on x86 side (but making that inconsistent with ARM, as you point out). But if you feel strongly about making the change you would have to have x86 maintainers agree to this (
arch/x86/kernel/pci-swiotlb.c).
OK. And from an x86 point of view, it makes sense for it to be called pci_xen_swiotlb_detect given that it is passed to IOMMU_INIT_FINISH in arch/x86/kernel/pci-swiotlb.c.
So, I'll follow you suggestion, keep the x86 side named as it is today, and provide a tiny wrapper so that we can still have an arch-neutral xen_swiotlb_detect function (on x86 just calls pci_xen_swiotlb_detect.)
See below.
From 5f6c91990df1e834c78501799905b04916105836 Mon Sep 17 00:00:00 2001
From: Stefano Stabellini <[email protected]>
Date: Thu, 18 Mar 2021 16:17:21 -0700
Subject: [PATCH] xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped
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.
Also implement xen_swiotlb_detect on x88 using the existing pci_xen_swiotlb_detect() so that we can share a common function declaration.
--- arch/arm/xen/mm.c | 14 +++++++++++++- arch/arm64/mm/dma-mapping.c | 2 +- arch/x86/include/asm/xen/swiotlb-xen.h | 4 ++-- arch/x86/xen/pci-swiotlb-xen.c | 7 ++++++- include/xen/interface/features.h | 14 ++++++++++++++ include/xen/swiotlb-xen.h | 6 ++++++ 6 files changed, 42 insertions(+), 5 deletions(-)
arch/arm/xen/mm.c +13 -1
@@ -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);
arch/arm64/mm/dma-mapping.c +1 -1
@@ -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 }
arch/x86/include/asm/xen/swiotlb-xen.h +2 -2
@@ -4,12 +4,12 @@#ifdef CONFIG_SWIOTLB_XEN extern int xen_swiotlb; -extern int __init pci_xen_swiotlb_detect (void ); +extern int pci_xen_swiotlb_detect (void );extern void __init pci_xen_swiotlb_init (void );extern int pci_xen_swiotlb_init_late (void );#else #define xen_swiotlb (0) -static inline int __init pci_xen_swiotlb_detect (void ) {return 0 ; } +static inline int pci_xen_swiotlb_detect (void ) {return 0 ; }static inline void __init pci_xen_swiotlb_init (void ) { }static inline int pci_xen_swiotlb_init_late (void ) {return -ENXIO ; }#endif
arch/x86/xen/pci-swiotlb-xen.c +6 -1
@@ -26,7 +26,7 @@ int xen_swiotlb __read_mostly;* This returns non-zero if we are forced to use xen_swiotlb (by the boot * option). */ -int __init pci_xen_swiotlb_detect (void ) +int pci_xen_swiotlb_detect (void ) {if (!xen_pv_domain ())
@@ -56,6 +56,11 @@ int __init pci_xen_swiotlb_detect(void)return xen_swiotlb; } +int xen_swiotlb_detect (void ) +{ +return pci_xen_swiotlb_detect (); +} +void __init pci_xen_swiotlb_init (void ) {if (xen_swiotlb) {
include/xen/interface/features.h +14 -0
@@ -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__ */
include/xen/swiotlb-xen.h +6 -0
@@ -12,4 +12,10 @@ void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,extern int xen_swiotlb_init (int verbose,bool early);extern const struct dma_map_ops xen_swiotlb_dma_ops; +#ifdef CONFIG_SWIOTLB_XEN +extern int xen_swiotlb_detect (void ); +#else +static inline int xen_swiotlb_detect (void ) {return 0 ; } +#endif +#endif /* __LINUX_SWIOTLB_XEN_H */
Signature · 1 line
2.17.1
Boris Ostrovsky
reviewerQuoted 4 lines · Stefano Stabellini
So, I'll follow you suggestion, keep the x86 side named as it is today, and provide a tiny wrapper so that we can still have an arch-neutral
xen_swiotlb_detectfunction (on x86 just callspci_xen_swiotlb_detect.)
But now on x86 side we end up with a routine that noone calls. And pci_xen_swiotlb_detect() becomes not __init and so it will have to stick around after boot for no good reason. (You could have made it __ref btw).
I think we should leave x86 alone. And if there is a declaration in include/xen/swiotlb-xen.h that's only relevant to ARM --- well, so be it. Or perhaps you can create arch/arm/include/asm/xen/swiotlb-xen.h
-boris
Stefano Stabellini
maintainerQuoted 11 lines · Boris Ostrovsky
Quoted 4 lines · Stefano Stabellini
So, I'll follow you suggestion, keep the x86 side named as it is today, and provide a tiny wrapper so that we can still have an arch-neutral
xen_swiotlb_detectfunction (on x86 just callspci_xen_swiotlb_detect.)But now on x86 side we end up with a routine that noone calls. And
pci_xen_swiotlb_detect()becomes not__initand so it will have to stick around after boot for no good reason. (You could have made it__refbtw).I think we should leave x86 alone. And if there is a declaration in
include/xen/swiotlb-xen.hthat's only relevant to ARM --- well, so be it. Or perhaps you can createarch/arm/include/asm/xen/swiotlb-xen.h
Yeah I wanted to avoid creating arch/arm/include/asm/xen/swiotlb-xen.h because I would have to do one of the following:
1) add one more #include <asm/xen/swiotlb-xen.h> to arch/arm64/mm/dma-mapping.c (#include <xen/swiotlb-xen.h> is there already)
2) add #include <asm/xen/swiotlb-xen.h> to include/xen/swiotlb-xen.h
What's your preference? If I have to create arch/arm/include/asm/xen/swiotlb-xen.h, I would go with 2).
Boris Ostrovsky
reviewerQuoted 13 lines · Stefano Stabellini
Quoted 9 lines · Boris Ostrovsky
Quoted 3 lines · Stefano Stabellini
So, I'll follow you suggestion, keep the x86 side named as it is today, and provide a tiny wrapper so that we can still have an arch-neutral
xen_swiotlb_detectfunction (on x86 just callspci_xen_swiotlb_detect.)But now on x86 side we end up with a routine that noone calls. And
pci_xen_swiotlb_detect()becomes not__initand so it will have to stick around after boot for no good reason. (You could have made it__refbtw).I think we should leave x86 alone. And if there is a declaration in
include/xen/swiotlb-xen.hthat's only relevant to ARM --- well, so be it. Or perhaps you can createarch/arm/include/asm/xen/swiotlb-xen.hYeah I wanted to avoid creating
arch/arm/include/asm/xen/swiotlb-xen.hbecause I would have to do one of the following:
Quoted 6 lines
1) add one more #include <
asm/xen/swiotlb-xen.h> toarch/arm64/mm/dma-mapping.c(#include <xen/swiotlb-xen.h> is there already)
2) add #include <asm/xen/swiotlb-xen.h> toinclude/xen/swiotlb-xen.hWhat's your preference? If I have to create
arch/arm/include/asm/xen/swiotlb-xen.h, I would go with 2).
Yes, I agree --- #2 is the better choice.
-boris
Hi Stefano,
Quoted 8 lines · Stefano Stabellini
Quoted 7 lines · Boris Ostrovsky
Quoted 4 lines · Stefano Stabellini
So, I'll follow you suggestion, keep the x86 side named as it is today, and provide a tiny wrapper so that we can still have an arch-neutral
xen_swiotlb_detectfunction (on x86 just callspci_xen_swiotlb_detect.)
Quoted 6 lines
Quoted 4 lines
But now on x86 side we end up with a routine that noone calls. And
pci_xen_swiotlb_detect()becomes not__initand so it will have to stick around after boot for no good reason. (You could have made it__refbtw).I think we should leave x86 alone. And if there is a declaration in
include/xen/swiotlb-xen.hthat's only relevant to ARM --- well, so be it. Or perhaps you can createarch/arm/include/asm/xen/swiotlb-xen.hYeah I wanted to avoid creating
arch/arm/include/asm/xen/swiotlb-xen.h
If the header is going to be useed by arch/arm and arch/arm64, then it should be defined in include/xen/arm/ to avoid any packaging issue.
Cheers,
Signature · 1 line
Julien Grall