Enable R52 support for the first chunk of MPU support
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".
Ayan Kumar Halder (3):
arm/mpu: Introduce MPU memory region map structure arm/mpu: Provide and populate MPU C data structures arm/mpu: Provide access to the MPU region from the C code
xen/arch/arm/arm32/asm-offsets.c | 6 ++ xen/arch/arm/arm32/mpu/head.S | 57 +++++++++++++++++++ xen/arch/arm/include/asm/arm32/mpu.h | 30 ++++++++-- xen/arch/arm/include/asm/arm64/mpu.h | 6 -- xen/arch/arm/include/asm/mpu.h | 8 ++- xen/arch/arm/include/asm/mpu/cpregs.h | 72 +++++++++++++++++++++++- xen/arch/arm/include/asm/mpu/regions.inc | 8 ++- xen/arch/arm/mpu/mm.c | 33 +++++++++-- 8 files changed, 201 insertions(+), 19 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 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.
Move pr_t definition to common code.
Also, enclose xn_0 within ARM64 as it is not present for ARM32.
--- xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)
xen/arch/arm/include/asm/arm32/mpu.h +25 -5
@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__ -/* MPU Protection Region */ -typedef struct { -uint32_t prbar; -uint32_t prlar; -}pr_t ; +#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 ;/* Acess Permission */ +unsigned long ro:1 ;/* Access Permission AP[1] */ +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 */ +unsigned int res0:2 ;/* Reserved 0 by hardware */ +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ;#endif /* __ASSEMBLY__ */
xen/arch/arm/include/asm/arm64/mpu.h +0 -6
@@ -34,12 +34,6 @@ typedef union {uint64_t bits; } prlar_t; -/* MPU Protection Region */ -typedef struct { -prbar_t prbar; -prlar_t prlar; -}pr_t ; -#endif /* __ASSEMBLY__ */ #endif /* ARM_ARM64_MPU_H */
xen/arch/arm/include/asm/mpu.h +6 -0
@@ -25,6 +25,12 @@#ifndef __ASSEMBLY__ +/* MPU Protection Region */ +typedef struct { +prbar_t prbar; +prlar_t prlar; +}pr_t ; +#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region.
xen/arch/arm/mpu/mm.c +2 -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_ARM64 .xn_0 =0 , +#endif .xn =PAGE_XN_MASK (flags), .ap_0 =0 , .ro =PAGE_RO_MASK (flags)
Signature · 1 line
2.25.1
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Hi Ayan,
Quoted 31 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-4@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__ -/* MPU Protection Region */ -typedef struct { - uint32_t prbar; - uint32_t prlar;
xen/arch/arm/include/asm/arm32/mpu.h line 16
Quoted 10 lines
xen/arch/arm/include/asm/arm32/mpu.h +9
-1-} pr_t; +#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; /* Acess Permission */ + unsigned long ro:1; /* Access Permission AP[1] */ + unsigned int sh:2; /* Sharebility */
Typo: Sharebility -> Shareability.
Also, from the patch the comments feels not aligned, is that the case?
Quoted 24 lines
xen/arch/arm/include/asm/arm32/mpu.h +16
-0+ 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 */ +unsigned int res0:2 ;/* Reserved 0 by hardware */ +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ;#endif /* __ASSEMBLY__ */ xen/arch/arm/include/asm/arm64/mpu.h +0
-0
xen/arch/arm/include/asm/arm64/mpu.h typedef union { · line 41
Quoted 8 lines
xen/arch/arm/include/asm/arm64/mpu.h +0
-5@@ -34,12 +34,6 @@ typedef union {uint64_t bits; } prlar_t; -/* MPU Protection Region */ -typedef struct { -prbar_t prbar; -prlar_t prlar; -}pr_t ;
I’m not sure I would do this, at some point there will be the transient flags and p2m type and we know arm32 will need to store them in pr_t as additional members, instead arm64 will store them as part of prbar/prlar using the not used space (without writing them in the HW registers)
Quoted 38 lines
xen/arch/arm/include/asm/arm64/mpu.h +0
-1-#endif /* __ASSEMBLY__ */ #endif /* ARM_ARM64_MPU_H */ xen/arch/arm/include/asm/mpu.h +6
-0@@ -25,6 +25,12 @@#ifndef __ASSEMBLY__ +/* MPU Protection Region */ +typedef struct { +prbar_t prbar; +prlar_t prlar; +}pr_t ; +#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. xen/arch/arm/mpu/mm.c +2
-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_ARM64 .xn_0 =0 , +#endif .xn =PAGE_XN_MASK (flags), .ap_0 =0 , .ro =PAGE_RO_MASK (flags)Signature · 1 line
2.25.1
Cheers,
Luca
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 28 lines
Quoted 28 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-0@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__
Quoted 15 lines
Quoted 4 lines
xen/arch/arm/include/asm/arm32/mpu.h +0
-4-/* MPU Protection Region */ -typedef struct { - uint32_t prbar; - uint32_t prlar;xen/arch/arm/include/asm/arm32/mpu.h line 16
Quoted 10 lines
xen/arch/arm/include/asm/arm32/mpu.h +9
-1-} pr_t; +#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; /* Acess Permission */ + unsigned long ro:1; /* Access Permission AP[1] */ + unsigned int sh:2; /* Sharebility */Typo: Sharebility -> Shareability.
Ack
Quoted 2 lines
Also, from the patch the comments feels not aligned, is that the case?
When you apply the patch, the comments look aligned (in the codebase). Does it look the same for you ?
Quoted 28 lines
Quoted 28 lines
xen/arch/arm/include/asm/arm32/mpu.h +16
-0+ 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 */ +unsigned int res0:2 ;/* Reserved 0 by hardware */ +unsigned int limit:26 ;/* Limit Address */ + } reg; +uint32_t bits; +}prlar_t ;#endif /* __ASSEMBLY__ */ xen/arch/arm/include/asm/arm64/mpu.h +0
-0@@ -34,12 +34,6 @@ typedef union {uint64_t bits; } prlar_t;
Quoted 9 lines
xen/arch/arm/include/asm/arm64/mpu.h typedef union { · line 41
Quoted 5 lines
xen/arch/arm/include/asm/arm64/mpu.h +0
-5-/* MPU Protection Region */ -typedef struct { -prbar_t prbar; -prlar_t prlar; -}pr_t ;I’m not sure I would do this, at some point there will be the transient flags and p2m type and we know arm32 will need to store them in
pr_tas additional members, instead arm64 will store them as part of prbar/prlar using the not used space (without writing them in the HW registers)
Ah I see. Ok, I will keep them separate as it is.
- Ayan
Quoted 43 lines
Quoted 39 lines
xen/arch/arm/include/asm/arm64/mpu.h +0
-1-#endif /* __ASSEMBLY__ */ #endif /* ARM_ARM64_MPU_H */ xen/arch/arm/include/asm/mpu.h +6
-0@@ -25,6 +25,12 @@#ifndef __ASSEMBLY__ +/* MPU Protection Region */ +typedef struct { +prbar_t prbar; +prlar_t prlar; +}pr_t ; +#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. xen/arch/arm/mpu/mm.c +2
-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_ARM64 .xn_0 =0 , +#endif .xn =PAGE_XN_MASK (flags), .ap_0 =0 , .ro =PAGE_RO_MASK (flags)Signature · 1 line
2.25.1Cheers,
Luca
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Hi Ayan,
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 16
Quoted 7 lines
xen/arch/arm/include/asm/arm32/mpu.h +7
-0+/* Hypervisor Protection Region Base Address Register */ +typedef union { + struct { + unsigned int xn:1; /* Execute-Never */ + unsigned int ap_0:1; /* Acess Permission */ + unsigned long ro:1; /* Access Permission AP[1] */ + unsigned int sh:2; /* Sharebility */Typo: Sharebility -> Shareability.
Quoted 4 lines
Ack
Quoted 2 lines
Also, from the patch the comments feels not aligned, is that the case?
When you apply the patch, the comments look aligned (in the codebase). Does it look the same for you ?
I didn’t apply the patch, ok then it’s just in my client I see it not aligned, sorry for the noise!
Cheers,
Luca
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
In reply to Ayan Kumar HalderQuoted 22 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-0
xen/arch/arm/include/asm/arm32/mpu.h line 8
Quoted 9 lines
xen/arch/arm/include/asm/arm32/mpu.h +1
-5@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__ -/* MPU Protection Region */ -typedef struct { -uint32_t prbar; -uint32_t prlar; -}pr_t ; +#define MPU_REGION_RES0 0x0
The name of the macro does not make a lot of sense in AArch32 context and can create a confusion for the reader.
xen/arch/arm/include/asm/arm32/mpu.h line 14
Quoted 6 lines
xen/arch/arm/include/asm/arm32/mpu.h +6
-0+ +/* Hypervisor Protection Region Base Address Register */ +typedef union { + struct { + unsigned int xn:1; /* Execute-Never */ + unsigned int ap_0:1; /* Acess Permission */
If you write AP[1] below, I would expect here AP[0] Also s/acess/access/
xen/arch/arm/include/asm/arm32/mpu.h line 17
Quoted 3 lines
xen/arch/arm/include/asm/arm32/mpu.h +3
-0+ unsigned long ro:1; /* Access Permission AP[1] */ + unsigned int sh:2; /* Sharebility */ + unsigned int res0:1; /* Reserved as 0 */
Here your comment for RES0 (which IMO could be just RES0) does not match...
xen/arch/arm/include/asm/arm32/mpu.h line 28
Quoted 11 lines
xen/arch/arm/include/asm/arm32/mpu.h +11
-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 */ + unsigned int res0:2; /* Reserved 0 by hardware */
this one. I don't think you need to explain what RES0 means.
~Michal
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Hi Michal,
Quoted 27 lines · Michal
Quoted 25 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-0@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__
Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 8
Quoted 6 lines
xen/arch/arm/include/asm/arm32/mpu.h +1
-5-/* MPU Protection Region */ -typedef struct { -uint32_t prbar; -uint32_t prlar; -}pr_t ; +#define MPU_REGION_RES0 0x0The name of the macro does not make a lot of sense in AArch32 context and can create a confusion for the reader.
I know, but I want to avoid introducing ifdef or have separate implementation (for arm32 and arm64) for the following
Refer xen/arch/arm/include/asm/mpu.h
static inline void pr_set_base(pr_t *pr, paddr_t base)
{
pr->prbar.reg.base = ((base & ~MPU_REGION_RES0) >> MPU_REGION_SHIFT); }
Let me know your preference.
Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 14
Quoted 7 lines
xen/arch/arm/include/asm/arm32/mpu.h +6
-0+ +/* Hypervisor Protection Region Base Address Register */ +typedef union { + struct { + unsigned int xn:1; /* Execute-Never */ + unsigned int ap_0:1; /* Acess Permission */If you write AP[1] below, I would expect here AP[0]
Again same reason as before, let me know if you want to have additional ifdef in pr_of_addr() or separate functions for arm32 and arm64
pr_t pr_of_addr(...)
{...
prbar = (prbar_t) {
.reg = {
#ifdef CONFIG_ARM64
.xn_0 = 0,
#endif
.xn = PAGE_XN_MASK(flags),
.ap_0 = 0,
.ro = PAGE_RO_MASK(flags)
}};
...
}
Quoted 1 line
Also s/acess/access/
Ack.
Quoted 5 lines
xen/arch/arm/include/asm/arm32/mpu.h line 17
Quoted 4 lines
xen/arch/arm/include/asm/arm32/mpu.h +3
-0+ unsigned long ro:1; /* Access Permission AP[1] */ + unsigned int sh:2; /* Sharebility */ + unsigned int res0:1; /* Reserved as 0 */Here your comment for RES0 (which IMO could be just RES0) does not match...
I will remove the comment here and ..
Quoted 13 lines
xen/arch/arm/include/asm/arm32/mpu.h line 28
Quoted 12 lines
xen/arch/arm/include/asm/arm32/mpu.h +11
-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 */ + unsigned int res0:2; /* Reserved 0 by hardware */this one. I don't think you need to explain what RES0 means.
here.
- Ayan
Quoted 3 lines
~Michal
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Quoted 42 lines · Ayan Kumar Halder
Hi Michal,
Quoted 27 lines · Michal
Quoted 25 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-0@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 8
Quoted 6 lines
xen/arch/arm/include/asm/arm32/mpu.h +1
-5-/* MPU Protection Region */ -typedef struct { -uint32_t prbar; -uint32_t prlar; -}pr_t ; +#define MPU_REGION_RES0 0x0The name of the macro does not make a lot of sense in AArch32 context and can create a confusion for the reader.
I know, but I want to avoid introducing ifdef or have separate implementation (for arm32 and arm64) for the following
Quoted 8 lines
Refer
xen/arch/arm/include/asm/mpu.hstatic inline void
pr_set_base(pr_t *pr, paddr_t base)
{
pr->prbar.reg.base= ((base & ~MPU_REGION_RES0) >>MPU_REGION_SHIFT);
}Let me know your preference.
I did not mean #ifdef-ing. I was more like suggesting to use a different macro name that would be more meaningful than this one.
Quoted 10 lines
Quoted 9 lines
xen/arch/arm/include/asm/arm32/mpu.h line 14
Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h +6
-0+ +/* Hypervisor Protection Region Base Address Register */ +typedef union { + struct { + unsigned int xn:1; /* Execute-Never */ + unsigned int ap_0:1; /* Acess Permission */If you write AP[1] below, I would expect here AP[0]
Quoted 2 lines
Again same reason as before, let me know if you want to have additional ifdef in
pr_of_addr()or separate functions for arm32 and arm64
I don't understand. My comment was only about changing comment to say /* Access Permission AP[0] */ because below you have a comment with AP[1].
~Michal
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Hi Michal,
Quoted 44 lines · Michal
Quoted 42 lines · Ayan Kumar Halder
Hi Michal,
Quoted 26 lines · Michal
Quoted 25 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/mpu.h | 30 +++++++++++++++++++++++----- xen/arch/arm/include/asm/arm64/mpu.h | 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +0
-0@@ -5,11 +5,31 @@#ifndef __ASSEMBLY__Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 8
Quoted 6 lines
xen/arch/arm/include/asm/arm32/mpu.h +1
-5-/* MPU Protection Region */ -typedef struct { -uint32_t prbar; -uint32_t prlar; -}pr_t ; +#define MPU_REGION_RES0 0x0The name of the macro does not make a lot of sense in AArch32 context and can create a confusion for the reader.
I know, but I want to avoid introducing ifdef or have separate implementation (for arm32 and arm64) for the following
Refer
xen/arch/arm/include/asm/mpu.h
Quoted 8 lines
Quoted 6 lines
static inline void
pr_set_base(pr_t *pr, paddr_t base)
{
pr->prbar.reg.base= ((base & ~MPU_REGION_RES0) >>MPU_REGION_SHIFT);
}Let me know your preference.
I did not mean #ifdef-ing. I was more like suggesting to use a different macro name that would be more meaningful than this one.
Now I understand you. However, I can't thing of a better name to make it more meaningful.
I have added a comment on top. Is this helpful ?
/* Unlike arm64, there are no reserved 0 bits beyond base in prbar register */
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/arm32/mpu.h line 14
Quoted 7 lines
xen/arch/arm/include/asm/arm32/mpu.h +6
-0+ +/* Hypervisor Protection Region Base Address Register */ +typedef union { + struct { + unsigned int xn:1; /* Execute-Never */ + unsigned int ap_0:1; /* Acess Permission */If you write AP[1] below, I would expect here AP[0]
Quoted 4 lines
Quoted 2 lines
Again same reason as before, let me know if you want to have additional ifdef in
pr_of_addr()or separate functions for arm32 and arm64I don't understand. My comment was only about changing comment to say /* Access Permission AP[0] */ because below you have a comment with AP[1].
Ah makes sense now.
- Ayan
Quoted 3 lines
~Michal
Re: [PATCH v1 1/3] arm/mpu: Introduce MPU memory region map structure
Quoted 52 lines · Ayan Kumar Halder
Hi Michal,
Quoted 49 lines · Michal
Quoted 47 lines · Ayan Kumar Halder
Hi Michal,
Quoted 19 lines · Michal
Quoted 18 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.Move
pr_tdefinition to common code.
Also, enclosexn_0within ARM64 as it is not present for ARM32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/mpu.h| 30
+++++++++++++++++++++++-----
xen/arch/arm/include/asm/arm64/mpu.h| 6 ------ xen/arch/arm/include/asm/mpu.h | 6 ++++++ xen/arch/arm/mpu/mm.c | 2 ++4 files changed, 33 insertions(+), 11 deletions(-)Quoted 14 lines
xen/arch/arm/include/asm/arm32/mpu.h line 8
Quoted 12 lines
xen/arch/arm/include/asm/arm32/mpu.h +0
-0@@ -5,11 +5,31 @@ #ifndef __ASSEMBLY__-/* MPU Protection Region */
xen/arch/arm/include/asm/arm32/mpu.h +1
-4-typedef struct { - uint32_t prbar; - uint32_t prlar; -}pr_t ; +#define MPU_REGION_RES0 0x0The name of the macro does not make a lot of sense in AArch32 context and can create a confusion for the reader.
I know, but I want to avoid introducing ifdef or have separate implementation (for arm32 and arm64) for the following
Refer
xen/arch/arm/include/asm/mpu.hstatic inline void
pr_set_base(pr_t *pr, paddr_t base)
{
pr->prbar.reg.base= ((base & ~MPU_REGION_RES0) >>MPU_REGION_SHIFT); }Let me know your preference.
Quoted 8 lines
Quoted 2 lines
I did not mean #ifdef-ing. I was more like suggesting to use a different macro name that would be more meaningful than this one.
Now I understand you. However, I can't thing of a better name to make it more meaningful.
I have added a comment on top. Is this helpful ?
/* Unlike arm64, there are no reserved 0 bits beyond base in prbar register */
/*
* Unlike arm64, there are no reserved 0 bits beyond base and limit bitfield in
* prbar and prlar registers respectively.
*/
- Ayan
PATCH 2/3 arm/mpu: Provide and populate MPU C data structures
In reply to Ayan Kumar HalderDo the arm32 equivalent initialization for commit id ca5df936c4.
--- xen/arch/arm/arm32/asm-offsets.c | 6 +++ xen/arch/arm/arm32/mpu/head.S | 57 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mpu/regions.inc | 8 +++- 3 files changed, 70 insertions(+), 1 deletion(-)
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/mpu/head.S +57 -0
75 lines not on this page · raw message
xen/arch/arm/include/asm/mpu/regions.inc +7 -1
@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */ .macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst] +.endm + +.macro invalidate_dcache_one reg + mcr CP32(\reg, DCIMVAC) .endm #endif
Signature · 1 line
2.25.1
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.
This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.
Quoted 30 lines
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/arm32/asm-offsets.c | 6 +++ xen/arch/arm/arm32/mpu/head.S | 57 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mpu/regions.inc | 8 +++- 3 files changed, 70 insertions(+), 1 deletion(-)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/mpu/head.S +0
-0
xen/arch/arm/arm32/mpu/head.S line 15
Quoted 6 lines
xen/arch/arm/arm32/mpu/head.S +3
-0@@ -10,6 +10,38 @@ #include <asm/mpu/regions.inc> #include <asm/page.h> +/* + * dcache_line_size - get the minimum D-cache line size from the CTR register. + */
I do think we should have a cache.S file to store cache related ops just like for Arm64.
Also, no need for multiline comment.
xen/arch/arm/arm32/mpu/head.S line 16
Quoted 1 line
xen/arch/arm/arm32/mpu/head.S +1
-0+ .macro dcache_line_size, reg, tmp1, tmp2
I would prefer to use the macro from Linux that uses one temporary register
xen/arch/arm/arm32/mpu/head.S line 17
Quoted 1 line
xen/arch/arm/arm32/mpu/head.S +1
-0+ mrc CP32(\reg, CTR) // read CTR
NIT: wrong comment style + wrong alignment
Quoted 31 lines
xen/arch/arm/arm32/mpu/head.S +27
-0+ ubfx \tmp1, \reg, #16, #4 // Extract DminLine (bits 19:16) into tmp1 + mov \tmp2, #1 + lsl \tmp2, \tmp2, \tmp1 // tmp2 = 2^DminLine + lsl \tmp2, \tmp2, #2 // tmp2 = 4 * 2^DminLine = cache line size in bytes + .endm + +/* + * __invalidate_dcache_area(addr, size) + * + * Ensure that the data held in the cache for the buffer is invalidated. + * + * - addr - start address of the buffer + * - size - size of the buffer + */ +FUNC(__invalidate_dcache_area) + dcache_line_size r2, r3, r4 + add r1, r0, r1 + sub r4, r2, #1 + bic r0, r0, r4 +1: mcr CP32(r0, DCIMVAC) /* invalidate D line / unified line */ + add r0, r0, r2 + cmp r0, r1 + blo 1b + dsb sy + ret +END(__invalidate_dcache_area) + /* * Set up the memory attribute type tables and enable EL2 MPU and data cache. * If the Background region is enabled, then the MPU uses the default memory
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 84
Quoted 4 lines
xen/arch/arm/arm32/mpu/head.S +1
-0@@ -49,6 +81,10 @@ FUNC(enable_boot_cpu_mm) mrc CP32(r5, MPUIR_EL2) and r5, r5, #NUM_MPU_REGIONS_MASK + ldr r0, =max_mpu_regions
Why ldr and not mov_w?
Quoted 13 lines
xen/arch/arm/arm32/mpu/head.S +6
-0+ str r5, [r0] + mcr CP32(r0, DCIMVAC) /* Invalidate cache for max_mpu_regions addr */ + /* x0: region sel */ mov r0, #0 /* Xen text section. */@@ -83,6 +119,27 @@ FUNC(enable_boot_cpu_mm) prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_DEVICE_PRBAR, attr_prlar=REGION_DEVICE_PRLAR #endif +zero_mpu: + /* Reset remaining MPU regions */ + cmp r0, r5
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 134
Quoted 10 lines
xen/arch/arm/arm32/mpu/head.S +10
-0+ beq out_zero_mpu + mov r1, #0 + mov r2, #1 + prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prlar=REGION_DISABLED_PRLAR + b zero_mpu + +out_zero_mpu: + /* Invalidate data cache for MPU data structures */ + mov r5, lr + ldr r0, =xen_mpumap_mask
Why not mov_w?
Quoted 16 lines
xen/arch/arm/arm32/mpu/head.S +8
-0+ mov r1, #XEN_MPUMAP_MASK_sizeof + bl __invalidate_dcache_area + + ldr r0, =xen_mpumap + mov r1, #XEN_MPUMAP_sizeof + bl __invalidate_dcache_area + mov lr, r5 + b enable_mpu END(enable_boot_cpu_mm)xen/arch/arm/include/asm/mpu/regions.inc +0
-0
xen/arch/arm/include/asm/mpu/regions.inc line 29
Quoted 7 lines
xen/arch/arm/include/asm/mpu/regions.inc +3
-1@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */ .macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst]
AFAIR there is STM instruction to do the same
xen/arch/arm/include/asm/mpu/regions.inc line 33
Quoted 4 lines
xen/arch/arm/include/asm/mpu/regions.inc +4
-0+.endm + +.macro invalidate_dcache_one reg + mcr CP32(\reg, DCIMVAC)
Why? You don't seem to use this macro
xen/arch/arm/include/asm/mpu/regions.inc line 36
Quoted 3 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0.endm #endif
~Michal
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
Hi Michal,
Quoted 6 lines · Michal
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.
We are following the same convention as Linux. IIRC this was updated because there was some collision with 10 characters in Linux (not sure if we have seen it in Xen yet).
[...]
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 29
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +3
-1.macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst]AFAIR there is STM instruction to do the same
AFAICT, one issue with stm is the ordering is forced by the instruction rather than the user. So \reg1 could be stored first.
I think it would be better to use "strd". It still has restriction
(the two registers need to have contiguous index). But I think that would be better if we want to reduce the number of instructions.
Cheers,
Quoted 13 lines
xen/arch/arm/include/asm/mpu/regions.inc line 33
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +4
-0+.endm + +.macro invalidate_dcache_one reg + mcr CP32(\reg, DCIMVAC)Why? You don't seem to use this macro
xen/arch/arm/include/asm/mpu/regions.inc line 36
Quoted 3 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0.endm #endif~Michal
Signature · 1 line
Julien Grall
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
Quoted 27 lines · Julien Grall
Hi Michal,
Quoted 6 lines · Michal
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.We are following the same convention as Linux. IIRC this was updated because there was some collision with 10 characters in Linux (not sure if we have seen it in Xen yet).
[...]
Quoted 4 lines
Quoted 4 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0Quoted 8 lines
Quoted 7 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */.macro
store_pairreg1, reg2, dst
- .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst]
+ add \dst, \dst, #4
+ str \reg2, [\dst]AFAIR there is STM instruction to do the same
Quoted 1 line
AFAICT, one issue with stm is the ordering is forced by the instruction rather than the user. So \reg1 could be stored first.
Sorry I meant \reg2.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
In reply to Julien GrallQuoted 30 lines · Julien Grall
Hi Michal,
Quoted 6 lines · Michal
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.We are following the same convention as Linux. IIRC this was updated because there was some collision with 10 characters in Linux (not sure if we have seen it in Xen yet).
[...]
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 29
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +3
-1.macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst]AFAIR there is STM instruction to do the same
Quoted 2 lines
AFAICT, one issue with stm is the ordering is forced by the instruction rather than the user. So \reg1 could be stored first.
Yes, I think it stores based on register number. So if you do {r2, r1} it will still store r1 first.
Quoted 4 lines
I think it would be better to use "strd". It still has restriction (the two registers need to have contiguous index). But I think that would be better if we want to reduce the number of instructions.
Ok
~Michal
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
In reply to Orzel, MichalHi Michal/Julien,
Quoted 5 lines · Michal
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.
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.
Use the macro definition for "dcache_line_size" from linux.
Does ^^^ read fine ?
Quoted 33 lines
Quoted 33 lines
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/arm32/asm-offsets.c | 6 +++ xen/arch/arm/arm32/mpu/head.S | 57 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mpu/regions.inc | 8 +++- 3 files changed, 70 insertions(+), 1 deletion(-)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/mpu/head.S +0
-0@@ -10,6 +10,38 @@ #include <asm/mpu/regions.inc> #include <asm/page.h>
Quoted 5 lines
xen/arch/arm/arm32/mpu/head.S line 15
Quoted 3 lines
xen/arch/arm/arm32/mpu/head.S +3
-0+/* + * dcache_line_size - get the minimum D-cache line size from the CTR register. + */I do think we should have a
cache.Sfile to store cache related ops just like for Arm64.
ok, I will introduce a new file.
Quoted 1 line
Also, no need for multiline comment.
ack.
Quoted 3 lines
xen/arch/arm/arm32/mpu/head.S line 16
Quoted 2 lines
xen/arch/arm/arm32/mpu/head.S +1
-0+ .macro dcache_line_size, reg, tmp1, tmp2I would prefer to use the macro from Linux that uses one temporary register
/*
* dcache_line_size - get the minimum D-cache line size from the CTR register
* on ARMv7.
*/
.macro dcache_line_size, reg, tmp
mrc p15, 0, \tmp, c0, c0, 1 /* read ctr */
lsr \tmp, \tmp, #16
and \tmp, \tmp, #0xf /* cache line size encoding */ mov \reg, #4 /* bytes per word */ mov \reg, \reg, lsl \tmp /* actual cache line size */ .endm
Quoted 3 lines
xen/arch/arm/arm32/mpu/head.S line 17
Quoted 2 lines
xen/arch/arm/arm32/mpu/head.S +1
-0+ mrc CP32(\reg, CTR) // read CTRNIT: wrong comment style + wrong alignment
yes, I should use /* ... */
Quoted 35 lines
Quoted 35 lines
xen/arch/arm/arm32/mpu/head.S +27
-0+ ubfx \tmp1, \reg, #16, #4 // Extract DminLine (bits 19:16) into tmp1 + mov \tmp2, #1 + lsl \tmp2, \tmp2, \tmp1 // tmp2 = 2^DminLine + lsl \tmp2, \tmp2, #2 // tmp2 = 4 * 2^DminLine = cache line size in bytes + .endm + +/* + * __invalidate_dcache_area(addr, size) + * + * Ensure that the data held in the cache for the buffer is invalidated. + * + * - addr - start address of the buffer + * - size - size of the buffer + */ +FUNC(__invalidate_dcache_area) + dcache_line_size r2, r3, r4 + add r1, r0, r1 + sub r4, r2, #1 + bic r0, r0, r4 +1: mcr CP32(r0, DCIMVAC) /* invalidate D line / unified line */ + add r0, r0, r2 + cmp r0, r1 + blo 1b + dsb sy + ret +END(__invalidate_dcache_area) + /* * Set up the memory attribute type tables and enable EL2 MPU and data cache. * If the Background region is enabled, then the MPU uses the default memory@@ -49,6 +81,10 @@ FUNC(enable_boot_cpu_mm) mrc CP32(r5, MPUIR_EL2) and r5, r5, #NUM_MPU_REGIONS_MASK
Quoted 2 lines
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 84
Quoted 1 line
xen/arch/arm/arm32/mpu/head.S +1
-0+ ldr r0, =max_mpu_regionsWhy ldr and not
mov_w?
mov_w r0, max_mpu_regions
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/arm32/mpu/head.S +3
-0+ str r5, [r0] + mcr CP32(r0, DCIMVAC) /* Invalidate cache for max_mpu_regions addr */ + /* x0: region sel */ mov r0, #0 /* Xen text section. */@@ -83,6 +119,27 @@ FUNC(enable_boot_cpu_mm) prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_DEVICE_PRBAR, attr_prlar=REGION_DEVICE_PRLAR #endif
Quoted 14 lines
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 134
Quoted 13 lines
xen/arch/arm/arm32/mpu/head.S +13
-0+zero_mpu: + /* Reset remaining MPU regions */ + cmp r0, r5 + beq out_zero_mpu + mov r1, #0 + mov r2, #1 + prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prlar=REGION_DISABLED_PRLAR + b zero_mpu + +out_zero_mpu: + /* Invalidate data cache for MPU data structures */ + mov r5, lr + ldr r0, =xen_mpumap_maskWhy not
mov_w?
mov_w r0, xen_mpumap_mask
Quoted 19 lines
Quoted 19 lines
xen/arch/arm/arm32/mpu/head.S +8
-0+ mov r1, #XEN_MPUMAP_MASK_sizeof + bl __invalidate_dcache_area + + ldr r0, =xen_mpumap + mov r1, #XEN_MPUMAP_sizeof + bl __invalidate_dcache_area + mov lr, r5 + b enable_mpu END(enable_boot_cpu_mm)xen/arch/arm/include/asm/mpu/regions.inc +0
-0@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 29
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +3
-1.macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst]AFAIR there is STM instruction to do the same
strd \reg1, \reg2, [\dst]
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 33
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +4
-0+.endm + +.macro invalidate_dcache_one reg + mcr CP32(\reg, DCIMVAC)Why? You don't seem to use this macro
oh, this can be removed.
- Ayan
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 36
Quoted 4 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0.endm #endif~Michal
Re: [PATCH v1 2/3] arm/mpu: Provide and populate MPU C data structures
Quoted 9 lines · Ayan Kumar Halder
Hi Michal/Julien,
Quoted 5 lines · Michal
Quoted 1 line · Ayan Kumar Halder
Do the arm32 equivalent initialization for commit id
ca5df936c4.This is not a good commit msg.
Also, we somewhat require passing 12 char long IDs.
Quoted 8 lines
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.Use the macro definition for "
dcache_line_size" from linux.Does ^^^ read fine ?
Yes, it certainly reads better.
~Michal
Quoted 169 lines
Quoted 34 lines
Quoted 34 lines
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/arm32/asm-offsets.c | 6 +++ xen/arch/arm/arm32/mpu/head.S | 57 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mpu/regions.inc | 8 +++- 3 files changed, 70 insertions(+), 1 deletion(-)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/mpu/head.S +0
-0@@ -10,6 +10,38 @@ #include <asm/mpu/regions.inc> #include <asm/page.h>Quoted 5 lines
xen/arch/arm/arm32/mpu/head.S line 15
Quoted 3 lines
xen/arch/arm/arm32/mpu/head.S +3
-0+/* + * dcache_line_size - get the minimum D-cache line size from the CTR register. + */I do think we should have a
cache.Sfile to store cache related ops just like for Arm64.ok, I will introduce a new file.
Quoted 1 line
Also, no need for multiline comment.
ack.
Quoted 3 lines
xen/arch/arm/arm32/mpu/head.S line 16
Quoted 2 lines
xen/arch/arm/arm32/mpu/head.S +1
-0+ .macro dcache_line_size, reg, tmp1, tmp2I would prefer to use the macro from Linux that uses one temporary register
/*
*dcache_line_size- get the minimum D-cache line size from the CTR
register
* on ARMv7.
*/
.macrodcache_line_size, reg, tmp
mrc p15, 0, \tmp, c0, c0, 1 /* read ctr */
lsr \tmp, \tmp, #16
and \tmp, \tmp, #0xf /* cache line size encoding */ mov \reg, #4 /* bytes per word */ mov \reg, \reg, lsl \tmp /* actual cache line size */ .endmQuoted 3 lines
xen/arch/arm/arm32/mpu/head.S line 17
Quoted 2 lines
xen/arch/arm/arm32/mpu/head.S +1
-0+ mrc CP32(\reg, CTR) // read CTRNIT: wrong comment style + wrong alignment
yes, I should use /* ... */
Quoted 35 lines
Quoted 35 lines
xen/arch/arm/arm32/mpu/head.S +27
-0+ ubfx \tmp1, \reg, #16, #4 // Extract DminLine (bits 19:16) into tmp1 + mov \tmp2, #1 + lsl \tmp2, \tmp2, \tmp1 // tmp2 = 2^DminLine + lsl \tmp2, \tmp2, #2 // tmp2 = 4 * 2^DminLine = cache line size in bytes + .endm + +/* + * __invalidate_dcache_area(addr, size) + * + * Ensure that the data held in the cache for the buffer is invalidated. + * + * - addr - start address of the buffer + * - size - size of the buffer + */ +FUNC(__invalidate_dcache_area) + dcache_line_size r2, r3, r4 + add r1, r0, r1 + sub r4, r2, #1 + bic r0, r0, r4 +1: mcr CP32(r0, DCIMVAC) /* invalidate D line / unified line */ + add r0, r0, r2 + cmp r0, r1 + blo 1b + dsb sy + ret +END(__invalidate_dcache_area) + /* * Set up the memory attribute type tables and enable EL2 MPU and data cache. * If the Background region is enabled, then the MPU uses the default memory@@ -49,6 +81,10 @@ FUNC(enable_boot_cpu_mm) mrc CP32(r5, MPUIR_EL2) and r5, r5, #NUM_MPU_REGIONS_MASKQuoted 2 lines
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 84
Quoted 1 line
xen/arch/arm/arm32/mpu/head.S +1
-0+ ldr r0, =max_mpu_regionsWhy ldr and not
mov_w?
mov_wr0,max_mpu_regionsQuoted 11 lines
Quoted 11 lines
xen/arch/arm/arm32/mpu/head.S +3
-0+ str r5, [r0] + mcr CP32(r0, DCIMVAC) /* Invalidate cache for max_mpu_regions addr */ + /* x0: region sel */ mov r0, #0 /* Xen text section. */@@ -83,6 +119,27 @@ FUNC(enable_boot_cpu_mm) prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_DEVICE_PRBAR, attr_prlar=REGION_DEVICE_PRLAR #endifQuoted 14 lines
xen/arch/arm/arm32/mpu/head.S FUNC(enable_boot_cpu_mm) · line 134
Quoted 13 lines
xen/arch/arm/arm32/mpu/head.S +13
-0+zero_mpu: + /* Reset remaining MPU regions */ + cmp r0, r5 + beq out_zero_mpu + mov r1, #0 + mov r2, #1 + prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prlar=REGION_DISABLED_PRLAR + b zero_mpu + +out_zero_mpu: + /* Invalidate data cache for MPU data structures */ + mov r5, lr + ldr r0, =xen_mpumap_maskWhy not
mov_w?
mov_wr0,xen_mpumap_maskQuoted 19 lines
Quoted 19 lines
xen/arch/arm/arm32/mpu/head.S +8
-0+ mov r1, #XEN_MPUMAP_MASK_sizeof + bl __invalidate_dcache_area + + ldr r0, =xen_mpumap + mov r1, #XEN_MPUMAP_sizeof + bl __invalidate_dcache_area + mov lr, r5 + b enable_mpu END(enable_boot_cpu_mm)xen/arch/arm/include/asm/mpu/regions.inc +0
-0@@ -24,7 +24,13 @@ #define XEN_MPUMAP_ENTRY_SHIFT 0x3 /* 8 byte structure */Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 29
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +3
-1.macro store_pair reg1, reg2, dst - .word 0xe7f000f0 /* unimplemented */ + str \reg1, [\dst] + add \dst, \dst, #4 + str \reg2, [\dst]AFAIR there is STM instruction to do the same
strd \reg1, \reg2, [\dst]
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 33
Quoted 5 lines
xen/arch/arm/include/asm/mpu/regions.inc +4
-0+.endm + +.macro invalidate_dcache_one reg + mcr CP32(\reg, DCIMVAC)Why? You don't seem to use this macro
oh, this can be removed.
- Ayan
Quoted 6 lines
xen/arch/arm/include/asm/mpu/regions.inc line 36
Quoted 4 lines
xen/arch/arm/include/asm/mpu/regions.inc +0
-0.endm #endif~Michal
PATCH 3/3 arm/mpu: Provide access to the MPU region from the C code
In reply to Ayan Kumar HalderEnable the helper functions defined in mpu/mm.c and asm/mpu.h for ARM32. Define the register definitions for HPRBAR{0..31} and HPRLAR{0..31}. One can directly access the first 32 MPU regions using the above registers without the use of PRSELR.
Also fix the register definition for HPRLAR.
--- xen/arch/arm/include/asm/mpu.h | 2 - xen/arch/arm/include/asm/mpu/cpregs.h | 72 ++++++++++++++++++++++++++- xen/arch/arm/mpu/mm.c | 31 ++++++++++-- 3 files changed, 98 insertions(+), 7 deletions(-)
xen/arch/arm/include/asm/mpu.h +0 -2
@@ -31,7 +31,6 @@ typedef struct {prlar_t prlar; } pr_t; -#ifdef CONFIG_ARM_64 /* * Set base address of MPU protection region. *
@@ -91,7 +90,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/include/asm/mpu/cpregs.h +71 -1
87 lines not on this page · raw message
xen/arch/arm/mpu/mm.c +27 -4
@@ -40,7 +40,10 @@ pr_t __cacheline_aligned __section(".data") xen_mpumap[MAX_MPU_REGION_NR];#define PRBAR_EL2_ (n) PRBAR##n##_EL2#define PRLAR_EL2_ (n) PRLAR##n##_EL2 -#endif /* CONFIG_ARM_64 */ +#else /* CONFIG_ARM_64 */ +#define PRBAR_EL2_ (n) HPRBAR##n +#define PRLAR_EL2_ (n) HPRLAR##n +#endif /* !CONFIG_ARM_64 */ #define GENERATE_WRITE_PR_REG_CASE (num, pr) \ case num: \
@@ -68,7 +71,6 @@ static void __init __maybe_unused build_assertions(void)BUILD_BUG_ON (PAGE_SIZE !=SZ_4K ); } -#ifdef CONFIG_ARM_64 /* * Armv8-R supports direct access and indirect access to the MPU regions through * registers:
@@ -85,6 +87,7 @@ static void __init __maybe_unused build_assertions(void)*/ static void prepare_selector (uint8_t *sel) { +#ifdef CONFIG_ARM_64 uint8_t cur_sel = *sel;/*
@@ -98,7 +101,8 @@ static void prepare_selector(uint8_t *sel)WRITE_SYSREG (cur_sel,PRSELR_EL2 ); isb(); } - *sel &=0xFU ; + *sel = *sel &0xFU ; +#endif }void read_protection_region (pr_t *pr_read,uint8_t sel)
@@ -123,6 +127,24 @@ void read_protection_region(pr_t *pr_read, uint8_t sel)GENERATE_READ_PR_REG_CASE (13 , pr_read);GENERATE_READ_PR_REG_CASE (14 , pr_read);GENERATE_READ_PR_REG_CASE (15 , pr_read); +#ifdef CONFIG_ARM_32 +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); +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); +#endif default :BUG ();/* Can't happen */ break ;
@@ -208,7 +230,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 */ }};
@@ -225,7 +249,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
Hi,
Quoted 4 lines · Ayan Kumar Halder
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".
I have submitted a v2 "[PATCH v2 0/3] Enable R52 support for the first chunk of MPU support" with all the comments addressed.
- Ayan