domain_use_host_layout() is not really architecture-specific, so move it
from the Arm header to the common header xen/domain.h and provide a common
implementation in xen/common/domain.c. domain_use_host_layout() potentially
is needed for x86 [1].
Turn the macro into a function to avoid header dependency issues. In
particular, the implementation depends on paging_mode_translate(), and
including xen/paging.h from xen/domain.h would introduce circular
dependencies via xen/sched.h which will lead to compilation errors as
implicit declaration of struct vcpu, or struct domain, or similar things
declared in xen/sched.h.
Adjust the implementation to take paging_mode_translate() into account
so it works correctly for all architectures, including x86. Some extra
details about implementation [2] and [3].
Also, inclusion of asm/p2m.h is dropped as xen/paging.h already includes
it.
[1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2602161038120.359097@ubuntu-linux-20-04-desktop/
[2] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2602271742400.3148344@ubuntu-linux-20-04-desktop/
[3] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2602271750190.3148344@ubuntu-linux-20-04-desktop/
Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in v2:
- Drop ifdef around defintion of domain_use_host_layout() as it
was suggested generic version. It could be returned back when
the real use case for it will appear.
- Add Suggested-by: and update the commit message.
- Make domain_use_host_layout() function instead of macros to
avoid ciclular header dependecies. Look at more details in
the commit message.
---
xen/arch/arm/include/asm/domain.h | 14 --------------
xen/common/domain.c | 8 +++++++-
xen/include/xen/domain.h | 16 ++++++++++++++++
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h
index 758ad807e461..1a04fe658c97 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -29,20 +29,6 @@ enum domain_type {
#define is_64bit_domain(d) (0)
#endif
-/*
- * Is the domain using the host memory layout?
- *
- * Direct-mapped domain will always have the RAM mapped with GFN == MFN.
- * To avoid any trouble finding space, it is easier to force using the
- * host memory layout.
- *
- * The hardware domain will use the host layout regardless of
- * direct-mapped because some OS may rely on a specific address ranges
- * for the devices.
- */
-#define domain_use_host_layout(d) (is_domain_direct_mapped(d) || \
- is_hardware_domain(d))
-
struct vtimer {
struct vcpu *v;
int irq;
diff --git a/xen/common/domain.c b/xen/common/domain.c
index ab910fcf9306..87a6a17575f9 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -26,6 +26,7 @@
#include <xen/hypercall.h>
#include <xen/delay.h>
#include <xen/shutdown.h>
+#include <xen/paging.h>
#include <xen/percpu.h>
#include <xen/multicall.h>
#include <xen/rcupdate.h>
@@ -35,7 +36,6 @@
#include <xen/argo.h>
#include <xen/llc-coloring.h>
#include <xen/xvmalloc.h>
-#include <asm/p2m.h>
#include <asm/processor.h>
#include <public/sched.h>
#include <public/sysctl.h>
@@ -2544,6 +2544,12 @@ void thaw_domains(void)
#endif /* CONFIG_SYSTEM_SUSPEND */
+bool domain_use_host_layout(struct domain *d)
+{
+ return is_domain_direct_mapped(d) ||
+ (paging_mode_translate(d) && is_hardware_domain(d));
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 93c0fd00c1d7..68fb1acd4083 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -62,6 +62,22 @@ void domid_free(domid_t domid);
#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap)
#define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem)
+/*
+ * Is the auto-translated domain using the host memory layout?
+ *
+ * domain_use_host_layout() is always False for PV guests.
+ *
+ * Direct-mapped domains (autotranslated domains with memory allocated
+ * contiguously and mapped 1:1 so that GFN == MFN) are always using the
+ * host memory layout to avoid address clashes.
+ *
+ * The hardware domain will use the host layout (regardless of
+ * direct-mapped) because some OS may rely on a specific address ranges
+ * for the devices. PV Dom0, like any other PV guests, has
+ * domain_use_host_layout() returning False.
+ */
+bool domain_use_host_layout(struct domain *d);
+
/*
* Arch-specifics.
*/
--
2.53.0