Skip to contentSkip to conversation

xen/mm: Introduce CONFIG_M2P and provide common fallback logic

PATCH In review Andrew Cooper 4 participants 4 messages Aug 24, 2020 – Sep 21, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/mm: Introduce CONFIG_M2P and provide common fallback logic

Architectures which don't implement an M2P shouldn't be forced to implement stubs. Implement them in common code.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>

I'm pretty sure the mfn_to_gmfn() stub is bogus before and after this change. The two uses in common code are getdomaininfo and in memory_exchange(), which result in junk.

I presume ARM toolstacks don't ever try to map info->shared_info_frame, because I can't see how it would work.

---
 xen/arch/x86/Kconfig     |  1 +
 xen/common/Kconfig       |  3 +++
 xen/include/asm-arm/mm.h |  5 -----
 xen/include/xen/mm.h     | 10 ++++++++++
 4 files changed, 14 insertions(+), 5 deletions(-)
xen/arch/x86/Kconfig +1 -0
index a636a4bb1e..9bc97a1cf5 100644
@@ -24,6 +24,7 @@ config X86
 	select HAS_SCHED_GRANULARITY
 	select HAS_UBSAN
 	select HAS_VPCI if !PV_SHIM_EXCLUSIVE && HVM
+	select M2P
 	select NEEDS_LIBELF
 	select NUMA
 
xen/common/Kconfig +3 -0
index 15e3b79ff5..0bc186d67b 100644
@@ -63,6 +63,9 @@ config HAS_IOPORTS
 config HAS_SCHED_GRANULARITY
 	bool
 
+config M2P
+	bool
+
 config NEEDS_LIBELF
 	bool
 
xen/include/asm-arm/mm.h +0 -5
index f8ba49b118..f4e1864703 100644
@@ -326,11 +326,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 #define SHARED_M2P_ENTRY         (~0UL - 1UL)
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
-/* Xen always owns P2M on ARM */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
-#define mfn_to_gmfn(_d, mfn)  (mfn)
-
-
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
xen/include/xen/mm.h +10 -0
index 1061765bcd..8f6858f954 100644
@@ -685,4 +685,14 @@ static inline void put_page_alloc_ref(struct page_info *page)
     }
 }
 
+/*
+ * For architectures which don't maintain their own M2P, provide a stub
+ * implementation for common code to use.
+ */
+#ifndef CONFIG_M2P
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) {}
+static inline unsigned long mfn_to_gmfn(
+    const struct domain *d, unsigned long mfn) { return mfn; }
+#endif
+
 #endif /* __XEN_MM_H__ */
Signature · 1 line
2.11.0
#1 lore raw

Hi Andrew,

Quoted 14 lines · On Mon, 24 Aug 2020, 19:15 Andrew Cooper, <[email protected]> wrote:

Architectures which don't implement an M2P shouldn't be forced to implement stubs. Implement them in common code.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>

Quoted 9 lines

I'm pretty sure the mfn_to_gmfn() stub is bogus before and after this change.
The two uses in common code are getdomaininfo and in memory_exchange(), which
result in junk.

I presume ARM toolstacks don't ever try to map info->shared_info_frame, because I can't see how it would work.

It is broken. I had a series that tried to remove the M2P (see [1]) but there was some disagreement on how to implement it.

---

Quoted 67 lines
 xen/arch/x86/Kconfig     |  1 +
 xen/common/Kconfig       |  3 +++
 xen/include/asm-arm/mm.h |  5 -----
 xen/include/xen/mm.h     | 10 ++++++++++
 4 files changed, 14 insertions(+), 5 deletions(-)
xen/arch/x86/Kconfig +1 -0
index a636a4bb1e..9bc97a1cf5 100644
@@ -24,6 +24,7 @@ config X86
        select HAS_SCHED_GRANULARITY
        select HAS_UBSAN
        select HAS_VPCI if !PV_SHIM_EXCLUSIVE && HVM
+       select M2P
        select NEEDS_LIBELF
        select NUMA
 
xen/common/Kconfig +3 -0
index 15e3b79ff5..0bc186d67b 100644
@@ -63,6 +63,9 @@ config HAS_IOPORTS
 config HAS_SCHED_GRANULARITY
        bool
 
+config M2P
+       bool
+
 config NEEDS_LIBELF
        bool
 
xen/include/asm-arm/mm.h +0 -5
index f8ba49b118..f4e1864703 100644
@@ -326,11 +326,6 @@ struct page_info *get_page_from_gva(struct vcpu *v,
 vaddr_t va,
 #define SHARED_M2P_ENTRY         (~0UL - 1UL)
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
-/* Xen always owns P2M on ARM */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); }
 while (0)
-#define mfn_to_gmfn(_d, mfn)  (mfn)
-
-
 /* Arch-specific portion of memory_op hypercall. */

long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);

xen/include/xen/mm.h +6 -0
index 1061765bcd..8f6858f954 100644
@@ -685,4 +685,14 @@ static inline void put_page_alloc_ref(struct
 page_info *page)
     }
 }
 
+/*
+ * For architectures which don't maintain their own M2P, provide a stub
+ * implementation for common code to use.
+ */
+#ifndef CONFIG_M2P
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long

pfn) {}

xen/include/xen/mm.h static inline void put_page_alloc_ref(struct page_info *page) · line 696

Quoted 3 lines
xen/include/xen/mm.h +3 -0
+static inline unsigned long mfn_to_gmfn(
+    const struct domain *d, unsigned long mfn) { return mfn; }
+#endif

Please don't add this hack in common code. This is a broken implementation and we are lucky it didn't result to a disaster yet.

The correct way to implement it is to remove mfn_to_gmfn from common code.

I would be happy to try to revive my series.

Cheers,

[1] https://patches.linaro.org/cover/165661/

+

Quoted 5 lines

#endif /* __XEN_MM_H__ */
--
2.11.0

#2 lore raw
In reply to Andrew Cooper
Quoted 3 lines · Andrew Cooper

I'm pretty sure the mfn_to_gmfn() stub is bogus before and after this change. The two uses in common code are getdomaininfo and in memory_exchange(), which result in junk.

It's been a long time back that I think I did suggest to restrict memory_exchange() to non-translated guests. I don't recall what the arguments against this were, but I'm quite sure it wasn't merely "it alters the ABI for such guests".

Jan

#3 lore raw

Hi Jan,

Quoted 9 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper

I'm pretty sure the mfn_to_gmfn() stub is bogus before and after this change. The two uses in common code are getdomaininfo and in memory_exchange(), which result in junk.

It's been a long time back that I think I did suggest to restrict memory_exchange() to non-translated guests. I don't recall what the arguments against this were, but I'm quite sure it wasn't merely "it alters the ABI for such guests".

This was just a low priority for me. But I revived the series (see [1]).

Cheers,

[1] <[email protected]>

Signature · 1 line
Julien Grall