diff mbox series

[v5,4/4] xen/mm: Provide dummy M2P-related helpers when the M2P is not supported

Message ID 20210703171152.15874-5-julien@xen.org (mailing list archive)
State New, archived
Headers show
Series xen/arm: Properly disable M2P on Arm | expand

Commit Message

Julien Grall July 3, 2021, 5:11 p.m. UTC
From: Julien Grall <julien.grall@arm.com>

At the moment, Arm is providing a dummy implementation for the M2P
helpers used in common code. However, they are quite isolated and could
be used by other architecture in the future. So move the helpers
necessary for compilation in xen/mm.h and gate them with a new config
!HAS_M2P. The other M2P related helpers are removed.

Take the opportunity to encode that CONFIG_MEM_SHARING requires
the M2P. It is done in the header rather than the Kconfig because
the option is not defined in the common Kconfig.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---
    INVALID_M2P_ENTRY needs to be defined because it is a parameter
    of set_gpfn_from_mfn(). The alternative would be to not
    evaluate the parameter 'pfn' (e.g. leave the helper as a macro)
    however this is a bit risky.

    Changes in v5:
        - Check that MEM_SHARING is not enabled without the M2P.

    Changes in v4:
        - The tags were dropped as the previous version was sent a long
        time ago.

    Changes in v3:
        - Add Stefano's reviewed-by
        - Add George's acked-by

    Changes in v2:
        - Patch added
---
 xen/arch/x86/Kconfig     |  1 +
 xen/include/asm-arm/mm.h | 11 -----------
 xen/include/xen/mm.h     | 17 +++++++++++++++++
 3 files changed, 18 insertions(+), 11 deletions(-)

Comments

Jan Beulich July 5, 2021, 9:15 a.m. UTC | #1
On 03.07.2021 19:11, Julien Grall wrote:
> From: Julien Grall <julien.grall@arm.com>
> 
> At the moment, Arm is providing a dummy implementation for the M2P
> helpers used in common code. However, they are quite isolated and could
> be used by other architecture in the future. So move the helpers
> necessary for compilation in xen/mm.h and gate them with a new config
> !HAS_M2P. The other M2P related helpers are removed.
> 
> Take the opportunity to encode that CONFIG_MEM_SHARING requires
> the M2P. It is done in the header rather than the Kconfig because
> the option is not defined in the common Kconfig.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

With the other Kconfig hunk moved here (from the earlier patch)
Reviewed-by: Jan Beulich <jbeulich@suse.com>

Jan
Stefano Stabellini July 14, 2021, 1:18 a.m. UTC | #2
On Mon, 5 Jul 2021, Jan Beulich wrote:
> On 03.07.2021 19:11, Julien Grall wrote:
> > From: Julien Grall <julien.grall@arm.com>
> > 
> > At the moment, Arm is providing a dummy implementation for the M2P
> > helpers used in common code. However, they are quite isolated and could
> > be used by other architecture in the future. So move the helpers
> > necessary for compilation in xen/mm.h and gate them with a new config
> > !HAS_M2P. The other M2P related helpers are removed.
> > 
> > Take the opportunity to encode that CONFIG_MEM_SHARING requires
> > the M2P. It is done in the header rather than the Kconfig because
> > the option is not defined in the common Kconfig.
> > 
> > Signed-off-by: Julien Grall <julien.grall@arm.com>
> 
> With the other Kconfig hunk moved here (from the earlier patch)
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>
diff mbox series

Patch

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 9b164db64187..a083d8194680 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -16,6 +16,7 @@  config X86
 	select HAS_FAST_MULTIPLY
 	select HAS_IOPORTS
 	select HAS_KEXEC
+	select HAS_M2P
 	select HAS_NS16550
 	select HAS_PASSTHROUGH
 	select HAS_PCI
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 07c24654a0b6..beff43786bda 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -318,17 +318,6 @@  static inline void *page_to_virt(const struct page_info *pg)
 struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
                                     unsigned long flags);
 
-/*
- * Arm does not have an M2P, but common code expects a handful of
- * M2P-related defines and functions. Provide dummy versions of these.
- */
-#define INVALID_M2P_ENTRY        (~0UL)
-#define SHARED_M2P_ENTRY         (~0UL - 1UL)
-#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
-
-/* We don't have a M2P on Arm */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
-
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 667f9dac83a4..b98a1a7f423f 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -612,4 +612,21 @@  static inline void put_page_alloc_ref(struct page_info *page)
     }
 }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.
+ */
+#ifndef CONFIG_HAS_M2P
+
+#ifdef CONFIG_MEM_SHARING
+# error "Memory sharing depends on the M2P"
+#endif
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P(_e)           ((void)(_e), false)
+
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) {}
+
+#endif
+
 #endif /* __XEN_MM_H__ */