Enable R52 support for the first chunk of MPU support
v3 cover Enable R52 support for the first chunk of MPU support
Hi all,
This patch serie enables R52 support based on Luca's series. "[PATCH v6 0/6] First chunk for Arm R82 and MPU support".
Changes from :-
v1 .. v2 - Changes mentioned in individual patches
v3 - Split "arm/mpu: Provide access to the MPU region from the C code" into 4 patches.
Ayan Kumar Halder (6):
arm/mpu: Introduce MPU memory region map structure arm/mpu: Provide and populate MPU C data structures arm/mpu: Move domain-page.c to arm32 specific dir arm/mpu: Move the functions to arm64 specific files arm/mpu: Define arm32 system registers
arm/mpu: Enable read/write to protection regions for arm32
xen/arch/arm/arm32/Makefile | 1 +
xen/arch/arm/arm32/asm-offsets.c | 6 +
xen/arch/arm/arm32/cache.S | 43 ++++++
xen/arch/arm/arm32/mpu/head.S | 41 ++++-
xen/arch/arm/include/asm/arm32/mpu.h | 34 ++++-
xen/arch/arm/include/asm/mpu.h | 2 -
xen/arch/arm/include/asm/mpu/cpregs.h | 68 ++++++++-
xen/arch/arm/include/asm/mpu/regions.inc | 2 +-
xen/arch/arm/mpu/Makefile | 3 +-
xen/arch/arm/mpu/arm32/Makefile | 2 +
xen/arch/arm/mpu/{ => arm32}/domain-page.c | 0
xen/arch/arm/mpu/arm32/mm.c | 165 +++++++++++++++++++++
xen/arch/arm/mpu/arm64/Makefile | 1 +
xen/arch/arm/mpu/arm64/mm.c | 130 ++++++++++++++++
xen/arch/arm/mpu/mm.c | 123 +--------------
15 files changed, 487 insertions(+), 134 deletions(-)
create mode 100644 xen/arch/arm/arm32/cache.S
create mode 100644 xen/arch/arm/mpu/arm32/Makefile
rename xen/arch/arm/mpu/{ => arm32}/domain-page.c (100%)
create mode 100644 xen/arch/arm/mpu/arm32/mm.c
create mode 100644 xen/arch/arm/mpu/arm64/Makefile
create mode 100644 xen/arch/arm/mpu/arm64/mm.cSignature · 1 line
2.25.1
PATCH v3 1/6 arm/mpu: Introduce MPU memory region map structure
Introduce pr_t typedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32 Armv8-R architecture.
Also, define MPU_REGION_RES0 to 0 as there are no reserved 0 bits beyond the BASE or LIMIT bitfields in prbar or prlar respectively.
In pr_of_addr(), enclose prbar and prlar arm64 specific bitfields with appropriate macros. So, that this function can be later reused for arm32 as well.
---
Changes from v1 :-
1. Preserve pr_t typedef in arch specific files.
2. Fix typo.
v2 :-
1. Change CONFIG_ARM64 to CONFIG_ARM_64 to enclose arm64 specific bitfields for prbar and prlar registers in pr_of_addr().
xen/arch/arm/include/asm/arm32/mpu.h | 34 ++++++++++++++++++++++++++-- xen/arch/arm/mpu/mm.c | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-)
xen/arch/arm/include/asm/arm32/mpu.h +32 -2
@@ -5,10 +5,40 @@#ifndef __ASSEMBLY__ +/* +* Unlike arm64, there are no reserved 0 bits beyond base and limit bitfield in +* prbar and prlar registers respectively. +*/ +#define MPU_REGION_RES0 0x0 + +/* Hypervisor Protection Region Base Address Register */ +typedef union { +struct { +unsigned int xn:1 ;/* Execute-Never */ +unsigned int ap_0:1 ;/* Access Permission AP[0] */ +unsigned int ro:1 ;/* Access Permission AP[1] */ +unsigned int sh:2 ;/* Shareability */ +unsigned int res0:1 ; +unsigned int base:26 ;/* Base Address */ + } reg; +uint32_t bits; +}prbar_t ; + +/* Hypervisor Protection Region Limit Address Register */ +typedef union { +struct { +unsigned int en:1 ;/* Region enable */ +unsigned int ai:3 ;/* Memory Attribute Index */ +unsigned int res0:2 ; +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ; +/* MPU Protection Region */ typedef struct { -uint32_t prbar; -uint32_t prlar; +prbar_t prbar; +prlar_t prlar; }pr_t ;#endif /* __ASSEMBLY__ */
xen/arch/arm/mpu/mm.c +4 -0
@@ -167,7 +167,9 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)/* Build up value for PRBAR_EL2. */ prbar = (prbar_t ) { .reg = { +#ifdef CONFIG_ARM_64 .xn_0 =0 , +#endif .xn =PAGE_XN_MASK (flags), .ap_0 =0 , .ro =PAGE_RO_MASK (flags)
@@ -206,7 +208,9 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)/* Build up value for PRLAR_EL2. */ prlar = (prlar_t ) { .reg = { +#ifdef CONFIG_ARM_64 .ns =0 ,/* Hyp mode is in secure world */ +#endif .ai = attr_idx, .en =1 ,/* Region enabled */ }};
Signature · 1 line
2.25.1
Re: [PATCH v3 1/6] arm/mpu: Introduce MPU memory region map structure
Hi Ayan,
Quoted 5 lines · Ayan Kumar Halder
Introduce
pr_ttypedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32 Armv8-R architecture.
Quoted 8 lines
Also, define
MPU_REGION_RES0to 0 as there are no reserved 0 bits beyond the BASE or LIMIT bitfields in prbar or prlar respectively.In
pr_of_addr(), enclose prbar and prlar arm64 specific bitfields with appropriate macros. So, that this function can be later reused for arm32 as well.Signed-off-by Ayan Kumar Halder <[email protected]>
LGTM! I’ve also built for Arm32 and Arm64.
Re: [PATCH v3 1/6] arm/mpu: Introduce MPU memory region map structure
In reply to Ayan Kumar HalderHi Ayan,
Quoted 11 lines · Ayan Kumar Halder
Introduce
pr_ttypedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32 Armv8-R architecture.Also, define
MPU_REGION_RES0to 0 as there are no reserved 0 bits beyond the BASE or LIMIT bitfields in prbar or prlar respectively.In
pr_of_addr(), enclose prbar and prlar arm64 specific bitfields with appropriate macros. So, that this function can be later reused for arm32 as well.Signed-off-by Ayan Kumar Halder <[email protected]>
Cheers,
Quoted 87 lines
---
Changes from v1 :-1. Preserve
pr_ttypedef in arch specific files.2. Fix typo.
v2 :-
1. Change
CONFIG_ARM64toCONFIG_ARM_64to enclose arm64 specific bitfields for prbar and prlar registers inpr_of_addr().xen/arch/arm/include/asm/arm32/mpu.h | 34 ++++++++++++++++++++++++++-- xen/arch/arm/mpu/mm.c | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +32
-2@@ -5,10 +5,40 @@#ifndef __ASSEMBLY__ +/* +* Unlike arm64, there are no reserved 0 bits beyond base and limit bitfield in +* prbar and prlar registers respectively. +*/ +#define MPU_REGION_RES0 0x0 + +/* Hypervisor Protection Region Base Address Register */ +typedef union { +struct { +unsigned int xn:1 ;/* Execute-Never */ +unsigned int ap_0:1 ;/* Access Permission AP[0] */ +unsigned int ro:1 ;/* Access Permission AP[1] */ +unsigned int sh:2 ;/* Shareability */ +unsigned int res0:1 ; +unsigned int base:26 ;/* Base Address */ + } reg; +uint32_t bits; +}prbar_t ; + +/* Hypervisor Protection Region Limit Address Register */ +typedef union { +struct { +unsigned int en:1 ;/* Region enable */ +unsigned int ai:3 ;/* Memory Attribute Index */ +unsigned int res0:2 ; +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ; +/* MPU Protection Region */ typedef struct { -uint32_t prbar; -uint32_t prlar; +prbar_t prbar; +prlar_t prlar; }pr_t ;#endif /* __ASSEMBLY__ */ xen/arch/arm/mpu/mm.c +4
-0@@ -167,7 +167,9 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)/* Build up value for PRBAR_EL2. */ prbar = (prbar_t ) { .reg = { +#ifdef CONFIG_ARM_64 .xn_0 =0 , +#endif .xn =PAGE_XN_MASK (flags), .ap_0 =0 , .ro =PAGE_RO_MASK (flags)@@ -206,7 +208,9 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)/* Build up value for PRLAR_EL2. */ prlar = (prlar_t ) { .reg = { +#ifdef CONFIG_ARM_64 .ns =0 ,/* Hyp mode is in secure world */ +#endif .ai = attr_idx, .en =1 ,/* Region enabled */ }};
Signature · 1 line
Julien Grall
PATCH v3 2/6 arm/mpu: Provide and populate MPU C data structures
In reply to Ayan Kumar HalderModify Arm32 assembly boot code to reset any unused MPU region, initialise 'max_mpu_regions' with the number of supported MPU regions and set/clear the bitmap 'xen_mpumap_mask' used to track the enabled regions.
Introduce cache.S to hold arm32 cache related functions.
Use the macro definition for "dcache_line_size" from linux.
Change the order of registers in prepare_xen_region() as 'strd' instruction is used to store {prbar, prlar} in arm32. Thus, 'prbar' has to be a even numbered register and 'prlar' is the consecutively ordered register.
---
Changes from v1 :-
1. Introduce cache.S to hold arm32 cache initialization instructions.
2. Use dcache_line_size macro definition from linux.
3. Use mov_w instead of ldr.
4. Use a single stm instruction for 'store_pair' macro definition.
v2 :-
1. Use strd instead of stm.
2. Fix some coding style issues.
xen/arch/arm/arm32/Makefile | 1 + xen/arch/arm/arm32/asm-offsets.c | 6 ++++ xen/arch/arm/arm32/cache.S | 43 ++++++++++++++++++++++++ xen/arch/arm/arm32/mpu/head.S | 41 +++++++++++++++++----- xen/arch/arm/include/asm/mpu/regions.inc | 2 +- 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 xen/arch/arm/arm32/cache.S
xen/arch/arm/arm32/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-y += lib/ obj-$(CONFIG_MMU) += mmu/ obj-$(CONFIG_MPU) += mpu/ +obj-y += cache.o obj-$(CONFIG_EARLY_PRINTK) += debug.o obj-y += domctl.o obj-y += domain.o
xen/arch/arm/arm32/asm-offsets.c +6 -0
@@ -75,6 +75,12 @@ void __dummy__(void) OFFSET(INITINFO_stack, struct init_info, stack);BLANK (); + +#ifdef CONFIG_MPU +DEFINE (XEN_MPUMAP_MASK_sizeof,sizeof (xen_mpumap_mask)); +DEFINE (XEN_MPUMAP_sizeof,sizeof (xen_mpumap)); +BLANK (); +#endif }/*
xen/arch/arm/arm32/cache.S new file +43 -0
43 lines not on this page · raw message
xen/arch/arm/arm32/mpu/head.S +33 -8
76 lines not on this page · raw message
xen/arch/arm/include/asm/mpu/regions.inc +1 -1
@@ -24,7 +24,7 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */ .macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + strd \reg1, \reg2, [\dst] .endm #endif
Signature · 1 line
2.25.1
Re: [PATCH v3 2/6] arm/mpu: Provide and populate MPU C data structures
Hi Ayan,
Quoted 8 lines · Ayan Kumar Halder
Modify Arm32 assembly boot code to reset any unused MPU region, initialise '
max_mpu_regions' with the number of supported MPU regions and set/clear the bitmap 'xen_mpumap_mask' used to track the enabled regions.Introduce
cache.Sto hold arm32 cache related functions.
Quoted 8 lines
Use the macro definition for "
dcache_line_size" from linux.Change the order of registers in
prepare_xen_region()as 'strd' instruction is used to store {prbar, prlar} in arm32. Thus, 'prbar' has to be a even numbered register and 'prlar' is the consecutively ordered register.Signed-off-by Ayan Kumar Halder <[email protected]>---
This LGTM, I’ve also built for Arm64 and Arm32.
Re: [PATCH v3 2/6] arm/mpu: Provide and populate MPU C data structures
In reply to Ayan Kumar HalderHi Ayan,
Quoted 6 lines · Ayan Kumar Halder
Modify Arm32 assembly boot code to reset any unused MPU region, initialise '
max_mpu_regions' with the number of supported MPU regions and set/clear the bitmap 'xen_mpumap_mask' used to track the enabled regions.Introduce
cache.Sto hold arm32 cache related functions.
Quoted 7 lines
Use the macro definition for "
dcache_line_size" from linux.Change the order of registers in
prepare_xen_region()as 'strd' instruction is used to store {prbar, prlar} in arm32. Thus, 'prbar' has to be a even numbered register and 'prlar' is the consecutively ordered register.Signed-off-by Ayan Kumar Halder <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 3/6 arm/mpu: Move domain-page.c to arm32 specific dir
In reply to Ayan Kumar HalderCreate xen/arch/arm/mpu/arm32 to hold arm32 specific bits.
---
Changes from :-
v1..v2 - New patch in v3.
xen/arch/arm/mpu/Makefile | 2 +-
xen/arch/arm/mpu/arm32/Makefile | 1 +
xen/arch/arm/mpu/{ => arm32}/domain-page.c | 0
3 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 xen/arch/arm/mpu/arm32/Makefile
rename xen/arch/arm/mpu/{ => arm32}/domain-page.c (100%)xen/arch/arm/mpu/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-$(CONFIG_ARM_32) += domain-page.o +obj-$(CONFIG_ARM_32) += arm32/ obj-y += mm.o obj-y += p2m.o obj-y += setup.init.o
xen/arch/arm/mpu/arm32/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += domain-page.o
xen/arch/arm/mpu/arm32/domain-page.c renamed from xen/arch/arm/mpu/domain-page.c +0 -0
Signature · 1 line
2.25.1
Re: [PATCH v3 3/6] arm/mpu: Move domain-page.c to arm32 specific dir
Hi Ayan,
Quoted 8 lines · Ayan Kumar Halder
Create xen/arch/arm/mpu/arm32 to hold arm32 specific bits.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-
Quoted 8 lines
v1..v2 - New patch in v3.
xen/arch/arm/mpu/Makefile | 2 +- xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/{ => arm32}/domain-page.c | 0 3 files changed, 2 insertions(+), 1 deletion(-)create mode 100644 xen/arch/arm/mpu/arm32/Makefile rename xen/arch/arm/mpu/{ =>
arm32}/domain-page.c(100%)
Uhm, why?
Arm64 is using domain-page.c:
https://gitlab.com/xen-project/people/lucafancellu/xen/-/commit/b28198d00078991d4a6502e94c8779d84fec0120
Did I miss something?
Cheers,
Luca
Re: [PATCH v3 3/6] arm/mpu: Move domain-page.c to arm32 specific dir
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 17 lines
Quoted 9 lines · Ayan Kumar Halder
Create xen/arch/arm/mpu/arm32 to hold arm32 specific bits.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-Quoted 8 lines
v1..v2 - New patch in v3.
xen/arch/arm/mpu/Makefile | 2 +- xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/{ => arm32}/domain-page.c | 0 3 files changed, 2 insertions(+), 1 deletion(-)create mode 100644 xen/arch/arm/mpu/arm32/Makefile rename xen/arch/arm/mpu/{ =>
arm32}/domain-page.c(100%)
Quoted 6 lines
Uhm, why?
Arm64 is using
domain-page.c:
https://gitlab.com/xen-project/people/lucafancellu/xen/-/commit/b28198d00078991d4a6502e94c8779d84fec0120Did I miss something?
Oh, I did not look at the future patches. I can drop this patch in my next series once you and Michal/Julien reviews the other patches.
I feel it is cleaner to have separate implementations for prepare_selector(), read_protection_region(), write_protection_region() between arm32 and arm64. (Refer patch 4 and 6)
Let me know how it looks like.
- Ayan
Quoted 3 lines
Cheers,
Luca
PATCH v3 4/6 arm/mpu: Move the functions to arm64 specific files
In reply to Ayan Kumar Halderprepare_selector(), read_protection_region() and write_protection_region() differ significantly between arm32 and arm64. Thus, move these functions to their specific folders.
GENERATE_{WRITE/READ}_PR_REG_CASE are duplicated for arm32 and arm64 so as to improve the code readability.
---
Changes from -
v1..v2 - New patch introduced in v3.
xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm64/Makefile | 1 + xen/arch/arm/mpu/arm64/mm.c | 130 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 117 ---------------------------- 4 files changed, 132 insertions(+), 117 deletions(-) create mode 100644 xen/arch/arm/mpu/arm64/Makefile create mode 100644 xen/arch/arm/mpu/arm64/mm.c
xen/arch/arm/mpu/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_ARM_32) += arm32/ +obj-$(CONFIG_ARM_64) += arm64/ obj-y += mm.o obj-y += p2m.o obj-y += setup.init.o
xen/arch/arm/mpu/arm64/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += mm.o
xen/arch/arm/mpu/arm64/mm.c new file +130 -0
130 lines not on this page · raw message
xen/arch/arm/mpu/mm.c +0 -117
129 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 4/6] arm/mpu: Move the functions to arm64 specific files
Hi Ayan,
Quoted 5 lines · Ayan Kumar Halder
prepare_selector(),read_protection_region()andwrite_protection_region()differ significantly between arm32 and arm64. Thus, move these functions to their specific folders.
^— NIT: “to sub-arch specific folder”? What do you think?
Quoted 3 lines
GENERATE_{WRITE/READ}_PR_REG_CASE are duplicated for arm32 and arm64 so as to improve the code readability.
It reads a bit hard in this way, what about:
“Also the macro GENERATE_{WRITE/READ}_PR_REG_CASE are moved, in order to keep them in the same file of their usage and improve readability"
Quoted 92 lines
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from -v1..v2 - New patch introduced in v3.
xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm64/Makefile | 1 + xen/arch/arm/mpu/arm64/mm.c | 130 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 117 ---------------------------- 4 files changed, 132 insertions(+), 117 deletions(-)create mode 100644 xen/arch/arm/mpu/arm64/Makefile create mode 100644
xen/arch/arm/mpu/arm64/mm.cxen/arch/arm/mpu/Makefile +0
-0@@ -1,4 +1,5 @@obj-$(CONFIG_ARM_32) += arm32/
+obj-$(CONFIG_ARM_64) += arm64/
obj-y += mm.o
obj-y += p2m.o
obj-y += setup.init.oxen/arch/arm/mpu/arm64/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y += mm.oxen/arch/arm/mpu/arm64/mm.c new file +54
-0@@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/bug.h> +#include <xen/types.h> +#include <asm/mpu.h> +#include <asm/sysregs.h> +#include <asm/system.h> + +/* +* The following are needed for the cases: GENERATE_WRITE_PR_REG_CASE +* and GENERATE_READ_PR_REG_CASE with num==0 +*/ +#define PRBAR0_EL2 PRBAR_EL2 +#define PRLAR0_EL2 PRLAR_EL2 + +#define PRBAR_EL2_ (n) PRBAR##n##_EL2 +#define PRLAR_EL2_ (n) PRLAR##n##_EL2 + +#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR_EL2_(num)); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR_EL2_(num)); \ + break; \ + } + +#define GENERATE_READ_PR_REG_CASE (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(PRBAR_EL2_(num)); \ + pr->prlar.bits = READ_SYSREG(PRLAR_EL2_(num)); \ + break; \ + } + +/* +* Armv8-R supports direct access and indirect access to the MPU regions through +* registers: +* - indirect access involves changing the MPU region selector, issuing an isb +* barrier and accessing the selected region through specific registers +* - direct access involves accessing specific registers that point to +* specific MPU regions, without changing the selector, avoiding the use of +* a barrier. +* For Arm64 the PR{B,L}AR_ELx (for n=0) and PR{B,L}AR<n>_ELx (for n=1..15) are +* used for the direct access to the regions selected by +* PRSELR_EL2.REGION<7:4>:n, so 16 regions can be directly accessed when the +* selector is a multiple of 16, giving access to all the supported memory +* regions. +*/ +static void prepare_selector (uint8_t *sel) +{ +uint8_t cur_sel = *sel; + +/* +* {read,write}_protection_region works using the direct access to the 0..15
xen/arch/arm/mpu/arm64/mm.c line 64
Quoted 10 lines
xen/arch/arm/mpu/arm64/mm.c new file +10
-0+* regions, so in order to save the isb() overhead, change the PRSELR_EL2 +* only when needed, so when the upper 4 bits of the selector will change. +*/ + cur_sel &=0xF0U ; +if (READ_SYSREG (PRSELR_EL2 ) != cur_sel ) + { +WRITE_SYSREG (cur_sel,PRSELR_EL2 ); +isb (); + } + *sel = *sel &0xFU ;
This one is different in the original file (*sel &= 0xFU;)
The rest looks good to me!
With the above fixed:
Cheers,
Luca
Re: [PATCH v3 4/6] arm/mpu: Move the functions to arm64 specific files
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 7 lines
Quoted 6 lines · Ayan Kumar Halder
prepare_selector(),read_protection_region()andwrite_protection_region()differ significantly between arm32 and arm64. Thus, move these functions to their specific folders.^— NIT: “to sub-arch specific folder”? What do you think?
yes
Quoted 7 lines
Quoted 3 lines
GENERATE_{WRITE/READ}_PR_REG_CASE are duplicated for arm32 and arm64 so as to improve the code readability.
It reads a bit hard in this way, what about:
“Also the macro GENERATE_{WRITE/READ}_PR_REG_CASE are moved, in order to keep them in the same file of their usage and improve readability"
yes, this reads better.
Quoted 95 lines
Quoted 95 lines
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from -v1..v2 - New patch introduced in v3.
xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm64/Makefile | 1 + xen/arch/arm/mpu/arm64/mm.c | 130 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 117 ---------------------------- 4 files changed, 132 insertions(+), 117 deletions(-)create mode 100644 xen/arch/arm/mpu/arm64/Makefile create mode 100644
xen/arch/arm/mpu/arm64/mm.cxen/arch/arm/mpu/Makefile +0
-0@@ -1,4 +1,5 @@obj-$(CONFIG_ARM_32) += arm32/
+obj-$(CONFIG_ARM_64) += arm64/
obj-y += mm.o
obj-y += p2m.o
obj-y += setup.init.oxen/arch/arm/mpu/arm64/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y += mm.oxen/arch/arm/mpu/arm64/mm.c new file +57
-0@@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/bug.h> +#include <xen/types.h> +#include <asm/mpu.h> +#include <asm/sysregs.h> +#include <asm/system.h> + +/* +* The following are needed for the cases: GENERATE_WRITE_PR_REG_CASE +* and GENERATE_READ_PR_REG_CASE with num==0 +*/ +#define PRBAR0_EL2 PRBAR_EL2 +#define PRLAR0_EL2 PRLAR_EL2 + +#define PRBAR_EL2_ (n) PRBAR##n##_EL2 +#define PRLAR_EL2_ (n) PRLAR##n##_EL2 + +#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR_EL2_(num)); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR_EL2_(num)); \ + break; \ + } + +#define GENERATE_READ_PR_REG_CASE (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(PRBAR_EL2_(num)); \ + pr->prlar.bits = READ_SYSREG(PRLAR_EL2_(num)); \ + break; \ + } + +/* +* Armv8-R supports direct access and indirect access to the MPU regions through +* registers: +* - indirect access involves changing the MPU region selector, issuing an isb +* barrier and accessing the selected region through specific registers +* - direct access involves accessing specific registers that point to +* specific MPU regions, without changing the selector, avoiding the use of +* a barrier. +* For Arm64 the PR{B,L}AR_ELx (for n=0) and PR{B,L}AR<n>_ELx (for n=1..15) are +* used for the direct access to the regions selected by +* PRSELR_EL2.REGION<7:4>:n, so 16 regions can be directly accessed when the +* selector is a multiple of 16, giving access to all the supported memory +* regions. +*/ +static void prepare_selector (uint8_t *sel) +{ +uint8_t cur_sel = *sel; + +/* +* {read,write}_protection_region works using the direct access to the 0..15 +* regions, so in order to save the isb() overhead, change the PRSELR_EL2 +* only when needed, so when the upper 4 bits of the selector will change. +*/
Quoted 8 lines
xen/arch/arm/mpu/arm64/mm.c line 64
Quoted 7 lines
xen/arch/arm/mpu/arm64/mm.c new file +7
-0+ cur_sel &=0xF0U ; +if (READ_SYSREG (PRSELR_EL2 ) != cur_sel ) + { +WRITE_SYSREG (cur_sel,PRSELR_EL2 ); +isb (); + } + *sel = *sel &0xFU ;This one is different in the original file (*sel &=
0xFU;)
Agree with all of the suggested changes.
Quoted 5 lines
The rest looks good to me!
With the above fixed:Reviewed-by Luca Fancellu <[email protected]>
- Ayan
PATCH v3 5/6 arm/mpu: Define arm32 system registers
In reply to Ayan Kumar HalderFix the definition for HPRLAR.
Define the base/limit address registers to access the first 32 protection regions.
---
Changes from :-
v1 - v1 - New patch introduced in v3 (Extracted from "arm/mpu: Provide access to the MPU region from the C code").
xen/arch/arm/include/asm/mpu/cpregs.h | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/mpu/cpregs.h +67 -1
@@ -9,7 +9,73 @@/* CP15 CR6: MPU Protection Region Base/Limit/Select Address Register */ #define HPRSELR p15,4,c6,c2,1#define HPRBAR p15,4,c6,c3,0 -#define HPRLAR p15,4,c6,c8,1 +#define HPRLAR p15,4,c6,c3,1 + +/* CP15 CR6: MPU Protection Region Base/Limit Address Register */ +#define HPRBAR0 p15,4,c6,c8,0 +#define HPRLAR0 p15,4,c6,c8,1 +#define HPRBAR1 p15,4,c6,c8,4 +#define HPRLAR1 p15,4,c6,c8,5 +#define HPRBAR2 p15,4,c6,c9,0 +#define HPRLAR2 p15,4,c6,c9,1 +#define HPRBAR3 p15,4,c6,c9,4 +#define HPRLAR3 p15,4,c6,c9,5 +#define HPRBAR4 p15,4,c6,c10,0 +#define HPRLAR4 p15,4,c6,c10,1 +#define HPRBAR5 p15,4,c6,c10,4 +#define HPRLAR5 p15,4,c6,c10,5 +#define HPRBAR6 p15,4,c6,c11,0 +#define HPRLAR6 p15,4,c6,c11,1 +#define HPRBAR7 p15,4,c6,c11,4 +#define HPRLAR7 p15,4,c6,c11,5 +#define HPRBAR8 p15,4,c6,c12,0 +#define HPRLAR8 p15,4,c6,c12,1 +#define HPRBAR9 p15,4,c6,c12,4 +#define HPRLAR9 p15,4,c6,c12,5 +#define HPRBAR10 p15,4,c6,c13,0 +#define HPRLAR10 p15,4,c6,c13,1 +#define HPRBAR11 p15,4,c6,c13,4 +#define HPRLAR11 p15,4,c6,c13,5 +#define HPRBAR12 p15,4,c6,c14,0 +#define HPRLAR12 p15,4,c6,c14,1 +#define HPRBAR13 p15,4,c6,c14,4 +#define HPRLAR13 p15,4,c6,c14,5 +#define HPRBAR14 p15,4,c6,c15,0 +#define HPRLAR14 p15,4,c6,c15,1 +#define HPRBAR15 p15,4,c6,c15,4 +#define HPRLAR15 p15,4,c6,c15,5 +#define HPRBAR16 p15,5,c6,c8,0 +#define HPRLAR16 p15,5,c6,c8,1 +#define HPRBAR17 p15,5,c6,c8,4 +#define HPRLAR17 p15,5,c6,c8,5 +#define HPRBAR18 p15,5,c6,c9,0 +#define HPRLAR18 p15,5,c6,c9,1 +#define HPRBAR19 p15,5,c6,c9,4 +#define HPRLAR19 p15,5,c6,c9,5 +#define HPRBAR20 p15,5,c6,c10,0 +#define HPRLAR20 p15,5,c6,c10,1 +#define HPRBAR21 p15,5,c6,c10,4 +#define HPRLAR21 p15,5,c6,c10,5 +#define HPRBAR22 p15,5,c6,c11,0 +#define HPRLAR22 p15,5,c6,c11,1 +#define HPRBAR23 p15,5,c6,c11,4 +#define HPRLAR23 p15,5,c6,c11,5 +#define HPRBAR24 p15,5,c6,c12,0 +#define HPRLAR24 p15,5,c6,c12,1 +#define HPRBAR25 p15,5,c6,c12,4 +#define HPRLAR25 p15,5,c6,c12,5 +#define HPRBAR26 p15,5,c6,c13,0 +#define HPRLAR26 p15,5,c6,c13,1 +#define HPRBAR27 p15,5,c6,c13,4 +#define HPRLAR27 p15,5,c6,c13,5 +#define HPRBAR28 p15,5,c6,c14,0 +#define HPRLAR28 p15,5,c6,c14,1 +#define HPRBAR29 p15,5,c6,c14,4 +#define HPRLAR29 p15,5,c6,c14,5 +#define HPRBAR30 p15,5,c6,c15,0 +#define HPRLAR30 p15,5,c6,c15,1 +#define HPRBAR31 p15,5,c6,c15,4 +#define HPRLAR31 p15,5,c6,c15,5/* Aliases of AArch64 names for use in common code */ #ifdef CONFIG_ARM_32
Signature · 1 line
2.25.1
Re: [PATCH v3 5/6] arm/mpu: Define arm32 system registers
Hi Ayan,
I checked the register definitions for HPR{B,L}AR<n> against the Arm Architecture Reference Manual Supplement for the Armv8-R AArch32 architecture profile (ARM DDI 0568A.c), specifically sections E2.2.3 and E2.2.6, and everything looks correct to me.
Quoted 6 lines · Ayan Kumar Halder
Fix the definition for HPRLAR.
Define the base/limit address registers to access the first 32 protection regions.Signed-off-by Ayan Kumar Halder <[email protected]>---
Many thanks,
Hari
Re: [PATCH v3 5/6] arm/mpu: Define arm32 system registers
Quoted 1 line · Hari Limaye
Hi Ayan,
Hi Hari,
Quoted 6 lines
I checked the register definitions for HPR{B,L}AR<n> against the Arm Architecture Reference Manual Supplement for the Armv8-R AArch32 architecture profile (ARM DDI
0568A.c), specifically sections E2.2.3 and E2.2.6, and everything looks correct to me.
Quoted 8 lines
Quoted 6 lines · Ayan Kumar Halder
Fix the definition for HPRLAR.
Define the base/limit address registers to access the first 32 protection regions.Signed-off-by Ayan Kumar Halder <[email protected]>---
Reviewed-by Hari Limaye <[email protected]>
Thanks and welcome to xen-devel. :)
- Ayan
PATCH v3 6/6 arm/mpu: Enable read/write to protection regions for arm32
In reply to Ayan Kumar HalderDefine prepare_selector(), read_protection_region() and write_protection_region() for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.
Enable pr_{get/set}_{base/limit}(), region_is_valid() for arm32. Enable pr_of_addr() for arm32.
---
Changes from :-
v1 - 1. Enable write_protection_region() for aarch32.
v2 - 1. Enable access to protection regions from 0 - 255.
xen/arch/arm/include/asm/mpu.h | 2 - xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 165 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 2 - 4 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 xen/arch/arm/mpu/arm32/mm.c
xen/arch/arm/include/asm/mpu.h +0 -2
@@ -25,7 +25,6 @@#ifndef __ASSEMBLY__ -#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. *
@@ -85,7 +84,6 @@ static inline bool region_is_valid(const pr_t *pr) {return pr->prlar.reg.en; } -#endif /* CONFIG_ARM_64 */ #endif /* __ASSEMBLY__ */
xen/arch/arm/mpu/arm32/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += domain-page.o +obj-y += mm.o
xen/arch/arm/mpu/arm32/mm.c new file +165 -0
165 lines not on this page · raw message
xen/arch/arm/mpu/mm.c +0 -2
@@ -39,7 +39,6 @@ static void __init __maybe_unused build_assertions(void)BUILD_BUG_ON (PAGE_SIZE !=SZ_4K ); } -#ifdef CONFIG_ARM_64 pr_t pr_of_addr (paddr_t base,paddr_t limit,unsigned int flags) {unsigned int attr_idx =PAGE_AI_MASK (flags);
@@ -110,7 +109,6 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)return region; } -#endif /* CONFIG_ARM_64 */ void __init setup_mm (void ) {
Signature · 1 line
2.25.1
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
Hi Ayan,
Quoted 11 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Based on your v2 (https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/) I was imaging something like this:
xen/arch/arm/mpu/mm.c +24 -4
@@ -87,20 +87,28 @@ static void __init __maybe_unused build_assertions(void)*/ static void prepare_selector (uint8_t *sel) { -#ifdef CONFIG_ARM_64 uint8_t cur_sel = *sel; +#ifdef CONFIG_ARM_64 /* -* {read,write}_protection_region works using the direct access to the 0..15 -* regions, so in order to save the isb() overhead, change the PRSELR_EL2 -* only when needed, so when the upper 4 bits of the selector will change. +* {read,write}_protection_region works using the Arm64 direct access to the +* 0..15 regions, so in order to save the isb() overhead, change the +* PRSELR_EL2 only when needed, so when the upper 4 bits of the selector +* will change. */ cur_sel &=0xF0U ; +#else +/* Arm32 MPU can use direct access for 0-31 */ +if ( cur_sel >31 ) + cur_sel =0 ; +#endif if (READ_SYSREG (PRSELR_EL2 ) != cur_sel ) {WRITE_SYSREG (cur_sel,PRSELR_EL2 );isb (); } + +#ifdef CONFIG_ARM_64 *sel = *sel &0xFU ;#endif }
@@ -144,6 +152,12 @@ void read_protection_region(pr_t *pr_read, uint8_t sel)GENERATE_READ_PR_REG_CASE (29 , pr_read);GENERATE_READ_PR_REG_CASE (30 , pr_read);GENERATE_READ_PR_REG_CASE (31 , pr_read); + case 32 ... 255: + { + pr->prbar.bits =READ_SYSREG (PRBAR_EL2 ); + pr->prlar.bits =READ_SYSREG (PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */
@@ -190,6 +204,12 @@ void write_protection_region(const pr_t *pr_write, uint8_t sel)GENERATE_WRITE_PR_REG_CASE (29 , pr_write);GENERATE_WRITE_PR_REG_CASE (30 , pr_write);GENERATE_WRITE_PR_REG_CASE (31 , pr_write); + case 32 ... 255: + { +WRITE_SYSREG (pr->prbar.bits & ~MPU_REGION_RES0 ,PRBAR_EL2 ); +WRITE_SYSREG (pr->prlar.bits & ~MPU_REGION_RES0 ,PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */
Is it using too ifdefs in your opinion that would benefit the split you do in v3?
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 79 lines
Quoted 7 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Quoted 5 lines
Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Based on your v2 (https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/) I was imaging something like this:
xen/arch/arm/mpu/mm.c +24
-4@@ -87,20 +87,28 @@ static void __init __maybe_unused build_assertions(void)*/ static void prepare_selector (uint8_t *sel) { -#ifdef CONFIG_ARM_64 uint8_t cur_sel = *sel; +#ifdef CONFIG_ARM_64 /* -* {read,write}_protection_region works using the direct access to the 0..15 -* regions, so in order to save the isb() overhead, change the PRSELR_EL2 -* only when needed, so when the upper 4 bits of the selector will change. +* {read,write}_protection_region works using the Arm64 direct access to the +* 0..15 regions, so in order to save the isb() overhead, change the +* PRSELR_EL2 only when needed, so when the upper 4 bits of the selector +* will change. */ cur_sel &=0xF0U ; +#else +/* Arm32 MPU can use direct access for 0-31 */ +if ( cur_sel >31 ) + cur_sel =0 ; +#endif if (READ_SYSREG (PRSELR_EL2 ) != cur_sel ) {WRITE_SYSREG (cur_sel,PRSELR_EL2 );isb (); } + +#ifdef CONFIG_ARM_64 *sel = *sel &0xFU ;#endif }@@ -144,6 +152,12 @@ void read_protection_region(pr_t *pr_read, uint8_t sel)GENERATE_READ_PR_REG_CASE (29 , pr_read);GENERATE_READ_PR_REG_CASE (30 , pr_read);GENERATE_READ_PR_REG_CASE (31 , pr_read); + case 32 ... 255: + { + pr->prbar.bits =READ_SYSREG (PRBAR_EL2 ); + pr->prlar.bits =READ_SYSREG (PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */ @@ -190,6 +204,12 @@ void write_protection_region(const pr_t *pr_write, uint8_t sel)GENERATE_WRITE_PR_REG_CASE (29 , pr_write);GENERATE_WRITE_PR_REG_CASE (30 , pr_write);GENERATE_WRITE_PR_REG_CASE (31 , pr_write); + case 32 ... 255: + { +WRITE_SYSREG (pr->prbar.bits & ~MPU_REGION_RES0 ,PRBAR_EL2 ); +WRITE_SYSREG (pr->prlar.bits & ~MPU_REGION_RES0 ,PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */
Quoted 1 line
Is it using too ifdefs in your opinion that would benefit the split you do in v3?
Yes. However, I understand that this is subjective. I need your and Michal/Julien to have an opinion here whether to go with the split (which means some amount of code duplication) or introduce if-defs. I will be happy to proceed as per your opinions.
- Ayan
Quoted 2 lines
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
Quoted 83 lines · Ayan Kumar Halder
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 79 lines
Quoted 7 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Quoted 5 lines
Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Based on your v2 (https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/) I was imaging something like this:
xen/arch/arm/mpu/mm.c +24
-4@@ -87,20 +87,28 @@ static void __init __maybe_unused build_assertions(void)*/ static void prepare_selector (uint8_t *sel) { -#ifdef CONFIG_ARM_64 uint8_t cur_sel = *sel; +#ifdef CONFIG_ARM_64 /* -* {read,write}_protection_region works using the direct access to the 0..15 -* regions, so in order to save the isb() overhead, change the PRSELR_EL2 -* only when needed, so when the upper 4 bits of the selector will change. +* {read,write}_protection_region works using the Arm64 direct access to the +* 0..15 regions, so in order to save the isb() overhead, change the +* PRSELR_EL2 only when needed, so when the upper 4 bits of the selector +* will change. */ cur_sel &=0xF0U ; +#else +/* Arm32 MPU can use direct access for 0-31 */ +if ( cur_sel >31 ) + cur_sel =0 ; +#endif if (READ_SYSREG (PRSELR_EL2 ) != cur_sel ) {WRITE_SYSREG (cur_sel,PRSELR_EL2 );isb (); } + +#ifdef CONFIG_ARM_64 *sel = *sel &0xFU ;#endif }@@ -144,6 +152,12 @@ void read_protection_region(pr_t *pr_read, uint8_t sel)GENERATE_READ_PR_REG_CASE (29 , pr_read);GENERATE_READ_PR_REG_CASE (30 , pr_read);GENERATE_READ_PR_REG_CASE (31 , pr_read); + case 32 ... 255: + { + pr->prbar.bits =READ_SYSREG (PRBAR_EL2 ); + pr->prlar.bits =READ_SYSREG (PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */ @@ -190,6 +204,12 @@ void write_protection_region(const pr_t *pr_write, uint8_t sel)GENERATE_WRITE_PR_REG_CASE (29 , pr_write);GENERATE_WRITE_PR_REG_CASE (30 , pr_write);GENERATE_WRITE_PR_REG_CASE (31 , pr_write); + case 32 ... 255: + { +WRITE_SYSREG (pr->prbar.bits & ~MPU_REGION_RES0 ,PRBAR_EL2 ); +WRITE_SYSREG (pr->prlar.bits & ~MPU_REGION_RES0 ,PRLAR_EL2 ); +break ; + }#endif default :BUG ();/* Can't happen */
Quoted 6 lines
Quoted 1 line
Is it using too ifdefs in your opinion that would benefit the split you do in v3?
Yes. However, I understand that this is subjective. I need your and Michal/Julien to have an opinion here whether to go with the split (which means some amount of code duplication) or introduce if-defs. I will be happy to proceed as per your opinions.
I don't have a strong opinion here. Maybe I slightly prefer the split to avoid ifdefery.
~Michal
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
In reply to Ayan Kumar HalderQuoted 151 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Enable
write_protection_region()for aarch32.v2 - 1. Enable access to protection regions from 0 - 255.
xen/arch/arm/include/asm/mpu.h | 2 - xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 165 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 2 - 4 files changed, 166 insertions(+), 4 deletions(-)create mode 100644
xen/arch/arm/mpu/arm32/mm.cxen/arch/arm/include/asm/mpu.h +0
-2@@ -25,7 +25,6 @@#ifndef __ASSEMBLY__ -#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. * @@ -85,7 +84,6 @@ static inline bool region_is_valid(const pr_t *pr) {return pr->prlar.reg.en; } -#endif /* CONFIG_ARM_64 */ #endif /* __ASSEMBLY__ */ xen/arch/arm/mpu/arm32/Makefile +1
-0@@ -1 +1,2 @@ obj-y += domain-page.o +obj-y += mm.oxen/arch/arm/mpu/arm32/mm.c new file +96
-0@@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/bug.h> +#include <xen/types.h> +#include <asm/mpu.h> +#include <asm/sysregs.h> +#include <asm/system.h> + +#define PRBAR_EL2_ (n) HPRBAR##n +#define PRLAR_EL2_ (n) HPRLAR##n + +#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR_EL2_(num)); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR_EL2_(num)); \ + break; \ + } + +#define GENERATE_WRITE_PR_REG_OTHERS (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, HPRBAR); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, HPRLAR); \ + break; \ + } + +#define GENERATE_READ_PR_REG_CASE (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(PRBAR_EL2_(num)); \ + pr->prlar.bits = READ_SYSREG(PRLAR_EL2_(num)); \ + break; \ + } + +#define GENERATE_READ_PR_REG_OTHERS (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(HPRBAR); \ + pr->prlar.bits = READ_SYSREG(HPRLAR); \ + break; \ + } + +/* +* Armv8-R supports direct access and indirect access to the MPU regions through +* registers: +* - indirect access involves changing the MPU region selector, issuing an isb +* barrier and accessing the selected region through specific registers +* - direct access involves accessing specific registers that point to +* specific MPU regions, without changing the selector, avoiding the use of +* a barrier. +* For Arm32 the PR{B,L}AR<n>_ELx (for n=0..31) are used for direct access to the +* first 32 MPU regions. +* For MPU region numbered 32..255, one need to set the region number in PRSELR_ELx, +* followed by configuring PR{B,L}AR_ELx. +*/ +inline void prepare_selector (uint8_t *sel) +{ +uint8_t cur_sel = *sel; + +if ( cur_sel >0x1FU ) + { +WRITE_SYSREG (cur_sel,PRSELR_EL2 ); +isb (); + } +} + +void read_protection_region (pr_t *pr_read,uint8_t sel) +{ +prepare_selector (&sel); + +switch ( sel ) + { +GENERATE_READ_PR_REG_CASE (0 , pr_read); +GENERATE_READ_PR_REG_CASE (1 , pr_read); +GENERATE_READ_PR_REG_CASE (2 , pr_read); +GENERATE_READ_PR_REG_CASE (3 , pr_read); +GENERATE_READ_PR_REG_CASE (4 , pr_read); +GENERATE_READ_PR_REG_CASE (5 , pr_read); +GENERATE_READ_PR_REG_CASE (6 , pr_read); +GENERATE_READ_PR_REG_CASE (7 , pr_read); +GENERATE_READ_PR_REG_CASE (8 , pr_read); +GENERATE_READ_PR_REG_CASE (9 , pr_read); +GENERATE_READ_PR_REG_CASE (10 , pr_read); +GENERATE_READ_PR_REG_CASE (11 , pr_read); +GENERATE_READ_PR_REG_CASE (12 , pr_read); +GENERATE_READ_PR_REG_CASE (13 , pr_read); +GENERATE_READ_PR_REG_CASE (14 , pr_read); +GENERATE_READ_PR_REG_CASE (15 , pr_read); +GENERATE_READ_PR_REG_CASE (16 , pr_read); +GENERATE_READ_PR_REG_CASE (17 , pr_read); +GENERATE_READ_PR_REG_CASE (18 , pr_read); +GENERATE_READ_PR_REG_CASE (19 , pr_read); +GENERATE_READ_PR_REG_CASE (20 , pr_read); +GENERATE_READ_PR_REG_CASE (21 , pr_read); +GENERATE_READ_PR_REG_CASE (22 , pr_read);
xen/arch/arm/mpu/arm32/mm.c line 106
Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c new file +10
-0+GENERATE_READ_PR_REG_CASE (23 , pr_read); +GENERATE_READ_PR_REG_CASE (24 , pr_read); +GENERATE_READ_PR_REG_CASE (25 , pr_read); +GENERATE_READ_PR_REG_CASE (26 , pr_read); +GENERATE_READ_PR_REG_CASE (27 , pr_read); +GENERATE_READ_PR_REG_CASE (28 , pr_read); +GENERATE_READ_PR_REG_CASE (29 , pr_read); +GENERATE_READ_PR_REG_CASE (30 , pr_read); +GENERATE_READ_PR_REG_CASE (31 , pr_read); + GENERATE_READ_PR_REG_OTHERS(32 ... 255, pr_read);
This should be 32 ... 254 . Thanks Luca for pointing this out.
The max number of regions supported is 255 (not 256). It is the maximum value of HMPUIR.
- Ayan
Quoted 79 lines
xen/arch/arm/mpu/arm32/mm.c new file +59
-0+default : +BUG ();/* Can't happen */ +break ; + } +} + +void write_protection_region (const pr_t *pr_write,uint8_t sel) +{ +prepare_selector (&sel); + +switch ( sel ) + { +GENERATE_WRITE_PR_REG_CASE (0 , pr_write); +GENERATE_WRITE_PR_REG_CASE (1 , pr_write); +GENERATE_WRITE_PR_REG_CASE (2 , pr_write); +GENERATE_WRITE_PR_REG_CASE (3 , pr_write); +GENERATE_WRITE_PR_REG_CASE (4 , pr_write); +GENERATE_WRITE_PR_REG_CASE (5 , pr_write); +GENERATE_WRITE_PR_REG_CASE (6 , pr_write); +GENERATE_WRITE_PR_REG_CASE (7 , pr_write); +GENERATE_WRITE_PR_REG_CASE (8 , pr_write); +GENERATE_WRITE_PR_REG_CASE (9 , pr_write); +GENERATE_WRITE_PR_REG_CASE (10 , pr_write); +GENERATE_WRITE_PR_REG_CASE (11 , pr_write); +GENERATE_WRITE_PR_REG_CASE (12 , pr_write); +GENERATE_WRITE_PR_REG_CASE (13 , pr_write); +GENERATE_WRITE_PR_REG_CASE (14 , pr_write); +GENERATE_WRITE_PR_REG_CASE (15 , pr_write); +GENERATE_WRITE_PR_REG_CASE (16 , pr_write); +GENERATE_WRITE_PR_REG_CASE (17 , pr_write); +GENERATE_WRITE_PR_REG_CASE (18 , pr_write); +GENERATE_WRITE_PR_REG_CASE (19 , pr_write); +GENERATE_WRITE_PR_REG_CASE (20 , pr_write); +GENERATE_WRITE_PR_REG_CASE (21 , pr_write); +GENERATE_WRITE_PR_REG_CASE (22 , pr_write); +GENERATE_WRITE_PR_REG_CASE (23 , pr_write); +GENERATE_WRITE_PR_REG_CASE (24 , pr_write); +GENERATE_WRITE_PR_REG_CASE (25 , pr_write); +GENERATE_WRITE_PR_REG_CASE (26 , pr_write); +GENERATE_WRITE_PR_REG_CASE (27 , pr_write); +GENERATE_WRITE_PR_REG_CASE (28 , pr_write); +GENERATE_WRITE_PR_REG_CASE (29 , pr_write); +GENERATE_WRITE_PR_REG_CASE (30 , pr_write); +GENERATE_WRITE_PR_REG_CASE (31 , pr_write); + GENERATE_WRITE_PR_REG_OTHERS(32 ... 255, pr_write); +default : +BUG ();/* Can't happen */ +break ; + } +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/mpu/mm.c +0
-2@@ -39,7 +39,6 @@ static void __init __maybe_unused build_assertions(void)BUILD_BUG_ON (PAGE_SIZE !=SZ_4K ); } -#ifdef CONFIG_ARM_64 pr_t pr_of_addr (paddr_t base,paddr_t limit,unsigned int flags) {unsigned int attr_idx =PAGE_AI_MASK (flags);@@ -110,7 +109,6 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)return region; } -#endif /* CONFIG_ARM_64 */ void __init setup_mm (void ) {
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
In reply to Ayan Kumar HalderHi Ayan,
Quoted 63 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Enable
write_protection_region()for aarch32.v2 - 1. Enable access to protection regions from 0 - 255.
xen/arch/arm/include/asm/mpu.h | 2 - xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 165 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 2 - 4 files changed, 166 insertions(+), 4 deletions(-)create mode 100644
xen/arch/arm/mpu/arm32/mm.cxen/arch/arm/include/asm/mpu.h +0
-2@@ -25,7 +25,6 @@#ifndef __ASSEMBLY__ -#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. * @@ -85,7 +84,6 @@ static inline bool region_is_valid(const pr_t *pr) {return pr->prlar.reg.en; } -#endif /* CONFIG_ARM_64 */ #endif /* __ASSEMBLY__ */ xen/arch/arm/mpu/arm32/Makefile +0
-0@@ -1 +1,2 @@obj-y += domain-page.o
xen/arch/arm/mpu/arm32/Makefile +1
-0+obj-y += mm.oxen/arch/arm/mpu/arm32/mm.c new file +6
-0@@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/bug.h> +#include <xen/types.h> +#include <asm/mpu.h> +#include <asm/sysregs.h>
xen/arch/arm/mpu/arm32/mm.c line 16
Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c new file +10
-0+#include <asm/system.h> + +#define PRBAR_EL2_ (n) HPRBAR##n +#define PRLAR_EL2_ (n) HPRLAR##n + +#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR_EL2_(num)); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR_EL2_(num)); \
Maybe you don’t need '& ~MPU_REGION_RES0’ since your MPU_REGION_RES0 is zero, here and below
Quoted 26 lines
xen/arch/arm/mpu/arm32/mm.c new file +26
-0+break ; \ + } + +#define GENERATE_WRITE_PR_REG_OTHERS (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, HPRBAR); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, HPRLAR); \ + break; \ + } + +#define GENERATE_READ_PR_REG_CASE (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(PRBAR_EL2_(num)); \ + pr->prlar.bits = READ_SYSREG(PRLAR_EL2_(num)); \ + break; \ + } + +#define GENERATE_READ_PR_REG_OTHERS (num, pr) \ + case num: \ + { \ + pr->prbar.bits = READ_SYSREG(HPRBAR); \ + pr->prlar.bits = READ_SYSREG(HPRLAR); \ + break; \ + }
xen/arch/arm/mpu/arm32/mm.c line 52
Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c new file +10
-0+ +/* +* Armv8-R supports direct access and indirect access to the MPU regions through +* registers: +* - indirect access involves changing the MPU region selector, issuing an isb +* barrier and accessing the selected region through specific registers +* - direct access involves accessing specific registers that point to +* specific MPU regions, without changing the selector, avoiding the use of +* a barrier. +* For Arm32 the PR{B,L}AR<n>_ELx (for n=0..31) are used for direct access to the
Arm32 have PR{B,L}AR but it’s not EL2, you mean HPRBAR here and below
xen/arch/arm/mpu/arm32/mm.c line 54
Quoted 2 lines
xen/arch/arm/mpu/arm32/mm.c new file +2
-0+* first 32 MPU regions. +* For MPU region numbered 32..255, one need to set the region number in PRSELR_ELx,
32..254
and also maybe you can use HPRSELR instead of PRSELR_ELx
xen/arch/arm/mpu/arm32/mm.c line 61
Quoted 7 lines
xen/arch/arm/mpu/arm32/mm.c new file +7
-0+* followed by configuring PR{B,L}AR_ELx. +*/ +inline void prepare_selector (uint8_t *sel) +{ +uint8_t cur_sel = *sel; + +if ( cur_sel >0x1FU )
can we use 31 here? instead of the hex? It would be quicker to be read by a developer.
Quoted 35 lines
xen/arch/arm/mpu/arm32/mm.c new file +35
-0+ { +WRITE_SYSREG (cur_sel,PRSELR_EL2 ); +isb (); + } +} + +void read_protection_region (pr_t *pr_read,uint8_t sel) +{ +prepare_selector (&sel); + +switch ( sel ) + { +GENERATE_READ_PR_REG_CASE (0 , pr_read); +GENERATE_READ_PR_REG_CASE (1 , pr_read); +GENERATE_READ_PR_REG_CASE (2 , pr_read); +GENERATE_READ_PR_REG_CASE (3 , pr_read); +GENERATE_READ_PR_REG_CASE (4 , pr_read); +GENERATE_READ_PR_REG_CASE (5 , pr_read); +GENERATE_READ_PR_REG_CASE (6 , pr_read); +GENERATE_READ_PR_REG_CASE (7 , pr_read); +GENERATE_READ_PR_REG_CASE (8 , pr_read); +GENERATE_READ_PR_REG_CASE (9 , pr_read); +GENERATE_READ_PR_REG_CASE (10 , pr_read); +GENERATE_READ_PR_REG_CASE (11 , pr_read); +GENERATE_READ_PR_REG_CASE (12 , pr_read); +GENERATE_READ_PR_REG_CASE (13 , pr_read); +GENERATE_READ_PR_REG_CASE (14 , pr_read); +GENERATE_READ_PR_REG_CASE (15 , pr_read); +GENERATE_READ_PR_REG_CASE (16 , pr_read); +GENERATE_READ_PR_REG_CASE (17 , pr_read); +GENERATE_READ_PR_REG_CASE (18 , pr_read); +GENERATE_READ_PR_REG_CASE (19 , pr_read); +GENERATE_READ_PR_REG_CASE (20 , pr_read); +GENERATE_READ_PR_REG_CASE (21 , pr_read); +GENERATE_READ_PR_REG_CASE (22 , pr_read);
xen/arch/arm/mpu/arm32/mm.c line 106
Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c new file +10
-0+GENERATE_READ_PR_REG_CASE (23 , pr_read); +GENERATE_READ_PR_REG_CASE (24 , pr_read); +GENERATE_READ_PR_REG_CASE (25 , pr_read); +GENERATE_READ_PR_REG_CASE (26 , pr_read); +GENERATE_READ_PR_REG_CASE (27 , pr_read); +GENERATE_READ_PR_REG_CASE (28 , pr_read); +GENERATE_READ_PR_REG_CASE (29 , pr_read); +GENERATE_READ_PR_REG_CASE (30 , pr_read); +GENERATE_READ_PR_REG_CASE (31 , pr_read); + GENERATE_READ_PR_REG_OTHERS(32 ... 255, pr_read);
32 … 254 here and in the below.
Quoted 83 lines
xen/arch/arm/mpu/arm32/mm.c new file +59
-0+default : +BUG ();/* Can't happen */ +break ; + } +} + +void write_protection_region (const pr_t *pr_write,uint8_t sel) +{ +prepare_selector (&sel); + +switch ( sel ) + { +GENERATE_WRITE_PR_REG_CASE (0 , pr_write); +GENERATE_WRITE_PR_REG_CASE (1 , pr_write); +GENERATE_WRITE_PR_REG_CASE (2 , pr_write); +GENERATE_WRITE_PR_REG_CASE (3 , pr_write); +GENERATE_WRITE_PR_REG_CASE (4 , pr_write); +GENERATE_WRITE_PR_REG_CASE (5 , pr_write); +GENERATE_WRITE_PR_REG_CASE (6 , pr_write); +GENERATE_WRITE_PR_REG_CASE (7 , pr_write); +GENERATE_WRITE_PR_REG_CASE (8 , pr_write); +GENERATE_WRITE_PR_REG_CASE (9 , pr_write); +GENERATE_WRITE_PR_REG_CASE (10 , pr_write); +GENERATE_WRITE_PR_REG_CASE (11 , pr_write); +GENERATE_WRITE_PR_REG_CASE (12 , pr_write); +GENERATE_WRITE_PR_REG_CASE (13 , pr_write); +GENERATE_WRITE_PR_REG_CASE (14 , pr_write); +GENERATE_WRITE_PR_REG_CASE (15 , pr_write); +GENERATE_WRITE_PR_REG_CASE (16 , pr_write); +GENERATE_WRITE_PR_REG_CASE (17 , pr_write); +GENERATE_WRITE_PR_REG_CASE (18 , pr_write); +GENERATE_WRITE_PR_REG_CASE (19 , pr_write); +GENERATE_WRITE_PR_REG_CASE (20 , pr_write); +GENERATE_WRITE_PR_REG_CASE (21 , pr_write); +GENERATE_WRITE_PR_REG_CASE (22 , pr_write); +GENERATE_WRITE_PR_REG_CASE (23 , pr_write); +GENERATE_WRITE_PR_REG_CASE (24 , pr_write); +GENERATE_WRITE_PR_REG_CASE (25 , pr_write); +GENERATE_WRITE_PR_REG_CASE (26 , pr_write); +GENERATE_WRITE_PR_REG_CASE (27 , pr_write); +GENERATE_WRITE_PR_REG_CASE (28 , pr_write); +GENERATE_WRITE_PR_REG_CASE (29 , pr_write); +GENERATE_WRITE_PR_REG_CASE (30 , pr_write); +GENERATE_WRITE_PR_REG_CASE (31 , pr_write); + GENERATE_WRITE_PR_REG_OTHERS(32 ... 255, pr_write); +default : +BUG ();/* Can't happen */ +break ; + } +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/mpu/mm.c +0
-2@@ -39,7 +39,6 @@ static void __init __maybe_unused build_assertions(void)BUILD_BUG_ON (PAGE_SIZE !=SZ_4K ); } -#ifdef CONFIG_ARM_64 pr_t pr_of_addr (paddr_t base,paddr_t limit,unsigned int flags) {unsigned int attr_idx =PAGE_AI_MASK (flags);@@ -110,7 +109,6 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)return region; } -#endif /* CONFIG_ARM_64 */ void __init setup_mm (void ) {Signature · 1 line
2.25.1
Cheers,
Luca
Re: [PATCH v3 6/6] arm/mpu: Enable read/write to protection regions for arm32
In reply to Ayan Kumar HalderHi Ayan,
Quoted 63 lines · Ayan Kumar Halder
Define
prepare_selector(),read_protection_region()andwrite_protection_region()for arm32. Also, define GENERATE_{READ/WRITE}_PR_REG_OTHERS to access MPU regions from 32 to 255.Enable pr_{get/set}_{base/limit}(),
region_is_valid()for arm32. Enablepr_of_addr()for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Enable
write_protection_region()for aarch32.v2 - 1. Enable access to protection regions from 0 - 255.
xen/arch/arm/include/asm/mpu.h | 2 - xen/arch/arm/mpu/arm32/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 165 ++++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 2 - 4 files changed, 166 insertions(+), 4 deletions(-)create mode 100644
xen/arch/arm/mpu/arm32/mm.cxen/arch/arm/include/asm/mpu.h +0
-2@@ -25,7 +25,6 @@#ifndef __ASSEMBLY__ -#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. * @@ -85,7 +84,6 @@ static inline bool region_is_valid(const pr_t *pr) {return pr->prlar.reg.en; } -#endif /* CONFIG_ARM_64 */ #endif /* __ASSEMBLY__ */ xen/arch/arm/mpu/arm32/Makefile +0
-0@@ -1 +1,2 @@obj-y += domain-page.o
xen/arch/arm/mpu/arm32/Makefile +1
-0+obj-y += mm.oxen/arch/arm/mpu/arm32/mm.c new file +6
-0@@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/bug.h> +#include <xen/types.h> +#include <asm/mpu.h> +#include <asm/sysregs.h>
xen/arch/arm/mpu/arm32/mm.c line 16
Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c new file +10
-0+#include <asm/system.h> + +#define PRBAR_EL2_ (n) HPRBAR##n +#define PRLAR_EL2_ (n) HPRLAR##n + +#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ + case num: \ + { \ + WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR_EL2_(num)); \ + WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR_EL2_(num)); \
I was also thinking that in this file now you can use directly HPR{B,L}AR<N> instead of PR{B,L}AR<N>_EL2
Cheers,
Luca