Enable early bootup of AArch64 MPU systems
v2 cover Enable early bootup of AArch64 MPU systems
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: Implement a dummy enable_secondary_cpu_mm
SUPPORT.md | 1 + xen/arch/Kconfig | 1 + xen/arch/arm/Kconfig | 26 ++- xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 186 +++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/config.h | 4 +- xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/layout.h | 27 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 ++ xen/arch/arm/platforms/Kconfig | 2 +- xen/arch/arm/xen.lds.S | 1 + 15 files changed, 321 insertions(+), 3 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/arm64/mpu/sysregs.h 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
PATCH v2 1/4 xen/arm: mpu: Introduce choice between MMU and MPU
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. MPU is now gated by UNSUPPORTED.
Updated SUPPORT.md to state that the support for MPU is experimental.
---
Changes from :-
v1 - 1. Reworded the help messages.
2. Updated Support.md.
SUPPORT.md | 1 + xen/arch/arm/Kconfig | 16 +++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-)
SUPPORT.md +1 -0
@@ -40,6 +40,7 @@ supported in this document. Status, Xen in AArch64 mode: Supported Status, Xen in AArch32 mode: Tech Preview + Status, Xen with MPU: Experimental Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supported
xen/arch/arm/Kconfig +15 -1
@@ -58,10 +58,24 @@ 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. + config MMU - def_bool y + bool "MMU" select HAS_PMAP select HAS_VMAP + help + Select it if you plan to run Xen on A-profile Armv7+ + +config MPU + bool "MPU" if UNSUPPORTED + help + Memory protection unit is supported on some Armv8-R systems (UNSUPPORTED). +endchoice source "arch/Kconfig"
xen/arch/arm/platforms/Kconfig +1 -1
@@ -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
Re: [PATCH v2 1/4] xen/arm: mpu: Introduce choice between MMU and MPU
Hi Ayan,
Quoted 51 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 (egSTATIC_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. MPU is now gated by UNSUPPORTED.
Updated SUPPORT.md to state that the support for MPU is experimental.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Reworded the help messages.
2. Updated Support.md.SUPPORT.md | 1 + xen/arch/arm/Kconfig | 16 +++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-)SUPPORT.md +1
-0@@ -40,6 +40,7 @@ supported in this document. Status, Xen in AArch64 mode: Supported Status, Xen in AArch32 mode: Tech Preview + Status, Xen with MPU: Experimental Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supportedxen/arch/arm/Kconfig +6
-1@@ -58,10 +58,24 @@ 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. + config MMU - def_bool y
xen/arch/arm/Kconfig config PADDR_BITS · line 77
Quoted 10 lines
xen/arch/arm/Kconfig +8
-0+ bool "MMU" select HAS_PMAP select HAS_VMAP + help + Select it if you plan to run Xen on A-profile Armv7+ + +config MPU + bool "MPU" if UNSUPPORTED + help + Memory protection unit is supported on some Armv8-R systems (UNSUPPORTED).
I am a bit confused with this statement. Does this mean that not all Armv8-R supports MPU? Or are you trying to say that not all of them support EL2?
If the former, we probably want to check pretty early during boot that the an MPU is present *and* we have enough regions.
Quoted 9 lines
xen/arch/arm/Kconfig +1
-0+endchoice source "arch/Kconfig"xen/arch/arm/platforms/Kconfig +0
-0
xen/arch/arm/platforms/Kconfig line 5
Quoted 6 lines
xen/arch/arm/platforms/Kconfig +1
-1@@ -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.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/4] xen/arm: mpu: Introduce choice between MMU and MPU
Hi,
Quoted 60 lines · Julien Grall
Hi Ayan,
Quoted 42 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 (egSTATIC_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. MPU is now gated by UNSUPPORTED.
Updated SUPPORT.md to state that the support for MPU is experimental.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-
v1 - 1. Reworded the help messages.
2. Updated Support.md.SUPPORT.md | 1 + xen/arch/arm/Kconfig | 16 +++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-)SUPPORT.md +1
-0@@ -40,6 +40,7 @@ supported in this document. Status, Xen in AArch64 mode: Supported Status, Xen in AArch32 mode: Tech Preview + Status, Xen with MPU: Experimental Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfigindex
323c967361..e881f5ba57100644xen/arch/arm/Kconfig +5
-1@@ -58,10 +58,24 @@ 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. + config MMU - def_bool yxen/arch/arm/Kconfig config PADDR_BITS · line 76
Quoted 10 lines
xen/arch/arm/Kconfig +8
-0+ bool "MMU" select HAS_PMAP select HAS_VMAP + help + Select it if you plan to run Xen on A-profile Armv7+ + +config MPU + bool "MPU" if UNSUPPORTED + help + Memory protection unit is supported on some Armv8-R systems (UNSUPPORTED).I am a bit confused with this statement. Does this mean that not all Armv8-R supports MPU? Or are you trying to say that not all of them support EL2?
Quoted 1 line
If the former, we probably want to check pretty early during boot that the an MPU is present *and* we have enough regions.
On Armv8-R if there is EL2 then there is an MPU at EL2.
Only EL1 might have an MMU with the MPU (but i do not think it can have only an MMU).
Cheers
Bertrand
Quoted 19 lines
Quoted 8 lines
xen/arch/arm/Kconfig +1
-0+endchoice source "arch/Kconfig" diff --git a/xen/arch/arm/platforms/Kconfig b/xen/arch/arm/platforms/Kconfigindex
76f7e76b1b..02322c259c100644xen/arch/arm/platforms/Kconfig line 5
Quoted 6 lines
xen/arch/arm/platforms/Kconfig +1
-1@@ -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.Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/4] xen/arm: mpu: Introduce choice between MMU and MPU
In reply to Julien GrallQuoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 56 lines · Ayan Kumar Halder
Quoted 54 lines
There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (egSTATIC_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. MPU is now gated by UNSUPPORTED.
Updated SUPPORT.md to state that the support for MPU is experimental.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Reworded the help messages.
2. Updated Support.md.SUPPORT.md | 1 + xen/arch/arm/Kconfig | 16 +++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)SUPPORT.md +0
-0@@ -40,6 +40,7 @@ supported in this document.Status, Xen in AArch64 mode: Supported
Status, Xen in AArch32 mode: Tech Preview
+ Status, Xen with MPU: Experimental
Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index323c967361..e881f5ba57100644xen/arch/arm/Kconfig +0
-0@@ -58,10 +58,24 @@ config PADDR_BITSdefault 40 if
ARM_PA_BITS_40
default 48 ifARM_64
+choice
+ prompt "Memory management system"
+ default MMU if ARM
+ help
+ User can choose between the different forms of memory management system.
+
config MMU
-def_booly
+ bool "MMU"
selectHAS_PMAP
selectHAS_VMAP
+ help
+ Select it if you plan to run Xen on A-profile Armv7+
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/Kconfig +5
-0+ +config MPU + bool "MPU" if UNSUPPORTED + help + Memory protection unit is supported on some Armv8-R systems(UNSUPPORTED).
I am a bit confused with this statement. Does this mean that not all Armv8-R supports MPU? Or are you trying to say that not all of them support EL2?
My bad. All Armv8-R system supports MPU at EL2 (as Bertrand correctly pointed out). Some of them (eg R82) supports both MMU and MPU at EL1. While others (eg R52) supports only MPU at EL1.
I should rewrite it as
"Memory protection unit is supported on Armv8-R systems (UNSUPPORTED)."
- Ayan
Quoted 19 lines
If the former, we probably want to check pretty early during boot that the an MPU is present *and* we have enough regions.
Quoted 7 lines
+endchoice
source "arch/Kconfig"
diff --git a/xen/arch/arm/platforms/Kconfig b/xen/arch/arm/platforms/Kconfig index76f7e76b1b..02322c259c100644xen/arch/arm/platforms/Kconfig +0
-0@@ -1,5 +1,5 @@Quoted 6 lines
choice
- prompt "Platform Support"
+ prompt "Platform Support" if MMU
defaultALL_PLAT
help
Choose which hardware platform to enable in Xen.Cheers,
Re: [PATCH v2 1/4] xen/arm: mpu: Introduce choice between MMU and MPU
Quoted 69 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 56 lines · Ayan Kumar Halder
Quoted 54 lines
There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address.
Also, some of the Xen features (egSTATIC_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. MPU is now gated by UNSUPPORTED.
Updated SUPPORT.md to state that the support for MPU is experimental.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Reworded the help messages.
2. Updated Support.md.SUPPORT.md | 1 + xen/arch/arm/Kconfig | 16 +++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)SUPPORT.md +0
-0@@ -40,6 +40,7 @@ supported in this document.Status, Xen in AArch64 mode: Supported
Status, Xen in AArch32 mode: Tech Preview
+ Status, Xen with MPU: Experimental
Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index323c967361..e881f5ba57100644xen/arch/arm/Kconfig +0
-0@@ -58,10 +58,24 @@ config PADDR_BITSdefault 40 if
ARM_PA_BITS_40
default 48 ifARM_64
+choice
+ prompt "Memory management system"
+ default MMU if ARM
+ help
+ User can choose between the different forms of memory management system.
+
config MMU
-def_booly
+ bool "MMU"
selectHAS_PMAP
selectHAS_VMAP
+ help
+ Select it if you plan to run Xen on A-profile Armv7+Quoted 8 lines
Quoted 6 lines
xen/arch/arm/Kconfig +5
-0+ +config MPU + bool "MPU" if UNSUPPORTED + help + Memory protection unit is supported on some Armv8-R systems(UNSUPPORTED).
I am a bit confused with this statement. Does this mean that not all Armv8-R supports MPU? Or are you trying to say that not all of them support EL2?
Quoted 5 lines
My bad. All Armv8-R system supports MPU at EL2 (as Bertrand correctly pointed out). Some of them (eg R82) supports both MMU and MPU at EL1. While others (eg R52) supports only MPU at EL1.
I should rewrite it as
"Memory protection unit is supported on Armv8-R systems (UNSUPPORTED)."
I think it would be more consistent with CONFIG_MMU if you write the following:
"Memory Protection Unit (MPU). Select if you plan to run Xen on ARMv8-R systems supporting EL2. (UNSUPPORTED)"
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/4] xen/arm: mpu: Introduce choice between MMU and MPU
In reply to Ayan Kumar Halderxen/arch/arm/Kconfig config PADDR_BITS · line 63
Quoted 9 lines · Ayan Kumar Halder
xen/arch/arm/Kconfig +3
-0@@ -58,10 +58,24 @@ config PADDR_BITS default 40 if ARM_PA_BITS_40 default 48 if ARM_64 +choice + prompt "Memory management system" + default MMU if ARM
Why the "if ARM", when ARM=y in all cases?
Jan
PATCH v2 2/4 xen/arm: mpu: Define Xen start address for MPU systems
In reply to Ayan Kumar HalderFrom: 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, we introduce a Kconfig option for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment.
In case if the user forgets to set the start address, then 0xffffffff is used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address.
Also updated config.h so that it includes mpu/layout.h when CONFIG_MPU is defined.
---
Changes from :-
v1 - 1. Fixed some of the coding style issues.
2. Reworded the help message.
3. Updated the commit message.
xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/include/asm/config.h | 4 +++- xen/arch/arm/include/asm/mpu/layout.h | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/include/asm/mpu/layout.h
xen/arch/arm/Kconfig +10 -0
@@ -23,6 +23,16 @@ 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 + Used to set customized address at which which Xen will be linked on MPU + systems. Must be aligned to 4KB. + 0xFFFFFFFF is used as default value to indicate that user has not + customized this address. + menu "Architecture Features" choice
xen/arch/arm/include/asm/config.h +3 -1
@@ -69,8 +69,10 @@#include <xen/const.h> #include <xen/page-size.h> -#ifdef CONFIG_MMU +#if defined(CONFIG_MMU )#include <asm/mmu/layout.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/layout.h> #else # error "Unknown memory management layout"#endif
xen/arch/arm/include/asm/mpu/layout.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_LAYOUT_H__ +#define __ARM_MPU_LAYOUT_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_MPU_LAYOUT_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.25.1
Re: [PATCH v2 2/4] xen/arm: mpu: Define Xen start address for MPU systems
Hi Ayan,
Quoted 10 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 2 lines
So, we introduce a
Kconfigoption for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment.
It would suggest to add some explanation why you want the start address to be 4KB aligned.
Quoted 14 lines
In case if the user forgets to set the start address, then
0xffffffffis used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address.Also updated
config.hso that it includesmpu/layout.hwhenCONFIG_MPUis defined.Signed-off-by Wei Chen <[email protected]>Signed-off-by Jiamei.Xie <[email protected]>Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-
Quoted 7 lines
v1 - 1. Fixed some of the coding style issues.
2. Reworded the help message.
3. Updated the commit message.xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/include/asm/config.h | 4 +++- xen/arch/arm/include/asm/mpu/layout.h | 27 +++++++++++++++++++++++++++
Looking at this patch again, I don't see any modification in xen.lds.S. Is it intended?
Quoted 47 lines
3 files changed, 40 insertions(+), 1 deletion(-)create mode 100644
xen/arch/arm/include/asm/mpu/layout.hxen/arch/arm/Kconfig +10
-0@@ -23,6 +23,16 @@ 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 + Used to set customized address at which which Xen will be linked on MPU + systems. Must be aligned to 4KB. + 0xFFFFFFFF is used as default value to indicate that user has not + customized this address. + menu "Architecture Features" choicexen/arch/arm/include/asm/config.h +3
-1@@ -69,8 +69,10 @@#include <xen/const.h> #include <xen/page-size.h> -#ifdef CONFIG_MMU +#if defined(CONFIG_MMU )#include <asm/mmu/layout.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/layout.h> #else # error "Unknown memory management layout"#endif xen/arch/arm/include/asm/mpu/layout.h new file +1
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */
xen/arch/arm/include/asm/mpu/layout.h line 11
Quoted 10 lines
xen/arch/arm/include/asm/mpu/layout.h new file +10
-0+ +#ifndef __ARM_MPU_LAYOUT_H__ +#define __ARM_MPU_LAYOUT_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.
Strictly speaking, this doesn't match the Kconfig. AFAIU, we still said the internal code may continue to rely on PAGE_SIZE for the time being. But I think we would want to have a BUILD_BUG_ON(PAGE_SIZE != SZ_4K) to catch any value change.
xen/arch/arm/include/asm/mpu/layout.h line 14
Quoted 3 lines
xen/arch/arm/include/asm/mpu/layout.h new file +3
-0+*/ +#if (XEN_START_ADDRESS %PAGE_SIZE ) !=0 +#error "XEN_START_ADDRESS must be aligned to PAGE_SIZE"
In the error message, you want to mention 4KB.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 2/4] xen/arm: mpu: Define Xen start address for MPU systems
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 12 lines · Ayan Kumar Halder
Quoted 10 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 4 lines
Quoted 2 lines
So, we introduce a
Kconfigoption for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment.It would suggest to add some explanation why you want the start address to be 4KB aligned.
Let me know if this makes sense.
"MPU allows us to define regions which are 64 bits aligned. This restriction comes from the bitfields of PRBAR, PRLAR (the lower 6 bits are 0 extended to provide the base and limit address of a region). This means that the start address of Xen needs to be at least 64 bits aligned (as it will correspond to the start address of memory protection region).
As for now Xen on MPU tries to use the same memory alignment restrictions as it has been for MMU. Unlike MMU where the starting virtual address is 2MB, Xen on MPU needs the start address to be 4 KB (ie page size) aligned."
Thinking about this a bit more (and based on the discussion in "Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems"), I think we can keep the 4 KB restriction for now and relax it later. Let me know what you think.
Quoted 19 lines
Quoted 19 lines
In case if the user forgets to set the start address, then
0xffffffffis used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address.Also updated
config.hso that it includesmpu/layout.hwhenCONFIG_MPUis defined.Signed-off-by Wei Chen <[email protected]>Signed-off-by Jiamei.Xie <[email protected]>Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Fixed some of the coding style issues.
2. Reworded the help message.
3. Updated the commit message.
Quoted 5 lines
Quoted 3 lines
xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/include/asm/config.h | 4 +++-
xen/arch/arm/include/asm/mpu/layout.h| 27 +++++++++++++++++++++++++++Looking at this patch again, I don't see any modification in
xen.lds.S. Is it intended?
If we agree with the justification provided before, then this should be the modification.
xen/arch/arm/xen.lds.S +0 -0
@@ -232,6 +232,12 @@ SECTIONS
*/
ASSERT(_start == XEN_VIRT_START, "_start != XEN_VIRT_START")
+/*
+ * On MPU based platforms, the starting address is to be provided by user.
+ * One need to check that it is 4KB aligned.
+ */
+ASSERT(IS_ALIGNED(_start, 4096), "starting address is misaligned") +
Quoted 52 lines
Quoted 52 lines
3 files changed, 40 insertions(+), 1 deletion(-)create mode 100644
xen/arch/arm/include/asm/mpu/layout.hxen/arch/arm/Kconfig +0
-0@@ -23,6 +23,16 @@ config ARCH_DEFCONFIGdefault "
arch/arm/configs/arm32_defconfig" ifARM_32default "arch/arm/configs/arm64_defconfig" ifARM_64+configXEN_START_ADDRESS
+ hex "Xen start address: keep default to use platform defined address"
+ default0xFFFFFFFF
+ depends on MPU
+ help
+ Used to set customized address at which which Xen will be linked on MPU
+ systems. Must be aligned to 4KB.
+0xFFFFFFFFis used as default value to indicate that user has not + customized this address.
+
menu "Architecture Features"
choicexen/arch/arm/include/asm/config.h +0
-0@@ -69,8 +69,10 @@ #include <xen/const.h> #include <xen/page-size.h>-#ifdef
CONFIG_MMU
+#ifdefined(CONFIG_MMU)
#include <asm/mmu/layout.h>xen/arch/arm/include/asm/config.h +2
-0+#elif defined(CONFIG_MPU ) +#include <asm/mpu/layout.h> #else
# error "Unknown memory management layout" #endifxen/arch/arm/include/asm/mpu/layout.h new file +6
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_LAYOUT_H__ +#define __ARM_MPU_LAYOUT_H__ + +#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/include/asm/mpu/layout.h new file +3
-0+ +/* +* 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 aPAGE_SIZE.Strictly speaking, this doesn't match the
Kconfig. AFAIU, we still said the internal code may continue to rely onPAGE_SIZEfor the time being. But I think we would want to have aBUILD_BUG_ON(PAGE_SIZE != SZ_4K)to catch any value change.
Yes, I can add this.
Quoted 6 lines
xen/arch/arm/include/asm/mpu/layout.h
Quoted 4 lines
+ */
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"In the error message, you want to mention 4KB.
Ack.
- Ayan
Quoted 3 lines
Cheers,
Re: [PATCH v2 2/4] xen/arm: mpu: Define Xen start address for MPU systems
Quoted 21 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 12 lines · Ayan Kumar Halder
Quoted 10 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 4 lines
Quoted 2 lines
So, we introduce a
Kconfigoption for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment.It would suggest to add some explanation why you want the start address to be 4KB aligned.
Quoted 7 lines
Let me know if this makes sense.
"MPU allows us to define regions which are 64 bits aligned. This restriction comes from the bitfields of PRBAR, PRLAR (the lower 6 bits are 0 extended to provide the base and limit address of a region). This means that the start address of Xen needs to be at least 64 bits aligned (as it will correspond to the start address of memory protection region).
As for now Xen on MPU tries to use the same memory alignment restrictions as it has been for MMU. Unlike MMU where the starting virtual address is 2MB, Xen on MPU needs the start address to be 4 KB (ie page size) aligned."
Thinking about this a bit more (and based on the discussion in "Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems"), I think we can keep the 4 KB restriction for now and relax it later. Let me know what you think.
I am fine with that.
Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
In case if the user forgets to set the start address, then
0xffffffffis used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address.Also updated
config.hso that it includesmpu/layout.hwhenCONFIG_MPUis defined.Signed-off-by Wei Chen <[email protected]>Signed-off-by Jiamei.Xie <[email protected]>Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Fixed some of the coding style issues.
2. Reworded the help message.
3. Updated the commit message.Quoted 5 lines
Quoted 3 lines
xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/include/asm/config.h | 4 +++-
xen/arch/arm/include/asm/mpu/layout.h| 27 +++++++++++++++++++++++++++Looking at this patch again, I don't see any modification in
xen.lds.S. Is it intended?If we agree with the justification provided before, then this should be the modification.
xen/arch/arm/xen.lds.S SECTIONS · line 240
Quoted 9 lines
xen/arch/arm/xen.lds.S +6
-0@@ -232,6 +232,12 @@ SECTIONS */ ASSERT(_start == XEN_VIRT_START, "_start != XEN_VIRT_START") +/* + * On MPU based platforms, the starting address is to be provided by user. + * One need to check that it is 4KB aligned. + */ +ASSERT(IS_ALIGNED(_start, 4096), "starting address is misaligned") +
Ah I wasn't asking to add an ASSERT (although it would be good so long it is protected by CONFIG_MPU). Instead I was expecting XEN_VIRT_START to be replaced. But looking at the code again, I see you define XEN_VIRT_START for the MPU.
I think this is a little bit odd to use XEN_VIRT_* defined for the MPU but it would be ok. Is the expectation that all the MPU code should be using XEN_START_ADDRESS? If so, maybe it would be worth add a comment on top of XEN_VIRT_ADDRESS.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 2/4] xen/arm: mpu: Define Xen start address for MPU systems
Hi Julien,
Quoted 81 lines · Julien Grall
Quoted 21 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 12 lines · Ayan Kumar Halder
Quoted 10 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 4 lines
Quoted 2 lines
So, we introduce a
Kconfigoption for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment.It would suggest to add some explanation why you want the start address to be 4KB aligned.
Quoted 7 lines
Let me know if this makes sense.
"MPU allows us to define regions which are 64 bits aligned. This restriction comes from the bitfields of PRBAR, PRLAR (the lower 6 bits are 0 extended to provide the base and limit address of a region). This means that the start address of Xen needs to be at least 64 bits aligned (as it will correspond to the start address of memory protection region).
As for now Xen on MPU tries to use the same memory alignment restrictions as it has been for MMU. Unlike MMU where the starting virtual address is 2MB, Xen on MPU needs the start address to be 4 KB (ie page size) aligned."
Thinking about this a bit more (and based on the discussion in "Re: [PATCH v1 2/4] xen/arm: mpu: Define Xen start address for MPU systems"), I think we can keep the 4 KB restriction for now and relax it later. Let me know what you think.
I am fine with that.
Quoted 37 lines
Quoted 20 lines
Quoted 20 lines
In case if the user forgets to set the start address, then
0xffffffffis used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address.Also updated
config.hso that it includesmpu/layout.hwhenCONFIG_MPUis defined.Signed-off-by Wei Chen <[email protected]>Signed-off-by Jiamei.Xie <[email protected]>Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Fixed some of the coding style issues.
2. Reworded the help message.
3. Updated the commit message.Quoted 6 lines
Quoted 4 lines
xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/include/asm/config.h | 4 +++-
xen/arch/arm/include/asm/mpu/layout.h| 27
+++++++++++++++++++++++++++Looking at this patch again, I don't see any modification in
xen.lds.S. Is it intended?If we agree with the justification provided before, then this should be the modification.
xen/arch/arm/xen.lds.S +2
-0@@ -232,6 +232,12 @@ SECTIONS */ ASSERT(_start == XEN_VIRT_START, "_start != XEN_VIRT_START") +/* + * On MPU based platforms, the starting address is to be provided byQuoted 6 lines
user.
+ * One need to check that it is 4KB aligned.
+ */
+ASSERT(IS_ALIGNED(_start, 4096), "starting address is misaligned")
+Ah I wasn't asking to add an ASSERT (although it would be good so long it is protected by
CONFIG_MPU). Instead I was expectingXEN_VIRT_STARTto be replaced. But looking at the code again, I see you defineXEN_VIRT_STARTfor the MPU.
Quoted 1 line
I think this is a little bit odd to use XEN_VIRT_* defined for the MPU but it would be ok. Is the expectation that all the MPU code should be using
XEN_START_ADDRESS? If so, maybe it would be worth add a comment on top ofXEN_VIRT_ADDRESS.
I have defined XEN_VIRT_START as XEN_START_ADDRESS , so that the code continues to use XEN_VIRT_START (as it does for the MMU) and we avoid introducing #if-defs.
Does this comment make sense ?
/*
* For MPU, XEN's virtual start address is same as the physical address.
* The reason being MPU treats VA == PA. IOW, it cannot map the physical
* address to a different fixed virtual address. So, the virtual start
* address is determined by the physical address at which Xen is loaded. */
#define XEN_VIRT_START _AT(paddr_t, XEN_START_ADDRESS)
- Ayan
Quoted 3 lines
Cheers,
PATCH v2 3/4 xen/arm: mpu: Create boot-time MPU protection regions
In reply to Ayan Kumar HalderDefine 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)
If the number of MPU regions created is greater than the count defined in MPUIR_EL2, then the boot fails.
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.
MPU specific registers are defined inxen/arch/arm/include/asm/arm64/mpu/sysregs.h.
---
Changes from :-
v1 - 1. Instead of mapping a (XEN_START_ADDRESS + 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).
2. Introduced a label (__init_data_begin) to mark the beginning of the init data section.
3. Moved MPU specific register definitions to mpu/sysregs.h.
4. Fixed coding style issues.
5. Included page.h in mpu/head.S as page.h includes sysregs.h. I haven't seen sysregs.h included directly from head.S or mmu/head.S. (Outstanding comment not addressed).
xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176 +++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 + 9 files changed, 253 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/arm64/mpu/sysregs.h 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
@@ -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
@@ -0,0 +1 @@ +obj-y += head.o
xen/arch/arm/arm64/mpu/head.S new file +176 -0
176 lines not on this page · raw message
xen/arch/arm/include/asm/arm64/mpu/sysregs.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_ARM_ARM64_MPU_SYSREGS_H +#define __ASM_ARM_ARM64_MPU_SYSREGS_H + +/* Number of EL2 MPU regions */ +#define MPUIR_EL2 S3_4_C0_C0_4 + +/* EL2 MPU Protection Region Base Address Register encode */ +#define PRBAR_EL2 S3_4_C6_C8_0 + +/* EL2 MPU Protection Region Limit Address Register encode */ +#define PRLAR_EL2 S3_4_C6_C8_1 + +/* MPU Protection Region Selection Register encode */ +#define PRSELR_EL2 S3_4_C6_C2_1 + +#endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/include/asm/arm64/sysregs.h +3 -0
@@ -2,6 +2,9 @@#define __ASM_ARM_ARM64_SYSREGS_H#include <xen/stringify.h> +#if defined(CONFIG_MPU ) +#include <asm/arm64/mpu/sysregs.h> +#endif /* * GIC System register assembly aliases picked from kernel
xen/arch/arm/include/asm/mm.h +2 -0
@@ -16,6 +16,8 @@#if defined(CONFIG_MMU )# include <asm/mmu/mm.h> +#elif defined(CONFIG_MPU ) +# include <asm/mpu/mm.h> #else # error "Unknown memory management layout"#endif
xen/arch/arm/include/asm/mpu/arm64/mm.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* mm.h: Arm Memory Protection Unit definitions. +*/ + +#ifndef __ARM64_MPU_MM_H__ +#define __ARM64_MPU_MM_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_MM_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/include/asm/mpu/mm.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_MM__ +#define __ARM_MPU_MM__ + +#if defined(CONFIG_ARM_64 ) +# include <asm/mpu/arm64/mm.h> +#else +# error "unknown ARM variant" +#endif + +#endif /* __ARM_MPU_MM__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/xen.lds.S +1 -0
@@ -157,6 +157,7 @@ SECTIONS *(.altinstr_replacement) } :text . = ALIGN(PAGE_SIZE); + __init_data_begin = .; .init.data : { *(.init.rodata) *(.init.rodata.*)
Signature · 1 line
2.25.1
Re: [PATCH v2 3/4] xen/arm: mpu: Create boot-time MPU protection regions
Hi Ayan,
Quoted 109 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)If the number of MPU regions created is greater than the count defined in
MPUIR_EL2, then the boot fails.One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of
PRBAR_EL2,PRLAR_EL2andPRSELR_EL2registers. 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.
MPU specific registers are defined in
xen/arch/arm/include/asm/arm64/mpu/sysregs.h.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Instead of mapping a (
XEN_START_ADDRESS+ 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).2. Introduced a label (
__init_data_begin) to mark the beginning of the init data section.3. Moved MPU specific register definitions to
mpu/sysregs.h.4. Fixed coding style issues.
5. Included
page.hinmpu/head.Saspage.hincludessysregs.h. I haven't seensysregs.hincluded directly fromhead.Sormmu/head.S. (Outstanding comment not addressed).xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176 +++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 + 9 files changed, 253 insertions(+)create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644
xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu/sysregs.hcreate mode 100644xen/arch/arm/include/asm/mpu/arm64/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hxen/arch/arm/Makefile +1
-0@@ -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@@ -0,0 +1 @@ +obj-y += head.oxen/arch/arm/arm64/mpu/head.S new file +14
-0@@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include <asm/mm.h> +#include <asm/page.h> + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ +
xen/arch/arm/arm64/mpu/head.S line 24
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+/* + * Macro to round up the section address to be PAGE_SIZE aligned + * Each section(e.g. .text, .data, etc) in xen.lds.S is page-aligned, + * which is usually guarded with ". = ALIGN(PAGE_SIZE)" in the head, + * or in the end + */ +.macro roundup_section, xb + add \xb, \xb, #(PAGE_SIZE-1) + and \xb, \xb, #PAGE_MASK +.endm
Can you explain why we need the region to be page-aligned? Would not 64-bytes alignment (IIRC this is the minimum by the MPU sufficient)
And more importantly, if those regions were effectively not aligned, would not this mean we would could configure the MPU with two clashing regions? IOW, this round up looks harmful to me.
Quoted 30 lines
xen/arch/arm/arm64/mpu/head.S new file +30
-0+ +/* + * Macro to prepare and set a EL2 MPU memory region. + * We will also create an according MPU memory region entry, which + * is a structure of pr_t, in table \prmap. + * + * Inputs: + * sel: region selector + * base: reg storing base address (should be page-aligned) + * limit: reg storing limit address + * prbar: store computed PRBAR_EL2 value + * prlar: store computed PRLAR_EL2 value + * attr_prbar: PRBAR_EL2-related memory attributes. If not specified it will be + * REGION_DATA_PRBAR + * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be + * REGION_NORMAL_PRLAR + * + * Clobber \tmp1, \tmp2 + * + */ +.macro prepare_xen_region, sel, base, limit, prbar, prlar, tmp1, tmp2, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR + /* Prepare value for PRBAR_EL2 reg and preserve it in \prbar.*/ + and \base, \base, #MPU_REGION_MASK + mov \prbar, #\attr_prbar + orr \prbar, \prbar, \base + + /* Prepare value for PRLAR_EL2 reg and preserve it in \prlar.*/ + /* Round up limit address to be PAGE_SIZE aligned */ + roundup_section \limit + /* Limit address should be inclusive */
xen/arch/arm/arm64/mpu/head.S line 64
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ sub \limit, \limit, #1 + and \limit, \limit, #MPU_REGION_MASK + mov \prlar, #\attr_prlar + orr \prlar, \prlar, \limit + + msr PRSELR_EL2, \sel + isb + msr PRBAR_EL2, \prbar + msr PRLAR_EL2, \prlar + dsb
Please use "dsb sy". This has the same meaning as "dsb" but more explicit for the reader.
xen/arch/arm/arm64/mpu/head.S line 74
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ isb +.endm + +/* Load the physical address of a symbol into xb */ +.macro load_paddr xb, sym + ldr \xb, =\sym + add \xb, \xb, x20 /* x20 - Phys offset */ +.endm + +.section .text.header, "ax", %progbits
Does the code below actually need to be in .text.header?
xen/arch/arm/arm64/mpu/head.S line 82
Quoted 8 lines
xen/arch/arm/arm64/mpu/head.S new file +8
-0+ +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses the default memory + * map as the Background region for generating the memory + * attributes when MPU is disabled. + * Since the default memory map of the Armv8-R AArch64 architecture is + * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.
Based on this sentence, I was expecting an instruction to clear SCTRL_EL2.BR. What did I miss?
xen/arch/arm/arm64/mpu/head.S line 92
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ * + * Clobbers x0 + * + */ +FUNC_LOCAL(enable_mpu) + mrs x0, SCTLR_EL2 + orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */ + orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ + orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */ + dsb sy
There is no memory access in enable_mpu. So what is this dsb for?
xen/arch/arm/arm64/mpu/head.S line 102
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ msr SCTLR_EL2, x0 + isb + + ret +END(enable_mpu) + +/* + * Maps the various sections of Xen (described in xen.lds.S) as different MPU + * regions. Some of these regions will be marked read only while the others will + * be read write or execute.
And some in the future may need to be memory region (e.g. to use the UART early) :). So how about just dropping it?
Quoted 16 lines
xen/arch/arm/arm64/mpu/head.S new file +16
-0+ *> + * Inputs: + * lr : Address to return to. + * + * Clobbers x0 - x7 + * + */ +FUNC(enable_boot_cpu_mm) + mov x7, lr> + + /* x0: region sel */ + mov x0, xzr + /* Xen text section. */ + load_paddr x1, _stext + load_paddr x2, _etext + prepare_xen_region x0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBAR + + add x0, x0, #1
xen/arch/arm/arm64/mpu/head.S line 130
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ /* Xen read-only data section. */ + load_paddr x1, _srodata + load_paddr x2, _erodata + prepare_xen_region x0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_RO_PRBAR + + add x0, x0, #1 + /* Xen read-only after init data section. */ + load_paddr x1, __ro_after_init_start + load_paddr x2, __ro_after_init_end + prepare_xen_region x0, x1, x2, x3, x4, x5, x6
Is it necessary to have a section for the ro-after-init? IOW, could we just fold into...
xen/arch/arm/arm64/mpu/head.S line 136
Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +6
-0+ + add x0, x0, #1 + /* Xen read-write data section. */ + load_paddr x1, __ro_after_init_end + load_paddr x2, __init_begin + prepare_xen_region x0, x1, x2, x3, x4, x5, x6
... this one during boot and then fold the ro-after-init to the read-only region? This would possibly reduce the number of used by Xen and also avoid reshfulling the MPU section.
Another possibility would be to move the ro-after-init MPU region at the end.
Quoted 13 lines
xen/arch/arm/arm64/mpu/head.S new file +13
-0+> + add x0, x0, #1 + /* Xen BSS section. */ + load_paddr x1, __bss_start + load_paddr x2, __bss_end + prepare_xen_region x0, x1, x2, x3, x4, x5, x6 + + add x0, x0, #1 + /* Xen init text section. */ + load_paddr x1, __init_begin + load_paddr x2, __init_data_begin + prepare_xen_region x0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBAR + + add x0, x0, #1
xen/arch/arm/arm64/mpu/head.S line 160
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+ /* Xen init data section. */ + load_paddr x1, __init_data_begin + load_paddr x2, __init_end + prepare_xen_region x0, x1, x2, x3, x4, x5, x6 + + /* Check if the number of regions exceeded the count specified in MPUIR_EL2 */ + mrs x1, MPUIR_EL2 + cmp x0, x1 + bgt 1f + bl enable_mpu
It seems to be a bit odd to check *after* we wrote. It would be useful to explain why this is fine.
Quoted 54 lines
xen/arch/arm/arm64/mpu/head.S new file +16
-0+ + mov lr, x7 + ret + +1: + PRINT("- Number of MPU regions set in MPUIR_EL2 is too less -\r\n") + wfe + b 1b +END(enable_boot_cpu_mm) + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */xen/arch/arm/include/asm/arm64/mpu/sysregs.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_ARM_ARM64_MPU_SYSREGS_H +#define __ASM_ARM_ARM64_MPU_SYSREGS_H + +/* Number of EL2 MPU regions */ +#define MPUIR_EL2 S3_4_C0_C0_4 + +/* EL2 MPU Protection Region Base Address Register encode */ +#define PRBAR_EL2 S3_4_C6_C8_0 + +/* EL2 MPU Protection Region Limit Address Register encode */ +#define PRLAR_EL2 S3_4_C6_C8_1 + +/* MPU Protection Region Selection Register encode */ +#define PRSELR_EL2 S3_4_C6_C2_1 + +#endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/include/asm/arm64/sysregs.h +0
-0
xen/arch/arm/include/asm/arm64/sysregs.h line 7
Quoted 6 lines
xen/arch/arm/include/asm/arm64/sysregs.h +3
-0@@ -2,6 +2,9 @@#define __ASM_ARM_ARM64_SYSREGS_H#include <xen/stringify.h> +#if defined(CONFIG_MPU ) +#include <asm/arm64/mpu/sysregs.h> +#endif
I would expect the number of user for the MPU sysregs to be limited. So can we include the header only when it is necessary?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 3/4] xen/arm: mpu: Create boot-time MPU protection regions
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarifications.
Quoted 115 lines · Ayan Kumar Halder
Quoted 113 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)If the number of MPU regions created is greater than the count defined in
MPUIR_EL2, then the boot fails.One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of
PRBAR_EL2,PRLAR_EL2andPRSELR_EL2registers. 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.
MPU specific registers are defined in
xen/arch/arm/include/asm/arm64/mpu/sysregs.h.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Instead of mapping a (
XEN_START_ADDRESS+ 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).2. Introduced a label (
__init_data_begin) to mark the beginning of the init data section.3. Moved MPU specific register definitions to
mpu/sysregs.h.4. Fixed coding style issues.
5. Included
page.hinmpu/head.Saspage.hincludessysregs.h. I haven't seensysregs.hincluded directly fromhead.Sormmu/head.S. (Outstanding comment not addressed).xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176 +++++++++++++++++++
xen/arch/arm/include/asm/arm64/mpu/sysregs.h| 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 +9 files changed, 253 insertions(+)create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644
xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu/sysregs.hcreate mode 100644xen/arch/arm/include/asm/mpu/arm64/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hxen/arch/arm/Makefile +0
-0@@ -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@@ -0,0 +1 @@ +obj-y += head.oxen/arch/arm/arm64/mpu/head.S new file +18
-0@@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include <asm/mm.h> +#include <asm/page.h> + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ + +/* + * Macro to round up the section address to be PAGE_SIZE aligned + * Each section(e.g. .text, .data, etc) in xen.lds.S is page-aligned, + * which is usually guarded with ". = ALIGN(PAGE_SIZE)" in the head,
Quoted 8 lines
xen/arch/arm/arm64/mpu/head.S line 24
Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +6
-0+ * or in the end + */ +.macro roundup_section, xb + add \xb, \xb, #(PAGE_SIZE-1) + and \xb, \xb, #PAGE_MASK +.endmCan you explain why we need the region to be page-aligned? Would not 64-bytes alignment (IIRC this is the minimum by the MPU sufficient)
We are aligning the limit address only (not the base address). However ...
Quoted 2 lines
And more importantly, if those regions were effectively not aligned, would not this mean we would could configure the MPU with two clashing regions? IOW, this round up looks harmful to me.
you are correct that there is chance that limit address might overlap between 2 regions. Also (thinking again), the limit address is 0x3f extended when is programmed into PRLAR. So, we might not need alignment at all for the limit address.
Quoted 38 lines
Quoted 38 lines
xen/arch/arm/arm64/mpu/head.S new file +13
-0+ +/* + * Macro to prepare and set a EL2 MPU memory region. + * We will also create an according MPU memory region entry, which + * is a structure of pr_t, in table \prmap. + * + * Inputs: + * sel: region selector + * base: reg storing base address (should be page-aligned) + * limit: reg storing limit address + * prbar: store computed PRBAR_EL2 value + * prlar: store computed PRLAR_EL2 value + * attr_prbar: PRBAR_EL2-related memory attributes. If notspecified it will be
+ *REGION_DATA_PRBAR
+ * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be
+ *REGION_NORMAL_PRLAR
+ *
+ * Clobber \tmp1, \tmp2
+ *
+ */
+.macroprepare_xen_region, sel, base, limit, prbar, prlar, tmp1, tmp2, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR + /* Prepare value forPRBAR_EL2reg and preserve it in \prbar.*/ + and \base, \base, #MPU_REGION_MASK
+ mov \prbar, #\attr_prbar
+ orr \prbar, \prbar, \base
+
+ /* Prepare value forPRLAR_EL2reg and preserve it in \prlar.*/ + /* Round up limit address to bePAGE_SIZEaligned */ +roundup_section\limit
+ /* Limit address should be inclusive */
+ sub \limit, \limit, #1
+ and \limit, \limit, #MPU_REGION_MASK
+ mov \prlar, #\attr_prlar
+ orr \prlar, \prlar, \limit
Quoted 8 lines
Quoted 6 lines
+
+ msrPRSELR_EL2, \sel
+ isb
+ msrPRBAR_EL2, \prbar
+ msrPRLAR_EL2, \prlar
+ dsbPlease use "dsb sy". This has the same meaning as "dsb" but more explicit for the reader.
Ack
Quoted 13 lines
xen/arch/arm/arm64/mpu/head.S line 74
Quoted 11 lines
+ isb
+.endmxen/arch/arm/arm64/mpu/head.S new file +8
-0+ +/* Load the physical address of a symbol into xb */ +.macro load_paddr xb, sym + ldr \xb, =\sym + add \xb, \xb, x20 /* x20 - Phys offset */ +.endm + +.section .text.header, "ax", %progbitsDoes the code below actually need to be in .text.header?
I can remove this altogether. As I understand, the code should be in .text section.
Quoted 13 lines
Quoted 11 lines
xen/arch/arm/arm64/mpu/head.S new file +4
-0+ +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses thedefault memory
+ * map as the Background region for generating the memory
+ * attributes when MPU is disabled.
+ * Since the default memory map of the Armv8-R AArch64 architecture is
+ * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.Based on this sentence, I was expecting an instruction to clear SCTRL_EL2.BR. What did I miss?
Sorry, based on https://developer.arm.com/documentation/102670/0300/AArch64-registers/AArch64-register-descriptions/AArch64-other-register-description/SCTLR-EL2--System-Control-Register--EL2- , SCTLR_EL2.BR == 0 (reset value). Thus, the background region is disabled by default.
Should I still set SCTLR_EL2.BR = 0 ? Or do I update the description with this info.
Quoted 12 lines
Quoted 11 lines
+ *
+ * Clobbers x0
+ *
+ */
+FUNC_LOCAL(enable_mpu)
+ mrs x0,SCTLR_EL2
+ orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */ + orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ + orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */ + dsb sy
Quoted 1 line
There is no memory access in
enable_mpu. So what is this dsb for?
We need to ensure that the outstanding memory accesses are completed before the MPU is enabled. I think the same rationale applies here as
enable_mmu()
{
...
"dsb sy /* Flush PTE writes and finish reads */"
..
}
In the case of MPU, we need the reads to be completed.
Quoted 15 lines
Quoted 9 lines
+ msr
SCTLR_EL2, x0
+ isbxen/arch/arm/arm64/mpu/head.S new file +6
-0+ + ret +END(enable_mpu) + +/* + * Maps the various sections of Xen (described in xen.lds.S) asQuoted 4 lines
different MPU
+ * regions. Some of these regions will be marked read only while the others will
+ * be read write or execute.And some in the future may need to be memory region (e.g. to use the UART early) :). So how about just dropping it?
Yes.
Quoted 32 lines
Quoted 21 lines
+ *> + * Inputs:
+ * lr : Address to return to.
+ *
+ * Clobbers x0 - x7
+ *
+ */
+FUNC(enable_boot_cpu_mm)
+ mov x7, lr> +
+ /* x0: region sel */
+ mov x0, xzr
+ /* Xen text section. */
+load_paddrx1,_stext
+load_paddrx2,_etext
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only data section. */
+load_paddrx1,_srodata
+load_paddrx2,_erodataQuoted 8 lines
+
prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_RO_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only after init data section. */ +load_paddrx1,__ro_after_init_start
+load_paddrx2,__ro_after_init_end
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6Is it necessary to have a section for the ro-after-init? IOW, could we just fold into...
Quoted 8 lines
Quoted 6 lines
+
+ add x0, x0, #1
+ /* Xen read-write data section. */
+load_paddrx1,__ro_after_init_end
+load_paddrx2,__init_begin
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6... this one during boot
This makes sense. So what you are saying is that there should be a single RW data region from __ro_after_init_start to _eteemediator (not __init_begin as it would overlap with the next).
Followed by a text region from __init_begin to _einittext. However _eteemediator is same as __init_begin, so should we be inserting a dummy page in between ?
A RW data region from __init_data_begin to __bss_end. Can we combine the BSS section and init data section into one region ?
Quoted 1 line
and then fold the ro-after-init to the read-only region?
This I did not understand.
Quoted 23 lines
This would possibly reduce the number of used by Xen and also avoid reshfulling the MPU section.
Another possibility would be to move the ro-after-init MPU region at the end.
Quoted 19 lines
+> + add x0, x0, #1
+ /* Xen BSS section. */
+load_paddrx1,__bss_start
+load_paddrx2,__bss_end
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6 +
+ add x0, x0, #1
+ /* Xen init text section. */
+load_paddrx1,__init_begin
+load_paddrx2,__init_data_begin
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBARxen/arch/arm/arm64/mpu/head.S new file +7
-0+ + add x0, x0, #1 + /* Xen init data section. */ + load_paddr x1, __init_data_begin + load_paddr x2, __init_end + prepare_xen_region x0, x1, x2, x3, x4, x5, x6 +
Quoted 8 lines
Quoted 6 lines
+ /* Check if the number of regions exceeded the count specified in
MPUIR_EL2*/
+ mrs x1,MPUIR_EL2
+ cmp x0, x1
+ bgt 1f
+ blenable_mpuIt seems to be a bit odd to check *after* we wrote. It would be useful to explain why this is fine.
Sorry, it needs to be checked each time we create a new region. I will fix this.
Quoted 54 lines
Quoted 54 lines
xen/arch/arm/arm64/mpu/head.S new file +16
-0+ + mov lr, x7 + ret + +1: + PRINT("- Number of MPU regions set in MPUIR_EL2 is too less -\r\n") + wfe + b 1b +END(enable_boot_cpu_mm) + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */xen/arch/arm/include/asm/arm64/mpu/sysregs.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_ARM_ARM64_MPU_SYSREGS_H +#define __ASM_ARM_ARM64_MPU_SYSREGS_H + +/* Number of EL2 MPU regions */ +#define MPUIR_EL2 S3_4_C0_C0_4 + +/* EL2 MPU Protection Region Base Address Register encode */ +#define PRBAR_EL2 S3_4_C6_C8_0 + +/* EL2 MPU Protection Region Limit Address Register encode */ +#define PRLAR_EL2 S3_4_C6_C8_1 + +/* MPU Protection Region Selection Register encode */ +#define PRSELR_EL2 S3_4_C6_C2_1 + +#endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/include/asm/arm64/sysregs.h +0
-0
Quoted 8 lines
xen/arch/arm/include/asm/arm64/sysregs.h line 6
Quoted 6 lines
xen/arch/arm/include/asm/arm64/sysregs.h +3
-0@@ -2,6 +2,9 @@ #define __ASM_ARM_ARM64_SYSREGS_H #include <xen/stringify.h> +#if defined(CONFIG_MPU ) +#include <asm/arm64/mpu/sysregs.h> +#endif I would expect the number of user for the MPU sysregs to be limited. So can we include the header only when it is necessary?
ok.
- Ayan
Quoted 3 lines
Cheers,
Re: [PATCH v2 3/4] xen/arm: mpu: Create boot-time MPU protection regions
Hi Ayan,
Quoted 131 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarifications.
Quoted 115 lines · Ayan Kumar Halder
Quoted 113 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)If the number of MPU regions created is greater than the count defined in
MPUIR_EL2, then the boot fails.One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of
PRBAR_EL2,PRLAR_EL2andPRSELR_EL2registers. 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.
MPU specific registers are defined in
xen/arch/arm/include/asm/arm64/mpu/sysregs.h.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Instead of mapping a (
XEN_START_ADDRESS+ 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).2. Introduced a label (
__init_data_begin) to mark the beginning of the init data section.3. Moved MPU specific register definitions to
mpu/sysregs.h.4. Fixed coding style issues.
5. Included
page.hinmpu/head.Saspage.hincludessysregs.h. I haven't seensysregs.hincluded directly fromhead.Sormmu/head.S. (Outstanding comment not addressed).xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176 +++++++++++++++++++
xen/arch/arm/include/asm/arm64/mpu/sysregs.h| 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 +9 files changed, 253 insertions(+)create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644
xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu/sysregs.hcreate mode 100644xen/arch/arm/include/asm/mpu/arm64/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hxen/arch/arm/Makefile +0
-0@@ -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@@ -0,0 +1 @@ +obj-y += head.oxen/arch/arm/arm64/mpu/head.S new file +18
-0@@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include <asm/mm.h> +#include <asm/page.h> + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ + +/* + * Macro to round up the section address to be PAGE_SIZE aligned + * Each section(e.g. .text, .data, etc) in xen.lds.S is page-aligned, + * which is usually guarded with ". = ALIGN(PAGE_SIZE)" in the head,Quoted 8 lines
xen/arch/arm/arm64/mpu/head.S line 24
Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +6
-0+ * or in the end + */ +.macro roundup_section, xb + add \xb, \xb, #(PAGE_SIZE-1) + and \xb, \xb, #PAGE_MASK +.endmCan you explain why we need the region to be page-aligned? Would not 64-bytes alignment (IIRC this is the minimum by the MPU sufficient)
Quoted 5 lines
We are aligning the limit address only (not the base address). However ...
Quoted 2 lines
And more importantly, if those regions were effectively not aligned, would not this mean we would could configure the MPU with two clashing regions? IOW, this round up looks harmful to me.
you are correct that there is chance that limit address might overlap between 2 regions. Also (thinking again), the limit address is
0x3fextended when is programmed into PRLAR. So, we might not need alignment at all for the limit address.
I am not sure I fully understand what you wrote. Can you point me to the code you are referring to?
Quoted 78 lines
Quoted 39 lines
Quoted 39 lines
xen/arch/arm/arm64/mpu/head.S new file +13
-0+ +/* + * Macro to prepare and set a EL2 MPU memory region. + * We will also create an according MPU memory region entry, which + * is a structure of pr_t, in table \prmap. + * + * Inputs: + * sel: region selector + * base: reg storing base address (should be page-aligned) + * limit: reg storing limit address + * prbar: store computed PRBAR_EL2 value + * prlar: store computed PRLAR_EL2 value + * attr_prbar: PRBAR_EL2-related memory attributes. If notspecified it will be
+ *REGION_DATA_PRBAR
+ * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be
+ *REGION_NORMAL_PRLAR
+ *
+ * Clobber \tmp1, \tmp2
+ *
+ */
+.macroprepare_xen_region, sel, base, limit, prbar, prlar, tmp1, tmp2, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR + /* Prepare value forPRBAR_EL2reg and preserve it in \prbar.*/ + and \base, \base, #MPU_REGION_MASK
+ mov \prbar, #\attr_prbar
+ orr \prbar, \prbar, \base
+
+ /* Prepare value forPRLAR_EL2reg and preserve it in \prlar.*/ + /* Round up limit address to bePAGE_SIZEaligned */ +roundup_section\limit
+ /* Limit address should be inclusive */
+ sub \limit, \limit, #1
+ and \limit, \limit, #MPU_REGION_MASK
+ mov \prlar, #\attr_prlar
+ orr \prlar, \prlar, \limitQuoted 8 lines
Quoted 6 lines
+
+ msrPRSELR_EL2, \sel
+ isb
+ msrPRBAR_EL2, \prbar
+ msrPRLAR_EL2, \prlar
+ dsbPlease use "dsb sy". This has the same meaning as "dsb" but more explicit for the reader.
Ack
Quoted 13 lines
xen/arch/arm/arm64/mpu/head.S line 74
Quoted 11 lines
+ isb
+.endmxen/arch/arm/arm64/mpu/head.S new file +8
-0+ +/* Load the physical address of a symbol into xb */ +.macro load_paddr xb, sym + ldr \xb, =\sym + add \xb, \xb, x20 /* x20 - Phys offset */ +.endm + +.section .text.header, "ax", %progbitsDoes the code below actually need to be in .text.header?
I can remove this altogether. As I understand, the code should be in .text section.
Quoted 13 lines
Quoted 11 lines
xen/arch/arm/arm64/mpu/head.S new file +4
-0+ +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses thedefault memory
+ * map as the Background region for generating the memory
+ * attributes when MPU is disabled.
+ * Since the default memory map of the Armv8-R AArch64 architecture is
+ * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.Based on this sentence, I was expecting an instruction to clear SCTRL_EL2.BR. What did I miss?
Quoted 3 lines
Sorry, based on https://developer.arm.com/documentation/102670/0300/ AArch64-registers/AArch64-register-descriptions/AArch64-other-register- description/SCTLR-EL2--System-Control-Register--EL2- , SCTLR_EL2.BR == 0 (reset value). Thus, the background region is disabled by default.
Should I still set SCTLR_EL2.BR = 0 ? Or do I update the description with this info.
Both the Arm Arm and the TRM will tell us the state when the CPU boot. But I guess that there might be a firmware running before Xen. So we can't assume the values in the registers (unless this is documented in the boot protocol like Image).
So I think we need to set SCTLR_EL2.BR to 0.
Quoted 23 lines
Quoted 13 lines
Quoted 12 lines
+ *
+ * Clobbers x0
+ *
+ */
+FUNC_LOCAL(enable_mpu)
+ mrs x0,SCTLR_EL2
+ orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */ + orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ + orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */ + dsb syQuoted 1 line
There is no memory access in
enable_mpu. So what is this dsb for?We need to ensure that the outstanding memory accesses are completed before the MPU is enabled. I think the same rationale applies here as
enable_mmu(){
...
Quoted 7 lines
"dsb sy /* Flush PTE writes and finish reads */"
..
}
In the case of MPU, we need the reads to be completed.
I can't remember why a dsb was added there. But I don't see why we would need with the MPU as:
1/ we have a 1:1 mapping
2/ everytime we touch the MPU sections, we ensure the change will be
visible
Quoted 56 lines
Quoted 16 lines
Quoted 10 lines
+ msr
SCTLR_EL2, x0
+ isbxen/arch/arm/arm64/mpu/head.S new file +6
-0+ + ret +END(enable_mpu) + +/* + * Maps the various sections of Xen (described in xen.lds.S) asQuoted 4 lines
different MPU
+ * regions. Some of these regions will be marked read only while the others will
+ * be read write or execute.And some in the future may need to be memory region (e.g. to use the UART early) :). So how about just dropping it?
Yes.
Quoted 39 lines
Quoted 21 lines
+ *> + * Inputs:
+ * lr : Address to return to.
+ *
+ * Clobbers x0 - x7
+ *
+ */
+FUNC(enable_boot_cpu_mm)
+ mov x7, lr> +
+ /* x0: region sel */
+ mov x0, xzr
+ /* Xen text section. */
+load_paddrx1,_stext
+load_paddrx2,_etext
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only data section. */
+load_paddrx1,_srodata
+load_paddrx2,_erodataQuoted 8 lines
+
prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_RO_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only after init data section. */ +load_paddrx1,__ro_after_init_start
+load_paddrx2,__ro_after_init_end
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6Is it necessary to have a section for the ro-after-init? IOW, could we just fold into...
Quoted 6 lines
+
+ add x0, x0, #1
+ /* Xen read-write data section. */
+load_paddrx1,__ro_after_init_end
+load_paddrx2,__init_begin
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6
Quoted 4 lines
Quoted 1 line
... this one during boot
This makes sense. So what you are saying is that there should be a single RW data region from
__ro_after_init_startto _eteemediator (not__init_beginas it would overlap with the next).
_eteemediator may not be properly aligned. You will likely need another variable.
As a side note, I don't understand why the TEE mediator are part of RW. It is a separate problem though.
Quoted 2 lines
Followed by a text region from
__init_beginto_einittext. However_eteemediatoris same as__init_begin, so should we be inserting a dummy page in between ?
I don't understand what you mean. _init_begin should be suitably aligned to 4KB. So why would we need a page in between?
Quoted 2 lines
A RW data region from
__init_data_beginto__bss_end. Can we combine the BSS section and init data section into one region ?
If they have the same attribute then yes.
Quoted 4 lines
Quoted 2 lines
and then fold the ro-after-init to the read-only region?
This I did not understand.
I mean that the MPU regions would be updated so that after boot, one region would cover .rodata + .ro_after_init. The other region would cover .data up to .init (not included).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 3/4] xen/arm: mpu: Create boot-time MPU protection regions
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 134 lines · Ayan Kumar Halder
Quoted 132 lines · Julien Grall
Quoted 1 line
Hi Ayan,
Hi Julien,
I need some clarifications.
Quoted 124 lines · Ayan Kumar Halder
Quoted 110 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)If the number of MPU regions created is greater than the count defined in
MPUIR_EL2, then the boot fails.One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of
PRBAR_EL2,PRLAR_EL2andPRSELR_EL2registers. 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.
MPU specific registers are defined in
xen/arch/arm/include/asm/arm64/mpu/sysregs.h.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Instead of mapping a (
XEN_START_ADDRESS+ 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).2. Introduced a label (
__init_data_begin) to mark the beginning of the init data section.3. Moved MPU specific register definitions to
mpu/sysregs.h.4. Fixed coding style issues.
5. Included
page.hinmpu/head.Saspage.hincludessysregs.h. I haven't seensysregs.hincluded directly fromhead.Sormmu/head.S. (Outstanding comment not addressed).xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176
+++++++++++++++++++
xen/arch/arm/include/asm/arm64/mpu/sysregs.h| 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 +9 files changed, 253 insertions(+)create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644
xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu/sysregs.hcreate mode 100644xen/arch/arm/include/asm/mpu/arm64/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hxen/arch/arm/Makefile +0
-0@@ -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@@ -0,0 +1 @@ +obj-y += head.oxen/arch/arm/arm64/mpu/head.S new file +14
-0@@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include <asm/mm.h> +#include <asm/page.h> + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ +xen/arch/arm/arm64/mpu/head.S line 24
Quoted 10 lines
xen/arch/arm/arm64/mpu/head.S new file +10
-0+/* + * Macro to round up the section address to be PAGE_SIZE aligned + * Each section(e.g. .text, .data, etc) in xen.lds.S is page-aligned, + * which is usually guarded with ". = ALIGN(PAGE_SIZE)" in the head, + * or in the end + */ +.macro roundup_section, xb + add \xb, \xb, #(PAGE_SIZE-1) + and \xb, \xb, #PAGE_MASK +.endmCan you explain why we need the region to be page-aligned? Would not 64-bytes alignment (IIRC this is the minimum by the MPU sufficient)
Quoted 7 lines
Quoted 5 lines
We are aligning the limit address only (not the base address). However ...
Quoted 2 lines
And more importantly, if those regions were effectively not aligned, would not this mean we would could configure the MPU with two clashing regions? IOW, this round up looks harmful to me.
you are correct that there is chance that limit address might overlap between 2 regions. Also (thinking again), the limit address is
0x3fextended when is programmed into PRLAR. So, we might not need alignment at all for the limit address.I am not sure I fully understand what you wrote. Can you point me to the code you are referring to?
Actually I was referring to the ArmV8-R AArch32 docs ( ARM DDI 0568A.c ID110520) here.
In case of HPRBAR "Address[31:6] concatenated with zeroes to form Address[31:0]" , so the base address need to be at least 64 byte aligned.
However for HPRLAR, "Address[31:6] concatenated with the value 0x3F to form Address[31:0],". So even if we align the limit address to 4 KB or 64 byte or anything, the actual limit address will always be unaligned. So, I am thinking that aligning limit address might not make sense.
Quoted 80 lines
Quoted 80 lines
Quoted 40 lines
Quoted 40 lines
xen/arch/arm/arm64/mpu/head.S new file +13
-0+ +/* + * Macro to prepare and set a EL2 MPU memory region. + * We will also create an according MPU memory region entry, which + * is a structure of pr_t, in table \prmap. + * + * Inputs: + * sel: region selector + * base: reg storing base address (should be page-aligned) + * limit: reg storing limit address + * prbar: store computed PRBAR_EL2 value + * prlar: store computed PRLAR_EL2 value + * attr_prbar: PRBAR_EL2-related memory attributes. If notspecified it will be
+ *REGION_DATA_PRBAR
+ * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be
+ *REGION_NORMAL_PRLAR
+ *
+ * Clobber \tmp1, \tmp2
+ *
+ */
+.macroprepare_xen_region, sel, base, limit, prbar, prlar, tmp1, tmp2, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR + /* Prepare value forPRBAR_EL2reg and preserve it in \prbar.*/ + and \base, \base, #MPU_REGION_MASK
+ mov \prbar, #\attr_prbar
+ orr \prbar, \prbar, \base
+
+ /* Prepare value forPRLAR_EL2reg and preserve it in \prlar.*/ + /* Round up limit address to bePAGE_SIZEaligned */ +roundup_section\limit
+ /* Limit address should be inclusive */
+ sub \limit, \limit, #1
+ and \limit, \limit, #MPU_REGION_MASK
+ mov \prlar, #\attr_prlar
+ orr \prlar, \prlar, \limitQuoted 8 lines
Quoted 6 lines
+
+ msrPRSELR_EL2, \sel
+ isb
+ msrPRBAR_EL2, \prbar
+ msrPRLAR_EL2, \prlar
+ dsbPlease use "dsb sy". This has the same meaning as "dsb" but more explicit for the reader.
Ack
Quoted 13 lines
xen/arch/arm/arm64/mpu/head.S line 74
Quoted 11 lines
+ isb
+.endmxen/arch/arm/arm64/mpu/head.S new file +8
-0+ +/* Load the physical address of a symbol into xb */ +.macro load_paddr xb, sym + ldr \xb, =\sym + add \xb, \xb, x20 /* x20 - Phys offset */ +.endm + +.section .text.header, "ax", %progbitsDoes the code below actually need to be in .text.header?
I can remove this altogether. As I understand, the code should be in .text section.
Quoted 14 lines
Quoted 5 lines
xen/arch/arm/arm64/mpu/head.S new file +4
-0+ +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses theQuoted 7 lines
default memory
+ * map as the Background region for generating the memory
+ * attributes when MPU is disabled.
+ * Since the default memory map of the Armv8-R AArch64 architecture is
+ * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.Based on this sentence, I was expecting an instruction to clear SCTRL_EL2.BR. What did I miss?
Quoted 7 lines
Quoted 3 lines
Sorry, based on https://developer.arm.com/documentation/102670/0300/ AArch64-registers/AArch64-register-descriptions/AArch64-other-register- description/SCTLR-EL2--System-Control-Register--EL2- , SCTLR_EL2.BR == 0 (reset value). Thus, the background region is disabled by default.
Should I still set SCTLR_EL2.BR = 0 ? Or do I update the description with this info.
Both the Arm Arm and the TRM will tell us the state when the CPU boot. But I guess that there might be a firmware running before Xen. So we can't assume the values in the registers (unless this is documented in the boot protocol like Image).
So I think we need to set SCTLR_EL2.BR to 0.
Ack.
Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
Quoted 13 lines
+ *
+ * Clobbers x0
+ *
+ */
+FUNC_LOCAL(enable_mpu)
+ mrs x0,SCTLR_EL2
+ orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */ + orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ + orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */ + dsb syQuoted 1 line
There is no memory access in
enable_mpu. So what is this dsb for?We need to ensure that the outstanding memory accesses are completed before the MPU is enabled. I think the same rationale applies here as
enable_mmu(){
...
"dsb sy /* Flush PTE writes and finish reads */"
..
Quoted 7 lines
Quoted 3 lines
}
In the case of MPU, we need the reads to be completed.
I can't remember why a dsb was added there. But I don't see why we would need with the MPU as:
1/ we have a 1:1 mapping
2/ everytime we touch the MPU sections, we ensure the change will be visible
ok, so we don't need any barriers here.
Quoted 61 lines
Quoted 57 lines
Quoted 17 lines
Quoted 11 lines
+ msr
SCTLR_EL2, x0
+ isbxen/arch/arm/arm64/mpu/head.S new file +6
-0+ + ret +END(enable_mpu) + +/* + * Maps the various sections of Xen (described in xen.lds.S) asQuoted 4 lines
different MPU
+ * regions. Some of these regions will be marked read only while the others will
+ * be read write or execute.And some in the future may need to be memory region (e.g. to use the UART early) :). So how about just dropping it?
Yes.
Quoted 39 lines
Quoted 21 lines
+ *> + * Inputs:
+ * lr : Address to return to.
+ *
+ * Clobbers x0 - x7
+ *
+ */
+FUNC(enable_boot_cpu_mm)
+ mov x7, lr> +
+ /* x0: region sel */
+ mov x0, xzr
+ /* Xen text section. */
+load_paddrx1,_stext
+load_paddrx2,_etext
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_TEXT_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only data section. */
+load_paddrx1,_srodata
+load_paddrx2,_erodataQuoted 8 lines
+
prepare_xen_regionx0, x1, x2, x3, x4, x5, x6, attr_prbar=REGION_RO_PRBAR
+
+ add x0, x0, #1
+ /* Xen read-only after init data section. */ +load_paddrx1,__ro_after_init_start
+load_paddrx2,__ro_after_init_end
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6Is it necessary to have a section for the ro-after-init? IOW, could we just fold into...
Quoted 6 lines
+
+ add x0, x0, #1
+ /* Xen read-write data section. */
+load_paddrx1,__ro_after_init_end
+load_paddrx2,__init_begin
+prepare_xen_regionx0, x1, x2, x3, x4, x5, x6Quoted 3 lines
Quoted 1 line
... this one during boot
This makes sense. So what you are saying is that there should be a single RW data region from
__ro_after_init_startto _eteemediator (not__init_beginas it would overlap with the next).
Quoted 8 lines
_eteemediatormay not be properly aligned. You will likely need another variable.As a side note, I don't understand why the TEE mediator are part of RW. It is a separate problem though.
Quoted 2 lines
Followed by a text region from
__init_beginto_einittext. However_eteemediatoris same as__init_begin, so should we be inserting a dummy page in between ?I don't understand what you mean.
_init_beginshould be suitably aligned to 4KB. So why would we need a page in between?
Sorry I didn't explain clearly. In my xen-syms.map
0x202000 D __ro_after_init_start
0x202000 D _eteemediator
0x202000 T __init_begin
So since __ro_after_init_start == _eteemediator, so the RW data region is empty. There is nothing to map here.
However if _eteemediator and __init_begin were 0x203000 , so I should create a RW data region from 0x202000 - 0x202FFF (ie __init_begin - 1).
And then there will be Text region from __init_begin to _einittext - 1.
Is my understanding correct ?
Quoted 5 lines
Quoted 3 lines
A RW data region from
__init_data_beginto__bss_end. Can we combine the BSS section and init data section into one region ?If they have the same attribute then yes.
ok, so my sections look like this (from readelf -DS)
[ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000200000 00000100 0000000000000832 0000000000000000 WAX 0 0 32 [ 2] .rodata PROGBITS 0000000000201000 00001100 0000000000000d78 0000000000000000 A 0 0 256 [ 3] .note.gnu.bu[...] NOTE 0000000000201d78 00001e78 0000000000000024 0000000000000000 A 0 0 4 [ 4] .data.ro_aft[...] PROGBITS 0000000000202000 00003170 0000000000000000 0000000000000000 WA 0 0 1 [ 5] .data PROGBITS 0000000000202000 00002100 0000000000000000 0000000000000000 WA 0 0 1 [ 6] .init.text PROGBITS 0000000000202000 00002100 0000000000000048 0000000000000000 AX 0 0 4 [ 7] .init.data PROGBITS 0000000000203000 00003100 0000000000000070 0000000000000000 A 0 0 1 [ 8] .bss NOBITS 0000000000208000 00003170 0000000000000000 0000000000000000 WA 0 0 1
IIUC, [2] and [3] will be combined.
[4] and [5] will be combined.
So we will be creating 6 MPU regions in total. Is this correct ?
- Ayan
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
and then fold the ro-after-init to the read-only region?
This I did not understand.
I mean that the MPU regions would be updated so that after boot, one region would cover .rodata + .ro_after_init. The other region would cover .data up to .init (not included).
Cheers,
Re: [PATCH v2 3/4] xen/arm: mpu: Create boot-time MPU protection regions
Hi,
Quoted 130 lines · Ayan Kumar Halder
Quoted 128 lines · Julien Grall
Quoted 127 lines · Ayan Kumar Halder
Quoted 115 lines · Julien Grall
Quoted 114 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.
To do this, Xen maps the following sections of the binary as separate regions (with permissions) :-
1. Text (Read only at EL2, execution is permitted)
2. RO data (Read only at EL2)
3. RO after init data (Read/Write at EL2 as the data is RW during init)
4. RW data (Read/Write at EL2)
5. BSS (Read/Write at EL2)
6. Init Text (Read only at EL2, execution is permitted)
7. Init data (Read/Write at EL2)If the number of MPU regions created is greater than the count defined in
MPUIR_EL2, then the boot fails.One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of
PRBAR_EL2,PRLAR_EL2andPRSELR_EL2registers. 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.
MPU specific registers are defined in
xen/arch/arm/include/asm/arm64/mpu/sysregs.h.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Instead of mapping a (
XEN_START_ADDRESS+ 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script).2. Introduced a label (
__init_data_begin) to mark the beginning of the init data section.3. Moved MPU specific register definitions to
mpu/sysregs.h.4. Fixed coding style issues.
5. Included
page.hinmpu/head.Saspage.hincludessysregs.h. I haven't seensysregs.hincluded directly fromhead.Sormmu/head.S. (Outstanding comment not addressed).xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 176 ++++++++++++++
+++++
xen/arch/arm/include/asm/arm64/mpu/sysregs.h| 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 +++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 +9 files changed, 253 insertions(+)create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644
xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu/sysregs.hcreate mode 100644xen/arch/arm/include/asm/mpu/arm64/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hxen/arch/arm/Makefile +0
-0@@ -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@@ -0,0 +1 @@ +obj-y += head.oxen/arch/arm/arm64/mpu/head.S new file +18
-0@@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include <asm/mm.h> +#include <asm/page.h> + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ + +/* + * Macro to round up the section address to be PAGE_SIZE aligned + * Each section(e.g. .text, .data, etc) in xen.lds.S is page-aligned, + * which is usually guarded with ". = ALIGN(PAGE_SIZE)" in the head,Quoted 8 lines
xen/arch/arm/arm64/mpu/head.S line 24
Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S new file +6
-0+ * or in the end + */ +.macro roundup_section, xb + add \xb, \xb, #(PAGE_SIZE-1) + and \xb, \xb, #PAGE_MASK +.endmCan you explain why we need the region to be page-aligned? Would not 64-bytes alignment (IIRC this is the minimum by the MPU sufficient)
We are aligning the limit address only (not the base address). However ...
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
And more importantly, if those regions were effectively not aligned, would not this mean we would could configure the MPU with two clashing regions? IOW, this round up looks harmful to me.
you are correct that there is chance that limit address might overlap between 2 regions. Also (thinking again), the limit address is
0x3fextended when is programmed into PRLAR. So, we might not need alignment at all for the limit address.I am not sure I fully understand what you wrote. Can you point me to the code you are referring to?
Actually I was referring to the ArmV8-R AArch32 docs ( ARM DDI
0568A.cID110520) here.
The code you are writing is for 64-bit :). So please provide some reference using the ArmV8-R AArch64 docs.
Quoted 2 lines
In case of HPRBAR "Address[31:6] concatenated with zeroes to form Address[31:0]" , so the base address need to be at least 64 byte aligned.
AFAICT, the 64-bit equivalent is PRBAR<n>_EL2. But indeed, we need the address to be 64-byte. That said, I would simply mask the bits rather than rounding up because all the address should be properly aligned (as we do for the MMU).
Quoted 2 lines
However for HPRLAR, "Address[31:6] concatenated with the value
0x3Fto form Address[31:0],". So even if we align the limit address to 4 KB or 64 byte or anything, the actual limit address will always be unaligned.
That's just the limit is inclusive. So it will always be 64-byte aligned - 1. Anyway...
Quoted 1 line
So, I am thinking that aligning limit address might not make sense.
... same as I above. I don't think we need to align anything. We can just mask it.
[...]
Quoted 13 lines
Quoted 3 lines
Quoted 1 line
Followed by a text region from
__init_beginto_einittext. However_eteemediatoris same as__init_begin, so should we be inserting a dummy page in between ?I don't understand what you mean.
_init_beginshould be suitably aligned to 4KB. So why would we need a page in between?Sorry I didn't explain clearly. In my xen-syms.map
0x202000D__ro_after_init_start
0x202000D_eteemediator
0x202000T__init_begin
Quoted 7 lines
So since
__ro_after_init_start==_eteemediator, so the RW data region is empty. There is nothing to map here.However if _eteemediator and __init_begin were
0x203000, so I should create a RW data region from0x202000-0x202FFF(ie__init_begin- 1).And then there will be Text region from
__init_beginto_einittext- 1.Is my understanding correct ?
Ah I understand your problem now. Technically all the regions can be empty. I don't think add a page between is nice because we would end up to waste some space in memory. Instead, we should check if a region is empty, if it is then skip it.
Quoted 28 lines
Quoted 6 lines
Quoted 4 lines
A RW data region from
__init_data_beginto__bss_end. Can we combine the BSS section and init data section into one region ?If they have the same attribute then yes.
ok, so my sections look like this (from readelf -DS)
[ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000200000 00000100 0000000000000832 0000000000000000 WAX 0 0 32 [ 2] .rodata PROGBITS 0000000000201000 00001100 0000000000000d78 0000000000000000 A 0 0 256 [ 3] .note.gnu.bu[...] NOTE
0000000000201d7800001e780000000000000024 0000000000000000 A 0 0 4 [ 4] .data.ro_aft[...] PROGBITS 0000000000202000 00003170 0000000000000000 0000000000000000 WA 0 0 1 [ 5] .data PROGBITS 0000000000202000 00002100 0000000000000000 0000000000000000 WA 0 0 1 [ 6] .init.text PROGBITS 0000000000202000 00002100 0000000000000048 0000000000000000 AX 0 0 4 [ 7] .init.data PROGBITS 0000000000203000 00003100 0000000000000070 0000000000000000 A 0 0 1 [ 8] .bss NOBITS 0000000000208000 00003170 0000000000000000 0000000000000000 WA 0 0 1
Quoted 5 lines
IIUC, [2] and [3] will be combined.
[4] and [5] will be combined.
So we will be creating 6 MPU regions in total. Is this correct ?
I think you could combine [7] and [8] as well. So it would look like:
1. [1] .text
2. [2] .rodata [3] .note.gnu.bu[...]
3. [4] .data.ro_aft[...] [3] .data
4. [6] .init.text
4. [7] .init.data [8] .bss
After boot, you would have:
1. [1] .text
2. [2] .rodata [3] .note.gnu.bu[...] [4] .data.ro_aft[...]
3. [3] .data
4. [8] .bss
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 4/4 xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
In reply to Ayan Kumar HalderSecondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
---
Changes from :-
v1 - 1. NR_CPUS is defined as 1 for MPU
2. Added a message in enable_secondary_cpu_mm()
xen/arch/Kconfig | 1 + xen/arch/arm/arm64/mpu/head.S | 10 ++++++++++ 2 files changed, 11 insertions(+)
xen/arch/Kconfig +1 -0
@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps
xen/arch/arm/arm64/mpu/head.S +10 -0
@@ -168,6 +168,16 @@ FUNC(enable_boot_cpu_mm) b 1b END(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: PRINT("- SMP not enabled yet -\r\n") + wfe + b 1b +ENDPROC(enable_secondary_cpu_mm) + /* * Local variables: * mode: ASM
Signature · 1 line
2.25.1
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Hi,
Quoted 32 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPU2. Added a message in
enable_secondary_cpu_mm()xen/arch/Kconfig | 1 + xen/arch/arm/arm64/mpu/head.S | 10 ++++++++++ 2 files changed, 11 insertions(+)xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmapsxen/arch/arm/arm64/mpu/head.S +0
-0
xen/arch/arm/arm64/mpu/head.S FUNC(enable_boot_cpu_mm) · line 173
Quoted 6 lines
xen/arch/arm/arm64/mpu/head.S +3
-0@@ -168,6 +168,16 @@ FUNC(enable_boot_cpu_mm) b 1b END(enable_boot_cpu_mm) +/* + * Secondary cpu has not yet been supported on MPU systems. We will block the + * secondary cpu bringup at this stage.
Given that NR_CPUS is 1, this should not be reachable. How about the following comment:
"We don't yet support secondary CPUs bring-up. Implement a dummy helper to please the common code."
xen/arch/arm/arm64/mpu/head.S FUNC(enable_boot_cpu_mm) · line 176
Quoted 3 lines
xen/arch/arm/arm64/mpu/head.S +3
-0+ */ +ENTRY(enable_secondary_cpu_mm) +1: PRINT("- SMP not enabled yet -\r\n")
You want the print to be outside of the loop. Otherwise, it will spam the console in the unlikely case the code is reached.
xen/arch/arm/arm64/mpu/head.S FUNC(enable_boot_cpu_mm) · line 183
Quoted 7 lines
xen/arch/arm/arm64/mpu/head.S +4
-0+ wfe + b 1b +ENDPROC(enable_secondary_cpu_mm) + /* * Local variables: * mode: ASM
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Quoted 1 line · Julien Grall
Hi,
Hi Julien,
Quoted 43 lines · Ayan Kumar Halder
Quoted 32 lines
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPU2. Added a message in
enable_secondary_cpu_mm()xen/arch/Kconfig | 1 +
xen/arch/arm/arm64/mpu/head.S| 10 ++++++++++2 files changed, 11 insertions(+)xen/arch/Kconfig +0
-0@@ -11,6 +11,7 @@ config NR_CPUSdefault "8" if ARM && RCAR3
default "4" if ARM && QEMU
default "4" if ARM && MPSOC
+ default "1" if ARM && MPU
default "128" if ARM
help
Controls the build-time size of various arrays and bitmapsxen/arch/arm/arm64/mpu/head.S +0
-0@@ -168,6 +168,16 @@ FUNC(enable_boot_cpu_mm)Quoted 6 lines
b 1b
END(enable_boot_cpu_mm)
+/*
+ * Secondary cpu has not yet been supported on MPU systems. We will block the
+ * secondary cpu bringup at this stage.Given that
NR_CPUSis 1, this should not be reachable. How about the following comment:
Quoted 1 line
"We don't yet support secondary CPUs bring-up. Implement a dummy helper to please the common code."
Ack.
Quoted 6 lines
Quoted 4 lines
+ */
+ENTRY(enable_secondary_cpu_mm)
+1:PRINT("- SMP not enabled yet -\r\n")You want the print to be outside of the loop. Otherwise, it will spam the console in the unlikely case the code is reached.
Ack.
- Ayan
Quoted 11 lines
Quoted 8 lines
+ wfe
+ b 1bxen/arch/arm/arm64/mpu/head.S +2
-0+ENDPROC(enable_secondary_cpu_mm) +/*
* Local variables:
* mode: ASMCheers,
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
In reply to Ayan Kumar HalderQuoted 8 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPU
Not quite, what you do is ...
xen/arch/Kconfig config NR_CPUS · line 17
Quoted 10 lines
xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps
... merely set the default. I wonder how useful that is, the more that
- as per the description - this is temporary only anyway.
Jan
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Hi Jan,
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPUNot quite, what you do is ...
Quoted 12 lines
xen/arch/Kconfig config NR_CPUS · line 17
Quoted 10 lines
xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps... merely set the default. I wonder how useful that is, the more that
- as per the description - this is temporary only anyway.
Yes, I can enforce a build time check like this.
xen/arch/arm/setup.c +0 -0
@@ -295,6 +295,12 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
struct domain *d;
int rc, i;
+ /*
+ * Currently MPU does not support SMP. + */
+#ifdef CONFIG_MPU
+ BUILD_BUG_ON(NR_CPUS > 1);
+#endif
dcache_line_bytes = read_dcache_line_bytes();
Does this look ok ?
- Ayan
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Quoted 44 lines · Ayan Kumar Halder
Hi Jan,
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPUNot quite, what you do is ...
Quoted 12 lines
xen/arch/Kconfig config NR_CPUS · line 17
Quoted 10 lines
xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps... merely set the default. I wonder how useful that is, the more that
- as per the description - this is temporary only anyway.Yes, I can enforce a build time check like this.
xen/arch/arm/setup.c +6
-0@@ -295,6 +295,12 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr) struct domain *d; int rc, i; + /* +* Currently MPU does not support SMP. +*/ +#ifdef CONFIG_MPU + BUILD_BUG_ON(NR_CPUS > 1); +#endif dcache_line_bytes = read_dcache_line_bytes();
Quoted 1 line
Does this look ok ?
Well, I'd still want to understand the purpose (if I was maintainer of this code at least). You can't bring up secondary processors yet - fine. But why does that mean you want to limit the build to NR_CPUS=1? Any number is fine, but just not useful?
Jan
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Hi Jan,
Quoted 45 lines · Jan Beulich
Quoted 44 lines · Ayan Kumar Halder
Hi Jan,
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPUNot quite, what you do is ...
Quoted 12 lines
xen/arch/Kconfig config NR_CPUS · line 17
Quoted 10 lines
xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps... merely set the default. I wonder how useful that is, the more that
- as per the description - this is temporary only anyway.Yes, I can enforce a build time check like this.
xen/arch/arm/setup.c +6
-0@@ -295,6 +295,12 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr) struct domain *d; int rc, i; + /* +* Currently MPU does not support SMP. +*/ +#ifdef CONFIG_MPU + BUILD_BUG_ON(NR_CPUS > 1); +#endif dcache_line_bytes = read_dcache_line_bytes();
Quoted 6 lines
Quoted 1 line
Does this look ok ?
Well, I'd still want to understand the purpose (if I was maintainer of this code at least). You can't bring up secondary processors yet - fine. But why does that mean you want to limit the build to NR_CPUS=1? Any number is fine, but just not useful?
I have suggested to restrict NR_CPUS because it is not clear whether cpu_up() would even work on MPU. In its current state, it may return an error but could also corrupt the system.
At least for Xen on Arm, we have no other way to temporarly disable SMP support (aside modify the provided DTB, but I would like to avoid it).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/4] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm
Quoted 55 lines · Julien Grall
Hi Jan,
Quoted 45 lines · Jan Beulich
Quoted 44 lines · Ayan Kumar Halder
Hi Jan,
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Ayan Kumar Halder
Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1.
NR_CPUSis defined as 1 for MPUNot quite, what you do is ...
Quoted 12 lines
xen/arch/Kconfig config NR_CPUS · line 17
Quoted 10 lines
xen/arch/Kconfig +1
-0@@ -11,6 +11,7 @@ config NR_CPUS default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps... merely set the default. I wonder how useful that is, the more that
- as per the description - this is temporary only anyway.Yes, I can enforce a build time check like this.
xen/arch/arm/setup.c +6
-0@@ -295,6 +295,12 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr) struct domain *d; int rc, i; + /* +* Currently MPU does not support SMP. +*/ +#ifdef CONFIG_MPU + BUILD_BUG_ON(NR_CPUS > 1); +#endif dcache_line_bytes = read_dcache_line_bytes();Quoted 6 lines
Quoted 1 line
Does this look ok ?
Well, I'd still want to understand the purpose (if I was maintainer of this code at least). You can't bring up secondary processors yet - fine. But why does that mean you want to limit the build to NR_CPUS=1? Any number is fine, but just not useful?
Quoted 6 lines
I have suggested to restrict
NR_CPUSbecause it is not clear whethercpu_up()would even work on MPU. In its current state, it may return an error but could also corrupt the system.At least for Xen on Arm, we have no other way to temporarly disable SMP support (aside modify the provided DTB, but I would like to avoid it).
I see. Ayan: Could this be made a little more clear in the description and / or code comment?
Furthermore I'm then puzzled by the use of BUILD_BUG_ON(). If you want to prevent people building SMP configs, wouldn't you be better off doing so right in Kconfig:
config NR_CPUS
int "Maximum number of CPUs"
range 1 16383 if !MPU
range 1 1
or
config NR_CPUS
int "Maximum number of CPUs"
range 1 1 if MPU
range 1 16383
? Since the 2nd form leaves the primary line untouched, I guess I like this slightly better, despite the outlier then coming first. (The above would presumably still require the default adjustment that you already have.)
Finally, having observed interesting build issues with newer gcc when trying to build UP configs, did you check that Arm actually builds fine that way with recent-ish gcc?
Jan