Fifth MPU Series
cover Fifth MPU Series
This series continues to further the ongoing work to introduce support for MPU systems in Xen.
The patches in this series aim to implement MPU specific p2m functions.
Harry Ramsey (2):
arm/mpu: Introduce v8r_el1_msa device tree property for domains arm/mpu: Implement p2m tables
Penny Zheng (1):
arm/mpu: implement setup_virt_paging for MPU system
docs/misc/arm/device-tree/booting.txt | 11 ++++ xen/arch/arm/arm64/mpu/p2m.c | 67 +++++++++++++++++++++- xen/arch/arm/dom0less-build.c | 25 +++++++++ xen/arch/arm/domain.c | 16 ++++++ xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 ++++- xen/arch/arm/include/asm/domain.h | 9 +++ xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/include/asm/mpu/p2m.h | 12 ++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 11 ++++ xen/arch/arm/mpu/p2m.c | 71 +++++++++++++++++++++++- xen/include/public/arch-arm.h | 4 ++ 15 files changed, 250 insertions(+), 7 deletions(-)
--
2.43.0
PATCH 1/3 arm/mpu: implement setup_virt_paging for MPU system
From: Penny Zheng <[email protected]>
For MMU system, setup_virt_paging is used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.
For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2 (default)
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2 (enabled with device tree proprty v8r_el1_msa)
--- xen/arch/arm/arm64/mpu/p2m.c | 67 +++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 +++-- xen/arch/arm/include/asm/mpu/p2m.h | 12 +++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 11 ++++ 6 files changed, 108 insertions(+), 4 deletions(-)
xen/arch/arm/arm64/mpu/p2m.c +66 -1
@@ -2,11 +2,76 @@#include <xen/bug.h> #include <xen/init.h> +#include <xen/warning.h> #include <asm/p2m.h> void __init setup_virt_paging (void ) { -BUG_ON ("unimplemented" ); +uint64_t vtcr_el2 =READ_SYSREG (VTCR_EL2 ), vstcr_el2 =READ_SYSREG (VSTCR_EL2 ); + +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 , +/* Invalid */ }; + +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits". +*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8r only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ; + +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register identify the +* memory system configurations supported. In Armv8-R AArch64, the +* only permitted value for ID_AA64MMFR0_EL1.MSA is 0b1111. +*/ +if ( system_cpuinfo.mm64.msa !=MM64_MSA_PMSA_SUPPORT ) + goto fault; + +/* Permitted values for ID_AA64MMFR0_EL1.MSA_frac are 0b0001 and 0b0010. */ +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; + +/* +* cpuinfo sanitization makes sure we support 16bits VMID only if all cores +* are supporting it. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if ( max_vmid ==MAX_VMID_16_BIT ) + vtcr_el2 |=VTCR_VS ; + +p2m_vmid_allocator_init (); + +WRITE_SYSREG (vtcr_el2,VTCR_EL2 ); + +/* +* VSTCR_EL2.SA defines secure stage 2 translation output address space. +* To make sure that all stage 2 translations for the Secure PA space access +* the Secure PA space, we keep SA bit as 0. +* +* VSTCR_EL2.SC is NS check enable bit. To make sure that Stage 2 NS +* configuration is checked against stage 1 NS configuration in EL1&0 +* translation regime for the given address, and generates a fault if they +* are different, we set SC bit 1. +*/ + vstcr_el2 &= ~VSTCR_EL2_SA ; + vstcr_el2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (vstcr_el2,VSTCR_EL2 ); + +return ; + + fault: +panic ("Hardware with no PMSAv8-64 support in any translation regime\n" ); }/*
xen/arch/arm/include/asm/arm64/sysregs.h +4 -0
@@ -462,6 +462,10 @@#define ZCR_ELx_LEN_SIZE 9#define ZCR_ELx_LEN_MASK 0x1ff +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2_SA (_AC(0x1,UL)<<30) +#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) +#ifdef CONFIG_MPU /* * The Armv8-R AArch64 architecture always executes code in Secure
xen/arch/arm/include/asm/cpufeature.h +10 -3
@@ -248,6 +248,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_MPU + unsigned long __res0:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res1:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;
@@ -255,6 +261,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;
@@ -267,13 +274,13 @@ struct cpuinfo_arm { unsigned long xnx:4; unsigned long twed:4; unsigned long ets:4; - unsigned long __res1:4; + unsigned long __res2:4; unsigned long afp:4; - unsigned long __res2:12; + unsigned long __res3:12; unsigned long ecbhb:4;/* MMFR2 */ - unsigned long __res3:64; + unsigned long __res4:64; }; } mm64;
xen/arch/arm/include/asm/mpu/p2m.h +12 -0
@@ -5,6 +5,18 @@struct p2m_domain ; +/* +* The architecture allows at most 255 EL2 MPU memory regions. The size of the +* MPU structure entry (pr_t) is 32 Bytes on AArch64 (requiring two 4KB pages) +* and 16 bytes on AArch32 (requiring one 4KB page). +*/ +#ifdef CONFIG_ARM_64 +#define P2M_ROOT_ORDER 1 +#else +#define P2M_ROOT_ORDER 0 +#endif + +/* Not used on MPU system */ static inline void p2m_clear_root_pages (struct p2m_domain *p2m) {}static inline void p2m_tlb_flush_sync (struct p2m_domain *p2m) {}
xen/arch/arm/include/asm/p2m.h +5 -0
@@ -48,8 +48,13 @@ struct p2m_domain {/* Current VMID in use */ uint16_t vmid; +#ifdef CONFIG_MMU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +register_t vsctlr; +#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;
xen/arch/arm/include/asm/processor.h +11 -0
@@ -403,6 +403,10 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define VTCR_NSA (_AC(0x1,UL)<<30) +#endif +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */
@@ -464,6 +468,13 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif +#ifndef __ASSEMBLER__extern register_t __cpu_logical_map[];
Signature · 1 line
2.43.0
Re: [PATCH 1/3] arm/mpu: implement setup_virt_paging for MPU system
Hi Harry,
Quoted 30 lines · Harry Ramsey
From: Penny Zheng <[email protected]>
For MMU system,
setup_virt_pagingis used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2 (default)
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2 (enabled with device tree proprtyv8r_el1_msa)Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Luca Fancellu <[email protected]>Signed-off-by Hari Limaye <[email protected]>Signed-off-by Harry Ramsey <[email protected]>--- xen/arch/arm/arm64/mpu/p2m.c | 67 +++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 +++-- xen/arch/arm/include/asm/mpu/p2m.h | 12 +++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 11 ++++ 6 files changed, 108 insertions(+), 4 deletions(-)xen/arch/arm/arm64/mpu/p2m.c +0
-0
xen/arch/arm/arm64/mpu/p2m.c line 10
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +2
-1@@ -2,11 +2,76 @@#include <xen/bug.h> #include <xen/init.h> +#include <xen/warning.h> #include <asm/p2m.h> void __init setup_virt_paging (void ) { -BUG_ON ("unimplemented" ); + uint64_t vtcr_el2 = READ_SYSREG(VTCR_EL2),
I think this register is redefined for R82 . See
Quoted 9 lines
xen/arch/arm/arm64/mpu/p2m.c +8
-0vstcr_el2 =READ_SYSREG (VSTCR_EL2 ); + +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 , +/* Invalid */ }; + +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits".
xen/arch/arm/arm64/mpu/p2m.c line 28
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8r only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ;
But the TRM says this
This bit behaves as 1 for all purposes other than reading back the value of the bit when the value of AArch64-VSTCR_EL2.SA is 1.
So shouldn't we keep it as 1.
Quoted 13 lines
xen/arch/arm/arm64/mpu/p2m.c +13
-0+ +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register identify the +* memory system configurations supported. In Armv8-R AArch64, the +* only permitted value for ID_AA64MMFR0_EL1.MSA is 0b1111. +*/ +if ( system_cpuinfo.mm64.msa !=MM64_MSA_PMSA_SUPPORT ) + goto fault; + +/* Permitted values for ID_AA64MMFR0_EL1.MSA_frac are 0b0001 and 0b0010. */ +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; +
xen/arch/arm/arm64/mpu/p2m.c line 51
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+/* +* cpuinfo sanitization makes sure we support 16bits VMID only if all cores +* are supporting it. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if ( max_vmid ==MAX_VMID_16_BIT ) + vtcr_el2 |=VTCR_VS ;
this field does not exist.
Quoted 111 lines
xen/arch/arm/arm64/mpu/p2m.c +23
-0+ +p2m_vmid_allocator_init (); + +WRITE_SYSREG (vtcr_el2,VTCR_EL2 ); + +/* +* VSTCR_EL2.SA defines secure stage 2 translation output address space. +* To make sure that all stage 2 translations for the Secure PA space access +* the Secure PA space, we keep SA bit as 0. +* +* VSTCR_EL2.SC is NS check enable bit. To make sure that Stage 2 NS +* configuration is checked against stage 1 NS configuration in EL1&0 +* translation regime for the given address, and generates a fault if they +* are different, we set SC bit 1. +*/ + vstcr_el2 &= ~VSTCR_EL2_SA ; + vstcr_el2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (vstcr_el2,VSTCR_EL2 ); + +return ; + + fault: +panic ("Hardware with no PMSAv8-64 support in any translation regime\n" ); }/*
xen/arch/arm/include/asm/arm64/sysregs.h +4
-0@@ -462,6 +462,10 @@#define ZCR_ELx_LEN_SIZE 9#define ZCR_ELx_LEN_MASK 0x1ff +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2_SA (_AC(0x1,UL)<<30) +#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) +#ifdef CONFIG_MPU /* * The Armv8-R AArch64 architecture always executes code in Secure xen/arch/arm/include/asm/cpufeature.h +10
-3@@ -248,6 +248,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_MPU + unsigned long __res0:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res1:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;@@ -255,6 +261,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;@@ -267,13 +274,13 @@ struct cpuinfo_arm { unsigned long xnx:4; unsigned long twed:4; unsigned long ets:4; - unsigned long __res1:4; + unsigned long __res2:4; unsigned long afp:4; - unsigned long __res2:12; + unsigned long __res3:12; unsigned long ecbhb:4;/* MMFR2 */ - unsigned long __res3:64; + unsigned long __res4:64; }; } mm64;xen/arch/arm/include/asm/mpu/p2m.h +12
-0@@ -5,6 +5,18 @@struct p2m_domain ; +/* +* The architecture allows at most 255 EL2 MPU memory regions. The size of the +* MPU structure entry (pr_t) is 32 Bytes on AArch64 (requiring two 4KB pages) +* and 16 bytes on AArch32 (requiring one 4KB page). +*/ +#ifdef CONFIG_ARM_64 +#define P2M_ROOT_ORDER 1 +#else +#define P2M_ROOT_ORDER 0 +#endif + +/* Not used on MPU system */ static inline void p2m_clear_root_pages (struct p2m_domain *p2m) {}static inline void p2m_tlb_flush_sync (struct p2m_domain *p2m) {}xen/arch/arm/include/asm/p2m.h +0
-0
xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 56
Quoted 9 lines
xen/arch/arm/include/asm/p2m.h +4
-0@@ -48,8 +48,13 @@ struct p2m_domain {/* Current VMID in use */ uint16_t vmid; +#ifdef CONFIG_MMU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +register_t vsctlr;
This exist only for Arm64 MPU. Should we enclose this in ARM_64 ?
Quoted 23 lines
xen/arch/arm/include/asm/p2m.h +1
-0+#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;xen/arch/arm/include/asm/processor.h +4
-0@@ -403,6 +403,10 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define VTCR_NSA (_AC(0x1,UL)<<30) +#endif +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */ @@ -464,6 +468,13 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif
xen/arch/arm/include/asm/processor.h line 480
Quoted 10 lines
xen/arch/arm/include/asm/processor.h +7
-0+#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif +#ifndef __ASSEMBLER__extern register_t __cpu_logical_map[];
Rest LGTM
- Ayan
Re: [PATCH 1/3] arm/mpu: implement setup_virt_paging for MPU system
Hi Ayan,
Quoted 31 lines
Review
Quoted 4 lines
void
__initsetup_virt_paging(void)
{(quoted diff) +1
-1- BUG_ON("unimplemented"); + uint64_t vtcr_el2 = READ_SYSREG(VTCR_EL2),I think this register is redefined for R82 . See
Quoted 9 lines
vstcr_el2=READ_SYSREG(VSTCR_EL2);xen/arch/arm/arm64/mpu/p2m.c +8
-0+ +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 , +/* Invalid */ }; + +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits". xen/arch/arm/arm64/mpu/p2m.c line 28
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8r only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ;But the TRM says this
Quoted 4 lines
This bit behaves as 1 for all purposes other than reading back the value of the bit when the value of AArch64-VSTCR_EL2.SA is 1.
So shouldn't we keep it as 1.
The way I’m reading the armv8-r aarch64 reference manual [1] is that if we set VSTCR_EL2.SA to 0, we need to clear also this one.
Quoted 16 lines
Quoted 16 lines
xen/arch/arm/arm64/mpu/p2m.c +16
-0+ +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register identify the +* memory system configurations supported. In Armv8-R AArch64, the +* only permitted value for ID_AA64MMFR0_EL1.MSA is 0b1111. +*/ +if ( system_cpuinfo.mm64.msa !=MM64_MSA_PMSA_SUPPORT ) + goto fault; + +/* Permitted values for ID_AA64MMFR0_EL1.MSA_frac are 0b0001 and 0b0010. */ +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; + +/* +* cpuinfo sanitization makes sure we support 16bits VMID only if all cores +* are supporting it.
Quoted 8 lines
xen/arch/arm/arm64/mpu/p2m.c line 51
Quoted 7 lines
xen/arch/arm/arm64/mpu/p2m.c +7
-0+*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if ( max_vmid ==MAX_VMID_16_BIT ) + vtcr_el2 |=VTCR_VS ;this field does not exist.
yes this exists in armv8-r aarch64 [1]
Quoted 10 lines
Quoted 10 lines
xen/arch/arm/include/asm/mpu/p2m.h +1
-0+/* Not used on MPU system */ static inline void p2m_clear_root_pages (struct p2m_domain *p2m) {}static inline void p2m_tlb_flush_sync (struct p2m_domain *p2m) {}xen/arch/arm/include/asm/p2m.h +0
-0@@ -48,8 +48,13 @@ struct p2m_domain {/* Current VMID in use */
Quoted 8 lines
xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 56
Quoted 7 lines
xen/arch/arm/include/asm/p2m.h +3
-0uint16_t vmid; +#ifdef CONFIG_MMU/* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +register_t vsctlr;This exist only for Arm64 MPU. Should we enclose this in
ARM_64?
I can see it exists in armv8-r aarch32 [2].
Cheers,
Luca
[1] https://developer.arm.com/documentation/ddi0628/latest
[2] https://developer.arm.com/documentation/ddi0568/latest/
Halder, Ayan Kumar
Reviewed-by Ayan Kumar HalderRe: [PATCH 1/3] arm/mpu: implement setup_virt_paging for MPU system
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 81 lines
Quoted 30 lines
Review
Quoted 5 lines
void
__initsetup_virt_paging(void)
{(quoted diff) +1
-1- BUG_ON("unimplemented"); + uint64_t vtcr_el2 = READ_SYSREG(VTCR_EL2),I think this register is redefined for R82 . See
Quoted 9 lines
vstcr_el2 = READ_SYSREG(VSTCR_EL2);xen/arch/arm/arm64/mpu/p2m.c +8
-0+ +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 , +/* Invalid */ }; + +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits". xen/arch/arm/arm64/mpu/p2m.c line 28
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8r only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ;But the TRM says this
Quoted 4 lines
This bit behaves as 1 for all purposes other than reading back the value of the bit when the value of AArch64-VSTCR_EL2.SA is 1.
So shouldn't we keep it as 1.
The way I’m reading the armv8-r aarch64 reference manual [1] is that if we set VSTCR_EL2.SA to 0, we need to clear also this one.
Quoted 16 lines
Quoted 16 lines
xen/arch/arm/arm64/mpu/p2m.c +16
-0+ +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register identify the +* memory system configurations supported. In Armv8-R AArch64, the +* only permitted value for ID_AA64MMFR0_EL1.MSA is 0b1111. +*/ +if ( system_cpuinfo.mm64.msa !=MM64_MSA_PMSA_SUPPORT ) + goto fault; + +/* Permitted values for ID_AA64MMFR0_EL1.MSA_frac are 0b0001 and 0b0010. */ +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; + +/* +* cpuinfo sanitization makes sure we support 16bits VMID only if all cores +* are supporting it. Quoted 8 lines
xen/arch/arm/arm64/mpu/p2m.c line 51
Quoted 7 lines
xen/arch/arm/arm64/mpu/p2m.c +7
-0+*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if ( max_vmid ==MAX_VMID_16_BIT ) + vtcr_el2 |=VTCR_VS ;this field does not exist.
yes this exists in armv8-r aarch64 [1]
Quoted 9 lines
Quoted 9 lines
xen/arch/arm/include/asm/mpu/p2m.h +1
-0+/* Not used on MPU system */ static inline void p2m_clear_root_pages (struct p2m_domain *p2m) {}static inline void p2m_tlb_flush_sync (struct p2m_domain *p2m) {}xen/arch/arm/include/asm/p2m.h +0
-0@@ -48,8 +48,13 @@ struct p2m_domain {/* Current VMID in use */ Quoted 8 lines
xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 56
Quoted 7 lines
xen/arch/arm/include/asm/p2m.h +3
-0uint16_t vmid; +#ifdef CONFIG_MMU/* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +register_t vsctlr;This exist only for Arm64 MPU. Should we enclose this in
ARM_64?
Quoted 1 line
I can see it exists in armv8-r aarch32 [2].
In that case,
Sorry for the false alarm.
- Ayan
Re: [PATCH 1/3] arm/mpu: implement setup_virt_paging for MPU system
In reply to Harry RamseyI guess this should be send as a v2 with listed changes between v2 and v1.
Quoted 71 lines · Harry Ramsey
From: Penny Zheng <[email protected]>
For MMU system,
setup_virt_pagingis used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2 (default)
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2 (enabled with device tree proprtyv8r_el1_msa)Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Luca Fancellu <[email protected]>Signed-off-by Hari Limaye <[email protected]>Signed-off-by Harry Ramsey <[email protected]>--- xen/arch/arm/arm64/mpu/p2m.c | 67 +++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 +++-- xen/arch/arm/include/asm/mpu/p2m.h | 12 +++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 11 ++++ 6 files changed, 108 insertions(+), 4 deletions(-)xen/arch/arm/arm64/mpu/p2m.c +33
-1@@ -2,11 +2,76 @@#include <xen/bug.h> #include <xen/init.h> +#include <xen/warning.h> #include <asm/p2m.h> void __init setup_virt_paging (void ) { -BUG_ON ("unimplemented" ); +uint64_t vtcr_el2 =READ_SYSREG (VTCR_EL2 ), vstcr_el2 =READ_SYSREG (VSTCR_EL2 ); + +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 , +/* Invalid */ }; + +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits". +*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8r only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ; + +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register identify the +* memory system configurations supported. In Armv8-R AArch64, the +* only permitted value for ID_AA64MMFR0_EL1.MSA is 0b1111. +*/ +if ( system_cpuinfo.mm64.msa !=MM64_MSA_PMSA_SUPPORT ) + goto fault; + +/* Permitted values for ID_AA64MMFR0_EL1.MSA_frac are 0b0001 and 0b0010. */ +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; +
xen/arch/arm/arm64/mpu/p2m.c line 51
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+/* +* cpuinfo sanitization makes sure we support 16bits VMID only if all cores +* are supporting it. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if ( max_vmid ==MAX_VMID_16_BIT ) + vtcr_el2 |=VTCR_VS ;
No need for max_vmid assignment. You can directory do:
if ( system_cpuinfo.mm64.vmid_bits == MM64_VMID_16_BITS_SUPPORT )
vtcr_el2 |= VTCR_VS;
to make things clearer.
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+ +p2m_vmid_allocator_init (); + +WRITE_SYSREG (vtcr_el2,VTCR_EL2 ); + +/* +* VSTCR_EL2.SA defines secure stage 2 translation output address space. +* To make sure that all stage 2 translations for the Secure PA space access +* the Secure PA space, we keep SA bit as 0. +*
xen/arch/arm/arm64/mpu/p2m.c line 71
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+* VSTCR_EL2.SC is NS check enable bit. To make sure that Stage 2 NS +* configuration is checked against stage 1 NS configuration in EL1&0 +* translation regime for the given address, and generates a fault if they +* are different, we set SC bit 1. +*/ + vstcr_el2 &= ~VSTCR_EL2_SA ; + vstcr_el2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (vstcr_el2,VSTCR_EL2 ); + +return ;
Shouldn't we have a printk message similar to what MMU has? printk("P2M: %d-bit IPA with %d-bit PA and %d-bit VMID\n"...)
Quoted 11 lines
xen/arch/arm/arm64/mpu/p2m.c +3
-0+ + fault: +panic ("Hardware with no PMSAv8-64 support in any translation regime\n" ); }/* xen/arch/arm/include/asm/arm64/sysregs.h +0
-0
xen/arch/arm/include/asm/arm64/sysregs.h line 466
Quoted 5 lines
xen/arch/arm/include/asm/arm64/sysregs.h +2
-0@@ -462,6 +462,10 @@#define ZCR_ELx_LEN_SIZE 9#define ZCR_ELx_LEN_MASK 0x1ff +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2_SA (_AC(0x1,UL)<<30)
Why UL and not U?
Also, please add spaces around <<
Quoted 52 lines
xen/arch/arm/include/asm/arm64/sysregs.h +2
-0+#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) +#ifdef CONFIG_MPU /* * The Armv8-R AArch64 architecture always executes code in Secure xen/arch/arm/include/asm/cpufeature.h +10
-3@@ -248,6 +248,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_MPU + unsigned long __res0:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res1:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;@@ -255,6 +261,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;@@ -267,13 +274,13 @@ struct cpuinfo_arm { unsigned long xnx:4; unsigned long twed:4; unsigned long ets:4; - unsigned long __res1:4; + unsigned long __res2:4; unsigned long afp:4; - unsigned long __res2:12; + unsigned long __res3:12; unsigned long ecbhb:4;/* MMFR2 */ - unsigned long __res3:64; + unsigned long __res4:64; }; } mm64;xen/arch/arm/include/asm/mpu/p2m.h +0
-0
xen/arch/arm/include/asm/mpu/p2m.h line 11
Quoted 7 lines
xen/arch/arm/include/asm/mpu/p2m.h +4
-0@@ -5,6 +5,18 @@struct p2m_domain ; +/* +* The architecture allows at most 255 EL2 MPU memory regions. The size of the +* MPU structure entry (pr_t) is 32 Bytes on AArch64 (requiring two 4KB pages) +* and 16 bytes on AArch32 (requiring one 4KB page).
It would be good to have a BUILD_BUG_ON to validate these calculations. Conversely, we could define root order with these calculations but it might not be well readable.
xen/arch/arm/include/asm/mpu/p2m.h line 16
Quoted 5 lines
xen/arch/arm/include/asm/mpu/p2m.h +5
-0+*/ +#ifdef CONFIG_ARM_64 +#define P2M_ROOT_ORDER 1 +#else +#define P2M_ROOT_ORDER 0
They don't seem to be used by this patch.
Quoted 11 lines
xen/arch/arm/include/asm/mpu/p2m.h +3
-0+#endif + +/* Not used on MPU system */ static inline void p2m_clear_root_pages (struct p2m_domain *p2m) {}static inline void p2m_tlb_flush_sync (struct p2m_domain *p2m) {}xen/arch/arm/include/asm/p2m.h +0
-0
xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 56
Quoted 9 lines
xen/arch/arm/include/asm/p2m.h +4
-0@@ -48,8 +48,13 @@ struct p2m_domain {/* Current VMID in use */ uint16_t vmid; +#ifdef CONFIG_MMU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +register_t vsctlr;
Why vsctlr and not vsctr?
This does not seem to be used in this patch, so maybe move it to another patch.
xen/arch/arm/include/asm/processor.h line 406
Quoted 13 lines
xen/arch/arm/include/asm/p2m.h +1
-0+#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;xen/arch/arm/include/asm/processor.h +1
-0@@ -403,6 +403,10 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 )
Would it make sense to have CONFIG_ARM_64_MPU to avoid specifying these two all the time?
Quoted 10 lines
xen/arch/arm/include/asm/processor.h +3
-0+#define VTCR_NSA (_AC(0x1,UL)<<30) +#endif +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */ @@ -464,6 +468,13 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif
xen/arch/arm/include/asm/processor.h line 480
Quoted 10 lines
xen/arch/arm/include/asm/processor.h +7
-0+#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif +#ifndef __ASSEMBLER__extern register_t __cpu_logical_map[];
~Michal
PATCH 2/3 arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
In reply to Harry RamseyAdd a new device tree property v8r_el1_msa to enable/disable the PMSAv8-64 translation regime at EL1.
--- docs/misc/arm/device-tree/booting.txt | 11 +++++++++++ xen/arch/arm/dom0less-build.c | 25 +++++++++++++++++++++++++ xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/include/asm/domain.h | 9 +++++++++ xen/include/public/arch-arm.h | 4 ++++ 5 files changed, 65 insertions(+)
docs/misc/arm/device-tree/booting.txt +11 -0
@@ -322,6 +322,17 @@ with the following properties: Should be used together with scmi-smc-passthrough Xen command line option. +- v8r_el1_msa + + A string property specifying whether, on Armv8-R aarch64 systems, a domain + should use PMSAv8-64 (MPU) at EL1 or VMSAv8-64 (MMU) at EL1. + + - "mmu" + Enables VMSAv8-64 at EL1. + + - "mpu" + Enables PMSAv8-64 at EL1. + Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk.
xen/arch/arm/dom0less-build.c +25 -0
@@ -315,6 +315,7 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,struct xen_domctl_createdomain *d_cfg = &bd->create_cfg;unsigned int flags = bd->create_flags;uint32_t val; +const char *v8r_el1_msa; d_cfg->arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ; d_cfg->flags |= XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap;
@@ -322,6 +323,30 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,if (domu_dt_sci_parse (node, d_cfg) )panic ("Error getting SCI configuration\n" ); +if (!dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa)) + { +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +if ( !strcmp (v8r_el1_msa,"mmu" ) ) + { +if ( system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) +panic ("Platform does not support VMSA at EL1 (v8r_el1_msa)\n" ); + d_cfg->arch.v8r_el1_msa =MPU_EL1_VMSA ; + } +else if ( !strcmp (v8r_el1_msa,"mpu" ) ) + { + d_cfg->arch.v8r_el1_msa =MPU_EL1_PMSA ; +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) +panic ("PMSA is not valid for domain without static allocation" +" and direct map (v8r_el1_msa)\n" ); + } +else +panic ("Invalid device tree option for v8r_el1_msa\n" ); +#else +panic ("'v8r_el1_msa' property requires CONFIG_MPU and CONFIG_ARM_64 to " +"be selected\n" ); +#endif + } +if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;
xen/arch/arm/domain.c +16 -0
@@ -35,6 +35,18 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); +/* If this domain should use PMSAv8-64 translation regime (MPU) at EL1. */ +static inline bool is_mpu_domain (struct domain *d) +{ +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +return d->arch.v8r_el1_msa ==MPU_EL1_PMSA ; +#elif defined(CONFIG_MPU ) +return true; +#else +return false; +#endif +} +static void do_idle (void ) {unsigned int cpu =smp_processor_id ();
@@ -731,6 +743,10 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; +#endif +return 0 ; fail:
xen/arch/arm/include/asm/domain.h +9 -0
@@ -29,6 +29,11 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define MPU_EL1_PMSA 0 +#define MPU_EL1_VMSA 1 +#endif +/* * Is the domain using the host memory layout? *
@@ -126,6 +131,10 @@ struct arch_domainvoid *sci_data;#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +uint8_t v8r_el1_msa; +#endif + } __cacheline_aligned;struct arch_vcpu
xen/include/public/arch-arm.h +4 -0
@@ -355,6 +355,10 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ uint8_t arm_sci_type; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +/* IN */ +uint8_t v8r_el1_msa; +#endif };#endif /* __XEN__ || __XEN_TOOLS__ */
Signature · 1 line
2.43.0
Re: [PATCH 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Hi Harry,
Just a suggestion. Please feel free to disagree.
Quoted 20 lines · Harry Ramsey
Add a new device tree property
v8r_el1_msato enable/disable the PMSAv8-64 translation regime at EL1.Signed-off-by Harry Ramsey <[email protected]>--- docs/misc/arm/device-tree/booting.txt | 11 +++++++++++ xen/arch/arm/dom0less-build.c | 25 +++++++++++++++++++++++++ xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/include/asm/domain.h | 9 +++++++++ xen/include/public/arch-arm.h | 4 ++++ 5 files changed, 65 insertions(+)docs/misc/arm/device-tree/booting.txt +0
-0@@ -322,6 +322,17 @@ with the following properties: Should be used together with scmi-smc-passthrough Xen command line option.
docs/misc/arm/device-tree/booting.txt with the following properties: · line 334
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +10
-0+- v8r_el1_msa + + A string property specifying whether, on Armv8-R aarch64 systems, a domain + should use PMSAv8-64 (MPU) at EL1 or VMSAv8-64 (MMU) at EL1. + + - "mmu" + Enables VMSAv8-64 at EL1. + + - "mpu" + Enables PMSAv8-64 at EL1.
We can reuse this property for arm32 although there is no mmu. This may help to keep the code common between arm64 and arm32 for v8-R. So, the changes I suggest are
Quoted 17 lines
docs/misc/arm/device-tree/booting.txt +1
-0+ Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk.xen/arch/arm/dom0less-build.c +1
-0@@ -315,6 +315,7 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,struct xen_domctl_createdomain *d_cfg = &bd->create_cfg;unsigned int flags = bd->create_flags;uint32_t val; +const char *v8r_el1_msa; d_cfg->arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ; d_cfg->flags |= XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap;
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 328
Quoted 6 lines
xen/arch/arm/dom0less-build.c +3
-0@@ -322,6 +323,30 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,if (domu_dt_sci_parse (node, d_cfg) )panic ("Error getting SCI configuration\n" ); +if (!dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa)) + { +#if defined(CONFIG_MPU )
#if
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 334
Quoted 7 lines
xen/arch/arm/dom0less-build.c +6
-0defined (CONFIG_ARM_64) + if ( !strcmp(v8r_el1_msa, "mmu") ) + { +if ( system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) +panic ("Platform does not support VMSA at EL1 (v8r_el1_msa)\n" ); + d_cfg->arch.v8r_el1_msa =MPU_EL1_VMSA ; + }
#endif
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 335
Quoted 1 line
xen/arch/arm/dom0less-build.c +1
-0+else if ( !strcmp (v8r_el1_msa,"mpu" ) )
if ( !strcmp( ....
Quoted 22 lines
xen/arch/arm/dom0less-build.c +14
-0+ { + d_cfg->arch.v8r_el1_msa =MPU_EL1_PMSA ; +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) +panic ("PMSA is not valid for domain without static allocation" +" and direct map (v8r_el1_msa)\n" ); + } + else + panic("Invalid device tree option for v8r_el1_msa\n"); +#else +panic ("'v8r_el1_msa' property requires CONFIG_MPU and CONFIG_ARM_64 to " +"be selected\n" ); +#endif + } +if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq = GUEST_VPL011_SPI;xen/arch/arm/domain.c +0
-0
xen/arch/arm/domain.c line 41
Quoted 7 lines
xen/arch/arm/domain.c +4
-0@@ -35,6 +35,18 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); +/* If this domain should use PMSAv8-64 translation regime (MPU) at EL1. */ +static inline bool is_mpu_domain (struct domain *d) +{ +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 )
#if defined(CONFIG_MPU)
xen/arch/arm/domain.c line 42
Quoted 1 line
xen/arch/arm/domain.c +1
-0+return d->arch.v8r_el1_msa ==MPU_EL1_PMSA ;
#else
return false;
#endif
Further if we can set v8r_el1_msa = mmu by default for everyone (Armv8-A, Armv8-R) , then we can reduce further if-def.
Quoted 53 lines
xen/arch/arm/domain.c +11
-0+#elif defined(CONFIG_MPU ) +return true; +#else +return false; +#endif +} +static void do_idle (void ) {unsigned int cpu =smp_processor_id ();@@ -731,6 +743,10 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; +#endif +return 0 ; fail:xen/arch/arm/include/asm/domain.h +9
-0@@ -29,6 +29,11 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +#define MPU_EL1_PMSA 0 +#define MPU_EL1_VMSA 1 +#endif +/* * Is the domain using the host memory layout? * @@ -126,6 +131,10 @@ struct arch_domainvoid *sci_data;#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +uint8_t v8r_el1_msa; +#endif + } __cacheline_aligned;struct arch_vcpu xen/include/public/arch-arm.h +0
-0
xen/include/public/arch-arm.h struct xen_arch_domainconfig { · line 364
Quoted 10 lines
xen/include/public/arch-arm.h +4
-0@@ -355,6 +355,10 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ uint8_t arm_sci_type; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +/* IN */ +uint8_t v8r_el1_msa; +#endif };#endif /* __XEN__ || __XEN_TOOLS__ */
LGTM.
- Ayan
Re: [PATCH 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Hi Ayan,
Quoted 3 lines
Further if we can set
v8r_el1_msa = mmuby default for everyone (Armv8-A, Armv8-R) , then we can reduce further if-def.
This was Michal suggestion to have mpu by default, so I would wait for his reply before proceeding further on this.
Cheers,
Luca
Re: [PATCH 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Quoted 7 lines · Luca Fancellu
Hi Ayan,
Quoted 3 lines
Further if we can set
v8r_el1_msa = mmuby default for everyone (Armv8-A, Armv8-R) , then we can reduce further if-def.This was Michal suggestion to have mpu by default, so I would wait for his reply before proceeding further on this.
Yes, we should keep mpu as a default which matches the Arm ARM. MMU is optional whereas MPU is not.
~Michal
Re: [PATCH 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
In reply to Harry RamseyQuoted 1 line · Harry Ramsey
Add a new device tree property
v8r_el1_msato enable/disable the
This reads as if it was on/off option. I think it's better to say "to select the MSA (memory system architecture) at EL1 i.e. MPU(default) or MMU.
Quoted 16 lines
PMSAv8-64 translation regime at EL1.
Signed-off-by Harry Ramsey <[email protected]>--- docs/misc/arm/device-tree/booting.txt | 11 +++++++++++ xen/arch/arm/dom0less-build.c | 25 +++++++++++++++++++++++++ xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/include/asm/domain.h | 9 +++++++++ xen/include/public/arch-arm.h | 4 ++++ 5 files changed, 65 insertions(+)docs/misc/arm/device-tree/booting.txt +0
-0
docs/misc/arm/device-tree/booting.txt with the following properties: · line 331
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +7
-0@@ -322,6 +322,17 @@ with the following properties: Should be used together with scmi-smc-passthrough Xen command line option. +- v8r_el1_msa + + A string property specifying whether, on Armv8-R aarch64 systems, a domain + should use PMSAv8-64 (MPU) at EL1 or VMSAv8-64 (MMU) at EL1. + + - "mmu" + Enables VMSAv8-64 at EL1.
You should mention that it might not be supported by hardware though.
docs/misc/arm/device-tree/booting.txt with the following properties: · line 334
Quoted 3 lines
docs/misc/arm/device-tree/booting.txt +3
-0+ + - "mpu" + Enables PMSAv8-64 at EL1.
You should mention that mpu is a default.
Quoted 31 lines
docs/misc/arm/device-tree/booting.txt +1
-0+ Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk.xen/arch/arm/dom0less-build.c +12
-0@@ -315,6 +315,7 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,struct xen_domctl_createdomain *d_cfg = &bd->create_cfg;unsigned int flags = bd->create_flags;uint32_t val; +const char *v8r_el1_msa; d_cfg->arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ; d_cfg->flags |= XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap;@@ -322,6 +323,30 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,if (domu_dt_sci_parse (node, d_cfg) )panic ("Error getting SCI configuration\n" ); +if (!dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa)) + { +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +if ( !strcmp (v8r_el1_msa,"mmu" ) ) + { +if ( system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) +panic ("Platform does not support VMSA at EL1 (v8r_el1_msa)\n" ); + d_cfg->arch.v8r_el1_msa =MPU_EL1_VMSA ; + } +else if ( !strcmp (v8r_el1_msa,"mpu" ) ) + {
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 346
Quoted 10 lines
xen/arch/arm/dom0less-build.c +10
-0+ d_cfg->arch.v8r_el1_msa =MPU_EL1_PMSA ; +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) +panic ("PMSA is not valid for domain without static allocation" + " and direct map (v8r_el1_msa)\n"); + } +else +panic ("Invalid device tree option for v8r_el1_msa\n" ); +#else +panic ("'v8r_el1_msa' property requires CONFIG_MPU and CONFIG_ARM_64 to " +"be selected\n" );
Please don't split printk messages
Quoted 11 lines
xen/arch/arm/dom0less-build.c +3
-0+#endif + } +if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;xen/arch/arm/domain.c +0
-0
xen/arch/arm/domain.c line 41
Quoted 7 lines
xen/arch/arm/domain.c +4
-0@@ -35,6 +35,18 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); +/* If this domain should use PMSAv8-64 translation regime (MPU) at EL1. */ +static inline bool is_mpu_domain (struct domain *d) +{ +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 )
I think Ayan's request to make this property generic to avoid ifdefery makes sense. There is a lot of #if/#else blocks. This property/variables would simply have a single field for Arm32. Also, you could perhaps make it enum and then protect VMSA option with Arm64.
Quoted 27 lines
xen/arch/arm/domain.c +12
-0+return d->arch.v8r_el1_msa ==MPU_EL1_PMSA ; +#elif defined(CONFIG_MPU ) +return true; +#else +return false; +#endif +} +static void do_idle (void ) {unsigned int cpu =smp_processor_id ();@@ -731,6 +743,10 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; +#endif +return 0 ; fail:xen/arch/arm/include/asm/domain.h +0
-0
xen/arch/arm/include/asm/domain.h enum domain_type { · line 32
Quoted 4 lines
xen/arch/arm/include/asm/domain.h +1
-0@@ -29,6 +29,11 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 )
I don't think it makes sense to protect macros. For me, it just results in additional churn.
Quoted 23 lines
xen/arch/arm/include/asm/domain.h +8
-0+#define MPU_EL1_PMSA 0 +#define MPU_EL1_VMSA 1 +#endif +/* * Is the domain using the host memory layout? * @@ -126,6 +131,10 @@ struct arch_domainvoid *sci_data;#endif +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +uint8_t v8r_el1_msa; +#endif + } __cacheline_aligned;struct arch_vcpu xen/include/public/arch-arm.h +0
-0
xen/include/public/arch-arm.h struct xen_arch_domainconfig { · line 364
Quoted 10 lines
xen/include/public/arch-arm.h +4
-0@@ -355,6 +355,10 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ uint8_t arm_sci_type; +#if defined(CONFIG_MPU ) && defined(CONFIG_ARM_64 ) +/* IN */ +uint8_t v8r_el1_msa; +#endif };#endif /* __XEN__ || __XEN_TOOLS__ */
~Michal
PATCH 3/3 arm/mpu: Implement p2m tables
In reply to Harry RamseyImplement p2m_alloc_table, p2m_init and p2m_final_teardown for MPU systems. Additionally implement a helper function generate_vsctlr for p2m initalization.
--- xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/mpu/p2m.c | 71 ++++++++++++++++++++++++++-- 4 files changed, 77 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/arm32/mpu.h +2 -0
@@ -11,6 +11,8 @@*/ #define MPU_REGION_RES0 0x0 +#define VSCTLR_VMID_SHIFT 16 +/* Hypervisor Protection Region Base Address Register */ typedef union { struct {
xen/arch/arm/include/asm/arm64/mpu.h +2 -0
@@ -7,6 +7,8 @@#define MPU_REGION_RES0 (0xFFFFULL << 48) +#define VSCTLR_VMID_SHIFT 48 +/* Protection Region Base Address Register */ typedef union { struct __packed {
xen/arch/arm/include/asm/mpu.h +5 -0
@@ -87,6 +87,11 @@ static inline bool region_is_valid(const pr_t *pr)return pr->prlar.reg.en; } +static inline register_t generate_vsctlr (uint16_t vmid) +{ +return ((register_t )vmid <<VSCTLR_VMID_SHIFT ); +} +#endif /* __ASSEMBLER__ */ #endif /* __ARM_MPU_H__ */
xen/arch/arm/mpu/p2m.c +68 -3
85 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 3/3] arm/mpu: Implement p2m tables
Quoted 5 lines · Harry Ramsey
Implement
p2m_alloc_table,p2m_initandp2m_final_teardownfor MPU systems. Additionally implement a helper functiongenerate_vsctlrfor p2m initalization.Signed-off-by Harry Ramsey <[email protected]>
- Ayan
Re: [PATCH 3/3] arm/mpu: Implement p2m tables
In reply to Harry RamseyQuoted 3 lines · Harry Ramsey
Implement
p2m_alloc_table,p2m_initandp2m_final_teardownfor MPU systems. Additionally implement a helper functiongenerate_vsctlrfor p2m initalization.
This means you know you will call it more than once in the future?
Quoted 56 lines
Signed-off-by Harry Ramsey <[email protected]>--- xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/mpu/p2m.c | 71 ++++++++++++++++++++++++++-- 4 files changed, 77 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/arm32/mpu.h +2
-0@@ -11,6 +11,8 @@*/ #define MPU_REGION_RES0 0x0 +#define VSCTLR_VMID_SHIFT 16 +/* Hypervisor Protection Region Base Address Register */ typedef union { struct {xen/arch/arm/include/asm/arm64/mpu.h +2
-0@@ -7,6 +7,8 @@#define MPU_REGION_RES0 (0xFFFFULL << 48) +#define VSCTLR_VMID_SHIFT 48 +/* Protection Region Base Address Register */ typedef union { struct __packed {xen/arch/arm/include/asm/mpu.h +5
-0@@ -87,6 +87,11 @@ static inline bool region_is_valid(const pr_t *pr)return pr->prlar.reg.en; } +static inline register_t generate_vsctlr (uint16_t vmid) +{ +return ((register_t )vmid <<VSCTLR_VMID_SHIFT ); +} +#endif /* __ASSEMBLER__ */ #endif /* __ARM_MPU_H__ */ xen/arch/arm/mpu/p2m.c +0
-0
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 31
Quoted 4 lines
xen/arch/arm/mpu/p2m.c +1
-0@@ -28,10 +28,62 @@ void p2m_dump_info(struct domain *d)BUG_ON ("unimplemented" ); } +static int __init p2m_alloc_table (struct domain *d)
Why __init?
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 36
Quoted 5 lines
xen/arch/arm/mpu/p2m.c +5
-0+{ +struct p2m_domain *p2m =p2m_get_hostp2m (d); +pr_t * p2m_map; + + p2m_map =alloc_xenheap_pages (P2M_ROOT_ORDER ,0 );
Why not assigning to p2m->root right away?
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 39
Quoted 3 lines
xen/arch/arm/mpu/p2m.c +3
-0+if ( !p2m_map ) + { +printk (XENLOG_G_ERR "DOM%pd: p2m: unable to allocate P2M MPU mapping table\n" , d);
No need for DOM. %pd already gives d prefix like d0
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 42
Quoted 3 lines
xen/arch/arm/mpu/p2m.c +3
-0+return -ENOMEM ; + } +clear_page (p2m_map);
P2M_ROOT_ORDER can be 1, meaning 2 pages. Here you only clear one.
Quoted 16 lines
xen/arch/arm/mpu/p2m.c +12
-2+ + p2m->root =virt_to_page ((const void *)p2m_map); + +return 0 ; +} +int p2m_init (struct domain *d) { -BUG_ON ("unimplemented" ); -return -EINVAL ; +struct p2m_domain *p2m =p2m_get_hostp2m (d); +int rc =0 ; +unsigned int cpu; + +rwlock_init (&p2m->lock); +
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 66
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10
-0+ p2m->vmid =INVALID_VMID ; + p2m->max_mapped_gfn =_gfn (0 ); + p2m->lowest_mapped_gfn =_gfn (ULONG_MAX ); + + p2m->default_access = p2m_access_rwx; +/* mem_access is NOT supported in MPU system. */ + p2m->mem_access_enabled = false; + +/* Ensure that the type chosen is large enough for MAX_VIRT_CPUS. */ +BUILD_BUG_ON ((1 << (sizeof (p2m->last_vcpu_ran[0 ]) *8 )) <MAX_VIRT_CPUS );
Why there is no check for INVALID_VCPU_ID?
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 69
Quoted 3 lines
xen/arch/arm/mpu/p2m.c +3
-0+ +for_each_possible_cpu (cpu) + p2m->last_vcpu_ran[cpu] =INVALID_VCPU_ID ;
Fix indentation - 4 spaces, not 3
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 79
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10
-0+ +/* +* "Trivial" initialization is now complete. Set the backpointer so that +* p2m_teardown() and related functions know to do something. +*/ + p2m->domain = d; + + rc =p2m_alloc_vmid (d); +if ( rc ) +return rc;
Please add empty line here
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 86
Quoted 7 lines
xen/arch/arm/mpu/p2m.c +7
-0+ p2m->vsctlr =generate_vsctlr (p2m->vmid); + + rc =p2m_alloc_table (d); +if ( rc ) +return rc; + +return rc;
Please, simplify return:
return p2m_alloc_table(d);
Quoted 6 lines
xen/arch/arm/mpu/p2m.c +0
-0}void p2m_save_state (struct vcpu *p)@@ -46,7 +98,20 @@ void p2m_restore_state(struct vcpu *n)void p2m_final_teardown (struct domain *d)
xen/arch/arm/mpu/p2m.c void p2m_restore_state(struct vcpu *n) · line 108
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +8
-1{ -BUG_ON ("unimplemented" ); +struct p2m_domain *p2m =p2m_get_hostp2m (d); + +/* p2m not actually initialized */ +if ( !p2m->domain ) +return ; + +if ( p2m->root ) +free_xenheap_pages (p2m->root,P2M_ROOT_ORDER );
free_xenheap_pages as oppose to free_domheap_pages expects vaddr, not page pointer.
xen/arch/arm/mpu/p2m.c void p2m_restore_state(struct vcpu *n) · line 117
Quoted 9 lines
xen/arch/arm/mpu/p2m.c +6
-0+ + p2m->root =NULL ; + +p2m_free_vmid (d); + + p2m->domain =NULL ; }bool p2m_resolve_translation_fault (struct domain *d,gfn_t gfn)
~Michal
Quoted 29 lines · Harry Ramsey
This series continues to further the ongoing work to introduce support for MPU systems in Xen.
The patches in this series aim to implement MPU specific p2m functions.
Harry Ramsey (2):
arm/mpu: Introducev8r_el1_msadevice tree property for domains arm/mpu: Implement p2m tablesPenny Zheng (1):
arm/mpu: implementsetup_virt_pagingfor MPU systemdocs/misc/arm/device-tree/booting.txt | 11 ++++ xen/arch/arm/arm64/mpu/p2m.c | 67 +++++++++++++++++++++- xen/arch/arm/dom0less-build.c | 25 +++++++++ xen/arch/arm/domain.c | 16 ++++++ xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 ++++- xen/arch/arm/include/asm/domain.h | 9 +++ xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/include/asm/mpu/p2m.h | 12 ++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 11 ++++ xen/arch/arm/mpu/p2m.c | 71 +++++++++++++++++++++++- xen/include/public/arch-arm.h | 4 ++ 15 files changed, 250 insertions(+), 7 deletions(-)
Quoted 3 lines
--
2.43.0
This is a complete rework of the previous patch: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
v2:
- Split implement setup_virt_paging for MPU system into arm/mpu: implement setup_virt_paging for MPU system and Implement p2m tables
- Rework register setup within setup_virt_paging to be more concise
- Introduce v8r_el1_msa device tree parameter