Skip to contentSkip to conversation

xen: arm: Split MMU code in preparation for MPU work (part 2)

PATCH Superseded Ayan Kumar Halder 4 participants 16 messages Aug 8, 2024 – Aug 13, 2024

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen: arm: Split MMU code in preparation for MPU work (part 2)

Hi,

In https://patchew.org/Xen/[email protected]/, Henry has reorganized some of the code between the MMU specific and generic files.

In this patch serie, we address the remaining code reorg so that MMU specific code is cleanly separated and we have added stubs wherever necessary to avoid introducing if-def.

Ayan Kumar Halder (4):
xen: arm: Add a new helper update_boot_mapping()
xen: arm: make VMAP only support in MMU system
xen: arm: Move the functions of domain_page to MMU specific
xen: arm: Enclose access to EL2 MMU specific registers under
CONFIG_MMU

 xen/arch/arm/Kconfig                 | 7 ++++++-
 xen/arch/arm/arm64/mmu/mm.c          | 5 +++++
 xen/arch/arm/arm64/smpboot.c         | 6 +++---
 xen/arch/arm/include/asm/mm.h        | 2 ++
 xen/arch/arm/mmu/Makefile            | 1 +
 xen/arch/arm/{ => mmu}/domain_page.c | 0
 xen/arch/arm/setup.c                 | 2 ++
 xen/arch/arm/traps.c                 | 6 ++++++
 xen/include/xen/vmap.h               | 2 ++
 9 files changed, 27 insertions(+), 4 deletions(-)
 rename xen/arch/arm/{ => mmu}/domain_page.c (100%)
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 2/4 xen: arm: make VMAP only support in MMU system

From: Penny Zheng <[email protected]>

VMAP is widely used in ALTERNATIVE feature to remap a range of memory with new memory attributes. Since this is highly dependent on virtual address translation, we choose to fold VMAP in MMU system.

In this patch, we introduce a new Kconfig CONFIG_HAS_VMAP, and make it only support in MMU system on ARM architecture. And ALTERNATIVE now depend on VMAP.

HARDEN_BRANCH_PREDICTOR is now gated on HAS_VMAP as speculative
attacks are not possible on non MMU based systems (ie Cortex-R52, R82).
See https://developer.arm.com/Arm%20Security%20Center/Speculative%20Processor%20Vulnerability.

Split "https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/" into Arm specific

---
Changes from :-

v1 - 1. HARDEN_BRANCH_PREDICTOR is now gated on HAS_VMAP.
2. cpuerrata.c is not gated on HAS_VMAP.

 xen/arch/arm/Kconfig   | 7 ++++++-
 xen/arch/arm/setup.c   | 2 ++
 xen/include/xen/vmap.h | 2 ++
 3 files changed, 10 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +6 -1
index 21d03d9f44..7d1dde89d7 100644
@@ -12,7 +12,7 @@ config ARM_64
 config ARM
 	def_bool y
 	select FUNCTION_ALIGNMENT_4B
-	select HAS_ALTERNATIVE
+	select HAS_ALTERNATIVE if HAS_VMAP
 	select HAS_DEVICE_TREE
 	select HAS_PASSTHROUGH
 	select HAS_UBSAN
@@ -58,9 +58,13 @@ config PADDR_BITS
 	default 40 if ARM_PA_BITS_40
 	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y
+
 config MMU
 	def_bool y
 	select HAS_PMAP
+	select HAS_VMAP
 
 source "arch/Kconfig"
 
@@ -171,6 +175,7 @@ config ARM_SSBD
 
 config HARDEN_BRANCH_PREDICTOR
 	bool "Harden the branch predictor against aliasing attacks" if EXPERT
+	depends on HAS_VMAP
 	default y
 	help
 	  Speculation attacks against some high-performance processors rely on
xen/arch/arm/setup.c +2 -0
index cb2c0a16b8..7f686d2cca 100644
@@ -447,7 +447,9 @@ void asmlinkage __init start_xen(unsigned long boot_phys_offset,
      * It needs to be called after do_initcalls to be able to use
      * stop_machine (tasklets initialized via an initcall).
      */
+#ifdef CONFIG_HAS_ALTERNATIVE
     apply_alternatives_all();
+#endif
     enable_errata_workarounds();
     enable_cpu_features();
 
xen/include/xen/vmap.h +2 -0
index fdae37e950..4c7dfe58ba 100644
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
 /* Initialises the VMAP_DEFAULT virtual range */
 static inline void vm_init(void)
 {
+#ifdef CONFIG_MMU
     vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
 }
 
 #endif /* __XEN_VMAP_H__ */
Signature · 1 line
2.25.1
#10 lore raw

PATCH v2 3/4 xen: arm: Moved domain_page.c to MMU specific

In reply to Ayan Kumar Halder

domain_page.c has been moved to mmu/domain_page.c. The reason being this file implements MMU specific logic for mapping, unmapping, etc domain page.

---
 xen/arch/arm/mmu/Makefile            | 1 +
 xen/arch/arm/{ => mmu}/domain_page.c | 0
 2 files changed, 1 insertion(+)
 rename xen/arch/arm/{ => mmu}/domain_page.c (100%)
xen/arch/arm/mmu/Makefile +1 -0
index 67475fcd80..2cb44b857d 100644
@@ -2,3 +2,4 @@ obj-y += p2m.o
 obj-y += pt.o
 obj-y += setup.o
 obj-y += smpboot.o
+obj-$(CONFIG_ARCH_MAP_DOMAIN_PAGE) += domain_page.o
xen/arch/arm/mmu/domain_page.c renamed from xen/arch/arm/domain_page.c +0 -0
similarity index 100%
rename from xen/arch/arm/domain_page.c
rename to xen/arch/arm/mmu/domain_page.c
Signature · 1 line
2.25.1
#13 lore raw

PATCH v2 4/4 xen: arm: Enclose access to EL2 MMU specific registers under CONFIG_MMU

In reply to Ayan Kumar Halder

All the EL2 MMU specific registers are enclosed within CONFIG_MMU.

---
Changes from v1 :-
1. 'vttbr_el2' field is enclosed with ifdef.
2. No movement of code.

 xen/arch/arm/traps.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/traps.c +6 -0
index aac6c599f8..f51e1424cb 100644
@@ -720,8 +720,10 @@ struct reg_ctxt {
     uint32_t ifsr32_el2;
 #endif
 
+#ifdef CONFIG_MMU
     /* Hypervisor-side state */
     uint64_t vttbr_el2;
+#endif
 };
 
 static const char *mode_string(register_t cpsr)
@@ -919,12 +921,16 @@ static void _show_registers(const struct cpu_user_regs *regs,
 #endif
     }
     printk("  VTCR_EL2: %"PRIregister"\n", READ_SYSREG(VTCR_EL2));
+#ifdef CONFIG_MMU
     printk(" VTTBR_EL2: %016"PRIx64"\n", ctxt->vttbr_el2);
+#endif
     printk("\n");
 
     printk(" SCTLR_EL2: %"PRIregister"\n", READ_SYSREG(SCTLR_EL2));
     printk("   HCR_EL2: %"PRIregister"\n", READ_SYSREG(HCR_EL2));
+#ifdef CONFIG_MMU
     printk(" TTBR0_EL2: %016"PRIx64"\n", READ_SYSREG64(TTBR0_EL2));
+#endif
     printk("\n");
     printk("   ESR_EL2: %"PRIregister"\n", regs->hsr);
     printk(" HPFAR_EL2: %"PRIregister"\n", READ_SYSREG(HPFAR_EL2));
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 xen: arm: Add a new helper update_boot_mapping()

In reply to Ayan Kumar Halder

update_boot_mapping() invokes update_identity_mapping() for the MMU specific code.
Later when the MPU code is added, update_boot_mapping() would invoke the equivalent.

The common code now invokes update_boot_mapping() instead of update_identity_mapping(). So, that there is clear abstraction between the common and MMU/MPU specific logic.

This is in continuation to commit
f661a20aa880: "Extract MMU-specific MM code".

---
Changes from :-

v1 - 1. Introduced update_boot_mapping() which invokes update_identity_mapping() in MMU specific code.

 xen/arch/arm/arm64/mmu/mm.c   | 5 +++++
 xen/arch/arm/arm64/smpboot.c  | 6 +++---
 xen/arch/arm/include/asm/mm.h | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
xen/arch/arm/arm64/mmu/mm.c +5 -0
index 293acb67e0..72e089a339 100644
@@ -125,6 +125,11 @@ void update_identity_mapping(bool enable)
     BUG_ON(rc);
 }
 
+void update_boot_mapping(bool enable)
+{
+    update_identity_mapping(enable);
+}
+
 extern void switch_ttbr_id(uint64_t ttbr);
 
 typedef void (switch_ttbr_fn)(uint64_t ttbr);
xen/arch/arm/arm64/smpboot.c +3 -3
index a225fae64d..789f352ab6 100644
@@ -112,18 +112,18 @@ int arch_cpu_up(int cpu)
     if ( !smp_enable_ops[cpu].prepare_cpu )
         return -ENODEV;
 
-    update_identity_mapping(true);
+    update_boot_mapping(true);
 
     rc = smp_enable_ops[cpu].prepare_cpu(cpu);
     if ( rc )
-        update_identity_mapping(false);
+        update_boot_mapping(false);
 
     return rc;
 }
 
 void arch_cpu_up_finish(void)
 {
-    update_identity_mapping(false);
+    update_boot_mapping(false);
 }
 
 /*
xen/arch/arm/include/asm/mm.h +2 -0
index f6ba611f01..e769d2d3b3 100644
@@ -426,6 +426,8 @@ static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn)
     } while ( (y = cmpxchg(&p->u.inuse.type_info, x, nx)) != x );
 }
 
+void update_boot_mapping(bool enable);
+
 #endif /*  __ARCH_ARM_MM__ */
 /*
  * Local variables:
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v2 2/4] xen: arm: make VMAP only support in MMU system

In reply to Ayan Kumar Halder

xen/arch/arm/Kconfig config PADDR_BITS · line 62

Quoted 6 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +2 -0
@@ -58,9 +58,13 @@ config PADDR_BITS
 	default 40 if ARM_PA_BITS_40
 	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y

With this being always enabled, ...

xen/arch/arm/Kconfig config PADDR_BITS · line 67

Quoted 4 lines
xen/arch/arm/Kconfig +1 -0
 config MMU
 	def_bool y
 	select HAS_PMAP
+	select HAS_VMAP

.. what use is this?

xen/include/xen/vmap.h void *arch_vmap_virt_end(void); · line 147

Quoted 10 lines
xen/include/xen/vmap.h +2 -0
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
 /* Initialises the VMAP_DEFAULT virtual range */
 static inline void vm_init(void)
 {
+#ifdef CONFIG_MMU
     vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
 }

What about non-Arm, which all have MMUs but no corresponding Kconfig setting? And why is this not CONFIG_HAS_VMAP anyway (with HAS_VMAP properly moved to common/Kconfig, where e.g. HAS_PMAP also lives, and then unconditionally selected by all other architectures)?

Jan

#11 lore raw

Re: [PATCH v2 3/4] xen: arm: Moved domain_page.c to MMU specific

In reply to Ayan Kumar Halder
Quoted 16 lines · Ayan Kumar Halder

domain_page.c has been moved to mmu/domain_page.c. The reason being this file implements MMU specific logic for mapping, unmapping, etc domain page.

---
 xen/arch/arm/mmu/Makefile            | 1 +
 xen/arch/arm/{ => mmu}/domain_page.c | 0
 2 files changed, 1 insertion(+)
 rename xen/arch/arm/{ => mmu}/domain_page.c (100%)
xen/arch/arm/mmu/Makefile +0 -0
index 67475fcd80..2cb44b857d 100644

xen/arch/arm/mmu/Makefile obj-y += p2m.o · line 5

Quoted 4 lines
xen/arch/arm/mmu/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-y += p2m.o
 obj-y += pt.o
 obj-y += setup.o
 obj-y += smpboot.o
+obj-$(CONFIG_ARCH_MAP_DOMAIN_PAGE) += domain_page.o

Don't you then also need to remove the respective line from arm/Makefile?

Jan

#6 lore raw

Re: [PATCH v2 2/4] xen: arm: make VMAP only support in MMU system

In reply to Jan Beulich

Hi Jan,

Quoted 8 lines · Jan Beulich

xen/arch/arm/Kconfig config PADDR_BITS · line 62

Quoted 6 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +2 -0
@@ -58,9 +58,13 @@ config PADDR_BITS
  	default 40 if ARM_PA_BITS_40
  	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y

With this being always enabled, ...

I had to define the config somewhere. It seemed this is the correct place to define as HAS_VMAP will be turned off when MPU is introduced.

So, it will be

config HAS_VMAP

           def_bool n

At that time, only MMU will select HAS_VMAP.

Quoted 7 lines

xen/arch/arm/Kconfig config PADDR_BITS · line 67

Quoted 5 lines
xen/arch/arm/Kconfig +1 -0
  config MMU
  	def_bool y
  	select HAS_PMAP
+	select HAS_VMAP

.. what use is this?

Quoted 12 lines

xen/include/xen/vmap.h void *arch_vmap_virt_end(void); · line 147

Quoted 10 lines
xen/include/xen/vmap.h +2 -0
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
  /* Initialises the VMAP_DEFAULT virtual range */
  static inline void vm_init(void)
  {
+#ifdef CONFIG_MMU
      vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
  }

What about non-Arm, which all have MMUs but no corresponding Kconfig setting?

AFAICS , the only file that is of our concern xen/common/vmap.c It is enclosed with VMAP_VIRT_START which is defined in mmu specific file (xen/arch/arm/include/asm/mmu/layout.h).

So, it will not be compiled for Arm MPU arch.

Quoted 3 lines

And why is this not CONFIG_HAS_VMAP anyway (with HAS_VMAP properly moved to common/Kconfig, where e.g. HAS_PMAP also lives, and then unconditionally selected by all other architectures)?

I am not sure why CONFIG_HAS_VMAP should be moved to common/Kconfig when it will be selected/deselected only for Arm architecture.

- Ayan

Quoted 2 lines

Jan

#12 lore raw

Re: [PATCH v2 3/4] xen: arm: Moved domain_page.c to MMU specific

In reply to Jan Beulich

Hi Jan,

Quoted 12 lines · Jan Beulich
Quoted 11 lines · Ayan Kumar Halder

domain_page.c has been moved to mmu/domain_page.c. The reason being this file implements MMU specific logic for mapping, unmapping, etc domain page.

---
  xen/arch/arm/mmu/Makefile            | 1 +
  xen/arch/arm/{ => mmu}/domain_page.c | 0
  2 files changed, 1 insertion(+)

rename xen/arch/arm/{ => mmu}/domain_page.c (100%)

Quoted 10 lines

xen/arch/arm/mmu/Makefile obj-y += p2m.o · line 5

Quoted 9 lines
xen/arch/arm/mmu/Makefile +1 -0
index 67475fcd80..2cb44b857d 100644
@@ -2,3 +2,4 @@ obj-y += p2m.o
  obj-y += pt.o
  obj-y += setup.o
  obj-y += smpboot.o
+obj-$(CONFIG_ARCH_MAP_DOMAIN_PAGE) += domain_page.o

Don't you then also need to remove the respective line from arm/Makefile?

Yes you are correct. I missed it.

- Ayan

Quoted 2 lines

Jan

#7 lore raw

Re: [PATCH v2 2/4] xen: arm: make VMAP only support in MMU system

In reply to Ayan Kumar Halder
Quoted 13 lines · Ayan Kumar Halder
Quoted 8 lines · Jan Beulich

xen/arch/arm/Kconfig config PADDR_BITS · line 62

Quoted 6 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +2 -0
@@ -58,9 +58,13 @@ config PADDR_BITS
  	default 40 if ARM_PA_BITS_40
  	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y

With this being always enabled, ...

I had to define the config somewhere. It seemed this is the correct place to define as HAS_VMAP will be turned off when MPU is introduced.

Quoted 7 lines

So, it will be

config HAS_VMAP

           def_bool n

At that time, only MMU will select HAS_VMAP.

Well, but why is it not simply

config HAS_VMAP
bool

from the very beginning? (There should never be "def_bool n" imo, btw.)

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/include/xen/vmap.h +0 -0
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
  /* Initialises the VMAP_DEFAULT virtual range */
Quoted 8 lines

xen/include/xen/vmap.h void *arch_vmap_virt_end(void); · line 147

Quoted 6 lines
xen/include/xen/vmap.h +2 -0
  static inline void vm_init(void)
  {
+#ifdef CONFIG_MMU
      vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
  }

What about non-Arm, which all have MMUs but no corresponding Kconfig setting?

Quoted 5 lines

AFAICS , the only file that is of our concern xen/common/vmap.c It is enclosed with VMAP_VIRT_START which is defined in mmu specific file (xen/arch/arm/include/asm/mmu/layout.h).

So, it will not be compiled for Arm MPU arch.

Yet that wasn't my question. I asked about non-Arm, for all of which it looks like you're changing behavior of vm_init() (by suddenly making it do nothing).

Quoted 6 lines
Quoted 3 lines

And why is this not CONFIG_HAS_VMAP anyway (with HAS_VMAP properly moved to common/Kconfig, where e.g. HAS_PMAP also lives, and then unconditionally selected by all other architectures)?

I am not sure why CONFIG_HAS_VMAP should be moved to common/Kconfig when it will be selected/deselected only for Arm architecture.

Because you will want to use that (not MMU) in vm_init().

Jan

#2 lore raw

Re: [PATCH v2 1/4] xen: arm: Add a new helper update_boot_mapping()

In reply to Ayan Kumar Halder

Hi Ayan,

Quoted 29 lines · Ayan Kumar Halder

update_boot_mapping() invokes update_identity_mapping() for the MMU specific code.
Later when the MPU code is added, update_boot_mapping() would invoke the equivalent.

The common code now invokes update_boot_mapping() instead of update_identity_mapping(). So, that there is clear abstraction between the common and MMU/MPU specific logic.

This is in continuation to commit
f661a20aa880: "Extract MMU-specific MM code".

---
Changes from :-

v1 - 1. Introduced update_boot_mapping() which invokes update_identity_mapping() in MMU specific code.

 xen/arch/arm/arm64/mmu/mm.c   | 5 +++++
 xen/arch/arm/arm64/smpboot.c  | 6 +++---
 xen/arch/arm/include/asm/mm.h | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
xen/arch/arm/arm64/mmu/mm.c +0 -0
index 293acb67e0..72e089a339 100644

xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 130

Quoted 6 lines
xen/arch/arm/arm64/mmu/mm.c +3 -0
@@ -125,6 +125,11 @@ void update_identity_mapping(bool enable)
     BUG_ON(rc);
 }
 
+void update_boot_mapping(bool enable)
+{
+    update_identity_mapping(enable);

With your approach, update_identity_mapping() would only be called from within this file, therefore it should be marked as static and the prototype removed.

Quoted 36 lines
xen/arch/arm/arm64/mmu/mm.c +2 -0
+}
+
 extern void switch_ttbr_id(uint64_t ttbr);
 
 typedef void (switch_ttbr_fn)(uint64_t ttbr);
xen/arch/arm/arm64/smpboot.c +3 -3
index a225fae64d..789f352ab6 100644
@@ -112,18 +112,18 @@ int arch_cpu_up(int cpu)
     if ( !smp_enable_ops[cpu].prepare_cpu )
         return -ENODEV;
 
-    update_identity_mapping(true);
+    update_boot_mapping(true);
 
     rc = smp_enable_ops[cpu].prepare_cpu(cpu);
     if ( rc )
-        update_identity_mapping(false);
+        update_boot_mapping(false);
 
     return rc;
 }
 
 void arch_cpu_up_finish(void)
 {
-    update_identity_mapping(false);
+    update_boot_mapping(false);
 }
 
 /*
xen/arch/arm/include/asm/mm.h +0 -0
index f6ba611f01..e769d2d3b3 100644

xen/arch/arm/include/asm/mm.h static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn) · line 429

Quoted 4 lines
xen/arch/arm/include/asm/mm.h +1 -0
@@ -426,6 +426,8 @@ static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn)
     } while ( (y = cmpxchg(&p->u.inuse.type_info, x, nx)) != x );
 }
 
+void update_boot_mapping(bool enable);

The definition is only present for arm64. Shouldn't the prototype be moved to arm64 header?

~Michal

#14 lore raw

Re: [PATCH v2 4/4] xen: arm: Enclose access to EL2 MMU specific registers under CONFIG_MMU

In reply to Ayan Kumar Halder

Hi Ayan,

Quoted 16 lines · Ayan Kumar Halder

All the EL2 MMU specific registers are enclosed within CONFIG_MMU.

---
Changes from v1 :-
1. 'vttbr_el2' field is enclosed with ifdef.
2. No movement of code.

 xen/arch/arm/traps.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/traps.c +0 -0
index aac6c599f8..f51e1424cb 100644

xen/arch/arm/traps.c struct reg_ctxt { · line 725

Quoted 6 lines
xen/arch/arm/traps.c +1 -0
@@ -720,8 +720,10 @@ struct reg_ctxt {
     uint32_t ifsr32_el2;
 #endif
 
+#ifdef CONFIG_MMU
     /* Hypervisor-side state */
     uint64_t vttbr_el2;

Given that you protected the field here, why did you leave assignments in show_registers() and vcpu_show_registers() unguarded?

~Michal

#3 lore raw

Re: [PATCH v2 1/4] xen: arm: Add a new helper update_boot_mapping()

In reply to Michal Orzel
Quoted 1 line · Michal Orzel

Hi Ayan,

Hi Michal,

Quoted 34 lines · Ayan Kumar Halder
Quoted 32 lines

update_boot_mapping() invokes update_identity_mapping() for the MMU specific code.
Later when the MPU code is added, update_boot_mapping() would invoke the equivalent.

The common code now invokes update_boot_mapping() instead of update_identity_mapping(). So, that there is clear abstraction between the common and MMU/MPU specific logic.

This is in continuation to commit
f661a20aa880: "Extract MMU-specific MM code".

---
Changes from :-

v1 - 1. Introduced update_boot_mapping() which invokes update_identity_mapping() in MMU specific code.

  xen/arch/arm/arm64/mmu/mm.c   | 5 +++++
  xen/arch/arm/arm64/smpboot.c  | 6 +++---
  xen/arch/arm/include/asm/mm.h | 2 ++
  3 files changed, 10 insertions(+), 3 deletions(-)
xen/arch/arm/arm64/mmu/mm.c +0 -0
index 293acb67e0..72e089a339 100644
@@ -125,6 +125,11 @@ void update_identity_mapping(bool enable)
      BUG_ON(rc);
  }
 
Quoted 5 lines

xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 130

Quoted 3 lines
xen/arch/arm/arm64/mmu/mm.c +3 -0
+void update_boot_mapping(bool enable)
+{
+    update_identity_mapping(enable);

With your approach, update_identity_mapping() would only be called from within this file, therefore it should be marked as static and the prototype removed.

yes, agreed.

Quoted 40 lines
Quoted 40 lines
xen/arch/arm/arm64/mmu/mm.c +2 -0
+}
+
  extern void switch_ttbr_id(uint64_t ttbr);
 
  typedef void (switch_ttbr_fn)(uint64_t ttbr);
xen/arch/arm/arm64/smpboot.c +3 -3
index a225fae64d..789f352ab6 100644
@@ -112,18 +112,18 @@ int arch_cpu_up(int cpu)
      if ( !smp_enable_ops[cpu].prepare_cpu )
          return -ENODEV;
 
-    update_identity_mapping(true);
+    update_boot_mapping(true);
 
      rc = smp_enable_ops[cpu].prepare_cpu(cpu);
      if ( rc )
-        update_identity_mapping(false);
+        update_boot_mapping(false);
 
      return rc;
  }
 
  void arch_cpu_up_finish(void)
  {
-    update_identity_mapping(false);
+    update_boot_mapping(false);
  }
 
  /*
xen/arch/arm/include/asm/mm.h +0 -0
index f6ba611f01..e769d2d3b3 100644
@@ -426,6 +426,8 @@ static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn)
      } while ( (y = cmpxchg(&p->u.inuse.type_info, x, nx)) != x );
  }
 
Quoted 2 lines

xen/arch/arm/include/asm/mm.h static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn) · line 429

Quoted 1 line
xen/arch/arm/include/asm/mm.h +1 -0
+void update_boot_mapping(bool enable);

The definition is only present for arm64. Shouldn't the prototype be moved to arm64 header?

Yes, I have replaced the prototype

update_identity_mapping() with update_boot_mapping() in xen/arch/arm/include/asm/arm64/mm.h

- Ayan

#8 lore raw

Re: [PATCH v2 2/4] xen: arm: make VMAP only support in MMU system

In reply to Jan Beulich

Hi Jan,

Quoted 39 lines · Jan Beulich
Quoted 12 lines · Ayan Kumar Halder
Quoted 8 lines · Jan Beulich

xen/arch/arm/Kconfig config PADDR_BITS · line 62

Quoted 6 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +2 -0
@@ -58,9 +58,13 @@ config PADDR_BITS
   	default 40 if ARM_PA_BITS_40
   	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y

With this being always enabled, ...

I had to define the config somewhere. It seemed this is the correct place to define as HAS_VMAP will be turned off when MPU is introduced.

Quoted 7 lines

So, it will be

config HAS_VMAP

           def_bool n

At that time, only MMU will select HAS_VMAP.

Well, but why is it not simply

config HAS_VMAP
bool

from the very beginning? (There should never be "def_bool n" imo, btw.)

Quoted 12 lines
Quoted 12 lines

xen/include/xen/vmap.h void *arch_vmap_virt_end(void); · line 147

Quoted 10 lines
xen/include/xen/vmap.h +2 -0
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
   /* Initialises the VMAP_DEFAULT virtual range */
   static inline void vm_init(void)
   {
+#ifdef CONFIG_MMU
       vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
   }

What about non-Arm, which all have MMUs but no corresponding Kconfig setting?

Quoted 8 lines
Quoted 5 lines

AFAICS , the only file that is of our concern xen/common/vmap.c It is enclosed with VMAP_VIRT_START which is defined in mmu specific file (xen/arch/arm/include/asm/mmu/layout.h).

So, it will not be compiled for Arm MPU arch.

Yet that wasn't my question. I asked about non-Arm, for all of which it looks like you're changing behavior of vm_init() (by suddenly making it do nothing).

Oh now I see what you mean. There is no CONFIG_MMU is x86 , yet it is used to enclose a common code which is a mistake.

So, we should introduce HAS_VMAP in xen/common/Kconfig and select it from X86, X86_64 and Arm.

Is my understanding correct ?

- Ayan

#15 lore raw

Re: [PATCH v2 4/4] xen: arm: Enclose access to EL2 MMU specific registers under CONFIG_MMU

In reply to Michal Orzel
Quoted 1 line · Michal Orzel

Hi Ayan,

Hi Michal,

Quoted 21 lines · Ayan Kumar Halder
Quoted 19 lines

All the EL2 MMU specific registers are enclosed within CONFIG_MMU.

---
Changes from v1 :-
1. 'vttbr_el2' field is enclosed with ifdef.
2. No movement of code.

  xen/arch/arm/traps.c | 6 ++++++
  1 file changed, 6 insertions(+)
xen/arch/arm/traps.c +0 -0
index aac6c599f8..f51e1424cb 100644
@@ -720,8 +720,10 @@ struct reg_ctxt {
      uint32_t ifsr32_el2;
  #endif
 
Quoted 5 lines

xen/arch/arm/traps.c struct reg_ctxt { · line 725

Quoted 3 lines
xen/arch/arm/traps.c +1 -0
+#ifdef CONFIG_MMU
      /* Hypervisor-side state */
      uint64_t vttbr_el2;

Given that you protected the field here, why did you leave assignments in show_registers() and vcpu_show_registers() unguarded?

Makes sense. Sorry I forgot about that.

- Ayan

#9 lore raw

Re: [PATCH v2 2/4] xen: arm: make VMAP only support in MMU system

In reply to Ayan Kumar Halder
Quoted 51 lines · Ayan Kumar Halder

Hi Jan,

Quoted 39 lines · Jan Beulich
Quoted 12 lines · Ayan Kumar Halder
Quoted 8 lines · Jan Beulich

xen/arch/arm/Kconfig config PADDR_BITS · line 62

Quoted 6 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +2 -0
@@ -58,9 +58,13 @@ config PADDR_BITS
   	default 40 if ARM_PA_BITS_40
   	default 48 if ARM_64
 
+config HAS_VMAP
+	def_bool y

With this being always enabled, ...

I had to define the config somewhere. It seemed this is the correct place to define as HAS_VMAP will be turned off when MPU is introduced.

Quoted 7 lines

So, it will be

config HAS_VMAP

           def_bool n

At that time, only MMU will select HAS_VMAP.

Well, but why is it not simply

config HAS_VMAP
bool

from the very beginning? (There should never be "def_bool n" imo, btw.)

Quoted 12 lines
Quoted 12 lines

xen/include/xen/vmap.h void *arch_vmap_virt_end(void); · line 147

Quoted 10 lines
xen/include/xen/vmap.h +2 -0
@@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void);
   /* Initialises the VMAP_DEFAULT virtual range */
   static inline void vm_init(void)
   {
+#ifdef CONFIG_MMU
       vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end());
+#endif
   }

What about non-Arm, which all have MMUs but no corresponding Kconfig setting?

Quoted 8 lines
Quoted 5 lines

AFAICS , the only file that is of our concern xen/common/vmap.c It is enclosed with VMAP_VIRT_START which is defined in mmu specific file (xen/arch/arm/include/asm/mmu/layout.h).

So, it will not be compiled for Arm MPU arch.

Yet that wasn't my question. I asked about non-Arm, for all of which it looks like you're changing behavior of vm_init() (by suddenly making it do nothing).

Quoted 7 lines

Oh now I see what you mean. There is no CONFIG_MMU is x86 , yet it is used to enclose a common code which is a mistake.

So, we should introduce HAS_VMAP in xen/common/Kconfig and select it from X86, X86_64 and Arm.

Is my understanding correct ?

Almost. On Arm the select would be conditional, depending on (or simply from) MMU.

Jan