Skip to contentSkip to conversation

Enable early bootup of AArch64 MPU systems.

PATCH Superseded Ayan Kumar Halder 4 participants 27 messages Aug 23, 2024 – Sep 11, 2024

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 xen/arm: mpu: Introduce choice between MMU and MPU

In reply to Ayan Kumar Halder

There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (eg STATIC_MEMORY) will be selected by the MPU configuration.

Thus, this patch introduces a choice between MMU and MPU for the type of memory management system. By default, MMU is selected. All the current platforms are now made dependent on MMU.

---
 xen/arch/arm/Kconfig           | 17 ++++++++++++++++-
 xen/arch/arm/platforms/Kconfig |  2 +-
 2 files changed, 17 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +16 -1
index 323c967361..686948cefd 100644
@@ -58,10 +58,25 @@ config PADDR_BITS
 	default 40 if ARM_PA_BITS_40
 	default 48 if ARM_64
 
+choice
+	prompt "Memory management system"
+	default MMU if ARM
+	help
+	  User can choose between the different forms of memory management system.
+	  Most of the Arm based systems support MMU.
+
 config MMU
-	def_bool y
+	bool "MMU"
 	select HAS_PMAP
 	select HAS_VMAP
+	help
+	  Memory management unit is supported on most Arm based systems.
+
+config MPU
+	bool "MPU"
+	help
+	  Memory protection unit is supported on some Cortex-R systems.
+endchoice
 
 source "arch/Kconfig"
 
xen/arch/arm/platforms/Kconfig +1 -1
index 76f7e76b1b..02322c259c 100644
@@ -1,5 +1,5 @@
 choice
-	prompt "Platform Support"
+	prompt "Platform Support" if MMU
 	default ALL_PLAT
 	help
 	Choose which hardware platform to enable in Xen.
Signature · 1 line
2.25.1
#0 lore raw

cover Enable early bootup of AArch64 MPU systems.

These patches are based on https://lore.kernel.org/all/[email protected]/T/
"[PATCH v4 0/4] xen: arm: Split MMU code in preparation for MPU work (part 2)"

We have enabled early booting of R82.

Ayan Kumar Halder (4):
xen/arm: mpu: Introduce choice between MMU and MPU xen/arm: mpu: Define Xen start address for MPU systems xen/arm: mpu: Create boot-time MPU protection regions xen/arm: mpu: Disable secondary cpu bringup

 xen/arch/arm/Kconfig                     | 28 ++++++++-
 xen/arch/arm/Makefile                    |  1 +
 xen/arch/arm/arm64/mpu/Makefile          |  1 +
 xen/arch/arm/arm64/mpu/head.S            | 79 ++++++++++++++++++++++++
 xen/arch/arm/include/asm/arm64/sysregs.h | 50 +++++++++++++++
 xen/arch/arm/include/asm/mpu/arm64/mm.h  | 13 ++++
 xen/arch/arm/include/asm/mpu/layout.h    | 25 ++++++++
 xen/arch/arm/include/asm/mpu/mm.h        | 18 ++++++
 xen/arch/arm/platforms/Kconfig           |  2 +-
 9 files changed, 215 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm64/mpu/Makefile
 create mode 100644 xen/arch/arm/arm64/mpu/head.S
 create mode 100644 xen/arch/arm/include/asm/mpu/arm64/mm.h
 create mode 100644 xen/arch/arm/include/asm/mpu/layout.h
 create mode 100644 xen/arch/arm/include/asm/mpu/mm.h
Signature · 1 line
2.25.1
#14 lore raw

PATCH 3/4 xen/arm: mpu: Create boot-time MPU protection regions

Define enable_boot_cpu_mm() for the AArch64-V8R system.

Like boot-time page table in MMU system, we need a boot-time MPU protection region configuration in MPU system so Xen can fetch code and data from normal memory.

START_ADDRESS + 2MB memory is mapped to contain the text and data required for early boot of Xen.

One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of PRBAR_EL2, PRLAR_EL2 and PRSELR_EL2 registers. Also, refer to G1.2 "Accessing MPU memory region registers", the following

```
The MPU provides two register interfaces to program the MPU regions:
 - Access to any of the MPU regions via PRSELR_ELx, PRBAR<n>_ELx, and
PRLAR<n>_ELx.
```

We use the above mechanism to configure the MPU memory regions.

---
 xen/arch/arm/Makefile                    |  1 +
 xen/arch/arm/arm64/mpu/Makefile          |  1 +
 xen/arch/arm/arm64/mpu/head.S            | 70 ++++++++++++++++++++++++
 xen/arch/arm/include/asm/arm64/sysregs.h | 50 +++++++++++++++++
 xen/arch/arm/include/asm/mpu/arm64/mm.h  | 13 +++++
 xen/arch/arm/include/asm/mpu/mm.h        | 18 ++++++
 6 files changed, 153 insertions(+)
 create mode 100644 xen/arch/arm/arm64/mpu/Makefile
 create mode 100644 xen/arch/arm/arm64/mpu/head.S
 create mode 100644 xen/arch/arm/include/asm/mpu/arm64/mm.h
 create mode 100644 xen/arch/arm/include/asm/mpu/mm.h
xen/arch/arm/Makefile +1 -0
index 7792bff597..aebccec63a 100644
@@ -1,6 +1,7 @@
 obj-$(CONFIG_ARM_32) += arm32/
 obj-$(CONFIG_ARM_64) += arm64/
 obj-$(CONFIG_MMU) += mmu/
+obj-$(CONFIG_MPU) += mpu/
 obj-$(CONFIG_ACPI) += acpi/
 obj-$(CONFIG_HAS_PCI) += pci/
 ifneq ($(CONFIG_NO_PLAT),y)
xen/arch/arm/arm64/mpu/Makefile new file +1 -0
new file mode 100644
index 0000000000..3340058c08
@@ -0,0 +1 @@
+obj-y += head.o
xen/arch/arm/arm64/mpu/head.S new file +70 -0

70 lines not on this page · raw message

xen/arch/arm/include/asm/arm64/sysregs.h +50 -0

56 lines not on this page · raw message

xen/arch/arm/include/asm/mpu/arm64/mm.h new file +13 -0
new file mode 100644
index 0000000000..d209eef6db
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * mpu.h: Arm Memory Protection Unit definitions.
+ */
+
+#ifndef __ARM64_MPU_H__
+#define __ARM64_MPU_H__
+
+#define MPU_REGION_SHIFT  6
+#define MPU_REGION_ALIGN  (_AC(1, UL) << MPU_REGION_SHIFT)
+#define MPU_REGION_MASK   (~(MPU_REGION_ALIGN - 1))
+
+#endif /* __ARM64_MPU_H__ */
xen/arch/arm/include/asm/mpu/mm.h new file +18 -0
new file mode 100644
index 0000000000..f5ebca8261
@@ -0,0 +1,18 @@
+#ifndef __ARCH_ARM_MPU__
+#define __ARCH_ARM_MPU__
+
+#if defined(CONFIG_ARM_64)
+# include <asm/mpu/arm64/mm.h>
+#else
+# error "unknown ARM variant"
+#endif
+
+#endif /*  __ARCH_ARM_MPU__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.25.1
#5 lore raw

PATCH 2/4 xen/arm: mpu: Define Xen start address for MPU systems

In reply to Ayan Kumar Halder

From: Wei Chen <[email protected]>

On Armv8-A, Xen has a fixed virtual start address (link address too) for all Armv8-A platforms. In an MMU based system, Xen can map its loaded address to this virtual start address. So, on Armv8-A platforms, the Xen start address does not need to be configurable. But on Armv8-R platforms, there is no MMU to map loaded address to a fixed virtual address and different platforms will have very different address space layout. So Xen cannot use a fixed physical address on MPU based system and need to have it configurable.

So in this patch, we reuse the existing arm/platforms to store Armv8-R platforms' parameters. And XEN_START_ADDRESS is one kind of MPU based platform's parameters. So we define default XEN_START_ADDRESS in the MPU specific header file.

We also introduce one Kconfig option for users to override the default Xen start address of selected platform, if they think the default address doesn't suit their scenarios. For this Kconfig option, we use an unaligned address "0xffffffff" as the default value to indicate that users haven't used a customized Xen start address.

---
 xen/arch/arm/Kconfig                  | 11 +++++++++++
 xen/arch/arm/include/asm/mpu/layout.h | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 xen/arch/arm/include/asm/mpu/layout.h
xen/arch/arm/Kconfig +11 -0
index 686948cefd..d722ca690c 100644
@@ -23,6 +23,17 @@ config ARCH_DEFCONFIG
 	default "arch/arm/configs/arm32_defconfig" if ARM_32
 	default "arch/arm/configs/arm64_defconfig" if ARM_64
 
+config XEN_START_ADDRESS
+	hex "Xen start address: keep default to use platform defined address"
+	default 0xFFFFFFFF
+	depends on MPU
+	help
+	  This option is allowed to set customized address at which Xen will be
+	  linked on MPU systems. This address must be aligned to a page size.
+	  Use 0xFFFFFFFF as the default value to indicate that user hasn't
+	  customized this address, and Xen use use the default value that has
+	  been defined in platform files.
+
 menu "Architecture Features"
 
 choice
xen/arch/arm/include/asm/mpu/layout.h new file +25 -0
new file mode 100644
index 0000000000..82a74b8b5b
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * config_mpu.h: A Linux-style configuration list for Arm MPU systems,
+ *               only can be included by config.h
+ */
+
+#ifndef __ARM_CONFIG_MPU_H__
+#define __ARM_CONFIG_MPU_H__
+
+
+#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
+
+/*
+ * All MPU platforms need to provide a XEN_START_ADDRESS for linker. This
+ * address indicates where Xen image will be loaded and run from. This
+ * address must be aligned to a PAGE_SIZE.
+ */
+#if (XEN_START_ADDRESS % PAGE_SIZE) != 0
+#error "XEN_START_ADDRESS must be aligned to PAGE_SIZE"
+#endif
+
+#define XEN_VIRT_START         _AT(paddr_t, XEN_START_ADDRESS)
+
+#endif /* __ARM_CONFIG_MPU_H__ */
+
Signature · 1 line
2.25.1
#24 lore raw

PATCH 4/4 xen/arm: mpu: Disable secondary cpu bringup

In reply to Ayan Kumar Halder

Secondary cpus are put in WFE state. We do not support SMP at this time.

---
 xen/arch/arm/arm64/mpu/head.S | 9 +++++++++
 1 file changed, 9 insertions(+)
xen/arch/arm/arm64/mpu/head.S +9 -0
index 2b023c346a..1579ac0408 100644
@@ -68,3 +68,12 @@ ENTRY(enable_boot_cpu_mm)
 
     ret
 ENDPROC(enable_boot_cpu_mm)
+
+/*
+ * Secondary cpu has not yet been supported on MPU systems. We will block the
+ * secondary cpu bringup at this stage.
+ */
+ENTRY(enable_secondary_cpu_mm)
+1:  wfe
+    b 1b
+ENDPROC(enable_secondary_cpu_mm)
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v1 1/4] xen/arm: mpu: Introduce choice between MMU and MPU

In reply to Ayan Kumar Halder

Hi,

Quoted 20 lines · Ayan Kumar Halder

There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (eg STATIC_MEMORY) will be selected by the MPU configuration.

Thus, this patch introduces a choice between MMU and MPU for the type of memory management system. By default, MMU is selected. All the current platforms are now made dependent on MMU.

---
  xen/arch/arm/Kconfig           | 17 ++++++++++++++++-
  xen/arch/arm/platforms/Kconfig |  2 +-
  2 files changed, 17 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +0 -0
index 323c967361..686948cefd 100644

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

Quoted 9 lines
xen/arch/arm/Kconfig +6 -0
@@ -58,10 +58,25 @@ config PADDR_BITS
  	default 40 if ARM_PA_BITS_40
  	default 48 if ARM_64
 
+choice
+	prompt "Memory management system"
+	default MMU if ARM
+	help
+	  User can choose between the different forms of memory management system.
+	  Most of the Arm based systems support MMU.

I feel this is quite subjective. So I would drop it.

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

Quoted 8 lines
xen/arch/arm/Kconfig +4 -1
+
  config MMU
-	def_bool y
+	bool "MMU"
  	select HAS_PMAP
  	select HAS_VMAP
+	help
+	  Memory management unit is supported on most Arm based systems.

For this case, I would write "Select it you are plan to run Xen on Armv7-A or Armv8-A".

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

Quoted 3 lines
xen/arch/arm/Kconfig +3 -0
+
+config MPU
+	bool "MPU"

I think it should be gated by UNSUPPORTED. SUPPORT.md also needs to be updated.

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

Quoted 2 lines
xen/arch/arm/Kconfig +2 -0
+	help
+	  Memory protection unit is supported on some Cortex-R systems.

Why do you make this specific to Cortex-R? Shouldn't this instead be Armv8-R?

Quoted 15 lines
xen/arch/arm/Kconfig +1 -0
+endchoice
 
  source "arch/Kconfig"
 
xen/arch/arm/platforms/Kconfig +1 -1
index 76f7e76b1b..02322c259c 100644
@@ -1,5 +1,5 @@
  choice
-	prompt "Platform Support"
+	prompt "Platform Support" if MMU
  	default ALL_PLAT
  	help
  	Choose which hardware platform to enable in Xen.
Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH v1 1/4] xen/arm: mpu: Introduce choice between MMU and MPU

Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines

There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (eg STATIC_MEMORY) will be selected by the MPU configuration.

Thus, this patch introduces a choice between MMU and MPU for the type of memory management system. By default, MMU is selected. All the current platforms are now made dependent on MMU.

---
  xen/arch/arm/Kconfig           | 17 ++++++++++++++++- xen/arch/arm/platforms/Kconfig |  2 +-

  2 files changed, 17 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 6 lines
xen/arch/arm/Kconfig +0 -0
index 323c967361..686948cefd 100644
@@ -58,10 +58,25 @@ config PADDR_BITS

      default 40 if ARM_PA_BITS_40

Quoted 8 lines

      default 48 if ARM_64
  +choice
+    prompt "Memory management system"
+    default MMU if ARM
+    help
+      User can choose between the different forms of memory management system.
+      Most of the Arm based systems support MMU.

I feel this is quite subjective. So I would drop it.

Agreed.

Quoted 11 lines
Quoted 9 lines

+
  config MMU
-    def_bool y
+    bool "MMU"
      select HAS_PMAP
      select HAS_VMAP
+    help
+      Memory management unit is supported on most Arm based systems.

For this case, I would write "Select it you are plan to run Xen on Armv7-A or Armv8-A".

Ack.

Quoted 7 lines

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

Quoted 5 lines
xen/arch/arm/Kconfig +3 -0
+
+config MPU
+    bool "MPU"

I think it should be gated by UNSUPPORTED. SUPPORT.md also needs to be updated.

Ack.

Quoted 5 lines
Quoted 3 lines

+    help
+      Memory protection unit is supported on some Cortex-R systems.

Why do you make this specific to Cortex-R? Shouldn't this instead be Armv8-R?

Yes, you are correct. It should be Armv8-R. Otherwise, someone might think it is applicable for Cortex-R5, R7, etc.

- Ayan

#6 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

In reply to Ayan Kumar Halder

Hi,

Quoted 12 lines · Ayan Kumar Halder

From: Wei Chen <[email protected]>

On Armv8-A, Xen has a fixed virtual start address (link address too) for all Armv8-A platforms. In an MMU based system, Xen can map its loaded address to this virtual start address. So, on Armv8-A platforms, the Xen start address does not need to be configurable. But on Armv8-R platforms, there is no MMU to map loaded address to a fixed virtual address and different platforms will have very different address space layout. So Xen cannot use a fixed physical address on MPU based system and need to have it configurable.

Quoted 4 lines

So in this patch, we reuse the existing arm/platforms to store Armv8-R platforms' parameters. And XEN_START_ADDRESS is one kind of MPU based platform's parameters. So we define default XEN_START_ADDRESS in the MPU specific header file.

This seems a left-over from as previous work?

Quoted 22 lines

We also introduce one Kconfig option for users to override the default Xen start address of selected platform, if they think the default address doesn't suit their scenarios. For this Kconfig option, we use an unaligned address "0xffffffff" as the default value to indicate that users haven't used a customized Xen start address.

---
  xen/arch/arm/Kconfig                  | 11 +++++++++++
  xen/arch/arm/include/asm/mpu/layout.h | 25 +++++++++++++++++++++++++
  2 files changed, 36 insertions(+)

create mode 100644 xen/arch/arm/include/asm/mpu/layout.h

xen/arch/arm/Kconfig +0 -0
index 686948cefd..d722ca690c 100644

xen/arch/arm/Kconfig config ARCH_DEFCONFIG · line 32

Quoted 10 lines
xen/arch/arm/Kconfig +7 -0
@@ -23,6 +23,17 @@ config ARCH_DEFCONFIG
  	default "arch/arm/configs/arm32_defconfig" if ARM_32
  	default "arch/arm/configs/arm64_defconfig" if ARM_64
 
+config XEN_START_ADDRESS
+	hex "Xen start address: keep default to use platform defined address"
+	default 0xFFFFFFFF
+	depends on MPU
+	help
+	  This option is allowed to set customized address at which Xen will be
+	  linked on MPU systems.

I don't quite understand what you mean by "allowed".

xen/arch/arm/Kconfig config ARCH_DEFCONFIG · line 35

Quoted 3 lines
xen/arch/arm/Kconfig +2 -0
 This address must be aligned to a page size.> +	  Use 0xFFFFFFFF as the default value to indicate that user hasn't
+	  customized this address, and Xen use use the default value that has
+	  been defined in platform files.

At least in this patch, there is no default set. Instead you will throw an error.

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

Quoted 11 lines
xen/arch/arm/Kconfig +1 -0
+
  menu "Architecture Features"
 
  choice
xen/arch/arm/include/asm/mpu/layout.h new file +1 -0
new file mode 100644
index 0000000000..82a74b8b5b
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only

Coding style: /* SPDX-... */

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

Quoted 4 lines
xen/arch/arm/include/asm/mpu/layout.h new file +4 -0
+/*
+ * config_mpu.h: A Linux-style configuration list for Arm MPU systems,
+ *               only can be included by config.h
+ */

I don't understand how this description match the content below. Also, shouldn't you include it from xen/config.h?

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

Quoted 3 lines
xen/arch/arm/include/asm/mpu/layout.h new file +3 -0
+
+#ifndef __ARM_CONFIG_MPU_H__
+#define __ARM_CONFIG_MPU_H__

This doesn't match the name of the file.

Quoted 7 lines
xen/arch/arm/include/asm/mpu/layout.h new file +7 -0
+
+
+#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
+
+/*
+ * All MPU platforms need to provide a XEN_START_ADDRESS for linker. This
+ * address indicates where Xen image will be loaded and run from. This

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

Quoted 10 lines
xen/arch/arm/include/asm/mpu/layout.h new file +10 -0
+ * address must be aligned to a PAGE_SIZE.
+ */
+#if (XEN_START_ADDRESS % PAGE_SIZE) != 0
+#error "XEN_START_ADDRESS must be aligned to PAGE_SIZE"
+#endif
+
+#define XEN_VIRT_START         _AT(paddr_t, XEN_START_ADDRESS)
+
+#endif /* __ARM_CONFIG_MPU_H__ */
+

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

In reply to Ayan Kumar Halder

Hi,

Quoted 60 lines · Ayan Kumar Halder

Define enable_boot_cpu_mm() for the AArch64-V8R system.

Like boot-time page table in MMU system, we need a boot-time MPU protection region configuration in MPU system so Xen can fetch code and data from normal memory.

START_ADDRESS + 2MB memory is mapped to contain the text and data required for early boot of Xen.

One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of PRBAR_EL2, PRLAR_EL2 and PRSELR_EL2 registers. Also, refer to G1.2 "Accessing MPU memory region registers", the following

```
The MPU provides two register interfaces to program the MPU regions:
  - Access to any of the MPU regions via PRSELR_ELx, PRBAR<n>_ELx, and
PRLAR<n>_ELx.
```

We use the above mechanism to configure the MPU memory regions.

---
  xen/arch/arm/Makefile                    |  1 +
  xen/arch/arm/arm64/mpu/Makefile          |  1 +
  xen/arch/arm/arm64/mpu/head.S            | 70 ++++++++++++++++++++++++
  xen/arch/arm/include/asm/arm64/sysregs.h | 50 +++++++++++++++++
  xen/arch/arm/include/asm/mpu/arm64/mm.h  | 13 +++++
  xen/arch/arm/include/asm/mpu/mm.h        | 18 ++++++
  6 files changed, 153 insertions(+)

create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644 xen/arch/arm/arm64/mpu/head.S create mode 100644 xen/arch/arm/include/asm/mpu/arm64/mm.h create mode 100644 xen/arch/arm/include/asm/mpu/mm.h

xen/arch/arm/Makefile +1 -0
index 7792bff597..aebccec63a 100644
@@ -1,6 +1,7 @@
  obj-$(CONFIG_ARM_32) += arm32/
  obj-$(CONFIG_ARM_64) += arm64/
  obj-$(CONFIG_MMU) += mmu/
+obj-$(CONFIG_MPU) += mpu/
  obj-$(CONFIG_ACPI) += acpi/
  obj-$(CONFIG_HAS_PCI) += pci/
  ifneq ($(CONFIG_NO_PLAT),y)
xen/arch/arm/arm64/mpu/Makefile new file +1 -0
new file mode 100644
index 0000000000..3340058c08
@@ -0,0 +1 @@
+obj-y += head.o
xen/arch/arm/arm64/mpu/head.S new file +0 -0
new file mode 100644
index 0000000000..2b023c346a

xen/arch/arm/arm64/mpu/head.S line 1

Quoted 1 line
xen/arch/arm/arm64/mpu/head.S new file +1 -0
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only

Coding style: /* ... */

xen/arch/arm/arm64/mpu/head.S line 7

Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +6 -0
+/*
+ * Start-of-day code for an Armv8-R MPU system.
+ */
+
+#include <asm/mm.h>
+#include <asm/page.h>

I can't see any use of the definition of page.h. Is it necessary?

xen/arch/arm/arm64/mpu/head.S line 8

Quoted 1 line
xen/arch/arm/arm64/mpu/head.S new file +1 -0
+#include <asm/early_printk.h>

You include early_printk.h but don't use it.

xen/arch/arm/arm64/mpu/head.S

Quoted 5 lines
xen/arch/arm/arm64/mpu/head.S new file +5 -0
+
+/*
+ * From the requirements of head.S we know that Xen image should
+ * be linked at XEN_START_ADDRESS, and all of text + data + bss
+ * must fit in 2MB.

Xen can be bigger than 2MB. But rather than hardcoding the limit, you want to use _end.

Quoted 6 lines

On MPU systems, XEN_START_ADDRESS is also the
+ * address that Xen image should be loaded at. So for initial MPU
+ * regions setup, we use 2MB for Xen data memory to setup boot
+ * region, or the create boot regions code below will need adjustment.
+ */
+#define XEN_START_MEM_SIZE 0x200000

See above.

Quoted 4 lines
xen/arch/arm/arm64/mpu/head.S new file +4 -0
+
+/*
+ * In boot stage, we will use 1 MPU region:
+ * Region#0: Normal memory for Xen text + data + bss (2MB)

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10 -0
+ */
+#define BOOT_NORMAL_REGION_IDX  0x0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

If a "dsb" is necessary, "sy" seems to be quite strict.

Quoted 5 lines
xen/arch/arm/arm64/mpu/head.S new file +5 -0
+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy
+    isb
+.endm

xen/arch/arm/arm64/mpu/head.S line 47

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10 -0
+
+.section .text.header, "ax", %progbits
+
+/*
+ * Static start-of-day EL2 MPU memory layout.
+ *
+ * It has a very simple structure, including:
+ *  - 2MB normal memory mappings of xen at XEN_START_ADDRESS, which
+ * is the address where Xen was loaded by the bootloader.
+ */

Please document a bit more the code and how the registers are used. For an example see the mmu/head.S code.

Quoted 13 lines
xen/arch/arm/arm64/mpu/head.S new file +13 -0
+ENTRY(enable_boot_cpu_mm)
+    /* Map Xen start memory to a normal memory region. */
+    mov x0, #BOOT_NORMAL_REGION_IDX
+    ldr x1, =XEN_START_ADDRESS
+    and x1, x1, #MPU_REGION_MASK
+    mov x3, #PRBAR_NORMAL_MEM
+    orr x1, x1, x3
+
+    ldr x2, =XEN_START_ADDRESS
+    mov x3, #(XEN_START_MEM_SIZE - 1)
+    add x2, x2, x3
+    and x2, x2, #MPU_REGION_MASK
+    mov x3, #PRLAR_NORMAL_MEM

xen/arch/arm/arm64/mpu/head.S line 70

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10 -0
+    orr x2, x2, x3
+
+    /*
+     * Write to MPU protection region:
+     * x0 for pr_sel, x1 for prbar x2 for prlar
+     */
+    write_pr x0, x1, x2
+
+    ret
+ENDPROC(enable_boot_cpu_mm)

Missing emacs magic.

xen/arch/arm/include/asm/arm64/sysregs.h line 466

Quoted 10 lines
xen/arch/arm/include/asm/arm64/sysregs.h +2 -0
index b593e4028b..0d122e1fa6 100644
@@ -462,6 +462,56 @@
  #define ZCR_ELx_LEN_SIZE             9
  #define ZCR_ELx_LEN_MASK             0x1ff
 
+/* System registers for AArch64 with PMSA */
+#ifdef CONFIG_MPU

Can we define the registers in mpu/sysregs.h? This can then be included only where it is needed.

Quoted 57 lines
xen/arch/arm/include/asm/arm64/sysregs.h +48 -0
+
+/* EL2 MPU Protection Region Base Address Register encode */
+#define PRBAR_EL2   S3_4_C6_C8_0
+#define PRBAR1_EL2  S3_4_C6_C8_4
+#define PRBAR2_EL2  S3_4_C6_C9_0
+#define PRBAR3_EL2  S3_4_C6_C9_4
+#define PRBAR4_EL2  S3_4_C6_C10_0
+#define PRBAR5_EL2  S3_4_C6_C10_4
+#define PRBAR6_EL2  S3_4_C6_C11_0
+#define PRBAR7_EL2  S3_4_C6_C11_4
+#define PRBAR8_EL2  S3_4_C6_C12_0
+#define PRBAR9_EL2  S3_4_C6_C12_4
+#define PRBAR10_EL2 S3_4_C6_C13_0
+#define PRBAR11_EL2 S3_4_C6_C13_4
+#define PRBAR12_EL2 S3_4_C6_C14_0
+#define PRBAR13_EL2 S3_4_C6_C14_4
+#define PRBAR14_EL2 S3_4_C6_C15_0
+#define PRBAR15_EL2 S3_4_C6_C15_4
+
+/* EL2 MPU Protection Region Limit Address Register encode */
+#define PRLAR_EL2   S3_4_C6_C8_1
+#define PRLAR1_EL2  S3_4_C6_C8_5
+#define PRLAR2_EL2  S3_4_C6_C9_1
+#define PRLAR3_EL2  S3_4_C6_C9_5
+#define PRLAR4_EL2  S3_4_C6_C10_1
+#define PRLAR5_EL2  S3_4_C6_C10_5
+#define PRLAR6_EL2  S3_4_C6_C11_1
+#define PRLAR7_EL2  S3_4_C6_C11_5
+#define PRLAR8_EL2  S3_4_C6_C12_1
+#define PRLAR9_EL2  S3_4_C6_C12_5
+#define PRLAR10_EL2 S3_4_C6_C13_1
+#define PRLAR11_EL2 S3_4_C6_C13_5
+#define PRLAR12_EL2 S3_4_C6_C14_1
+#define PRLAR13_EL2 S3_4_C6_C14_5
+#define PRLAR14_EL2 S3_4_C6_C15_1
+#define PRLAR15_EL2 S3_4_C6_C15_5
+
+/* MPU Protection Region Enable Register encode */
+#define PRENR_EL2 S3_4_C6_C1_1
+
+/* MPU Protection Region Selection Register encode */
+#define PRSELR_EL2 S3_4_C6_C2_1
+
+/* MPU Type registers encode */
+#define MPUIR_EL2 S3_4_C0_C0_4
+
+#endif
+
  /* Access to system registers */
 
  #define WRITE_SYSREG64(v, name) do {                    \
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +0 -0
new file mode 100644
index 0000000000..d209eef6db

xen/arch/arm/include/asm/mpu/arm64/mm.h line 1

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

Coding style: /* ... */

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

Quoted 2 lines
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +2 -0
+/*
+ * mpu.h: Arm Memory Protection Unit definitions.

The file is name mm.h.

xen/arch/arm/include/asm/mpu/arm64/mm.h line 13

Quoted 10 lines
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +10 -0
+ */
+
+#ifndef __ARM64_MPU_H__
+#define __ARM64_MPU_H__
+
+#define MPU_REGION_SHIFT  6
+#define MPU_REGION_ALIGN  (_AC(1, UL) << MPU_REGION_SHIFT)
+#define MPU_REGION_MASK   (~(MPU_REGION_ALIGN - 1))
+
+#endif /* __ARM64_MPU_H__ */

Missing emacs magic.

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

Quoted 5 lines
xen/arch/arm/include/asm/mpu/mm.h new file +0 -0
new file mode 100644
index 0000000000..f5ebca8261

Do we need this file?

Quoted 9 lines
xen/arch/arm/include/asm/mpu/mm.h new file +8 -0
@@ -0,0 +1,18 @@
+#ifndef __ARCH_ARM_MPU__
+#define __ARCH_ARM_MPU__
+
+#if defined(CONFIG_ARM_64)
+# include <asm/mpu/arm64/mm.h>
+#else
+# error "unknown ARM variant"
+#endif

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

Quoted 10 lines
xen/arch/arm/include/asm/mpu/mm.h new file +10 -0
+
+#endif /*  __ARCH_ARM_MPU__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

Cheers,

Signature · 1 line
Julien Grall
#25 lore raw

Re: [PATCH v1 4/4] xen/arm: mpu: Disable secondary cpu bringup

In reply to Ayan Kumar Halder

Hi Ayan,

The title is a bit confusing. It implies seconary CPU bringup used to work on the MPU. However, you are adding a stub for enable_secondary_cpu_mm.

Also, I am not entirely this is really sufficient to disable CPU bringup. There will be plenty of initialization done for secondary CPUs.

I would suggest to update NR_CPUS to 1 for MPU so we will fail early.

For the title, how about

xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm

Quoted 12 lines · Ayan Kumar Halder

Secondary cpus are put in WFE state. We do not support SMP at this time.

---
  xen/arch/arm/arm64/mpu/head.S | 9 +++++++++
  1 file changed, 9 insertions(+)
xen/arch/arm/arm64/mpu/head.S +0 -0
index 2b023c346a..1579ac0408 100644

xen/arch/arm/arm64/mpu/head.S ENTRY(enable_boot_cpu_mm) · line 76

Quoted 9 lines
xen/arch/arm/arm64/mpu/head.S +6 -0
@@ -68,3 +68,12 @@ ENTRY(enable_boot_cpu_mm)
 
      ret
  ENDPROC(enable_boot_cpu_mm)
+
+/*
+ * Secondary cpu has not yet been supported on MPU systems. We will block the
+ * secondary cpu bringup at this stage.
+ */
+ENTRY(enable_secondary_cpu_mm)

Can we print a message so it is easier to spot that enable_secondary_cpu_mm is not properly implemented?

xen/arch/arm/arm64/mpu/head.S ENTRY(enable_boot_cpu_mm) · line 79

Quoted 3 lines
xen/arch/arm/arm64/mpu/head.S +3 -0
+1:  wfe
+    b 1b
+ENDPROC(enable_secondary_cpu_mm)

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v1 1/4] xen/arm: mpu: Introduce choice between MMU and MPU

In reply to Ayan Kumar Halder

Hi,

Quoted 48 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines

There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (eg STATIC_MEMORY) will be selected by the MPU configuration.

Thus, this patch introduces a choice between MMU and MPU for the type of memory management system. By default, MMU is selected. All the current platforms are now made dependent on MMU.

---
  xen/arch/arm/Kconfig           | 17 ++++++++++++++++- xen/arch/arm/platforms/Kconfig |  2 +-

  2 files changed, 17 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 6 lines
xen/arch/arm/Kconfig +0 -0
index 323c967361..686948cefd 100644
@@ -58,10 +58,25 @@ config PADDR_BITS

      default 40 if ARM_PA_BITS_40

Quoted 8 lines

      default 48 if ARM_64
  +choice
+    prompt "Memory management system"
+    default MMU if ARM
+    help
+      User can choose between the different forms of memory management system.
+      Most of the Arm based systems support MMU.

I feel this is quite subjective. So I would drop it.

Agreed.

Quoted 10 lines
Quoted 9 lines

+
  config MMU
-    def_bool y
+    bool "MMU"
      select HAS_PMAP
      select HAS_VMAP
+    help
+      Memory management unit is supported on most Arm based systems.

Quoted 2 lines
Quoted 1 line

For this case, I would write "Select it you are plan to run Xen on Armv7-A or Armv8-A".

Ack.

Actually, thinking a bit more. We should be able to run Xen on Armv9. So maybe it would be beter to write:

"Select it if you plan to run Xen on A-profile Armv7+".

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

In reply to Julien Grall
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 14 lines · Ayan Kumar Halder
Quoted 12 lines

From: Wei Chen <[email protected]>

On Armv8-A, Xen has a fixed virtual start address (link address too) for all Armv8-A platforms. In an MMU based system, Xen can map its loaded address to this virtual start address. So, on Armv8-A platforms, the Xen start address does not need to be configurable. But on Armv8-R platforms, there is no MMU to map loaded address to a fixed virtual address and different platforms will have very different address space layout. So Xen cannot use a fixed physical address on MPU based system and need to have it configurable.

Quoted 6 lines
Quoted 4 lines

So in this patch, we reuse the existing arm/platforms to store Armv8-R platforms' parameters. And XEN_START_ADDRESS is one kind of MPU based platform's parameters. So we define default XEN_START_ADDRESS in the MPU specific header file.

This seems a left-over from as previous work?

Yes, this needs to be removed.

Quoted 28 lines
Quoted 28 lines

We also introduce one Kconfig option for users to override the default Xen start address of selected platform, if they think the default address doesn't suit their scenarios. For this Kconfig option, we use an unaligned address "0xffffffff" as the default value to indicate that users haven't used a customized Xen start address.

---
  xen/arch/arm/Kconfig                  | 11 +++++++++++ xen/arch/arm/include/asm/mpu/layout.h | 25 +++++++++++++++++++++++++

  2 files changed, 36 insertions(+)

  create mode 100644 xen/arch/arm/include/asm/mpu/layout.h

xen/arch/arm/Kconfig +0 -0
index 686948cefd..d722ca690c 100644
@@ -23,6 +23,17 @@ config ARCH_DEFCONFIG

      default "arch/arm/configs/arm32_defconfig" if ARM_32 default "arch/arm/configs/arm64_defconfig" if ARM_64 +config XEN_START_ADDRESS
+    hex "Xen start address: keep default to use platform defined address"

Quoted 8 lines
Quoted 6 lines

+    default 0xFFFFFFFF
+    depends on MPU
+    help
+      This option is allowed to set customized address at which Xen will be
+      linked on MPU systems.

I don't quite understand what you mean by "allowed".

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Quoted 8 lines
Quoted 2 lines

  This address must be aligned to a page size.> +      Use 0xFFFFFFFF

as the default value to indicate that user hasn't

Quoted 3 lines

+      customized this address, and Xen use use the default value that has
+      been defined in platform files.

At least in this patch, there is no default set. Instead you will throw an error.

Ack. See above.

Quoted 13 lines

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

Quoted 11 lines

+
  menu "Architecture Features"
    choice

xen/arch/arm/include/asm/mpu/layout.h new file +1 -0
new file mode 100644
index 0000000000..82a74b8b5b
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only

Coding style: /* SPDX-... */

Ack

Quoted 7 lines

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

Quoted 5 lines
xen/arch/arm/include/asm/mpu/layout.h new file +4 -0
+/*
+ * config_mpu.h: A Linux-style configuration list for Arm MPU systems,
+ *               only can be included by config.h
+ */

I don't understand how this description match the content below. Also, shouldn't you include it from xen/config.h?

My bad. This description is incorrect. I will remove the description as it is not needed at this point in time.

Quoted 6 lines

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

Quoted 4 lines
xen/arch/arm/include/asm/mpu/layout.h new file +3 -0
+
+#ifndef __ARM_CONFIG_MPU_H__
+#define __ARM_CONFIG_MPU_H__

This doesn't match the name of the file.

__ARM_MPU_LAYOUT_H__

Quoted 13 lines
Quoted 13 lines
xen/arch/arm/include/asm/mpu/layout.h new file +6 -0
+
+
+#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
+
+/*
+ * All MPU platforms need to provide a XEN_START_ADDRESS for linker. 

This
+ * address indicates where Xen image will be loaded and run from. This
+ * address must be aligned to a PAGE_SIZE.
+ */

xen/arch/arm/include/asm/mpu/layout.h new file +2 -0
+#if (XEN_START_ADDRESS % PAGE_SIZE) != 0
+#error "XEN_START_ADDRESS must be aligned to PAGE_SIZE"
Quoted 8 lines

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

Quoted 6 lines
xen/arch/arm/include/asm/mpu/layout.h new file +6 -0
+#endif
+
+#define XEN_VIRT_START         _AT(paddr_t, XEN_START_ADDRESS)
+
+#endif /* __ARM_CONFIG_MPU_H__ */
+

Cheers,

- Ayan

#16 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

In reply to Julien Grall
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

I need some clarifications.

Quoted 57 lines · Ayan Kumar Halder
Quoted 55 lines

Define enable_boot_cpu_mm() for the AArch64-V8R system.

Like boot-time page table in MMU system, we need a boot-time MPU protection region configuration in MPU system so Xen can fetch code and data from normal memory.

START_ADDRESS + 2MB memory is mapped to contain the text and data required for early boot of Xen.

One can refer to ARM DDI 0600B.a ID062922 G1.3  "General System Control Registers", to get the definitions of PRBAR_EL2, PRLAR_EL2 and PRSELR_EL2 registers. Also, refer to G1.2 "Accessing MPU memory region registers", the following

```
The MPU provides two register interfaces to program the MPU regions:
  - Access to any of the MPU regions via PRSELR_ELx, PRBAR<n>_ELx, and
PRLAR<n>_ELx.
```

We use the above mechanism to configure the MPU memory regions.

---
  xen/arch/arm/Makefile                    |  1 + xen/arch/arm/arm64/mpu/Makefile          |  1 + xen/arch/arm/arm64/mpu/head.S            | 70 ++++++++++++++++++++++++ xen/arch/arm/include/asm/arm64/sysregs.h | 50 +++++++++++++++++ xen/arch/arm/include/asm/mpu/arm64/mm.h  | 13 +++++ xen/arch/arm/include/asm/mpu/mm.h        | 18 ++++++

  6 files changed, 153 insertions(+)

  create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644 xen/arch/arm/arm64/mpu/head.S create mode 100644 xen/arch/arm/include/asm/mpu/arm64/mm.h create mode 100644 xen/arch/arm/include/asm/mpu/mm.h

xen/arch/arm/Makefile +0 -0
index 7792bff597..aebccec63a 100644
@@ -1,6 +1,7 @@

  obj-$(CONFIG_ARM_32) += arm32/
  obj-$(CONFIG_ARM_64) += arm64/
  obj-$(CONFIG_MMU) += mmu/
+obj-$(CONFIG_MPU) += mpu/
  obj-$(CONFIG_ACPI) += acpi/
  obj-$(CONFIG_HAS_PCI) += pci/
  ifneq ($(CONFIG_NO_PLAT),y)

xen/arch/arm/arm64/mpu/Makefile new file +1 -0
new file mode 100644
index 0000000000..3340058c08
@@ -0,0 +1 @@
+obj-y += head.o
xen/arch/arm/arm64/mpu/head.S +0 -0
Quoted 8 lines

xen/arch/arm/arm64/mpu/head.S line 1

Quoted 6 lines

new file mode 100644
index 0000000000..2b023c346a

xen/arch/arm/arm64/mpu/head.S new file +1 -0
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only

Coding style: /* ... */

Ack

Quoted 9 lines

xen/arch/arm/arm64/mpu/head.S line 7

Quoted 7 lines
xen/arch/arm/arm64/mpu/head.S new file +6 -0
+/*
+ * Start-of-day code for an Armv8-R MPU system.
+ */
+
+#include <asm/mm.h>
+#include <asm/page.h>

I can't see any use of the definition of page.h. Is it necessary?

I will remove this and ..

Quoted 4 lines

xen/arch/arm/arm64/mpu/head.S line 8

Quoted 2 lines
xen/arch/arm/arm64/mpu/head.S new file +1 -0
+#include <asm/early_printk.h>

You include early_printk.h but don't use it.

this as well.

Quoted 8 lines

xen/arch/arm/arm64/mpu/head.S

Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +5 -0
+
+/*
+ * From the requirements of head.S we know that Xen image should
+ * be linked at XEN_START_ADDRESS, and all of text + data + bss
+ * must fit in 2MB.

Xen can be bigger than 2MB. But rather than hardcoding the limit, you want to use _end.

I  was wondering if we can XEN_VIRT_SIZE here , but that would lead to mapping of a large memory region.

So I guess _end should be used here.

Quoted 9 lines
Quoted 7 lines

On MPU systems, XEN_START_ADDRESS is also the
+ * address that Xen image should be loaded at. So for initial MPU
+ * regions setup, we use 2MB for Xen data memory to setup boot
+ * region, or the create boot regions code below will need adjustment.
+ */
+#define XEN_START_MEM_SIZE      0x200000

See above.

Ack.

Quoted 17 lines
Quoted 5 lines
xen/arch/arm/arm64/mpu/head.S new file +4 -0
+
+/*
+ * In boot stage, we will use 1 MPU region:
+ * Region#0: Normal memory for Xen text + data + bss (2MB)

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10 -0
+ */
+#define BOOT_NORMAL_REGION_IDX  0x0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

ISB is not needed here as the memory protection hasn't been activated yet. The above instruction just selects the memory region and the below two instructions sets the base address and limit for that memory region. After the three instructions, we need an ISB so that the memory protection takes into affect for further instruction fetches.

However, a DSB is needed here as the below two instructions depend on this. So, we definitely want this instruction to complete.

Further, refer to the note in ARM DDI 0600A.d ID120821, C1.7.1 "Protection region attributes"

0.

```Writes to MPU registers are only guaranteed to be visible following a Context synchronization event and DSB operation.```

Thus, I infer that DSB is necessary here.

Quoted 2 lines

If a "dsb" is necessary, "sy" seems to be quite strict.

I can use "st" here as I am only interested in stores (ie MSR) to complete.

Now the whether we want to restrict it to inner shareable/outer shareable/POU/full system is a difficult decision to make.

May be here we can use ishst (stores to complete to inner shareable region). However ....

Quoted 4 lines
Quoted 4 lines

+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy

This should be visible to outer shareable domain atleast. The reason being one can use the SH[1:0] bits in PRBAR_EL2 to set the region to outer shareable.

Thus, the writes to these registers should be visible to outer shareable domain as well.

Quoted 6 lines
Quoted 6 lines

+    isb
+.endm

xen/arch/arm/arm64/mpu/head.S new file +4 -0
+
+.section .text.header, "ax", %progbits
+
+/*
Quoted 8 lines
Quoted 6 lines

+ * Static start-of-day EL2 MPU memory layout.
+ *
+ * It has a very simple structure, including:
+ *  - 2MB normal memory mappings of xen at XEN_START_ADDRESS, which
+ * is the address where Xen was loaded by the bootloader.
+ */

Please document a bit more the code and how the registers are used. For an example see the mmu/head.S code.

Ack

Quoted 18 lines
Quoted 18 lines
xen/arch/arm/arm64/mpu/head.S new file +17 -0
+ENTRY(enable_boot_cpu_mm)
+    /* Map Xen start memory to a normal memory region. */
+    mov x0, #BOOT_NORMAL_REGION_IDX
+    ldr x1, =XEN_START_ADDRESS
+    and x1, x1, #MPU_REGION_MASK
+    mov x3, #PRBAR_NORMAL_MEM
+    orr x1, x1, x3
+
+    ldr x2, =XEN_START_ADDRESS
+    mov x3, #(XEN_START_MEM_SIZE - 1)
+    add x2, x2, x3
+    and x2, x2, #MPU_REGION_MASK
+    mov x3, #PRLAR_NORMAL_MEM
+    orr x2, x2, x3
+
+    /*
+     * Write to MPU protection region:
Quoted 8 lines

xen/arch/arm/arm64/mpu/head.S line 70

Quoted 6 lines

+     * x0 for pr_sel, x1 for prbar x2 for prlar
+     */
+    write_pr x0, x1, x2

xen/arch/arm/arm64/mpu/head.S new file +3 -0
+
+    ret
+ENDPROC(enable_boot_cpu_mm)

Missing emacs magic.

You mean it should be

END(enable_boot_cpu_mm) .

/*
 * Local variables:
 * mode: ASM
 * indent-tabs-mode: nil
 * End:
 */

Quoted 12 lines
Quoted 10 lines
xen/arch/arm/include/asm/arm64/sysregs.h +0 -0
index b593e4028b..0d122e1fa6 100644
@@ -462,6 +462,56 @@
   #define ZCR_ELx_LEN_SIZE             9
   #define ZCR_ELx_LEN_MASK             0x1ff

  +/* System registers for AArch64 with PMSA */
+#ifdef CONFIG_MPU

Can we define the registers in mpu/sysregs.h? This can then be included only where it is needed.

Ack

Quoted 52 lines
Quoted 52 lines
xen/arch/arm/include/asm/arm64/sysregs.h +48 -0
+
+/* EL2 MPU Protection Region Base Address Register encode */
+#define PRBAR_EL2   S3_4_C6_C8_0
+#define PRBAR1_EL2  S3_4_C6_C8_4
+#define PRBAR2_EL2  S3_4_C6_C9_0
+#define PRBAR3_EL2  S3_4_C6_C9_4
+#define PRBAR4_EL2  S3_4_C6_C10_0
+#define PRBAR5_EL2  S3_4_C6_C10_4
+#define PRBAR6_EL2  S3_4_C6_C11_0
+#define PRBAR7_EL2  S3_4_C6_C11_4
+#define PRBAR8_EL2  S3_4_C6_C12_0
+#define PRBAR9_EL2  S3_4_C6_C12_4
+#define PRBAR10_EL2 S3_4_C6_C13_0
+#define PRBAR11_EL2 S3_4_C6_C13_4
+#define PRBAR12_EL2 S3_4_C6_C14_0
+#define PRBAR13_EL2 S3_4_C6_C14_4
+#define PRBAR14_EL2 S3_4_C6_C15_0
+#define PRBAR15_EL2 S3_4_C6_C15_4
+
+/* EL2 MPU Protection Region Limit Address Register encode */
+#define PRLAR_EL2   S3_4_C6_C8_1
+#define PRLAR1_EL2  S3_4_C6_C8_5
+#define PRLAR2_EL2  S3_4_C6_C9_1
+#define PRLAR3_EL2  S3_4_C6_C9_5
+#define PRLAR4_EL2  S3_4_C6_C10_1
+#define PRLAR5_EL2  S3_4_C6_C10_5
+#define PRLAR6_EL2  S3_4_C6_C11_1
+#define PRLAR7_EL2  S3_4_C6_C11_5
+#define PRLAR8_EL2  S3_4_C6_C12_1
+#define PRLAR9_EL2  S3_4_C6_C12_5
+#define PRLAR10_EL2 S3_4_C6_C13_1
+#define PRLAR11_EL2 S3_4_C6_C13_5
+#define PRLAR12_EL2 S3_4_C6_C14_1
+#define PRLAR13_EL2 S3_4_C6_C14_5
+#define PRLAR14_EL2 S3_4_C6_C15_1
+#define PRLAR15_EL2 S3_4_C6_C15_5
+
+/* MPU Protection Region Enable Register encode */
+#define PRENR_EL2 S3_4_C6_C1_1
+
+/* MPU Protection Region Selection Register encode */
+#define PRSELR_EL2 S3_4_C6_C2_1
+
+/* MPU Type registers encode */
+#define MPUIR_EL2 S3_4_C0_C0_4
+
+#endif
+

  /* Access to system registers */
    #define WRITE_SYSREG64(v, name) do {                    \

xen/arch/arm/include/asm/mpu/arm64/mm.h +0 -0
Quoted 8 lines

xen/arch/arm/include/asm/mpu/arm64/mm.h line 1

Quoted 6 lines

new file mode 100644
index 0000000000..d209eef6db

xen/arch/arm/include/asm/mpu/arm64/mm.h new file +1 -0
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-only

Coding style: /* ... */

Ack

Quoted 5 lines

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

Quoted 3 lines
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +2 -0
+/*
+ * mpu.h: Arm Memory Protection Unit definitions.

The file is name mm.h.

Ack

Quoted 13 lines

xen/arch/arm/include/asm/mpu/arm64/mm.h line 13

Quoted 11 lines
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +10 -0
+ */
+
+#ifndef __ARM64_MPU_H__
+#define __ARM64_MPU_H__
+
+#define MPU_REGION_SHIFT  6
+#define MPU_REGION_ALIGN  (_AC(1, UL) << MPU_REGION_SHIFT)
+#define MPU_REGION_MASK   (~(MPU_REGION_ALIGN - 1))
+
+#endif /* __ARM64_MPU_H__ */

Missing emacs magic.

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */

Quoted 8 lines

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

Quoted 6 lines
xen/arch/arm/include/asm/mpu/mm.h new file +0 -0
new file mode 100644
index 0000000000..f5ebca8261

Do we need this file?

In xen/arch/arm/arm64/mpu/head.S, we have

#include <asm/mm.h>

So, it should pick up this file.

- Ayan

Quoted 23 lines
Quoted 10 lines
xen/arch/arm/include/asm/mpu/mm.h new file +8 -0
@@ -0,0 +1,18 @@
+#ifndef __ARCH_ARM_MPU__
+#define __ARCH_ARM_MPU__
+
+#if defined(CONFIG_ARM_64)
+# include <asm/mpu/arm64/mm.h>
+#else
+# error "unknown ARM variant"
+#endif

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

Quoted 10 lines
xen/arch/arm/include/asm/mpu/mm.h new file +10 -0
+
+#endif /*  __ARCH_ARM_MPU__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

Cheers,

#17 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Hi Ayan,

Apologies but I can’t do a full review yet,

Quoted 15 lines
Quoted 10 lines

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 8 lines
xen/arch/arm/arm64/mpu/head.S new file +8 -0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

ISB is not needed here as the memory protection hasn't been activated yet. The above instruction just selects the memory region and the below two instructions sets the base address and limit for that memory region. After the three instructions, we need an ISB so that the memory protection takes into affect for further instruction fetches.

However, a DSB is needed here as the below two instructions depend on this. So, we definitely want this instruction to complete.

Quoted 8 lines

Further, refer to the note in ARM DDI 0600A.d ID120821, C1.7.1 "Protection region attributes"

0.

```Writes to MPU registers are only guaranteed to be visible following a Context synchronization event and DSB operation.```

Thus, I infer that DSB is necessary here.

I think this was a mistake from the author of this patch, in my opinion there should be an ISB after setting PRSELR_ELx, to enforce a synchronisation before writing PR{B,L}AR_ELx which depends on the value written on PRSELR.

Cheers,
Luca

#18 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Quoted 1 line · Luca Fancellu

Hi Ayan,

Hi Luca,

Quoted 2 lines

Apologies but I can’t do a full review yet,

No worries. :)

Quoted 19 lines
Quoted 19 lines
Quoted 11 lines

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +8 -0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

ISB is not needed here as the memory protection hasn't been activated yet. The above instruction just selects the memory region and the below two instructions sets the base address and limit for that memory region. After the three instructions, we need an ISB so that the memory protection takes into affect for further instruction fetches.

However, a DSB is needed here as the below two instructions depend on this. So, we definitely want this instruction to complete.

Further, refer to the note in ARM DDI 0600A.d ID120821, C1.7.1 "Protection region attributes"

0.

Quoted 7 lines
Quoted 4 lines

```Writes to MPU registers are only guaranteed to be visible following a Context synchronization event and DSB operation.```

Thus, I infer that DSB is necessary here.

I think this was a mistake from the author of this patch, in my opinion there should be an ISB after setting PRSELR_ELx, to enforce a synchronisation before writing PR{B,L}AR_ELx which depends on the value written on PRSELR.

That synchronisation is enforced by DSB.

From https://developer.arm.com/documentation/dui0489/c/arm-and-thumb-instructions/miscellaneous-instructions/dmb--dsb--and-isb ,

```Data Synchronization Barrier acts as a special kind of memory barrier. No instruction in program order after this instruction executes until this instruction completes.

...

Instruction Synchronization Barrier flushes the pipeline in the processor, ```

Why should we flush the instruction pipeline after setting PRSELR_ELx ? It does not have any impact on instruction fetch.

- Ayan

#19 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Hi Julien/Luca/all,

Quoted 38 lines · Ayan Kumar Halder
Quoted 1 line · Luca Fancellu

Hi Ayan,

Hi Luca,

Quoted 2 lines

Apologies but I can’t do a full review yet,

No worries. :)

Quoted 19 lines
Quoted 19 lines
Quoted 11 lines

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +8 -0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

ISB is not needed here as the memory protection hasn't been activated yet. The above instruction just selects the memory region and the below two instructions sets the base address and limit for that memory region. After the three instructions, we need an ISB so that the memory protection takes into affect for further instruction fetches.

However, a DSB is needed here as the below two instructions depend on this. So, we definitely want this instruction to complete.

Further, refer to the note in ARM DDI 0600A.d ID120821, C1.7.1 "Protection region attributes"

0.

Quoted 7 lines
Quoted 4 lines

   ```Writes to MPU registers are only guaranteed to be visible following a Context synchronization event and DSB operation.```

Thus, I infer that DSB is necessary here.

I think this was a mistake from the author of this patch, in my opinion there should be an ISB after setting PRSELR_ELx, to enforce a synchronisation before writing PR{B,L}AR_ELx which depends on the value written on PRSELR.

That synchronisation is enforced by DSB.

From https://developer.arm.com/documentation/dui0489/c/arm-and-thumb-instructions/miscellaneous-instructions/dmb--dsb--and-isb ,

Quoted 8 lines

```Data Synchronization Barrier acts as a special kind of memory barrier. No instruction in program order after this instruction executes until this instruction completes.

...

Instruction Synchronization Barrier flushes the pipeline in the processor, ```

Why should we flush the instruction pipeline after setting PRSELR_ELx ? It does not have any impact on instruction fetch.

After the discussion on matrix, I agree that we need an 'isb' here to ensure that there is no instruction reordering.

Thanks for the explanation.

- Ayan

#26 lore raw

Re: [PATCH v1 4/4] xen/arm: mpu: Disable secondary cpu bringup

In reply to Julien Grall
Quoted 1 line · Julien Grall

Hi Ayan,

Hi Julien,

Quoted 4 lines

The title is a bit confusing. It implies seconary CPU bringup used to work on the MPU. However, you are adding a stub for enable_secondary_cpu_mm.

Also, I am not entirely this is really sufficient to disable CPU bringup. There will be plenty of initialization done for secondary CPUs.

I agree. init_secondary() has already been invoked before this.

Quoted 2 lines

I would suggest to update NR_CPUS to 1 for MPU so we will fail early.

Yes, I will do this.

Quoted 13 lines

For the title, how about

xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm

Quoted 7 lines · Ayan Kumar Halder

Secondary cpus are put in WFE state. We do not support SMP at this time.

---
  xen/arch/arm/arm64/mpu/head.S | 9 +++++++++

  1 file changed, 9 insertions(+)
Quoted 16 lines
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S +0 -0
index 2b023c346a..1579ac0408 100644
@@ -68,3 +68,12 @@ ENTRY(enable_boot_cpu_mm)

        ret
  ENDPROC(enable_boot_cpu_mm)

xen/arch/arm/arm64/mpu/head.S +3 -0
+
+/*
+ * Secondary cpu has not yet been supported on MPU systems. We will 
Quoted 4 lines

block the
+ * secondary cpu bringup at this stage.
+ */
+ENTRY(enable_secondary_cpu_mm)

Can we print a message so it is easier to spot that enable_secondary_cpu_mm is not properly implemented?

yes, something like this

PRINT("- SMP NOT SUPPORTED -\r\n")

- Ayan

#8 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

In reply to Ayan Kumar Halder

Hi,

Quoted 62 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 14 lines · Ayan Kumar Halder
Quoted 12 lines

From: Wei Chen <[email protected]>

On Armv8-A, Xen has a fixed virtual start address (link address too) for all Armv8-A platforms. In an MMU based system, Xen can map its loaded address to this virtual start address. So, on Armv8-A platforms, the Xen start address does not need to be configurable. But on Armv8-R platforms, there is no MMU to map loaded address to a fixed virtual address and different platforms will have very different address space layout. So Xen cannot use a fixed physical address on MPU based system and need to have it configurable.

Quoted 6 lines
Quoted 4 lines

So in this patch, we reuse the existing arm/platforms to store Armv8-R platforms' parameters. And XEN_START_ADDRESS is one kind of MPU based platform's parameters. So we define default XEN_START_ADDRESS in the MPU specific header file.

This seems a left-over from as previous work?

Yes, this needs to be removed.

Quoted 28 lines
Quoted 28 lines

We also introduce one Kconfig option for users to override the default Xen start address of selected platform, if they think the default address doesn't suit their scenarios. For this Kconfig option, we use an unaligned address "0xffffffff" as the default value to indicate that users haven't used a customized Xen start address.

---
  xen/arch/arm/Kconfig                  | 11 +++++++++++ xen/arch/arm/include/asm/mpu/layout.h | 25 +++++++++++++++++++++++++

  2 files changed, 36 insertions(+)

  create mode 100644 xen/arch/arm/include/asm/mpu/layout.h

xen/arch/arm/Kconfig +0 -0
index 686948cefd..d722ca690c 100644
@@ -23,6 +23,17 @@ config ARCH_DEFCONFIG

      default "arch/arm/configs/arm32_defconfig" if ARM_32 default "arch/arm/configs/arm64_defconfig" if ARM_64 +config XEN_START_ADDRESS
+    hex "Xen start address: keep default to use platform defined address"

Quoted 8 lines
Quoted 6 lines

+    default 0xFFFFFFFF
+    depends on MPU
+    help
+      This option is allowed to set customized address at which Xen will be
+      linked on MPU systems.

I don't quite understand what you mean by "allowed".

Quoted 7 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

Cheers,

Signature · 1 line
Julien Grall
#20 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

In reply to Ayan Kumar Halder

Hi,

Quoted 29 lines · Ayan Kumar Halder
Quoted 8 lines · Julien Grall
Quoted 6 lines

On MPU systems, XEN_START_ADDRESS is also the
+ * address that Xen image should be loaded at. So for initial MPU
+ * regions setup, we use 2MB for Xen data memory to setup boot
+ * region, or the create boot regions code below will need adjustment.
+ */
+#define XEN_START_MEM_SIZE      0x200000

See above.

Ack.

Quoted 17 lines
Quoted 5 lines
xen/arch/arm/arm64/mpu/head.S new file +4 -0
+
+/*
+ * In boot stage, we will use 1 MPU region:
+ * Region#0: Normal memory for Xen text + data + bss (2MB)

xen/arch/arm/arm64/mpu/head.S line 32

Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10 -0
+ */
+#define BOOT_NORMAL_REGION_IDX  0x0
+
+/* MPU normal memory attributes. */
+#define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
+#define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
+
+.macro write_pr, sel, prbar, prlar
+    msr   PRSELR_EL2, \sel
+    dsb   sy

I am not sure I understand why this is a dsb rather than isb. Can you clarify?

Quoted 1 line

ISB is not needed here as the memory protection hasn't been activated yet. The above instruction just selects the memory region and the below two instructions sets the base address and limit for that memory region. After the three instructions, we need an ISB so that the memory protection takes into affect for further instruction fetches.

We discussed this on Matrix, I have also had a read of the Arm Arm again (D19.1.2 General behavior of accesses to the AArch64 System registers in ARM DDI 0487J.a). Writing down mainly for keeping track of the decision.

In general you need an a context synchronization event (e.g. isb) before the other system registers can start to rely on the change. There are some exceptions though, but AFAICT PRSELR_EL2 doesn't have any.

IIUC, the behavior of PRBAR_EL2 and PRLAR_EL2 will change depending on PRSELR_EL2.REGION. Therefore, we need to make sure the new value of PRSELR_EL2 is seen before we write to the two other registers.

Quoted 11 lines

However, a DSB is needed here as the below two instructions depend on this. So, we definitely want this instruction to complete.

Further, refer to the note in ARM DDI 0600A.d ID120821, C1.7.1 "Protection region attributes"

0.

   ```Writes to MPU registers are only guaranteed to be visible following a Context synchronization event and DSB operation.```

Thus, I infer that DSB is necessary here

I read it differently. To me it was more the "dsb" is necessary before the MPU can start using the new region values. But here an 'isb' should be fine.

That said, from my experience, certain section of the Arm Arm can be interpreted differently whic means that someone could implement your way. This is also not a hot path, so best to use the most restrictive approach. Therefore I am ok with adding a 'dsb'.

Quoted 11 lines
Quoted 3 lines

If a "dsb" is necessary, "sy" seems to be quite strict.

I can use "st" here as I am only interested in stores (ie MSR) to complete.

Now the whether we want to restrict it to inner shareable/outer shareable/POU/full system is a difficult decision to make.

May be here we can use ishst (stores to complete to inner shareable region). However ....

Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy

This should be visible to outer shareable domain atleast. The reason being one can use the SH[1:0] bits in PRBAR_EL2 to set the region to outer shareable.

Thus, the writes to these registers should be visible to outer shareable domain as well.

I am a bit confused. SH[1:0] is about how the region will be accessed not up to where should registers are visible. I was expecting that the MPU registers only need to be visible to the MPU itself.

For instance, when using the MMU, the translation unit is in the non-shareable domain. So a 'nsh' is sufficient regardless of the shareability of the page/block.

This is explicitely written in the Arm Arm (see D5-4929 in ARM DDI 0487H.a) but I can't find a similar section for the MPU yet. Although, I would be a bit surprised if the MPU is not in the non-shareable domain... Maybe this could be clarified with Arm?

Anyway, for now, I am open to use 'dsb sy' with a TODO to revisit it.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+    isb

Re-quoting the spec from you previous answer:

```
Writes to MPU registers are only guaranteed to be visible
following a Context synchronization event and DSB operation.
```

So this suggests that it should be first an 'isb' and then a 'dsb'. Any reason you wrote it the other way around?

Quoted 43 lines
Quoted 5 lines
Quoted 5 lines

+.endm

xen/arch/arm/arm64/mpu/head.S new file +4 -0
+
+.section .text.header, "ax", %progbits
+
+/*
Quoted 8 lines
Quoted 6 lines

+ * Static start-of-day EL2 MPU memory layout.
+ *
+ * It has a very simple structure, including:
+ *  - 2MB normal memory mappings of xen at XEN_START_ADDRESS, which
+ * is the address where Xen was loaded by the bootloader.
+ */

Please document a bit more the code and how the registers are used. For an example see the mmu/head.S code.

Ack

Quoted 18 lines
Quoted 18 lines
xen/arch/arm/arm64/mpu/head.S new file +17 -0
+ENTRY(enable_boot_cpu_mm)
+    /* Map Xen start memory to a normal memory region. */
+    mov x0, #BOOT_NORMAL_REGION_IDX
+    ldr x1, =XEN_START_ADDRESS
+    and x1, x1, #MPU_REGION_MASK
+    mov x3, #PRBAR_NORMAL_MEM
+    orr x1, x1, x3
+
+    ldr x2, =XEN_START_ADDRESS
+    mov x3, #(XEN_START_MEM_SIZE - 1)
+    add x2, x2, x3
+    and x2, x2, #MPU_REGION_MASK
+    mov x3, #PRLAR_NORMAL_MEM
+    orr x2, x2, x3
+
+    /*
+     * Write to MPU protection region:
Quoted 8 lines

xen/arch/arm/arm64/mpu/head.S line 70

Quoted 6 lines

+     * x0 for pr_sel, x1 for prbar x2 for prlar
+     */
+    write_pr x0, x1, x2

xen/arch/arm/arm64/mpu/head.S new file +3 -0
+
+    ret
+ENDPROC(enable_boot_cpu_mm)

Missing emacs magic.

You mean it should be

Quoted 8 lines

END(enable_boot_cpu_mm) .

/*
 * Local variables:
 * mode: ASM
 * indent-tabs-mode: nil
 * End:
 */

Correct.

Quoted 9 lines
Quoted 8 lines

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

Quoted 6 lines
xen/arch/arm/include/asm/mpu/mm.h new file +0 -0
new file mode 100644
index 0000000000..f5ebca8261

Do we need this file?

Quoted 5 lines

In xen/arch/arm/arm64/mpu/head.S, we have

#include <asm/mm.h>

So, it should pick up this file.

OOI, why can't you include asm/arm64/mm.h?

Cheers,

Signature · 1 line
Julien Grall
#21 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Hi Julien, Ayan,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/arm/arm64/mpu/head.S new file +3 -0
+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy
Quoted 8 lines
Quoted 2 lines

This should be visible to outer shareable domain atleast. The reason being one can use the SH[1:0] bits in PRBAR_EL2 to set the region to outer shareable. Thus, the writes to these registers should be visible to outer shareable domain as well.

I am a bit confused. SH[1:0] is about how the region will be accessed not up to where should registers are visible. I was expecting that the MPU registers only need to be visible to the MPU itself.

For instance, when using the MMU, the translation unit is in the non-shareable domain. So a 'nsh' is sufficient regardless of the shareability of the page/block.

This is explicitely written in the Arm Arm (see D5-4929 in ARM DDI 0487H.a) but I can't find a similar section for the MPU yet. Although, I would be a bit surprised if the MPU is not in the non-shareable domain... Maybe this could be clarified with Arm?

I got the feedback that DSB SY is ok here

Quoted 5 lines

Anyway, for now, I am open to use 'dsb sy' with a TODO to revisit it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ isb

Quoted 8 lines

Re-quoting the spec from you previous answer:

```
Writes to MPU registers are only guaranteed to be visible
following a Context synchronization event and DSB operation.
```

So this suggests that it should be first an 'isb' and then a 'dsb'. Any reason you wrote it the other way around?

I chased this internally and it was suggested the current order, dsb followed by the isb: DSB ensures the completion of prior instructions before the next executes, and then ISB ensures subsequent instruction fetch observes the updated MPU state.

Probably I will raise something to make awareness around the misleading order of that phrase.

Cheers,
Luca

#22 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Quoted 9 lines · Luca Fancellu

Hi Julien, Ayan,

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

xen/arch/arm/arm64/mpu/head.S line 35

Quoted 4 lines
xen/arch/arm/arm64/mpu/head.S new file +3 -0
+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy

This should be visible to outer shareable domain atleast. The reason being one can use the SH[1:0] bits in PRBAR_EL2 to set the region to outer shareable. Thus, the writes to these registers should be visible to outer shareable domain as well.

Quoted 7 lines
Quoted 5 lines

I am a bit confused. SH[1:0] is about how the region will be accessed not up to where should registers are visible. I was expecting that the MPU registers only need to be visible to the MPU itself.

For instance, when using the MMU, the translation unit is in the non-shareable domain. So a 'nsh' is sufficient regardless of the shareability of the page/block.

This is explicitely written in the Arm Arm (see D5-4929 in ARM DDI 0487H.a) but I can't find a similar section for the MPU yet. Although, I would be a bit surprised if the MPU is not in the non-shareable domain... Maybe this could be clarified with Arm?

I got the feedback that DSB SY is ok here

Thanks for asking. Does this mean that a "dsb nsh" would not be sufficient?

Quoted 13 lines
Quoted 13 lines

Anyway, for now, I am open to use 'dsb sy' with a TODO to revisit it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ isb

Re-quoting the spec from you previous answer:

```
Writes to MPU registers are only guaranteed to be visible
following a Context synchronization event and DSB operation.
```
Quoted 4 lines
Quoted 1 line

So this suggests that it should be first an 'isb' and then a 'dsb'. Any reason you wrote it the other way around?

I chased this internally and it was suggested the current order, dsb followed by the isb: DSB ensures the completion of prior instructions before the next executes, and then ISB ensures subsequent instruction fetch observes the updated MPU state.

I am confused. "DSB" doesn't ensure any completion of instructions. It just ensures memory access completion. Can you clarify?

Quoted 5 lines

Probably I will raise something to make awareness around the misleading order of that phrase.

Cheers,
Luca

Signature · 1 line
Julien Grall
#23 lore raw

Re: [PATCH v1 3/4] xen/arm: mpu: Create boot-time MPU protection regions

Quoted 15 lines · Julien Grall
Quoted 8 lines · Luca Fancellu

Hi Julien, Ayan,

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

xen/arch/arm/arm64/mpu/head.S line 35

Quoted 4 lines
xen/arch/arm/arm64/mpu/head.S new file +3 -0
+    msr   PRBAR_EL2, \prbar
+    msr   PRLAR_EL2, \prlar
+    dsb   sy

This should be visible to outer shareable domain atleast. The reason being one can use the SH[1:0] bits in PRBAR_EL2 to set the region to outer shareable. Thus, the writes to these registers should be visible to outer shareable domain as well.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

I am a bit confused. SH[1:0] is about how the region will be accessed not up to where should registers are visible. I was expecting that the MPU registers only need to be visible to the MPU itself.

For instance, when using the MMU, the translation unit is in the non-shareable domain. So a 'nsh' is sufficient regardless of the shareability of the page/block.

This is explicitely written in the Arm Arm (see D5-4929 in ARM DDI 0487H.a) but I can't find a similar section for the MPU yet. Although, I would be a bit surprised if the MPU is not in the non-shareable domain... Maybe this could be clarified with Arm?

I got the feedback that DSB SY is ok here

Thanks for asking. Does this mean that a "dsb nsh" would not be sufficient?

Unfortunately no one gave a straight answer on that, I was under the impression that nsh was sufficient, but didn’t have a confirmation. I will try to chase more in deep.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Anyway, for now, I am open to use 'dsb sy' with a TODO to revisit it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ isb

Re-quoting the spec from you previous answer:

```
Writes to MPU registers are only guaranteed to be visible
following a Context synchronization event and DSB operation.
```
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

So this suggests that it should be first an 'isb' and then a 'dsb'. Any reason you wrote it the other way around?

I chased this internally and it was suggested the current order, dsb followed by the isb: DSB ensures the completion of prior instructions before the next executes, and then ISB ensures subsequent instruction fetch observes the updated MPU state.

I am confused. "DSB" doesn't ensure any completion of instructions. It just ensures memory access completion. Can you clarify?

Sorry, I meant memory access completion.

Cheers,
Luca

#9 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

In reply to Julien Grall
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 12 lines · Ayan Kumar Halder
Quoted 8 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

From ARM DDI 0600A.d ID120821, C1.1.1 Protection regions

"Protection regions have a minimum size of 64 bytes."

Thus, I would infer that the minimum page size (in context of MPU) is 64 bytes.

Also, if you see the register fields of PRBAR and PRLAR, the lower 6 bits are 0 extended to provide the address.

So, may be I should say

".... address must be aligned to the minimum region size (ie 64 bytes). 0xFFFFFFFF is used ...."

Let me know if this sounds ok.

- Ayan

#10 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

Hi Ayan,

Quoted 23 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall

Hi,

Hi Julien,

Quoted 12 lines · Ayan Kumar Halder
Quoted 8 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

From ARM DDI 0600A.d ID120821, C1.1.1 Protection regions

"Protection regions have a minimum size of 64 bytes."

Thus, I would infer that the minimum page size (in context of MPU) is 64 bytes.

Quoted 1 line

Also, if you see the register fields of PRBAR and PRLAR, the lower 6

Quoted 8 lines

bits are 0 extended to provide the address.

So, may be I should say

".... address must be aligned to the minimum region size (ie 64 bytes). 0xFFFFFFFF is used ...."

Let me know if this sounds ok.

So what you provided is a minimum size/alignment of a region from the HW point of view. How about Xen? Will it be able to cope if Xen is booted at a 64-byte alignment?

Asking because it is unclear how the allocator will work with the MPU. Are we going to continue to allocate 4KB chunk at the time? Will it be smaller/larger?

Cheers,

Signature · 1 line
Julien Grall
#11 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

Quoted 1 line · Julien Grall

Hi Ayan,

Hi Julien,

Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines · Julien Grall
Quoted 1 line

Hi,

Hi Julien,

Quoted 11 lines · Ayan Kumar Halder
Quoted 8 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

 From ARM DDI 0600A.d ID120821, C1.1.1 Protection regions

"Protection regions have a minimum size of 64 bytes."

Thus, I would infer that the minimum page size (in context of MPU) is 64 bytes.

Quoted 1 line

Also, if you see the register fields of PRBAR and PRLAR, the lower 6

yes.

Quoted 4 lines
Quoted 4 lines

bits are 0 extended to provide the address.

So, may be I should say

Quoted 8 lines
Quoted 4 lines

".... address must be aligned to the minimum region size (ie 64 bytes). 0xFFFFFFFF is used ...."

Let me know if this sounds ok.

So what you provided is a minimum size/alignment of a region from the HW point of view. How about Xen? Will it be able to cope if Xen is booted at a 64-byte alignment?

Asking because it is unclear how the allocator will work with the MPU. Are we going to continue to allocate 4KB chunk at the time? Will it be smaller/larger?

MPU will work with static memory allocation only. It can allocate a fixed number of regions using PRBAR and PRLAR. We can make the addresses to be page aligned (ie 4KB) so that it is in parity with MMU. And we will keep the page size as 4 KB.  It makes sense to use the same page size to do the allocation irrespective of MPU or MMU. Also, it helps to keep a large part of the code as common.

However for MPU, we will calculate the limit address based on the number of pages requested and do the allocation. For eg in map_pages_to_xen(), we will invoke a function to calculate the limit address based on the base address and nr_mfns.

Let me know if this is clear.

- Ayan

#12 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

Hi Ayan,

Quoted 37 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall

Hi Ayan,

Hi Julien,

Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines · Julien Grall
Quoted 1 line

Hi,

Hi Julien,

Quoted 11 lines · Ayan Kumar Halder
Quoted 8 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

 From ARM DDI 0600A.d ID120821, C1.1.1 Protection regions

"Protection regions have a minimum size of 64 bytes."

Thus, I would infer that the minimum page size (in context of MPU) is 64 bytes.

Quoted 1 line

Also, if you see the register fields of PRBAR and PRLAR, the lower 6

yes.

Quoted 7 lines
Quoted 7 lines

bits are 0 extended to provide the address.

So, may be I should say

".... address must be aligned to the minimum region size (ie 64 bytes). 0xFFFFFFFF is used ...."

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Let me know if this sounds ok.

So what you provided is a minimum size/alignment of a region from the HW point of view. How about Xen? Will it be able to cope if Xen is booted at a 64-byte alignment?

Asking because it is unclear how the allocator will work with the MPU. Are we going to continue to allocate 4KB chunk at the time? Will it be smaller/larger?

MPU will work with static memory allocation only. It can allocate a fixed number of regions using PRBAR and PRLAR. We can make the addresses to be page aligned (ie 4KB) so that it is in parity with MMU. And we will keep the page size as 4 KB.  It makes sense to use the same page size to do the allocation irrespective of MPU or MMU. Also, it helps to keep a large part of the code as common.

TL;DR: I think we can use different chunk size (I find "page" confusing in the context of the MPU) and still sharing a large part of Xen. For now, I would be ok to use the same size. In the future, it would be beneficial to change it.

Now the longer answer. Looking at the specification, the architecture allows up to 128 regions. So the chance we will want to share a 4KB RAM region at the time is close to zero.

Yet we would still have one struct page_info per 4KB chunk to carry the metadata. This is not only going to be a waste of memory but also requires extra work. So to me it would make more sense to track larger chunk (maybe 2MB).

Now regarding the change necessary in Xen. I think we can divide it in two parts:
* Allocation within region
* Frame in the public interface

For the first part, Xen on Arm is now mainly page agnostic. So you could bump the PAGE_SIZE (barring the public interface see below) without any trouble. You may have to deal with extra memory wasted when using alloc_*heap_page*(). But that could be easily solved by using xmalloc() and/or introduce new wrappers.

For the frame definition in the public interface. So far, a frame covers 4KB (same as Xen page granularity) and this is bake into OSes (Xen doesn't have a way to return the page granularity used). So for the MMU, you sadly can't easily increase the page granularity used by Xen...

However for the MPU I think this is a different story. The bulk of the interface using frame number (such as increase/decrease memory) are not applicable for the MPU or would be unusable/severely limited (e.g grant table) given the number of MPU regions available.

Anyway, I am probably thinking quite far ahead :). For now, I am fine if you want to use 4KB chunk. So in the Kconfig you could write "Xen start address should be 4KB aligned" (let's not mention page).

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw

Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems

Quoted 1 line · Julien Grall

Hi Ayan,

Hi Julien,

Quoted 58 lines · Ayan Kumar Halder
Quoted 38 lines · Julien Grall
Quoted 1 line

Hi Ayan,

Hi Julien,

Quoted 19 lines · Ayan Kumar Halder
Quoted 17 lines · Julien Grall
Quoted 1 line

Hi,

Hi Julien,

Quoted 12 lines · Ayan Kumar Halder
Quoted 8 lines

I will rephrase this as ...

"Used to set customized address at which which Xen will be linked

on MPU systems. This address must be aligned to a page size. 0xFFFFFFFF is used as the default value to indicate that user hasn't customized this address."

Reading this comment, I would like to ask some clarification. In the context of the MPU how do you define a page size? The definition is pretty clear when using the MMU because the granularity if defined by the HW. But for the MPU, it is a bit blur. Is it still 4KB? If so, is it actually realistic (we don't have that many MPU regions)?

Quoted 7 lines
Quoted 6 lines

 From ARM DDI 0600A.d ID120821, C1.1.1 Protection regions

"Protection regions have a minimum size of 64 bytes."

Thus, I would infer that the minimum page size (in context of MPU) is 64 bytes.

Quoted 1 line

Also, if you see the register fields of PRBAR and PRLAR, the

lower 6

yes.

Quoted 7 lines
Quoted 7 lines

bits are 0 extended to provide the address.

So, may be I should say

".... address must be aligned to the minimum region size (ie 64 bytes). 0xFFFFFFFF is used ...."

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Let me know if this sounds ok.

So what you provided is a minimum size/alignment of a region from the HW point of view. How about Xen? Will it be able to cope if Xen is booted at a 64-byte alignment?

Asking because it is unclear how the allocator will work with the MPU. Are we going to continue to allocate 4KB chunk at the time? Will it be smaller/larger?

MPU will work with static memory allocation only. It can allocate a fixed number of regions using PRBAR and PRLAR. We can make the addresses to be page aligned (ie 4KB) so that it is in parity with MMU. And we will keep the page size as 4 KB.  It makes sense to use the same page size to do the allocation irrespective of MPU or MMU. Also, it helps to keep a large part of the code as common.

TL;DR: I think we can use different chunk size (I find "page" confusing in the context of the MPU) and still sharing a large part of Xen. For now, I would be ok to use the same size. In the future, it would be beneficial to change it.

Now the longer answer. Looking at the specification, the architecture allows up to 128 regions. So the chance we will want to share a 4KB RAM region at the time is close to zero.

Yet we would still have one struct page_info per 4KB chunk to carry the metadata. This is not only going to be a waste of memory but also requires extra work. So to me it would make more sense to track larger chunk (maybe 2MB).

Now regarding the change necessary in Xen. I think we can divide it in two parts:
  * Allocation within region
  * Frame in the public interface

Quoted 5 lines

For the first part, Xen on Arm is now mainly page agnostic. So you could bump the PAGE_SIZE (barring the public interface see below) without any trouble. You may have to deal with extra memory wasted when using alloc_*heap_page*(). But that could be easily solved by using xmalloc() and/or introduce new wrappers.

For the frame definition in the public interface. So far, a frame covers 4KB (same as Xen page granularity) and this is bake into OSes (Xen doesn't have a way to return the page granularity used). So for the MMU, you sadly can't easily increase the page granularity used by Xen...

However for the MPU I think this is a different story. The bulk of the interface using frame number (such as increase/decrease memory) are not applicable for the MPU or would be unusable/severely limited (e.g grant table) given the number of MPU regions available.

Thanks for the detailed explaination. :) Yes, the initial MPU support will be limited to booting of domains in dom0less mode. IOW, support for grant tables will not be a part of the initial set of patches.

Quoted 2 lines

Anyway, I am probably thinking quite far ahead :). For now, I am fine if you want to use 4KB chunk. So in the Kconfig you could write "Xen start address should be 4KB aligned" (let's not mention page).

Yes, I will use these words. When we get Xen up and running on R52 and R82 (with the basic features), then we can revisit this.

- Ayan