xen/arm: AArch32-V8R: Add MPU register definitions
PATCH v2 1/1 xen/arm: AArch32-V8R: Add MPU register definitions
Add the definitions for HPRBAR<0..31>, HPRLAR<0..31> and HPRENR. The definitions are taken from ARM DDI 0568A.c ID110520, E2.2.3 HPRBAR<n>, E2.2.4 HPRENR and E2.2.6 HPRLAR<n>.
Introduce pr_t typedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32-V8R architecture. This is the arm32 equivalent of
"arm/mpu: Introduce MPU memory region map structure".
Few differences worth noting:-
1. The XN in HPRBAR is 1 bit in Arm32 (unlike 2 bits in Arm64).
2. PRSELR_EL2 is not used to access HPRBAR<0..31> and HPRLAR<0..31>.
Introduce macros PR{B,L}AR_EL2_(num) to generate alias for the sysregs.
Also, took the opportunity to fix the register definition of HPRLAR.
---
Changes from :-
v1 - 1. Introduce macros for PR{B,L}AR_EL2_(num). Similar macros need to be defined for arm64 as well.
2. Some style fixes
Comments not addressed
1. Renaming of PRBAR_EL2_XN if needed.
2. Using res0 for ns.
This patch should be applied after
"[PATCH v3 0/7] First chunk for Arm R82 and MPU support" in order to enable compilation for AArch32 and macros need to be defined for Arm64 as well.
xen/arch/arm/include/asm/arm32/mpu.h | 59 +++++++++++++++++++++ xen/arch/arm/include/asm/mpu.h | 4 ++ xen/arch/arm/include/asm/mpu/cpregs.h | 75 ++++++++++++++++++++++++++- xen/arch/arm/include/asm/page.h | 7 ++- xen/arch/arm/mpu/mm.c | 14 +++-- 5 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 xen/arch/arm/include/asm/arm32/mpu.h
xen/arch/arm/include/asm/arm32/mpu.h new file +59 -0
@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* mpu.h: Arm Memory Protection Unit definitions for aarch64. +*/ + +#ifndef __ARM_ARM32_MPU_H +#define __ARM_ARM32_MPU_H + +#define XN_EL2_ENABLED 0x1 + +#ifndef __ASSEMBLY__ + +/* Hypervisor Protection Region Base Address Register */ +typedef union { +struct { +unsigned int xn:1 ;/* Execute-Never */ +unsigned int ap:2 ;/* Acess Permission */ +unsigned int sh:2 ;/* Sharebility */ +unsigned int res0:1 ;/* Reserved as 0 */ +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 */ +/* +* There is no actual ns bit in hardware. It is used here for +* compatibility with Arm64 code. Thus, we are reusing a res0 bit for ns. +*/ +unsigned int ns:1 ;/* Reserved 0 by hardware */ +unsigned int res0:1 ;/* Reserved 0 by hardware */ +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ; + +/* Protection Region */ +typedef struct { +prbar_t prbar; +prlar_t prlar; +uint64_t p2m_type;/* Used to store p2m types. */ +}pr_t ; + +#endif /* __ASSEMBLY__ */ + +#endif /* __ARM_ARM32_MPU_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/include/asm/mpu.h +4 -0
@@ -8,8 +8,12 @@#if defined(CONFIG_ARM_64 )# include <asm/arm64/mpu.h> +#elif defined(CONFIG_ARM_32 ) +# include <asm/arm32/mpu.h> #endif +#define PRENR_MASK GENMASK(31, 0) +#define MPU_REGION_SHIFT 6#define MPU_REGION_ALIGN (_AC(1, UL) << MPU_REGION_SHIFT)#define MPU_REGION_MASK (~(MPU_REGION_ALIGN - 1))
xen/arch/arm/include/asm/mpu/cpregs.h +74 -1
92 lines not on this page · raw message
xen/arch/arm/include/asm/page.h +6 -1
@@ -96,7 +96,8 @@/* * Layout of the flags used for updating MPU memory region attributes * [0:2] Memory attribute Index -* [3:4] Execute Never +* [3:4] Execute Never // For ARM_64 +* [3] Execute Never // For ARM_32 * [5:6] Access Permission * [7] Region Present */
@@ -105,7 +106,11 @@#define _PAGE_AP_BIT 5#define _PAGE_PRESENT_BIT 7#define _PAGE_AI (7U << _PAGE_AI_BIT) +#ifdef CONFIG_ARM_32 +#define _PAGE_XN (1U << _PAGE_XN_BIT) +#else #define _PAGE_XN (2U << _PAGE_XN_BIT) +#endif #define _PAGE_RO (2U << _PAGE_AP_BIT)#define _PAGE_PRESENT (1U << _PAGE_PRESENT_BIT)#define PAGE_AI_MASK (x) (((x) >> _PAGE_AI_BIT) & 0x7U)
xen/arch/arm/mpu/mm.c +10 -4
@@ -31,16 +31,16 @@ pr_t xen_mpumap[MAX_MPU_REGIONS];#define GENERATE_WRITE_PR_REG_CASE (num, pr) \ case num: \ { \ - WRITE_SYSREG(pr->prbar.bits & ~MPU_REGION_RES0, PRBAR##num##_EL2); \ - WRITE_SYSREG(pr->prlar.bits & ~MPU_REGION_RES0, PRLAR##num##_EL2); \ + 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##num##_EL2); \ - pr->prlar.bits = READ_SYSREG(PRLAR##num##_EL2); \ + pr->prbar.bits = READ_SYSREG(PRBAR_EL2_(num)); \ + pr->prlar.bits = READ_SYSREG(PRLAR_EL2_(num)); \ break; \ }
@@ -56,6 +56,11 @@ static void __init __maybe_unused build_assertions(void)static void prepare_selector (uint8_t *sel) { +/* +* In Arm32, one can access PRBAR<0..31>_EL2 and PRLAR<0..31>_EL2 without +* the need to configure PRSELR_EL2. +*/ +#ifdef CONFIG_ARM_64 uint8_t cur_sel = *sel;/* * {read,write}_protection_region works using the direct access to the 0..15
@@ -69,6 +74,7 @@ static void prepare_selector(uint8_t *sel) isb(); } *sel = *sel &0xFU ; +#endif }/*
Signature · 1 line
2.25.1
Hi Ayan,
Quoted 21 lines · Ayan Kumar Halder
Add the definitions for HPRBAR<0..31>, HPRLAR<0..31> and HPRENR. The definitions are taken from ARM DDI
0568A.cID110520, E2.2.3 HPRBAR<n>, E2.2.4 HPRENR and E2.2.6 HPRLAR<n>.Introduce
pr_ttypedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32-V8R architecture. This is the arm32 equivalent of
"arm/mpu: Introduce MPU memory region map structure".Few differences worth noting:-
1. The XN in HPRBAR is 1 bit in Arm32 (unlike 2 bits in Arm64).
2.PRSELR_EL2is not used to access HPRBAR<0..31> and HPRLAR<0..31>.Introduce macros PR{B,L}AR_EL2_(num) to generate alias for the sysregs.
Also, took the opportunity to fix the register definition of HPRLAR.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-
Quoted 7 lines
v1 - 1. Introduce macros for PR{B,L}AR_EL2_(num). Similar macros need to be defined for arm64 as well.
2. Some style fixesComments not addressed
1. Renaming ofPRBAR_EL2_XNif needed.
2. Using res0 for ns.
Why are you rushing sending a new version that doesn't address most of the comments when ...
Quoted 4 lines
This patch should be applied after
"[PATCH v3 0/7] First chunk for Arm R82 and MPU support" in order to enable compilation for AArch32 and macros need to be defined for Arm64 as well.
... this depends on a patch still under review? This is not a very good use of reviewers time.
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 27 lines · Ayan Kumar Halder
Quoted 25 lines
Add the definitions for HPRBAR<0..31>, HPRLAR<0..31> and HPRENR. The definitions are taken from ARM DDI
0568A.cID110520, E2.2.3 HPRBAR<n>, E2.2.4 HPRENR and E2.2.6 HPRLAR<n>.Introduce
pr_ttypedef which is a structure having the prbar and prlar members, each being structured as the registers of the AArch32-V8R architecture. This is the arm32 equivalent of
"arm/mpu: Introduce MPU memory region map structure".Few differences worth noting:-
1. The XN in HPRBAR is 1 bit in Arm32 (unlike 2 bits in Arm64).
2.PRSELR_EL2is not used to access HPRBAR<0..31> and HPRLAR<0..31>.Introduce macros PR{B,L}AR_EL2_(num) to generate alias for the sysregs.
Also, took the opportunity to fix the register definition of HPRLAR.
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from :-v1 - 1. Introduce macros for PR{B,L}AR_EL2_(num). Similar macros need to be defined for arm64 as well.
2. Some style fixes
Quoted 5 lines
Quoted 3 lines
Comments not addressed
1. Renaming ofPRBAR_EL2_XNif needed.
2. Using res0 for ns.Why are you rushing sending a new version that doesn't address most of the comments when ...
Sorry, as there were lot of comments, so I want to show the proposed changes. I should probably have waited until we are aligned on all the changes in v1.
Quoted 7 lines
Quoted 5 lines
This patch should be applied after
"[PATCH v3 0/7] First chunk for Arm R82 and MPU support" in order to enable compilation for AArch32 and macros need to be defined for Arm64 as well.... this depends on a patch still under review? This is not a very good use of reviewers time.
Ack.
- Ayan
Quoted 3 lines
Cheers,