Skip to contentSkip to conversation

MPU mm subsistem skeleton

PATCH Superseded Luca Fancellu 3 participants 35 messages Mar 12, 2025 – Mar 14, 2025

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover MPU mm subsistem skeleton

Hi all,

this serie implements the skeleton for the MPU memory management subsystem, at the end of the serie it will be possible to compile the Arm arch using MPU.

The minimum Arm Kconfig configuration is this one:

CONFIG_UNSUPPORTED=y
CONFIG_MPU=y
CONFIG_XEN_START_ADDRESS=0x0

Luca Fancellu (8):
xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH xen/arm: Restrict Kconfig configuration for LLC coloring arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt arm/mpu: Kconfig symbols for MPU build
arm/mpu: Implement stubs for ioremap_attr on MPU xen/arm: Rename setup_pagetables with a more generic name arm/mpu: Create the skeleton for MPU compilation

Penny Zheng (2):
arm/mpu: Implement virt/maddr conversion in MPU system xen/arm: introduce Kconfig HAS_PAGING_MEMPOOL

 xen/arch/arm/Kconfig                   |  9 ++-
 xen/arch/arm/arm64/mpu/Makefile        |  2 +
 xen/arch/arm/arm64/mpu/p2m.c           | 18 +++++
 xen/arch/arm/arm64/mpu/smpboot.c       | 23 +++++++
 xen/arch/arm/dom0less-build.c          |  2 +
 xen/arch/arm/include/asm/domain.h      |  2 +
 xen/arch/arm/include/asm/grant_table.h |  5 +-
 xen/arch/arm/include/asm/mm.h          | 33 +++++++--
 xen/arch/arm/include/asm/mmu/mm.h      |  7 ++
 xen/arch/arm/include/asm/mpu/layout.h  |  5 ++
 xen/arch/arm/include/asm/mpu/mm.h      | 30 ++++++++
 xen/arch/arm/include/asm/mpu/p2m.h     | 20 ++++++
 xen/arch/arm/include/asm/p2m.h         |  2 +-
 xen/arch/arm/mm.c                      |  5 ++
 xen/arch/arm/mmu/pt.c                  |  5 --
 xen/arch/arm/mmu/setup.c               |  2 +-
 xen/arch/arm/mpu/Makefile              |  3 +
 xen/arch/arm/mpu/mm.c                  | 41 +++++++++++
 xen/arch/arm/mpu/p2m.c                 | 94 ++++++++++++++++++++++++++
 xen/arch/arm/mpu/setup.c               | 42 ++++++++++++
 xen/arch/arm/mpu/vmap-mpu.c            | 24 +++++++
 xen/arch/arm/setup.c                   |  6 +-
 xen/arch/arm/xen.lds.S                 |  2 +
 xen/include/xen/iommu.h                | 54 ++++++++++++++-
 24 files changed, 414 insertions(+), 22 deletions(-)
 create mode 100644 xen/arch/arm/arm64/mpu/p2m.c
 create mode 100644 xen/arch/arm/arm64/mpu/smpboot.c
 create mode 100644 xen/arch/arm/include/asm/mpu/mm.h
 create mode 100644 xen/arch/arm/include/asm/mpu/p2m.h
 create mode 100644 xen/arch/arm/mpu/p2m.c
 create mode 100644 xen/arch/arm/mpu/setup.c
 create mode 100644 xen/arch/arm/mpu/vmap-mpu.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/10 xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH

When Xen is built without HAS_PASSTHROUGH, there are some parts in arm where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built.

So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support.

For gnttab_need_iommu_mapping() in the Arm part, modify the macro to use IS_ENABLED for the HAS_PASSTHROUGH Kconfig.

Fixes 0388a5979b21 ("xen/arm: mpu: Introduce choice between MMU and MPU")

---
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
v5 changes:
- Add Ack-by Julien and Jan
- Add comment in iommu_add_dt_device
- adjusted aligment for iommu_use_hap_pt
v4 changes:
- re-introduced stub for iommu_use_hap_pt, Stefano suggested it is ok to have it in iommu.h.
- Reworded comment in iommu_domain_init from Jan suggestion
v3 Changes:
- removed stub for iommu_use_hap_pt, another solution will be done for the instance in common arm code.
- Moved a comment close to the macro it was referred to
- add comment to iommu_domain_init() stub
- modified commit message
- Add fixes tag

v2 Changes:
- modify gnttab_need_iommu_mapping to use IS_ENABLED
- removed macro that didn't allow some of the parameter to be evaluated
- Changed commit message
---

---
 xen/arch/arm/include/asm/grant_table.h |  5 ++-
 xen/include/xen/iommu.h                | 54 +++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/grant_table.h +3 -2
index d3c518a926b9..c5d87b60c4df 100644
@@ -73,8 +73,9 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame,
 #define gnttab_status_gfn(d, t, i)                                       \
     page_get_xenheap_gfn(gnttab_status_page(t, i))
 
-#define gnttab_need_iommu_mapping(d)                    \
-    (is_domain_direct_mapped(d) && is_iommu_enabled(d))
+#define gnttab_need_iommu_mapping(d)                                     \
+    (IS_ENABLED(CONFIG_HAS_PASSTHROUGH) && is_domain_direct_mapped(d) && \
+     is_iommu_enabled(d))
 
 #endif /* __ASM_GRANT_TABLE_H__ */
 /*
xen/include/xen/iommu.h +53 -1

94 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/10 arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S

In reply to Luca Fancellu

The define HYPERVISOR_VIRT_START is required by the common code, even if MPU system doesn't use virtual memory, define it in mpu/layout.h in order to reuse existing code.

Disable a check in the linker script for arm for !MMU systems.

---
 xen/arch/arm/include/asm/mpu/layout.h | 2 ++
 xen/arch/arm/xen.lds.S                | 2 ++
 2 files changed, 4 insertions(+)
xen/arch/arm/include/asm/mpu/layout.h +2 -0
index d6d397f4c2ac..248e55f8882d 100644
@@ -22,6 +22,8 @@
  */
 #define XEN_VIRT_START         _AT(paddr_t, XEN_START_ADDRESS)
 
+#define HYPERVISOR_VIRT_START  XEN_VIRT_START
+
 #endif /* __ARM_MPU_LAYOUT_H__ */
 /*
  * Local variables:
xen/arch/arm/xen.lds.S +2 -0
index bbccff1a0350..4342e54422a7 100644
@@ -239,4 +239,6 @@ ASSERT(IS_ALIGNED(__bss_start,      POINTER_ALIGN), "__bss_start is misaligned")
 ASSERT(IS_ALIGNED(__bss_end,        POINTER_ALIGN), "__bss_end is misaligned")
 /* To simplify the logic in head.S, we want to _end to be page aligned */
 ASSERT(IS_ALIGNED(_end,             PAGE_SIZE), "_end is not page aligned")
+#ifdef CONFIG_MMU
 ASSERT((_end - _start) <= XEN_VIRT_SIZE, "Xen is too big")
+#endif
Signature · 1 line
2.34.1
Reviewed-by on v1 3/10
#3 lore raw

Re: [PATCH 03/10] arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S

Quoted 9 lines · Luca Fancellu

The define HYPERVISOR_VIRT_START is required by the common code, even if MPU system doesn't use virtual memory, define it in mpu/layout.h in order to reuse existing code.

Disable a check in the linker script for arm for !MMU systems.

~Michal

#4 lore raw

PATCH 4/10 arm/mpu: Implement virt/maddr conversion in MPU system

In reply to Luca Fancellu

From: Penny Zheng <[email protected]>

virt_to_maddr and maddr_to_virt are used widely in Xen code. So even there is no VMSA in MPU system, we keep the interface in MPU to don't change the existing common code.

In order to do that, move the virt_to_maddr() definition to mmu/mm.h, instead for maddr_to_virt() it's more difficult to isolate it under mmu/ so it will be protected by #ifdef CONFIG_MMU.

Finally implement virt_to_maddr() and maddr_to_virt() for MPU systems under mpu/mm.h, the MPU version of virt/maddr conversion is simple since VA==PA.

While there, take the occasion to add emacs footer to mpu/mm.c.

---
 xen/arch/arm/include/asm/mm.h     | 13 +++++++------
 xen/arch/arm/include/asm/mmu/mm.h |  7 +++++++
 xen/arch/arm/include/asm/mpu/mm.h | 27 +++++++++++++++++++++++++++
 xen/arch/arm/mpu/mm.c             |  9 +++++++++
 4 files changed, 50 insertions(+), 6 deletions(-)
 create mode 100644 xen/arch/arm/include/asm/mpu/mm.h
xen/arch/arm/include/asm/mm.h +7 -6
index a0d8e5afe977..e7767cdab493 100644
@@ -16,8 +16,10 @@
 
 #if defined(CONFIG_MMU)
 # include <asm/mmu/mm.h>
-#elif !defined(CONFIG_MPU)
-# error "Unknown memory management layout"
+#elif defined(CONFIG_MPU)
+# include <asm/mpu/mm.h>
+#else
+#error "Unknown memory management layout"
 #endif
 
 /* Align Xen to a 2 MiB boundary. */
@@ -261,10 +263,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 /* Page-align address and convert to frame number format */
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
-#define virt_to_maddr(va) ({                                        \
-    vaddr_t va_ = (vaddr_t)(va);                                    \
-    (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
-})
+#if defined(CONFIG_MMU)
 
 #ifdef CONFIG_ARM_32
 /**
@@ -310,6 +309,8 @@ static inline void *maddr_to_virt(paddr_t ma)
 }
 #endif
 
+#endif /* CONFIG_MMU */
+
 /*
  * Translate a guest virtual address to a machine address.
  * Return the fault information if the translation has failed else 0.
xen/arch/arm/include/asm/mmu/mm.h +7 -0
index f5a00558c47b..5ff2071133ee 100644
@@ -2,6 +2,8 @@
 #ifndef __ARM_MMU_MM_H__
 #define __ARM_MMU_MM_H__
 
+#include <asm/page.h>
+
 /* Non-boot CPUs use this to find the correct pagetables. */
 extern uint64_t init_ttbr;
 
@@ -14,6 +16,11 @@ extern unsigned long directmap_base_pdx;
 
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
 
+#define virt_to_maddr(va) ({                                                   \
+    vaddr_t va_ = (vaddr_t)(va);                                               \
+    (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
+})
+
 /*
  * Print a walk of a page table or p2m
  *
xen/arch/arm/include/asm/mpu/mm.h new file +27 -0
new file mode 100644
index 000000000000..57f1e558fd44
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARM_MPU_MM__
+#define __ARM_MPU_MM__
+
+#include <xen/macros.h>
+
+#define virt_to_maddr(va) ({  \
+    (paddr_t)va;              \
+})
+
+/* On MPU systems there is no translation, ma == va. */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    return _p(ma);
+}
+
+#endif /* __ARM_MPU_MM__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/mpu/mm.c +9 -0
index 0b8748e57598..a11e017d8a96 100644
@@ -13,3 +13,12 @@ static void __init __maybe_unused build_assertions(void)
      */
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 04/10] arm/mpu: Implement virt/maddr conversion in MPU system

Quoted 11 lines · Luca Fancellu

From: Penny Zheng <[email protected]>

virt_to_maddr and maddr_to_virt are used widely in Xen code. So even there is no VMSA in MPU system, we keep the interface in MPU to don't change the existing common code.

In order to do that, move the virt_to_maddr() definition to mmu/mm.h, instead for maddr_to_virt() it's more difficult to isolate it under mmu/ so it will be protected by #ifdef CONFIG_MMU.

I don't understand this rationale. I did a quick test and moving maddr_to_virt to mmu/mm.h works just fine.

Quoted 87 lines

Finally implement virt_to_maddr() and maddr_to_virt() for MPU systems under mpu/mm.h, the MPU version of virt/maddr conversion is simple since VA==PA.

While there, take the occasion to add emacs footer to mpu/mm.c.

---
 xen/arch/arm/include/asm/mm.h     | 13 +++++++------
 xen/arch/arm/include/asm/mmu/mm.h |  7 +++++++
 xen/arch/arm/include/asm/mpu/mm.h | 27 +++++++++++++++++++++++++++
 xen/arch/arm/mpu/mm.c             |  9 +++++++++
 4 files changed, 50 insertions(+), 6 deletions(-)
 create mode 100644 xen/arch/arm/include/asm/mpu/mm.h
xen/arch/arm/include/asm/mm.h +7 -6
index a0d8e5afe977..e7767cdab493 100644
@@ -16,8 +16,10 @@
 
 #if defined(CONFIG_MMU)
 # include <asm/mmu/mm.h>
-#elif !defined(CONFIG_MPU)
-# error "Unknown memory management layout"
+#elif defined(CONFIG_MPU)
+# include <asm/mpu/mm.h>
+#else
+#error "Unknown memory management layout"
 #endif
 
 /* Align Xen to a 2 MiB boundary. */
@@ -261,10 +263,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 /* Page-align address and convert to frame number format */
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
-#define virt_to_maddr(va) ({                                        \
-    vaddr_t va_ = (vaddr_t)(va);                                    \
-    (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
-})
+#if defined(CONFIG_MMU)
 
 #ifdef CONFIG_ARM_32
 /**
@@ -310,6 +309,8 @@ static inline void *maddr_to_virt(paddr_t ma)
 }
 #endif
 
+#endif /* CONFIG_MMU */
+
 /*
  * Translate a guest virtual address to a machine address.
  * Return the fault information if the translation has failed else 0.
xen/arch/arm/include/asm/mmu/mm.h +7 -0
index f5a00558c47b..5ff2071133ee 100644
@@ -2,6 +2,8 @@
 #ifndef __ARM_MMU_MM_H__
 #define __ARM_MMU_MM_H__
 
+#include <asm/page.h>
+
 /* Non-boot CPUs use this to find the correct pagetables. */
 extern uint64_t init_ttbr;
 
@@ -14,6 +16,11 @@ extern unsigned long directmap_base_pdx;
 
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
 
+#define virt_to_maddr(va) ({                                                   \
+    vaddr_t va_ = (vaddr_t)(va);                                               \
+    (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
+})
+
 /*
  * Print a walk of a page table or p2m
  *
xen/arch/arm/include/asm/mpu/mm.h new file +0 -0
new file mode 100644
index 000000000000..57f1e558fd44

xen/arch/arm/include/asm/mpu/mm.h line 3

Quoted 3 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARM_MPU_MM__

Missing _H? Should be: __ARM_MPU_MM_H__

xen/arch/arm/include/asm/mpu/mm.h line 6

Quoted 3 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
+#define __ARM_MPU_MM__
+
+#include <xen/macros.h>

I guess you also need xen/types.h

xen/arch/arm/include/asm/mpu/mm.h line 10

Quoted 4 lines
xen/arch/arm/include/asm/mpu/mm.h new file +4 -0
+
+#define virt_to_maddr(va) ({  \
+    (paddr_t)va;              \
+})

Why multiline? Also, shouldn't we take PA bits into account? I'd imagine:
((paddr_t)((vaddr_t)(va) & PADDR_MASK))

xen/arch/arm/include/asm/mpu/mm.h line 15

Quoted 5 lines
xen/arch/arm/include/asm/mpu/mm.h new file +5 -0
+
+/* On MPU systems there is no translation, ma == va. */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    return _p(ma);

Why do we need to cast paddr_t to unsigned long before casting to void? Why not:
return (void *)(ma);

xen/arch/arm/include/asm/mpu/mm.h line 18

Quoted 3 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
+}
+
+#endif /* __ARM_MPU_MM__ */

__ARM_MPU_MM_H__

Quoted 27 lines
xen/arch/arm/include/asm/mpu/mm.h new file +9 -0
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/mpu/mm.c +9 -1
index 0b8748e57598..a11e017d8a96 100644
@@ -13,3 +13,12 @@ static void __init __maybe_unused build_assertions(void)
      */
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

2.34.1

~Michal

#6 lore raw

Re: [PATCH 04/10] arm/mpu: Implement virt/maddr conversion in MPU system

Quoted 11 lines · Michal
Quoted 8 lines · Luca Fancellu

From: Penny Zheng <[email protected]>

virt_to_maddr and maddr_to_virt are used widely in Xen code. So even there is no VMSA in MPU system, we keep the interface in MPU to don't change the existing common code.

Quoted 5 lines
Quoted 3 lines

In order to do that, move the virt_to_maddr() definition to mmu/mm.h, instead for maddr_to_virt() it's more difficult to isolate it under mmu/ so it will be protected by #ifdef CONFIG_MMU.

I don't understand this rationale. I did a quick test and moving maddr_to_virt to mmu/mm.h works just fine.

Ignore this comment. I was not right.

~Michal

#7 lore raw

Re: [PATCH 04/10] arm/mpu: Implement virt/maddr conversion in MPU system

In reply to Orzel, Michal

Hi Michal,

thanks for your review,

Quoted 24 lines

xen/arch/arm/include/asm/mpu/mm.h line 3

Quoted 9 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
new file mode 100644
index 000000000000..57f1e558fd44
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARM_MPU_MM__

Missing _H? Should be: __ARM_MPU_MM_H__

xen/arch/arm/include/asm/mpu/mm.h line 6

Quoted 3 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
+#define __ARM_MPU_MM__
+
+#include <xen/macros.h>

I guess you also need xen/types.h

xen/arch/arm/include/asm/mpu/mm.h line 10

Quoted 4 lines
xen/arch/arm/include/asm/mpu/mm.h new file +4 -0
+
+#define virt_to_maddr(va) ({  \
+    (paddr_t)va;              \
+})

Why multiline? Also, shouldn't we take PA bits into account? I'd imagine:
((paddr_t)((vaddr_t)(va) & PADDR_MASK))

Quoted 8 lines

xen/arch/arm/include/asm/mpu/mm.h line 15

Quoted 5 lines
xen/arch/arm/include/asm/mpu/mm.h new file +5 -0
+
+/* On MPU systems there is no translation, ma == va. */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    return _p(ma);

Why do we need to cast paddr_t to unsigned long before casting to void? Why not:
return (void *)(ma);

So it was pointed out on a previous review that it’s ok to use _p() instead of doing straight the cast:
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/#25404105

please let me know your thought about it.

Quoted 6 lines

xen/arch/arm/include/asm/mpu/mm.h line 18

Quoted 4 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
+}
+
+#endif /* __ARM_MPU_MM__ */

__ARM_MPU_MM_H__

I’ll fix all the other points you mentioned.

Cheers,
Luca

#8 lore raw

Re: [PATCH 04/10] arm/mpu: Implement virt/maddr conversion in MPU system

Quoted 39 lines · Luca Fancellu

Hi Michal,

thanks for your review,

Quoted 24 lines

xen/arch/arm/include/asm/mpu/mm.h line 3

Quoted 9 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
new file mode 100644
index 000000000000..57f1e558fd44
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARM_MPU_MM__

Missing _H? Should be: __ARM_MPU_MM_H__

xen/arch/arm/include/asm/mpu/mm.h line 6

Quoted 3 lines
xen/arch/arm/include/asm/mpu/mm.h new file +3 -0
+#define __ARM_MPU_MM__
+
+#include <xen/macros.h>

I guess you also need xen/types.h

xen/arch/arm/include/asm/mpu/mm.h line 10

Quoted 4 lines
xen/arch/arm/include/asm/mpu/mm.h new file +4 -0
+
+#define virt_to_maddr(va) ({  \
+    (paddr_t)va;              \
+})

Why multiline? Also, shouldn't we take PA bits into account? I'd imagine:
((paddr_t)((vaddr_t)(va) & PADDR_MASK))

Quoted 8 lines

xen/arch/arm/include/asm/mpu/mm.h line 15

Quoted 5 lines
xen/arch/arm/include/asm/mpu/mm.h new file +5 -0
+
+/* On MPU systems there is no translation, ma == va. */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    return _p(ma);

Why do we need to cast paddr_t to unsigned long before casting to void? Why not:
return (void *)(ma);

Quoted 4 lines

So it was pointed out on a previous review that it’s ok to use _p() instead of doing straight the cast:
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/#25404105

please let me know your thought about it.

I'm ok with that.

~Michal

#9 lore raw

Re: [PATCH 04/10] arm/mpu: Implement virt/maddr conversion in MPU system

In reply to Luca Fancellu

Hi Luca,

Quoted 5 lines · Luca Fancellu

From: Penny Zheng <[email protected]>

virt_to_maddr and maddr_to_virt are used widely in Xen code. So even there is no VMSA in MPU system, we keep the interface in MPU to don't change the existing common code.

Typo: I think you mean "to avoid changing".

Quoted 4 lines

In order to do that, move the virt_to_maddr() definition to mmu/mm.h, instead for maddr_to_virt() it's more difficult to isolate it under mmu/ so it will be protected by #ifdef CONFIG_MMU.

I think defining maddr_to_virt() in asm/mm.h for the MMU but not the MPU is a bit odd. Can you provide more details on the exact issue?

And if it really can't be solved, then I would rather prefer if both virt_to_maddr() and maddr_to_virt() are defined in asm/mm.h for both the MPU and MMU because they are related to each other.

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw

PATCH v5 2/10 xen/arm: Restrict Kconfig configuration for LLC coloring

In reply to Luca Fancellu

Xen LLC coloring feature can be used only on the MMU subsystem, move the code that selects it from ARM_64 to MMU and add the ARM_64 dependency.

---
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
v5 changes:
- no changes
v4 changes:
- clarified that it's the Xen feature LLC coloring that is not applicable to the MPU subsystem, not the generic cache coloring method.
- Add R-by Michal

v3 changes:
- Dropped comment on top of boot_fdt_info()

v2 changes:
- dropped part of the v1 code, now this one is simpler, I will discuss better how to design a common boot flow for MPU and implement on another patch.

---

---
 xen/arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/Kconfig +1 -1
index a26d3e11827c..ffdff1f0a36c 100644
@@ -8,7 +8,6 @@ config ARM_64
 	depends on !ARM_32
 	select 64BIT
 	select HAS_FAST_MULTIPLY
-	select HAS_LLC_COLORING if !NUMA
 
 config ARM
 	def_bool y
@@ -76,6 +75,7 @@ choice
 
 config MMU
 	bool "MMU"
+	select HAS_LLC_COLORING if !NUMA && ARM_64
 	select HAS_PMAP
 	select HAS_VMAP
 	select HAS_PASSTHROUGH
Signature · 1 line
2.34.1
#11 lore raw

PATCH 5/10 arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

In reply to Luca Fancellu

Introduce variables and functions used in the common Arm code by MPU memory management subsystem, provide struct page_info and the MPU implementation for helpers and macros used in the common arm code.

Moving virt_to_page helper to mmu/mpu part is not easy as it needs visibility of 'struct page_info', so protect it with CONFIG_MMU and provide the MPU variant in the #else branch.

Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c.

---
 xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
 xen/arch/arm/include/asm/mpu/layout.h |  3 +++
 xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
 xen/arch/arm/mpu/mm.c                 |  4 ++++
 4 files changed, 28 insertions(+)
xen/arch/arm/include/asm/mm.h +18 -0
index e7767cdab493..c96d33aceaf0 100644
@@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
 #define virt_to_mfn(va)     __virt_to_mfn(va)
 #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
 
+#ifdef CONFIG_MMU
+
 /* Convert between Xen-heap virtual addresses and page-info structures. */
 static inline struct page_info *virt_to_page(const void *v)
 {
@@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void *v)
     return frame_table + pdx - frametable_base_pdx;
 }
 
+#else /* !CONFIG_MMU */
+
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    unsigned long pdx;
+
+    pdx = paddr_to_pdx(virt_to_maddr(v));
+    ASSERT(pdx >= frametable_base_pdx);
+    ASSERT(pdx < frametable_pdx_end);
+
+    return frame_table + pdx - frametable_base_pdx;
+}
+
+#endif /* CONFIG_MMU */
+
 static inline void *page_to_virt(const struct page_info *pg)
 {
     return mfn_to_virt(mfn_x(page_to_mfn(pg)));
xen/arch/arm/include/asm/mpu/layout.h +3 -0
index 248e55f8882d..c46b634c9c15 100644
@@ -3,6 +3,9 @@
 #ifndef __ARM_MPU_LAYOUT_H__
 #define __ARM_MPU_LAYOUT_H__
 
+#define FRAMETABLE_SIZE   GB(32)
+#define FRAMETABLE_NR     (FRAMETABLE_SIZE / sizeof(*frame_table))
+
 #define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
 
 /*
xen/arch/arm/include/asm/mpu/mm.h +3 -0
index 57f1e558fd44..2219c9979548 100644
@@ -5,6 +5,9 @@
 
 #include <xen/macros.h>
 
+extern struct page_info *frame_table;
+extern unsigned long frametable_pdx_end;
+
 #define virt_to_maddr(va) ({  \
     (paddr_t)va;              \
 })
xen/arch/arm/mpu/mm.c +4 -0
index a11e017d8a96..4036dd62eeeb 100644
@@ -3,6 +3,10 @@
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/sizes.h>
+#include <xen/mm.h>
+
+struct page_info *frame_table;
+unsigned long __read_mostly frametable_pdx_end;
 
 static void __init __maybe_unused build_assertions(void)
 {
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

Hi,

Quoted 8 lines · Luca Fancellu

Introduce variables and functions used in the common Arm code by MPU memory management subsystem, provide struct page_info and the MPU implementation for helpers and macros used in the common arm code.

Moving virt_to_page helper to mmu/mpu part is not easy as it needs visibility of 'struct page_info', so protect it with CONFIG_MMU and provide the MPU variant in the #else branch.

Have you considered including "asm/{mmu,mpu}/mm.h" **after** struct page_info is declared?

Quoted 3 lines

Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c.

Maybe clarify in the commit message that the frametable will be setup at a later stage?

Quoted 49 lines
---
  xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
  xen/arch/arm/include/asm/mpu/layout.h |  3 +++
  xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
  xen/arch/arm/mpu/mm.c                 |  4 ++++
  4 files changed, 28 insertions(+)
xen/arch/arm/include/asm/mm.h +18 -0
index e7767cdab493..c96d33aceaf0 100644
@@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
  #define virt_to_mfn(va)     __virt_to_mfn(va)
  #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
 
+#ifdef CONFIG_MMU
+
  /* Convert between Xen-heap virtual addresses and page-info structures. */
  static inline struct page_info *virt_to_page(const void *v)
  {
@@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void *v)
      return frame_table + pdx - frametable_base_pdx;
  }
 
+#else /* !CONFIG_MMU */
+
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    unsigned long pdx;
+
+    pdx = paddr_to_pdx(virt_to_maddr(v));
+    ASSERT(pdx >= frametable_base_pdx);
+    ASSERT(pdx < frametable_pdx_end);
+
+    return frame_table + pdx - frametable_base_pdx;
+}
+
+#endif /* CONFIG_MMU */
+
  static inline void *page_to_virt(const struct page_info *pg)
  {
      return mfn_to_virt(mfn_x(page_to_mfn(pg)));
xen/arch/arm/include/asm/mpu/layout.h +0 -0
index 248e55f8882d..c46b634c9c15 100644

xen/arch/arm/include/asm/mpu/layout.h line 6

Quoted 4 lines
xen/arch/arm/include/asm/mpu/layout.h +1 -0
@@ -3,6 +3,9 @@
  #ifndef __ARM_MPU_LAYOUT_H__
  #define __ARM_MPU_LAYOUT_H__
 
+#define FRAMETABLE_SIZE   GB(32)

I guess you copied the value for the MMU code for arm64. But is this value still sensible for MPU? What about arm32?

In any case, some documentation would be useful.

Quoted 24 lines
xen/arch/arm/include/asm/mpu/layout.h +2 -0
+#define FRAMETABLE_NR     (FRAMETABLE_SIZE / sizeof(*frame_table))
+
  #define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
 
  /*
xen/arch/arm/include/asm/mpu/mm.h +3 -0
index 57f1e558fd44..2219c9979548 100644
@@ -5,6 +5,9 @@
 
  #include <xen/macros.h>
 
+extern struct page_info *frame_table;
+extern unsigned long frametable_pdx_end;
+
  #define virt_to_maddr(va) ({  \
      (paddr_t)va;              \
  })
xen/arch/arm/mpu/mm.c +0 -0
index a11e017d8a96..4036dd62eeeb 100644

xen/arch/arm/mpu/mm.c line 12

Quoted 10 lines
xen/arch/arm/mpu/mm.c +4 -0
@@ -3,6 +3,10 @@
  #include <xen/lib.h>
  #include <xen/init.h>
  #include <xen/sizes.h>
+#include <xen/mm.h>
+
+struct page_info *frame_table;
+unsigned long __read_mostly frametable_pdx_end;
 
  static void __init __maybe_unused build_assertions(void)
  {

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw

Re: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

Hi Julien,

Quoted 13 lines · Julien Grall

Hi,

Quoted 7 lines · Luca Fancellu

Introduce variables and functions used in the common Arm code by MPU memory management subsystem, provide struct page_info and the MPU implementation for helpers and macros used in the common arm code.
Moving virt_to_page helper to mmu/mpu part is not easy as it needs visibility of 'struct page_info', so protect it with CONFIG_MMU and provide the MPU variant in the #else branch.

Quoted 1 line

Have you considered including "asm/{mmu,mpu}/mm.h" **after** struct page_info is declared?

I didn’t tried that, but if we do that we solve all the issues (I don’t like #includes in the middle of headers, because of that I didn’t try).

This is what it looks like:

xen/arch/arm/include/asm/mm.h +4 -52
index 9bf5c846c86c..b49ec9c3dd1a 100644
@@ -14,14 +14,6 @@
 # error "unknown ARM variant"
 #endif
 
-#if defined(CONFIG_MMU)
-# include <asm/mmu/mm.h>
-#elif defined(CONFIG_MPU)
-# include <asm/mpu/mm.h>
-#else
-#error "Unknown memory management layout"
-#endif
-
 /* Align Xen to a 2 MiB boundary. */
 #define XEN_PADDR_ALIGN (1 << 21)
 
@@ -264,53 +256,13 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
 #if defined(CONFIG_MMU)
-
-#ifdef CONFIG_ARM_32
-/**
- * Find the virtual address corresponding to a machine address
- *
- * Only memory backing the XENHEAP has a corresponding virtual address to
- * be found. This is so we can save precious virtual space, as it's in
- * short supply on arm32. This mapping is not subject to PDX compression
- * because XENHEAP is known to be physically contiguous and can't hence
- * jump over the PDX hole. This means we can avoid the roundtrips
- * converting to/from pdx.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
-    ma -= mfn_to_maddr(directmap_mfn_start);
-    return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
-}
+# include <asm/mmu/mm.h>
+#elif defined(CONFIG_MPU)
+# include <asm/mpu/mm.h>
 #else
-/**
- * Find the virtual address corresponding to a machine address
- *
- * The directmap covers all conventional memory accesible by the
- * hypervisor. This means it's subject to PDX compression.
- *
- * Note there's an extra offset applied (directmap_base_pdx) on top of the
- * regular PDX compression logic. Its purpose is to skip over the initial
- * range of non-existing memory, should there be one.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) <
-           (DIRECTMAP_SIZE >> PAGE_SHIFT));
-    return (void *)(XENHEAP_VIRT_START -
-                    (directmap_base_pdx << PAGE_SHIFT) +
-                    maddr_to_directmapoff(ma));
-}
+#error "Unknown memory management layout"
 #endif
 
-#endif /* CONFIG_MMU */
-
 /*
  * Translate a guest virtual address to a machine address.
  * Return the fault information if the translation has failed else 0.
xen/arch/arm/include/asm/mmu/mm.h +44 -0

50 lines not on this page · raw message

Quoted 5 lines
Quoted 2 lines

Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c.

Maybe clarify in the commit message that the frametable will be setup at a later stage?

Sure

Quoted 53 lines
Quoted 47 lines
---
 xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
 xen/arch/arm/include/asm/mpu/layout.h |  3 +++
 xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
 xen/arch/arm/mpu/mm.c                 |  4 ++++
 4 files changed, 28 insertions(+)
xen/arch/arm/include/asm/mm.h +16 -0
index e7767cdab493..c96d33aceaf0 100644
@@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
 #define virt_to_mfn(va)     __virt_to_mfn(va)
 #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
 +#ifdef CONFIG_MMU
+
 /* Convert between Xen-heap virtual addresses and page-info structures. */
 static inline struct page_info *virt_to_page(const void *v)
 {
@@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void *v)
     return frame_table + pdx - frametable_base_pdx;
 }
 +#else /* !CONFIG_MMU */
+
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    unsigned long pdx;
+
+    pdx = paddr_to_pdx(virt_to_maddr(v));
+    ASSERT(pdx >= frametable_base_pdx);
+    ASSERT(pdx < frametable_pdx_end);
+
+    return frame_table + pdx - frametable_base_pdx;
+}
+
+#endif /* CONFIG_MMU */
+
 static inline void *page_to_virt(const struct page_info *pg)
 {
     return mfn_to_virt(mfn_x(page_to_mfn(pg)));
xen/arch/arm/include/asm/mpu/layout.h +0 -0
index 248e55f8882d..c46b634c9c15 100644

xen/arch/arm/include/asm/mpu/layout.h line 5

Quoted 3 lines
xen/arch/arm/include/asm/mpu/layout.h +0 -0
@@ -3,6 +3,9 @@
 #ifndef __ARM_MPU_LAYOUT_H__
 #define __ARM_MPU_LAYOUT_H__
 +#define FRAMETABLE_SIZE   GB(32)

I guess you copied the value for the MMU code for arm64. But is this value still sensible for MPU? What about arm32?

Quoted 1 line

In any case, some documentation would be useful.

Yes I took the one from arm64, here I probably need some help as there are not too many informations about how to size this.

#14 lore raw

Re: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

Quoted 220 lines · Luca Fancellu

Hi Julien,

Quoted 13 lines · Julien Grall

Hi,

Quoted 7 lines · Luca Fancellu

Introduce variables and functions used in the common Arm code by MPU memory management subsystem, provide struct page_info and the MPU implementation for helpers and macros used in the common arm code.
Moving virt_to_page helper to mmu/mpu part is not easy as it needs visibility of 'struct page_info', so protect it with CONFIG_MMU and provide the MPU variant in the #else branch.

Quoted 1 line

Have you considered including "asm/{mmu,mpu}/mm.h" **after** struct page_info is declared?

I didn’t tried that, but if we do that we solve all the issues (I don’t like #includes in the middle of headers, because of that I didn’t try).

This is what it looks like:

xen/arch/arm/include/asm/mm.h +4 -52
index 9bf5c846c86c..b49ec9c3dd1a 100644
@@ -14,14 +14,6 @@
 # error "unknown ARM variant"
 #endif
 
-#if defined(CONFIG_MMU)
-# include <asm/mmu/mm.h>
-#elif defined(CONFIG_MPU)
-# include <asm/mpu/mm.h>
-#else
-#error "Unknown memory management layout"
-#endif
-
 /* Align Xen to a 2 MiB boundary. */
 #define XEN_PADDR_ALIGN (1 << 21)
 
@@ -264,53 +256,13 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
 #if defined(CONFIG_MMU)
-
-#ifdef CONFIG_ARM_32
-/**
- * Find the virtual address corresponding to a machine address
- *
- * Only memory backing the XENHEAP has a corresponding virtual address to
- * be found. This is so we can save precious virtual space, as it's in
- * short supply on arm32. This mapping is not subject to PDX compression
- * because XENHEAP is known to be physically contiguous and can't hence
- * jump over the PDX hole. This means we can avoid the roundtrips
- * converting to/from pdx.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
-    ma -= mfn_to_maddr(directmap_mfn_start);
-    return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
-}
+# include <asm/mmu/mm.h>
+#elif defined(CONFIG_MPU)
+# include <asm/mpu/mm.h>
 #else
-/**
- * Find the virtual address corresponding to a machine address
- *
- * The directmap covers all conventional memory accesible by the
- * hypervisor. This means it's subject to PDX compression.
- *
- * Note there's an extra offset applied (directmap_base_pdx) on top of the
- * regular PDX compression logic. Its purpose is to skip over the initial
- * range of non-existing memory, should there be one.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) <
-           (DIRECTMAP_SIZE >> PAGE_SHIFT));
-    return (void *)(XENHEAP_VIRT_START -
-                    (directmap_base_pdx << PAGE_SHIFT) +
-                    maddr_to_directmapoff(ma));
-}
+#error "Unknown memory management layout"
 #endif
 
-#endif /* CONFIG_MMU */
-
 /*
  * Translate a guest virtual address to a machine address.
  * Return the fault information if the translation has failed else 0.
xen/arch/arm/include/asm/mmu/mm.h +44 -0
index 5ff2071133ee..9557f632d8e6 100644
@@ -21,6 +21,50 @@ extern unsigned long directmap_base_pdx;
     (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
 })
 
+#ifdef CONFIG_ARM_32
+/**
+ * Find the virtual address corresponding to a machine address
+ *
+ * Only memory backing the XENHEAP has a corresponding virtual address to
+ * be found. This is so we can save precious virtual space, as it's in
+ * short supply on arm32. This mapping is not subject to PDX compression
+ * because XENHEAP is known to be physically contiguous and can't hence
+ * jump over the PDX hole. This means we can avoid the roundtrips
+ * converting to/from pdx.
+ *
+ * @param ma Machine address
+ * @return Virtual address mapped to `ma`
+ */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
+    ma -= mfn_to_maddr(directmap_mfn_start);
+    return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
+}
+#else
+/**
+ * Find the virtual address corresponding to a machine address
+ *
+ * The directmap covers all conventional memory accesible by the
+ * hypervisor. This means it's subject to PDX compression.
+ *
+ * Note there's an extra offset applied (directmap_base_pdx) on top of the
+ * regular PDX compression logic. Its purpose is to skip over the initial
+ * range of non-existing memory, should there be one.
+ *
+ * @param ma Machine address
+ * @return Virtual address mapped to `ma`
+ */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) <
+           (DIRECTMAP_SIZE >> PAGE_SHIFT));
+    return (void *)(XENHEAP_VIRT_START -
+                    (directmap_base_pdx << PAGE_SHIFT) +
+                    maddr_to_directmapoff(ma));
+}
+#endif
+
 /*
  * Print a walk of a page table or p2m
  *
Quoted 8 lines
Quoted 5 lines

Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c.

Maybe clarify in the commit message that the frametable will be setup at a later stage?

Sure

Quoted 53 lines
Quoted 47 lines
---
 xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
 xen/arch/arm/include/asm/mpu/layout.h |  3 +++
 xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
 xen/arch/arm/mpu/mm.c                 |  4 ++++
 4 files changed, 28 insertions(+)
xen/arch/arm/include/asm/mm.h +16 -0
index e7767cdab493..c96d33aceaf0 100644
@@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
 #define virt_to_mfn(va)     __virt_to_mfn(va)
 #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
 +#ifdef CONFIG_MMU
+
 /* Convert between Xen-heap virtual addresses and page-info structures. */
 static inline struct page_info *virt_to_page(const void *v)
 {
@@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void *v)
     return frame_table + pdx - frametable_base_pdx;
 }
 +#else /* !CONFIG_MMU */
+
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    unsigned long pdx;
+
+    pdx = paddr_to_pdx(virt_to_maddr(v));
+    ASSERT(pdx >= frametable_base_pdx);
+    ASSERT(pdx < frametable_pdx_end);
+
+    return frame_table + pdx - frametable_base_pdx;
+}
+
+#endif /* CONFIG_MMU */
+
 static inline void *page_to_virt(const struct page_info *pg)
 {
     return mfn_to_virt(mfn_x(page_to_mfn(pg)));
xen/arch/arm/include/asm/mpu/layout.h +0 -0
index 248e55f8882d..c46b634c9c15 100644

xen/arch/arm/include/asm/mpu/layout.h line 5

Quoted 3 lines
xen/arch/arm/include/asm/mpu/layout.h +0 -0
@@ -3,6 +3,9 @@
 #ifndef __ARM_MPU_LAYOUT_H__
 #define __ARM_MPU_LAYOUT_H__
 +#define FRAMETABLE_SIZE   GB(32)

I guess you copied the value for the MMU code for arm64. But is this value still sensible for MPU? What about arm32?

Quoted 4 lines
Quoted 1 line

In any case, some documentation would be useful.

Yes I took the one from arm64, here I probably need some help as there are not too many informations about how to size this.

It depends on your estimate about max RAM size you want to support in MPU case. 32GB / 56B (size of page_info on Arm64) - tells you how many page_info structs you can have. The above value * 4K - tells you amount of RAM supported.

~Michal

#15 lore raw

Re: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

In reply to Luca Fancellu
Quoted 10 lines · Luca Fancellu

Introduce variables and functions used in the common Arm code by MPU memory management subsystem, provide struct page_info and the MPU implementation for helpers and macros used in the common arm code.

Moving virt_to_page helper to mmu/mpu part is not easy as it needs visibility of 'struct page_info', so protect it with CONFIG_MMU and provide the MPU variant in the #else branch.

I see we move some helpers to mmu,mpu while others stay in generic mm.h. If it's not possible to do the movement, then I'd suggest to keep the pairs in generic mm.h to avoid situation where one helper e.g. MMU is in generic mm.h and for MPU in mpu/mm.h

Quoted 29 lines

Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c.

---
 xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
 xen/arch/arm/include/asm/mpu/layout.h |  3 +++
 xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
 xen/arch/arm/mpu/mm.c                 |  4 ++++
 4 files changed, 28 insertions(+)
xen/arch/arm/include/asm/mm.h +2 -0
index e7767cdab493..c96d33aceaf0 100644
@@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
 #define virt_to_mfn(va)     __virt_to_mfn(va)
 #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
 
+#ifdef CONFIG_MMU
+
 /* Convert between Xen-heap virtual addresses and page-info structures. */
 static inline struct page_info *virt_to_page(const void *v)
 {
@@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void *v)
     return frame_table + pdx - frametable_base_pdx;
 }
 

xen/arch/arm/include/asm/mm.h static inline struct page_info *virt_to_page(const void *v) · line 369

Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10 -0
+#else /* !CONFIG_MMU */
+
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    unsigned long pdx;
+
+    pdx = paddr_to_pdx(virt_to_maddr(v));
+    ASSERT(pdx >= frametable_base_pdx);
+    ASSERT(pdx < frametable_pdx_end);

I struggle to see the usefulness of frametable_pdx_end and we don't generally add more that start, size. Looking at your tree, the only use of frametable_pdx_end is in this ASSERT which is a bit pointless considering release build. You already have start, size, so you could open code it.

Quoted 42 lines
xen/arch/arm/include/asm/mm.h +6 -0
+
+    return frame_table + pdx - frametable_base_pdx;
+}
+
+#endif /* CONFIG_MMU */
+
 static inline void *page_to_virt(const struct page_info *pg)
 {
     return mfn_to_virt(mfn_x(page_to_mfn(pg)));
xen/arch/arm/include/asm/mpu/layout.h +3 -0
index 248e55f8882d..c46b634c9c15 100644
@@ -3,6 +3,9 @@
 #ifndef __ARM_MPU_LAYOUT_H__
 #define __ARM_MPU_LAYOUT_H__
 
+#define FRAMETABLE_SIZE   GB(32)
+#define FRAMETABLE_NR     (FRAMETABLE_SIZE / sizeof(*frame_table))
+
 #define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
 
 /*
xen/arch/arm/include/asm/mpu/mm.h +3 -0
index 57f1e558fd44..2219c9979548 100644
@@ -5,6 +5,9 @@
 
 #include <xen/macros.h>
 
+extern struct page_info *frame_table;
+extern unsigned long frametable_pdx_end;
+
 #define virt_to_maddr(va) ({  \
     (paddr_t)va;              \
 })
xen/arch/arm/mpu/mm.c +0 -0
index a11e017d8a96..4036dd62eeeb 100644

xen/arch/arm/mpu/mm.c line 6

Quoted 4 lines
xen/arch/arm/mpu/mm.c +1 -0
@@ -3,6 +3,10 @@
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/sizes.h>
+#include <xen/mm.h>

It's not great for a relatively new header to not have its includes sorted. Please take the occasion to reorder them.

Quoted 9 lines
xen/arch/arm/mpu/mm.c +3 -1
+
+struct page_info *frame_table;
+unsigned long __read_mostly frametable_pdx_end;
 
 static void __init __maybe_unused build_assertions(void)
 {
--

2.34.1

~Michal

#16 lore raw

PATCH 6/10 arm/mpu: Kconfig symbols for MPU build

In reply to Luca Fancellu

Currently the MPU system requires static memory to work, select that when building this memory management subsystem.

While there, provide a restriction for the ARM_EFI Kconfig parameter to be built only when !MPU, the EFI stub is not used as there are no implementation of UEFI services for armv8-r.

---
 xen/arch/arm/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +2 -1
index ffdff1f0a36c..5ac6ec0212d2 100644
@@ -85,6 +85,7 @@ config MMU
 
 config MPU
 	bool "MPU" if UNSUPPORTED
+	select STATIC_MEMORY
 	help
 	  Memory Protection Unit (MPU). Select if you plan to run Xen on ARMv8-R
 	  systems supporting EL2. (UNSUPPORTED)
@@ -102,7 +103,7 @@ config ACPI
 
 config ARM_EFI
 	bool "UEFI boot service support"
-	depends on ARM_64
+	depends on ARM_64 && !MPU
 	default y
 	help
 	  This option provides support for boot services through
Signature · 1 line
2.34.1
Reviewed-by on v1 6/10
#17 lore raw

Re: [PATCH 06/10] arm/mpu: Kconfig symbols for MPU build

Quoted 3 lines · Luca Fancellu

Currently the MPU system requires static memory to work,

Currently, meaning in the future it might not be needed?
Also, I don't see how is this change required to enable compilation (the main goal of this series) for MPU but because we will have to enable it anyway...

Quoted 8 lines

select that when building this memory management subsystem.

While there, provide a restriction for the ARM_EFI Kconfig parameter to be built only when !MPU, the EFI stub is not used as there are no implementation of UEFI services for armv8-r.

~Michal

#18 lore raw

Re: [PATCH 06/10] arm/mpu: Kconfig symbols for MPU build

Hi MIchal,

Quoted 9 lines · Michal
Quoted 3 lines · Luca Fancellu

Currently the MPU system requires static memory to work,

Currently, meaning in the future it might not be needed?

No, maybe I’m not clear, my understanding is that static memory is always required for MPU.

Do you want me to change this one?

Quoted 2 lines

Also, I don't see how is this change required to enable compilation (the main goal of this series) for MPU but because we will have to enable it anyway...

yes I thought the same

Quoted 13 lines
Quoted 9 lines

select that when building this memory management subsystem.

While there, provide a restriction for the ARM_EFI Kconfig parameter to be built only when !MPU, the EFI stub is not used as there are no implementation of UEFI services for armv8-r.

~Michal

#19 lore raw

Re: [PATCH 06/10] arm/mpu: Kconfig symbols for MPU build

Quoted 8 lines · Luca Fancellu

Hi MIchal,

Quoted 4 lines · Michal
Quoted 7 lines
Quoted 5 lines · Luca Fancellu
Quoted 3 lines

Currently the MPU system requires static memory to work,

Currently, meaning in the future it might not be needed?

No, maybe I’m not clear, my understanding is that static memory is always required for MPU.

I think so too. I'd suggest to drop "Currently" as it reads as if it was a temporary requirement.

~Michal

#20 lore raw

PATCH 7/10 arm/mpu: Implement stubs for ioremap_attr on MPU

In reply to Luca Fancellu

Implement ioremap_attr() stub for MPU system; the implementation of ioremap() is the same between MMU and MPU system, and it relies on ioremap_attr(), so move the definition from mmu/pt.c to arm/mm.c.

---
 xen/arch/arm/mm.c     | 5 +++++
 xen/arch/arm/mmu/pt.c | 5 -----
 xen/arch/arm/mpu/mm.c | 6 ++++++
 3 files changed, 11 insertions(+), 5 deletions(-)
xen/arch/arm/mm.c +5 -0
index a56e20ba2bdc..5a52f0c623e5 100644
@@ -395,6 +395,11 @@ unsigned long get_upper_mfn_bound(void)
     return max_page - 1;
 }
 
+void *ioremap(paddr_t pa, size_t len)
+{
+    return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/mmu/pt.c +0 -5
index da28d669e796..11cb1c66dac8 100644
@@ -223,11 +223,6 @@ void *ioremap_attr(paddr_t start, size_t len, unsigned int attributes)
     return ptr + offs;
 }
 
-void *ioremap(paddr_t pa, size_t len)
-{
-    return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE);
-}
-
 static int create_xen_table(lpae_t *entry)
 {
     mfn_t mfn;
xen/arch/arm/mpu/mm.c +6 -0
index 4036dd62eeeb..b196661a2312 100644
@@ -18,6 +18,12 @@ static void __init __maybe_unused build_assertions(void)
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
 
+void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
2.34.1
Reviewed-by on v1 7/10
#21 lore raw

Re: [PATCH 07/10] arm/mpu: Implement stubs for ioremap_attr on MPU

Quoted 6 lines · Luca Fancellu

Implement ioremap_attr() stub for MPU system; the implementation of ioremap() is the same between MMU and MPU system, and it relies on ioremap_attr(), so move the definition from mmu/pt.c to arm/mm.c.

I could see this bundled with the last patch, but as you already split it.

Quoted 2 lines

~Michal

#22 lore raw

PATCH 8/10 xen/arm: Rename setup_pagetables with a more generic name

In reply to Luca Fancellu

Rename the setup_pagetables function to setup_mappings in order to be implemented also for MPU system that does not have page tables.

Introduce a stub implementation for MPU in order to allow the compilation.

---
 xen/arch/arm/include/asm/mm.h |  2 +-
 xen/arch/arm/mmu/setup.c      |  2 +-
 xen/arch/arm/mpu/Makefile     |  1 +
 xen/arch/arm/mpu/setup.c      | 18 ++++++++++++++++++
 xen/arch/arm/setup.c          |  6 +++---
 5 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 xen/arch/arm/mpu/setup.c
xen/arch/arm/include/asm/mm.h +1 -1
index c96d33aceaf0..9bf5c846c86c 100644
@@ -206,7 +206,7 @@ extern unsigned long frametable_base_pdx;
 #define PDX_GROUP_SHIFT SECOND_SHIFT
 
 /* Boot-time pagetable setup */
-extern void setup_pagetables(void);
+extern void setup_mappings(void);
 /* Map FDT in boot pagetable */
 extern void *early_fdt_map(paddr_t fdt_paddr);
 /* Remove early mappings */
xen/arch/arm/mmu/setup.c +1 -1
index 30afe9778194..35ffa5479dd3 100644
@@ -354,7 +354,7 @@ static void __init create_llc_coloring_mappings(void)
  * Boot-time pagetable setup.
  * Changes here may need matching changes in head.S
  */
-void __init setup_pagetables(void)
+void __init setup_mappings(void)
 {
     uint64_t ttbr;
     lpae_t pte, *p;
xen/arch/arm/mpu/Makefile +1 -0
index b18cec483671..04df0b2ee760 100644
@@ -1 +1,2 @@
 obj-y += mm.o
+obj-y += setup.init.o
xen/arch/arm/mpu/setup.c new file +18 -0
new file mode 100644
index 000000000000..45214bfeb661
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/bug.h>
+#include <xen/init.h>
+
+void __init setup_mappings(void)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/setup.c +3 -3
index ffcae900d72e..4c9ed747f9a8 100644
@@ -338,10 +338,10 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
     llc_coloring_init();
 
     /*
-     * Page tables must be setup after LLC coloring initialization because
-     * coloring info are required in order to create colored mappings
+     * On MMU, page tables must be setup after LLC coloring initialization
+     * because coloring info are required in order to create colored mappings
      */
-    setup_pagetables();
+    setup_mappings();
     /* Device-tree was mapped in boot page tables, remap it in the new tables */
     device_tree_flattened = early_fdt_map(fdt_paddr);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 8/10
#23 lore raw

Re: [PATCH 08/10] xen/arm: Rename setup_pagetables with a more generic name

Quoted 5 lines · Luca Fancellu

Rename the setup_pagetables function to setup_mappings in order to be implemented also for MPU system that does not have page tables.

mappings is better than pagetables, so:

but I'd like to understand what will be implementation of setup_mappings for MPU. I suppose regions setup such that the following call to early_fdt_map can succeed and doing this in setup_mm is already too late?

~Michal

#24 lore raw

Re: [PATCH 08/10] xen/arm: Rename setup_pagetables with a more generic name

Hi Michal,

Quoted 11 lines · Michal
Quoted 5 lines · Luca Fancellu

Rename the setup_pagetables function to setup_mappings in order to be implemented also for MPU system that does not have page tables.

Quoted 6 lines

mappings is better than pagetables, so:

but I'd like to understand what will be implementation of setup_mappings for MPU. I suppose regions setup such that the following call to early_fdt_map can succeed and doing this in setup_mm is already too late?

So on the MPU side, mappings are well defined in HW by registers, so we don’t need to allocate pagetables, so setup_mappings in reality will only prepare our logical data structure that tracks the MPU region state (few regions are already written by the asm early code and needs to be tracked).

early_fdt_map won’t use this logical view of the MPU (as it’s called early), it will use low level API to access the MPU registers, like the early asm code did, basically to map the DTB.

Doing that, we ensure that the current code flow in start_xen can be reused as it.

Cheers,
Luca

#25 lore raw

Re: [PATCH 08/10] xen/arm: Rename setup_pagetables with a more generic name

Quoted 27 lines · Luca Fancellu

Hi Michal,

Quoted 11 lines · Michal
Quoted 5 lines · Luca Fancellu

Rename the setup_pagetables function to setup_mappings in order to be implemented also for MPU system that does not have page tables.

Quoted 6 lines

mappings is better than pagetables, so:

but I'd like to understand what will be implementation of setup_mappings for MPU. I suppose regions setup such that the following call to early_fdt_map can succeed and doing this in setup_mm is already too late?

So on the MPU side, mappings are well defined in HW by registers, so we don’t need to allocate pagetables, so setup_mappings in reality will only prepare our logical data structure that tracks the MPU region state (few regions are already written by the asm early code and needs to be tracked).

Quoted 4 lines

early_fdt_map won’t use this logical view of the MPU (as it’s called early), it will use low level API to access the MPU registers, like the early asm code did, basically to map the DTB.

Doing that, we ensure that the current code flow in start_xen can be reused as it.

Then the question is: can the MPU part be moved to setup_mm if early_fdt_map does not need setup_mappings? If so, we can avoid introducing a function with a name that is at least odd in MPU context and leave setup_pagetables only for MMU. Adding a function with not ideal name just for the sake of avoiding #ifdef MMU does not sound like a good idea for me.

You can check with others on this one.

~Michal

#26 lore raw

Re: [PATCH 08/10] xen/arm: Rename setup_pagetables with a more generic name

Quoted 37 lines · Michal
Quoted 30 lines · Luca Fancellu

Hi Michal,

Quoted 11 lines · Michal
Quoted 5 lines · Luca Fancellu

Rename the setup_pagetables function to setup_mappings in order to be implemented also for MPU system that does not have page tables.

Quoted 6 lines

mappings is better than pagetables, so:

but I'd like to understand what will be implementation of setup_mappings for MPU. I suppose regions setup such that the following call to early_fdt_map can succeed and doing this in setup_mm is already too late?

So on the MPU side, mappings are well defined in HW by registers, so we don’t need to allocate pagetables, so setup_mappings in reality will only prepare our logical data structure that tracks the MPU region state (few regions are already written by the asm early code and needs to be tracked).

early_fdt_map won’t use this logical view of the MPU (as it’s called early), it will use low level API to access the MPU registers, like the early asm code did, basically to map the DTB.

Quoted 8 lines
Quoted 1 line

Doing that, we ensure that the current code flow in start_xen can be reused as it.

Then the question is: can the MPU part be moved to setup_mm if early_fdt_map does not need setup_mappings? If so, we can avoid introducing a function with a name that is at least odd in MPU context and leave setup_pagetables only for MMU. Adding a function with not ideal name just for the sake of avoiding #ifdef MMU does not sound like a good idea for me.

You can check with others on this one.

I think you are right, I could provide a stub implementation for setup_pagetables() on MPU since there are no pagetables and introduce earlier setup_mm which will setup the datastructure.

I don’t think anyone will oppose to that, so if I don’t ear from anyone I will drop this patch and implement the above

Quoted 3 lines

~Michal

#27 lore raw

PATCH 9/10 xen/arm: introduce Kconfig HAS_PAGING_MEMPOOL

In reply to Luca Fancellu

From: Penny Zheng <[email protected]>

ARM MPU system doesn't need to use paging memory pool, as MPU memory mapping table at most takes only one 4KB page, which is enough to manage the maximum 255 MPU memory regions, for all EL2 stage 1 translation and EL1 stage 2 translation.

Introduce HAS_PAGING_MEMPOOL Kconfig symbol for Arm, selected for MMU systems.

Wrap code accessing the 'struct paging_domain' paging member with the new Kconfig, introduce arch_{get,set}_paging_mempool_size implementation for MPU system, provide stubs for p2m_teardown and p2m_teardown_allocation because they will not be used for MPU systems, remove 'struct paging_domain' from Arm 'struct arch_domain' when the field is not required.

---
 xen/arch/arm/Kconfig              |  4 ++++
 xen/arch/arm/dom0less-build.c     |  2 ++
 xen/arch/arm/include/asm/domain.h |  2 ++
 xen/arch/arm/mpu/Makefile         |  1 +
 xen/arch/arm/mpu/p2m.c            | 36 +++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+)
 create mode 100644 xen/arch/arm/mpu/p2m.c
xen/arch/arm/Kconfig +4 -0
index 5ac6ec0212d2..89c099ff464b 100644
@@ -76,6 +76,7 @@ choice
 config MMU
 	bool "MMU"
 	select HAS_LLC_COLORING if !NUMA && ARM_64
+	select HAS_PAGING_MEMPOOL
 	select HAS_PMAP
 	select HAS_VMAP
 	select HAS_PASSTHROUGH
@@ -158,6 +159,9 @@ config VGICV2
 config HVM
         def_bool y
 
+config HAS_PAGING_MEMPOOL
+	bool
+
 config NEW_VGIC
 	bool "Use new VGIC implementation"
 	select GICV2
xen/arch/arm/dom0less-build.c +2 -0
index 31f31c38da3f..feaba576198b 100644
@@ -865,11 +865,13 @@ static int __init construct_domU(struct domain *d,
                 p2m_mem_mb << (20 - PAGE_SHIFT) :
                 domain_p2m_pages(mem, d->max_vcpus);
 
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
     spin_lock(&d->arch.paging.lock);
     rc = p2m_set_allocation(d, p2m_pages, NULL);
     spin_unlock(&d->arch.paging.lock);
     if ( rc != 0 )
         return rc;
+#endif
 
     printk("*** LOADING DOMU cpus=%u memory=%#"PRIx64"KB ***\n",
            d->max_vcpus, mem);
xen/arch/arm/include/asm/domain.h +2 -0
index 50b6a4b00982..fadec7d8fa9e 100644
@@ -75,7 +75,9 @@ struct arch_domain
 
     struct hvm_domain hvm;
 
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
     struct paging_domain paging;
+#endif
 
     struct vmmio vmmio;
 
xen/arch/arm/mpu/Makefile +1 -0
index 04df0b2ee760..f1417cd1b9db 100644
@@ -1,2 +1,3 @@
 obj-y += mm.o
+obj-y += p2m.o
 obj-y += setup.init.o
xen/arch/arm/mpu/p2m.c new file +36 -0
new file mode 100644
index 000000000000..7525d9b00bcb
@@ -0,0 +1,36 @@
+
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/domain.h>
+#include <asm/p2m.h>
+
+/* Not used on MPU system */
+int p2m_teardown(struct domain *d)
+{
+    return 0;
+}
+
+/* Not used on MPU system */
+int p2m_teardown_allocation(struct domain *d)
+{
+    return 0;
+}
+
+int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
+{
+    return -EOPNOTSUPP;
+}
+
+int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
+{
+    return -EOPNOTSUPP;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.34.1
#28 lore raw

Re: [PATCH 09/10] xen/arm: introduce Kconfig HAS_PAGING_MEMPOOL

Quoted 6 lines · Luca Fancellu

From: Penny Zheng <[email protected]>

ARM MPU system doesn't need to use paging memory pool, as MPU memory mapping table at most takes only one 4KB page, which is enough to

NIT: I always wonder what "mapping" means in MPU world. Is this common to use this word even though there's no mapping being done? I'd expect to see e.g. protection table or similar.

Quoted 5 lines

manage the maximum 255 MPU memory regions, for all EL2 stage 1 translation and EL1 stage 2 translation.

Introduce HAS_PAGING_MEMPOOL Kconfig symbol for Arm, selected for MMU systems.

I don't think this should be Arm symbol. After all, we have common helpers like arch_get_paging_mempool_size(), so I'd naturally expect this symbol to be in the common Kconfig.

Quoted 33 lines

Wrap code accessing the 'struct paging_domain' paging member with the new Kconfig, introduce arch_{get,set}_paging_mempool_size implementation for MPU system, provide stubs for p2m_teardown and p2m_teardown_allocation because they will not be used for MPU systems, remove 'struct paging_domain' from Arm 'struct arch_domain' when the field is not required.

---
 xen/arch/arm/Kconfig              |  4 ++++
 xen/arch/arm/dom0less-build.c     |  2 ++
 xen/arch/arm/include/asm/domain.h |  2 ++
 xen/arch/arm/mpu/Makefile         |  1 +
 xen/arch/arm/mpu/p2m.c            | 36 +++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+)
 create mode 100644 xen/arch/arm/mpu/p2m.c
xen/arch/arm/Kconfig +1 -0
index 5ac6ec0212d2..89c099ff464b 100644
@@ -76,6 +76,7 @@ choice
 config MMU
        bool "MMU"
        select HAS_LLC_COLORING if !NUMA && ARM_64
+       select HAS_PAGING_MEMPOOL
        select HAS_PMAP
        select HAS_VMAP
        select HAS_PASSTHROUGH

xen/arch/arm/Kconfig config VGICV2 · line 163

Quoted 5 lines
xen/arch/arm/Kconfig +2 -0
@@ -158,6 +159,9 @@ config VGICV2
 config HVM
         def_bool y
 
+config HAS_PAGING_MEMPOOL
+       bool

See above

Quoted 9 lines
xen/arch/arm/Kconfig +1 -0
+
 config NEW_VGIC
        bool "Use new VGIC implementation"
        select GICV2
xen/arch/arm/dom0less-build.c +0 -0
index 31f31c38da3f..feaba576198b 100644

xen/arch/arm/dom0less-build.c static int __init construct_domU(struct domain *d, · line 874

Quoted 10 lines
xen/arch/arm/dom0less-build.c +2 -0
@@ -865,11 +865,13 @@ static int __init construct_domU(struct domain *d,
                 p2m_mem_mb << (20 - PAGE_SHIFT) :
                 domain_p2m_pages(mem, d->max_vcpus);
 
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
     spin_lock(&d->arch.paging.lock);
     rc = p2m_set_allocation(d, p2m_pages, NULL);
     spin_unlock(&d->arch.paging.lock);
     if ( rc != 0 )
         return rc;
+#endif

That's does not look right. If we don't have P2M pool for MPU domains, then xen,domain-p2m-mem-mb dom0less parameter does not make sense as well as its handling above that you did not protect.

Quoted 31 lines
xen/arch/arm/dom0less-build.c +0 -0
     printk("*** LOADING DOMU cpus=%u memory=%#"PRIx64"KB ***\n",
            d->max_vcpus, mem);
xen/arch/arm/include/asm/domain.h +2 -0
index 50b6a4b00982..fadec7d8fa9e 100644
@@ -75,7 +75,9 @@ struct arch_domain
 
     struct hvm_domain hvm;
 
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
     struct paging_domain paging;
+#endif
 
     struct vmmio vmmio;
 
xen/arch/arm/mpu/Makefile +1 -0
index 04df0b2ee760..f1417cd1b9db 100644
@@ -1,2 +1,3 @@
 obj-y += mm.o
+obj-y += p2m.o
 obj-y += setup.init.o
xen/arch/arm/mpu/p2m.c new file +0 -0
new file mode 100644
index 000000000000..7525d9b00bcb

xen/arch/arm/mpu/p2m.c line 5

Quoted 5 lines
xen/arch/arm/mpu/p2m.c new file +5 -0
@@ -0,0 +1,36 @@
+
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/domain.h>
+#include <asm/p2m.h>

Why do we need to include p2m.h at this stage?

xen/arch/arm/mpu/p2m.c line 17

Quoted 12 lines
xen/arch/arm/mpu/p2m.c new file +12 -0
+
+/* Not used on MPU system */
+int p2m_teardown(struct domain *d)
+{
+    return 0;
+}
+
+/* Not used on MPU system */
+int p2m_teardown_allocation(struct domain *d)
+{
+    return 0;
+}

What's the reason for adding e.g. p2m_teardown() but not p2m_final_teardown() in this patch? I initially thought that in the next patch other functions will be added that require implementation in the future (i.e. stubs) but then I saw relinquish_p2m_mapping() which returns 0 same as these 2 functions.

Quoted 20 lines
xen/arch/arm/mpu/p2m.c new file +19 -1
+
+int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
+{
+    return -EOPNOTSUPP;
+}
+
+int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
+{
+    return -EOPNOTSUPP;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

2.34.1

~Michal

#29 lore raw

Re: [PATCH 09/10] xen/arm: introduce Kconfig HAS_PAGING_MEMPOOL

Hi Michal,

Quoted 7 lines · Michal
Quoted 2 lines · Luca Fancellu
Quoted 7 lines
Quoted 4 lines

From: Penny Zheng <[email protected]>

ARM MPU system doesn't need to use paging memory pool, as MPU memory mapping table at most takes only one 4KB page, which is enough to

NIT: I always wonder what "mapping" means in MPU world. Is this common to use this word even though there's no mapping being done? I'd expect to see e.g. protection table or similar.

well if we have a look on the Arm specifications for Armv8-r aarch64, chapter C1 PMSA, it refers to “address map” and “flat maps”, so I think mapping is still ok for MPU.

Quoted 9 lines
Quoted 6 lines

manage the maximum 255 MPU memory regions, for all EL2 stage 1 translation and EL1 stage 2 translation.

Introduce HAS_PAGING_MEMPOOL Kconfig symbol for Arm, selected for MMU systems.

I don't think this should be Arm symbol. After all, we have common helpers like arch_get_paging_mempool_size(), so I'd naturally expect this symbol to be in the common Kconfig.

yes you are right, I’ll move this

Quoted 53 lines
Quoted 37 lines

Wrap code accessing the 'struct paging_domain' paging member with the new Kconfig, introduce arch_{get,set}_paging_mempool_size implementation for MPU system, provide stubs for p2m_teardown and p2m_teardown_allocation because they will not be used for MPU systems, remove 'struct paging_domain' from Arm 'struct arch_domain' when the field is not required.

---

xen/arch/arm/Kconfig              |  4 ++++
xen/arch/arm/dom0less-build.c     |  2 ++
xen/arch/arm/include/asm/domain.h |  2 ++
xen/arch/arm/mpu/Makefile         |  1 +
xen/arch/arm/mpu/p2m.c            | 36 +++++++++++++++++++++++++++++++
5 files changed, 45 insertions(+)

create mode 100644 xen/arch/arm/mpu/p2m.c

xen/arch/arm/Kconfig +0 -0
index 5ac6ec0212d2..89c099ff464b 100644
@@ -76,6 +76,7 @@ choice

config MMU

       bool "MMU"
       select HAS_LLC_COLORING if !NUMA && ARM_64
xen/arch/arm/Kconfig +1 -0
+       select HAS_PAGING_MEMPOOL
       select HAS_PMAP
       select HAS_VMAP
       select HAS_PASSTHROUGH
@@ -158,6 +159,9 @@ config VGICV2

config HVM
def_bool y

xen/arch/arm/Kconfig config VGICV2 · line 163

Quoted 2 lines
xen/arch/arm/Kconfig +2 -0
+config HAS_PAGING_MEMPOOL
+       bool

See above

Quoted 12 lines

+
config NEW_VGIC
bool "Use new VGIC implementation"
select GICV2

xen/arch/arm/dom0less-build.c +0 -0
index 31f31c38da3f..feaba576198b 100644
@@ -865,11 +865,13 @@ static int __init construct_domU(struct domain *d,
                p2m_mem_mb << (20 - PAGE_SHIFT) :
                domain_p2m_pages(mem, d->max_vcpus);
 
Quoted 10 lines

xen/arch/arm/dom0less-build.c static int __init construct_domU(struct domain *d, · line 874

Quoted 7 lines
xen/arch/arm/dom0less-build.c +2 -0
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
    spin_lock(&d->arch.paging.lock);
    rc = p2m_set_allocation(d, p2m_pages, NULL);
    spin_unlock(&d->arch.paging.lock);
    if ( rc != 0 )
        return rc;
+#endif

That's does not look right. If we don't have P2M pool for MPU domains, then xen,domain-p2m-mem-mb dom0less parameter does not make sense as well as its handling above that you did not protect.

yes the protection should be extended above

    rc = dt_property_read_u32(node, "xen,domain-p2m-mem-mb", &p2m_mem_mb);

Shall we throw any warning if !HAS_PAGING_MEMPOOL but the user sets "xen,domain-p2m-mem-mb”?

Quoted 30 lines
Quoted 30 lines
xen/arch/arm/dom0less-build.c +0 -0
    printk("*** LOADING DOMU cpus=%u memory=%#"PRIx64"KB ***\n",
           d->max_vcpus, mem);
xen/arch/arm/include/asm/domain.h +2 -0
index 50b6a4b00982..fadec7d8fa9e 100644
@@ -75,7 +75,9 @@ struct arch_domain
 
    struct hvm_domain hvm;
 
+#ifdef CONFIG_HAS_PAGING_MEMPOOL
    struct paging_domain paging;
+#endif
 
    struct vmmio vmmio;
 
xen/arch/arm/mpu/Makefile +0 -0
index 04df0b2ee760..f1417cd1b9db 100644
@@ -1,2 +1,3 @@

obj-y += mm.o
+obj-y += p2m.o
obj-y += setup.init.o

xen/arch/arm/mpu/p2m.c new file +0 -1
new file mode 100644
index 000000000000..7525d9b00bcb
--- /dev/null
Quoted 8 lines

xen/arch/arm/mpu/p2m.c line 5

Quoted 7 lines

+++ b/xen/arch/arm/mpu/p2m.c

xen/arch/arm/mpu/p2m.c new file +5 -0
@@ -0,0 +1,36 @@
+
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/domain.h>
+#include <asm/p2m.h>

Why do we need to include p2m.h at this stage?

it was to have visibility of the declarations, but ...

Quoted 17 lines

xen/arch/arm/mpu/p2m.c line 17

Quoted 13 lines
xen/arch/arm/mpu/p2m.c new file +12 -0
+
+/* Not used on MPU system */
+int p2m_teardown(struct domain *d)
+{
+    return 0;
+}
+
+/* Not used on MPU system */
+int p2m_teardown_allocation(struct domain *d)
+{
+    return 0;
+}

What's the reason for adding e.g. p2m_teardown() but not p2m_final_teardown() in this patch? I initially thought that in the next patch other functions will be added that require implementation in the future (i.e. stubs) but then I saw relinquish_p2m_mapping() which returns 0 same as these 2 functions.

as you said these can be part of the last patch? Or would you like an additional patch that defines all the functions that are implemented as stubs (e.g. like these two whose implementation is already defined and don’t require implementation in the future)?

Cheers,
Luca

#30 lore raw

PATCH 10/10 arm/mpu: Create the skeleton for MPU compilation

In reply to Luca Fancellu

This commit introduces the skeleton for the MPU memory management subsystem that allows the compilation.

---
The implementation of setup_virt_paging() is under arm64/mpu because it will have a different implementation from arm32.
---

---
 xen/arch/arm/arm64/mpu/Makefile    |  2 ++
 xen/arch/arm/arm64/mpu/p2m.c       | 18 ++++++++++
 xen/arch/arm/arm64/mpu/smpboot.c   | 23 ++++++++++++
 xen/arch/arm/include/asm/mpu/p2m.h | 20 +++++++++++
 xen/arch/arm/include/asm/p2m.h     |  2 +-
 xen/arch/arm/mpu/Makefile          |  1 +
 xen/arch/arm/mpu/mm.c              | 22 ++++++++++++
 xen/arch/arm/mpu/p2m.c             | 58 ++++++++++++++++++++++++++++++
 xen/arch/arm/mpu/setup.c           | 24 +++++++++++++
 xen/arch/arm/mpu/vmap-mpu.c        | 24 +++++++++++++
 10 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/arm64/mpu/p2m.c
 create mode 100644 xen/arch/arm/arm64/mpu/smpboot.c
 create mode 100644 xen/arch/arm/include/asm/mpu/p2m.h
 create mode 100644 xen/arch/arm/mpu/vmap-mpu.c
xen/arch/arm/arm64/mpu/Makefile +2 -0
index 3340058c08c6..cf0540aecc84 100644
@@ -1 +1,3 @@
 obj-y += head.o
+obj-y += p2m.o
+obj-y += smpboot.o
xen/arch/arm/arm64/mpu/p2m.c new file +18 -0
new file mode 100644
index 000000000000..df8de5c7d823
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/init.h>
+#include <asm/p2m.h>
+
+void __init setup_virt_paging(void)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/arm64/mpu/smpboot.c new file +23 -0
new file mode 100644
index 000000000000..3f3e54294e54
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/mm.h>
+
+int prepare_secondary_mm(int cpu)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void update_boot_mapping(bool enable)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/mpu/p2m.h new file +20 -0
new file mode 100644
index 000000000000..e5c0e302167c
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ARM_MPU_P2M_H__
+#define __ARM_MPU_P2M_H__
+
+/* Not used on MPU system */
+static inline void p2m_clear_root_pages(struct p2m_domain *p2m) {}
+
+/* Not used on MPU system */
+static inline void p2m_tlb_flush_sync(struct p2m_domain *p2m) {}
+
+#endif /* __ARM_MPU_P2M_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/p2m.h +1 -1
index 594dc4004138..2d53bf9b6177 100644
@@ -168,7 +168,7 @@ typedef enum {
 #if defined(CONFIG_MMU)
 # include <asm/mmu/p2m.h>
 #else
-# error "Unknown memory management layout"
+# include <asm/mpu/p2m.h>
 #endif
 
 static inline bool arch_acquire_resource_check(struct domain *d)
xen/arch/arm/mpu/Makefile +1 -0
index f1417cd1b9db..a963b35db88d 100644
@@ -1,3 +1,4 @@
 obj-y += mm.o
 obj-y += p2m.o
 obj-y += setup.init.o
+obj-y += vmap-mpu.o
xen/arch/arm/mpu/mm.c +22 -0
index b196661a2312..12703c4f3d4f 100644
@@ -18,6 +18,28 @@ static void __init __maybe_unused build_assertions(void)
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
 
+void __init setup_mm(void)
+{
+    BUG_ON("unimplemented");
+}
+
+int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void dump_hyp_walk(vaddr_t addr)
+{
+    BUG_ON("unimplemented");
+}
+
+/* Release all __init and __initdata ranges to be reused */
+void free_init_memory(void)
+{
+    BUG_ON("unimplemented");
+}
+
 void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags)
 {
     BUG_ON("unimplemented");
xen/arch/arm/mpu/p2m.c +58 -0

64 lines not on this page · raw message

xen/arch/arm/mpu/setup.c +24 -0
index 45214bfeb661..28119e008341 100644
@@ -2,12 +2,36 @@
 
 #include <xen/bug.h>
 #include <xen/init.h>
+#include <xen/types.h>
+#include <asm/setup.h>
 
 void __init setup_mappings(void)
 {
     BUG_ON("unimplemented");
 }
 
+void * __init early_fdt_map(paddr_t fdt_paddr)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+/*
+ * copy_from_paddr - copy data from a physical address
+ * @dst: destination virtual address
+ * @paddr: source physical address
+ * @len: length to copy
+ */
+void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
+{
+    BUG_ON("unimplemented");
+}
+
+void __init remove_early_mappings(void)
+{
+    BUG_ON("unimplemented");
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/mpu/vmap-mpu.c new file +24 -0
new file mode 100644
index 000000000000..cb92407476de
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/mm.h>
+#include <xen/vmap.h>
+
+void *vmap_contig(mfn_t mfn, unsigned int nr)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+void vunmap(const void *va)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.34.1
#31 lore raw

Re: [PATCH 10/10] arm/mpu: Create the skeleton for MPU compilation

Quoted 4 lines · Luca Fancellu

This commit introduces the skeleton for the MPU memory management subsystem that allows the compilation.

You forgot to mention that you're talking about Arm64 only. For Arm32, Ayan has a series containing a few patches to enable compilation.

P.S.
Once your series are merged, I'll send a patch enabling CI compilation for both Arm64 and Arm32 MPU.

Quoted 37 lines

---
The implementation of setup_virt_paging() is under arm64/mpu because it will have a different implementation from arm32.
---

---
 xen/arch/arm/arm64/mpu/Makefile    |  2 ++
 xen/arch/arm/arm64/mpu/p2m.c       | 18 ++++++++++
 xen/arch/arm/arm64/mpu/smpboot.c   | 23 ++++++++++++
 xen/arch/arm/include/asm/mpu/p2m.h | 20 +++++++++++
 xen/arch/arm/include/asm/p2m.h     |  2 +-
 xen/arch/arm/mpu/Makefile          |  1 +
 xen/arch/arm/mpu/mm.c              | 22 ++++++++++++
 xen/arch/arm/mpu/p2m.c             | 58 ++++++++++++++++++++++++++++++
 xen/arch/arm/mpu/setup.c           | 24 +++++++++++++
 xen/arch/arm/mpu/vmap-mpu.c        | 24 +++++++++++++
 10 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/arm64/mpu/p2m.c
 create mode 100644 xen/arch/arm/arm64/mpu/smpboot.c
 create mode 100644 xen/arch/arm/include/asm/mpu/p2m.h
 create mode 100644 xen/arch/arm/mpu/vmap-mpu.c
xen/arch/arm/arm64/mpu/Makefile +2 -0
index 3340058c08c6..cf0540aecc84 100644
@@ -1 +1,3 @@
 obj-y += head.o
+obj-y += p2m.o
+obj-y += smpboot.o
xen/arch/arm/arm64/mpu/p2m.c new file +0 -0
new file mode 100644
index 000000000000..df8de5c7d823

xen/arch/arm/arm64/mpu/p2m.c line 4

Quoted 4 lines
xen/arch/arm/arm64/mpu/p2m.c new file +4 -0
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/init.h>
+#include <asm/p2m.h>

Why do we need to include p2m.h at this stage?

Quoted 20 lines
xen/arch/arm/arm64/mpu/p2m.c new file +14 -0
+
+void __init setup_virt_paging(void)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/arm64/mpu/smpboot.c new file +0 -0
new file mode 100644
index 000000000000..3f3e54294e54

xen/arch/arm/arm64/mpu/smpboot.c line 3

Quoted 3 lines
xen/arch/arm/arm64/mpu/smpboot.c new file +3 -0
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/mm.h>

I can't see anything mm.h related here. I'd expect types.h/stdbool.h and bug.h

Quoted 26 lines
xen/arch/arm/arm64/mpu/smpboot.c new file +20 -0
+
+int prepare_secondary_mm(int cpu)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void update_boot_mapping(bool enable)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/mpu/p2m.h new file +0 -0
new file mode 100644
index 000000000000..e5c0e302167c

xen/arch/arm/include/asm/mpu/p2m.h line 1

Quoted 1 line
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */

Empty line here please

xen/arch/arm/include/asm/mpu/p2m.h line 5

Quoted 4 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +4 -0
+#ifndef __ARM_MPU_P2M_H__
+#define __ARM_MPU_P2M_H__
+
+/* Not used on MPU system */

I personally don't see a value in such comments. Initially when there were just 1, 2 instances I was ok, but then I realized you keep adding them. It's pretty clear that if a stub does not have BUG_ON, it means it's not used. I worry the files will look awful with so many "Not used on MPU system" comments. If at all, the only place they would make sense is if they were in MMU/MPU common code. Can we get rid of them completely?

xen/arch/arm/include/asm/mpu/p2m.h line 6

Quoted 1 line
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
+static inline void p2m_clear_root_pages(struct p2m_domain *p2m) {}

You should at least forward declare struct p2m_domain.

Quoted 32 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +14 -0
+
+/* Not used on MPU system */
+static inline void p2m_tlb_flush_sync(struct p2m_domain *p2m) {}
+
+#endif /* __ARM_MPU_P2M_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/p2m.h +1 -1
index 594dc4004138..2d53bf9b6177 100644
@@ -168,7 +168,7 @@ typedef enum {
 #if defined(CONFIG_MMU)
 # include <asm/mmu/p2m.h>
 #else
-# error "Unknown memory management layout"
+# include <asm/mpu/p2m.h>
 #endif
 
 static inline bool arch_acquire_resource_check(struct domain *d)
xen/arch/arm/mpu/Makefile +0 -0
index f1417cd1b9db..a963b35db88d 100644

xen/arch/arm/mpu/Makefile line 4

Quoted 4 lines
xen/arch/arm/mpu/Makefile +1 -0
@@ -1,3 +1,4 @@
 obj-y += mm.o
 obj-y += p2m.o
 obj-y += setup.init.o
+obj-y += vmap-mpu.o

What's the point of adding -mpu suffix to the file located already under /mpu?

Quoted 107 lines
xen/arch/arm/mpu/mm.c +22 -0
index b196661a2312..12703c4f3d4f 100644
@@ -18,6 +18,28 @@ static void __init __maybe_unused build_assertions(void)
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
 
+void __init setup_mm(void)
+{
+    BUG_ON("unimplemented");
+}
+
+int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void dump_hyp_walk(vaddr_t addr)
+{
+    BUG_ON("unimplemented");
+}
+
+/* Release all __init and __initdata ranges to be reused */
+void free_init_memory(void)
+{
+    BUG_ON("unimplemented");
+}
+
 void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags)
 {
     BUG_ON("unimplemented");
xen/arch/arm/mpu/p2m.c +58 -0
index 7525d9b00bcb..b059c86bde43 100644
@@ -4,6 +4,64 @@
 #include <xen/domain.h>
 #include <asm/p2m.h>
 
+int p2m_set_entry(struct p2m_domain *p2m, gfn_t sgfn, unsigned long nr,
+                  mfn_t smfn, p2m_type_t t, p2m_access_t a)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t *t,
+                    p2m_access_t *a, unsigned int *page_order, bool *valid)
+{
+    BUG_ON("unimplemented");
+    return INVALID_MFN;
+}
+
+void p2m_dump_info(struct domain *d)
+{
+    BUG_ON("unimplemented");
+}
+
+int p2m_init(struct domain *d)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void p2m_save_state(struct vcpu *p)
+{
+    BUG_ON("unimplemented");
+}
+
+void p2m_restore_state(struct vcpu *n)
+{
+    BUG_ON("unimplemented");
+}
+
+void p2m_final_teardown(struct domain *d)
+{
+    BUG_ON("unimplemented");
+}
+
+/* Not used on MPU system */
+void p2m_flush_vm(struct vcpu *v) {}
+
+bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn)
+{
+    BUG_ON("unimplemented");
+    return false;
+}
+
+/* Not used on MPU system */
+int relinquish_p2m_mapping(struct domain *d)
+{
+    return 0;
+}
+
+/* Not used on MPU system */
+void p2m_domain_creation_finished(struct domain *d) {}
+
 /* Not used on MPU system */
 int p2m_teardown(struct domain *d)
 {
xen/arch/arm/mpu/setup.c +0 -0
index 45214bfeb661..28119e008341 100644

xen/arch/arm/mpu/setup.c line 6

Quoted 5 lines
xen/arch/arm/mpu/setup.c +2 -0
@@ -2,12 +2,36 @@
 
 #include <xen/bug.h>
 #include <xen/init.h>
+#include <xen/types.h>
+#include <asm/setup.h>

Please sort alphabetically

Quoted 37 lines
xen/arch/arm/mpu/setup.c +22 -0
 void __init setup_mappings(void)
 {
     BUG_ON("unimplemented");
 }
 
+void * __init early_fdt_map(paddr_t fdt_paddr)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+/*
+ * copy_from_paddr - copy data from a physical address
+ * @dst: destination virtual address
+ * @paddr: source physical address
+ * @len: length to copy
+ */
+void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
+{
+    BUG_ON("unimplemented");
+}
+
+void __init remove_early_mappings(void)
+{
+    BUG_ON("unimplemented");
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/mpu/vmap-mpu.c new file +0 -0
new file mode 100644
index 000000000000..cb92407476de

xen/arch/arm/mpu/vmap-mpu.c line 4

Quoted 4 lines
xen/arch/arm/mpu/vmap-mpu.c new file +4 -0
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/mm.h>
+#include <xen/vmap.h>

I don't see any use of vmap.h in this file

Quoted 21 lines
xen/arch/arm/mpu/vmap-mpu.c new file +20 -1
+
+void *vmap_contig(mfn_t mfn, unsigned int nr)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+void vunmap(const void *va)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

2.34.1

~Michal

#32 lore raw

Re: [PATCH 10/10] arm/mpu: Create the skeleton for MPU compilation

Hi Michal,

Quoted 11 lines · Michal
Quoted 4 lines · Luca Fancellu

This commit introduces the skeleton for the MPU memory management subsystem that allows the compilation.

You forgot to mention that you're talking about Arm64 only. For Arm32, Ayan has a series containing a few patches to enable compilation.

Yes I’ll be more specific here that we enable arm64 MPU build

Quoted 4 lines

P.S.
Once your series are merged, I'll send a patch enabling CI compilation for both Arm64 and Arm32 MPU.

thanks a lot for that

Quoted 4 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+#include <xen/mm.h>

I can't see anything mm.h related here. I'd expect types.h/stdbool.h and bug.h

I’ll add

Quoted 30 lines
Quoted 27 lines
xen/arch/arm/arm64/mpu/smpboot.c new file +20 -0
+
+int prepare_secondary_mm(int cpu)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void update_boot_mapping(bool enable)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/mpu/p2m.h new file +0 -0
new file mode 100644
index 000000000000..e5c0e302167c

xen/arch/arm/include/asm/mpu/p2m.h line 1

Quoted 1 line
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */

Empty line here please

Quoted 10 lines

xen/arch/arm/include/asm/mpu/p2m.h line 5

Quoted 4 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +4 -0
+#ifndef __ARM_MPU_P2M_H__
+#define __ARM_MPU_P2M_H__
+
+/* Not used on MPU system */

I personally don't see a value in such comments. Initially when there were just 1, 2 instances I was ok, but then I realized you keep adding them. It's pretty clear that if a stub does not have BUG_ON, it means it's not used. I worry the files will look awful with so many "Not used on MPU system" comments. If at all, the only place they would make sense is if they were in MMU/MPU common code. Can we get rid of them completely?

Sure, I’ll get rid of them

Quoted 3 lines

xen/arch/arm/include/asm/mpu/p2m.h line 6

Quoted 2 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
+static inline void p2m_clear_root_pages(struct p2m_domain *p2m) {}

You should at least forward declare struct p2m_domain.

Ok I’ll fix, should I include asm/p2m.h for the visibility of this structure or because we won’t use that I should just forward declare?

Quoted 12 lines
Quoted 11 lines

static inline bool arch_acquire_resource_check(struct domain *d)

xen/arch/arm/mpu/Makefile +0 -0
index f1417cd1b9db..a963b35db88d 100644
@@ -1,3 +1,4 @@

obj-y += mm.o
obj-y += p2m.o
obj-y += setup.init.o
+obj-y += vmap-mpu.o

What's the point of adding -mpu suffix to the file located already under /mpu?

ok I’ll rename to vmap

Quoted 11 lines

xen/arch/arm/mpu/setup.c line 6

Quoted 10 lines
xen/arch/arm/mpu/setup.c +2 -0
index 45214bfeb661..28119e008341 100644
@@ -2,12 +2,36 @@
 
 #include <xen/bug.h>
 #include <xen/init.h>
+#include <xen/types.h>
+#include <asm/setup.h>

Please sort alphabetically

Isn’t xen/* first followed by asm/* ?

Cheers,
Luca

#33 lore raw

Re: [PATCH 10/10] arm/mpu: Create the skeleton for MPU compilation

Quoted 74 lines · Luca Fancellu

Hi Michal,

Quoted 11 lines · Michal
Quoted 4 lines · Luca Fancellu

This commit introduces the skeleton for the MPU memory management subsystem that allows the compilation.

You forgot to mention that you're talking about Arm64 only. For Arm32, Ayan has a series containing a few patches to enable compilation.

Yes I’ll be more specific here that we enable arm64 MPU build

Quoted 4 lines

P.S.
Once your series are merged, I'll send a patch enabling CI compilation for both Arm64 and Arm32 MPU.

thanks a lot for that

Quoted 4 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+#include <xen/mm.h>

I can't see anything mm.h related here. I'd expect types.h/stdbool.h and bug.h

I’ll add

Quoted 30 lines
Quoted 27 lines
xen/arch/arm/arm64/mpu/smpboot.c new file +20 -0
+
+int prepare_secondary_mm(int cpu)
+{
+    BUG_ON("unimplemented");
+    return -EINVAL;
+}
+
+void update_boot_mapping(bool enable)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/mpu/p2m.h new file +0 -0
new file mode 100644
index 000000000000..e5c0e302167c

xen/arch/arm/include/asm/mpu/p2m.h line 1

Quoted 1 line
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */

Empty line here please

Quoted 10 lines

xen/arch/arm/include/asm/mpu/p2m.h line 5

Quoted 4 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +4 -0
+#ifndef __ARM_MPU_P2M_H__
+#define __ARM_MPU_P2M_H__
+
+/* Not used on MPU system */

I personally don't see a value in such comments. Initially when there were just 1, 2 instances I was ok, but then I realized you keep adding them. It's pretty clear that if a stub does not have BUG_ON, it means it's not used. I worry the files will look awful with so many "Not used on MPU system" comments. If at all, the only place they would make sense is if they were in MMU/MPU common code. Can we get rid of them completely?

Quoted 8 lines

Sure, I’ll get rid of them

Quoted 3 lines

xen/arch/arm/include/asm/mpu/p2m.h line 6

Quoted 2 lines
xen/arch/arm/include/asm/mpu/p2m.h new file +1 -0
+static inline void p2m_clear_root_pages(struct p2m_domain *p2m) {}

You should at least forward declare struct p2m_domain.

Ok I’ll fix, should I include asm/p2m.h for the visibility of this structure or because we won’t use that I should just forward declare?

forward declare

Quoted 23 lines
Quoted 13 lines
Quoted 8 lines

static inline bool arch_acquire_resource_check(struct domain *d)

xen/arch/arm/mpu/Makefile +0 -0
index f1417cd1b9db..a963b35db88d 100644
@@ -1,3 +1,4 @@
Quoted 4 lines

obj-y += mm.o
obj-y += p2m.o
obj-y += setup.init.o
+obj-y += vmap-mpu.o

What's the point of adding -mpu suffix to the file located already under /mpu?

ok I’ll rename to vmap

Quoted 6 lines
Quoted 6 lines
xen/arch/arm/mpu/setup.c +0 -0
index 45214bfeb661..28119e008341 100644
@@ -2,12 +2,36 @@
 
Quoted 7 lines
Quoted 5 lines

xen/arch/arm/mpu/setup.c line 6

Quoted 4 lines
xen/arch/arm/mpu/setup.c +2 -0
 #include <xen/bug.h>
 #include <xen/init.h>
+#include <xen/types.h>
+#include <asm/setup.h>

Please sort alphabetically

Isn’t xen/* first followed by asm/* ?

Oops, I missed the fact that this is xen/ and asm/. Ignore then.

~Michal

#34 lore raw
In reply to Luca Fancellu
Quoted 9 lines · Luca Fancellu

Hi all,

this serie implements the skeleton for the MPU memory management subsystem, at the end of the serie it will be possible to compile the Arm arch using MPU.

The minimum Arm Kconfig configuration is this one:

Quoted 7 lines

CONFIG_UNSUPPORTED=y
CONFIG_MPU=y
CONFIG_XEN_START_ADDRESS=0x0

Luca Fancellu (8):
xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH xen/arm: Restrict Kconfig configuration for LLC coloring

These patches have necessary tags, so I committed them right away.

~Michal