Fifth MPU Series
v4 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.
This serie is based on staging 99912d346009fda1e7fb1510c9501fbab17e92a0.
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 systems
docs/misc/arm/device-tree/booting.txt | 14 ++++ xen/arch/arm/arm64/mpu/p2m.c | 80 ++++++++++++++++++++- xen/arch/arm/dom0less-build.c | 3 + xen/arch/arm/domain.c | 4 ++ 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 | 4 ++ xen/arch/arm/include/asm/domain_build.h | 8 +++ xen/arch/arm/include/asm/mmu/domain-build.h | 46 ++++++++++++ xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/include/asm/mpu/domain-build.h | 27 +++++++ xen/arch/arm/include/asm/mpu/p2m.h | 12 ++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/include/asm/processor.h | 8 +++ xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 5 ++ xen/arch/arm/mpu/arm64/mm.c | 5 ++ xen/arch/arm/mpu/domain-build.c | 76 ++++++++++++++++++++ xen/arch/arm/mpu/p2m.c | 78 +++++++++++++++++++- xen/include/public/arch-arm.h | 7 ++ xen/include/public/domctl.h | 4 +- 23 files changed, 404 insertions(+), 9 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/domain-build.h create mode 100644 xen/arch/arm/include/asm/mpu/domain-build.h create mode 100644 xen/arch/arm/mpu/domain-build.c
Signature · 1 line
2.34.1
PATCH v4 1/3 arm/mpu: implement setup_virt_paging for MPU systems
From: Penny Zheng <[email protected]>
Implement setup_virt_paging for AArch64 MPU systems, taking care of stage 2 address translation regime, IPA bits, supported VMID length configuration and VTCR_EL2/VSTCR_EL2 register programming.
Implement also the Armv8-R specific changes to ID_AA64MMFR0_EL1, related to the supported memory system architecture (PMSA/VMSA) and check that when MPU is built, the underlying HW is compatible with PMSA. By default MPU at EL2 and EL1 is required.
---
v4:
- Fixed typo in the comments
- Fixed typo in the commit title and message
- moved p2m_vmid_allocator_init() after write of
VTCR_EL2
- Fixed printf format specifier %d -> %u
v3:
- Refactor unused code to more relevant commits.
- Add P2M print information
- Formatting issues
- Update commit message
v2:
- Separate commit into multiple commits
--- xen/arch/arm/arm64/mpu/p2m.c | 80 +++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 +++- xen/arch/arm/include/asm/processor.h | 8 +++ 4 files changed, 101 insertions(+), 4 deletions(-)
xen/arch/arm/arm64/mpu/p2m.c +79 -1
@@ -2,11 +2,89 @@#include <xen/bug.h> #include <xen/init.h> +#include <xen/lib.h> #include <asm/p2m.h> void __init setup_virt_paging (void ) { -BUG_ON ("unimplemented" ); +register_t vtcr_el2 =READ_SYSREG (VTCR_EL2 ); +register_t 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 PA size. +*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* 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_PMSA_SUPPORT ) && + (system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) ) + goto fault; + +/* Stage 1 EL1&0 translation regime uses PMSAv8 by default */ + vtcr_el2 &= ~VTCR_MSA ; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8-R only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ; + +/* +* cpuinfo sanitization makes sure we support 16-bits VMID only if all cores +* are supporting it. +* +* Set the VS bit only if 16 bit VMID is supported. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + { + vtcr_el2 |=VTCR_VS ; + max_vmid =MAX_VMID_16_BIT ; + } +else + vtcr_el2 &= ~VTCR_VS ; + +WRITE_SYSREG (vtcr_el2,VTCR_EL2 ); + +p2m_vmid_allocator_init (); + +/* +* 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 ); + +printk ("P2M: %u-bit IPA with %u-bit PA and %u-bit VMID\n" , + p2m_ipa_bits, + pa_range_info[system_cpuinfo.mm64.pa_range], + (MAX_VMID ==MAX_VMID_16_BIT ) ?16 :8 ); + +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,U) << 30) +#define VSTCR_EL2_SC (_AC(0x1,U) << 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/processor.h +8 -0
@@ -403,6 +403,9 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#define VTCR_MSA (_AC(0x1,UL)<<31) +#define VTCR_NSA (_AC(0x1,UL)<<30) +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */
@@ -464,6 +467,11 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif +#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 +#ifndef __ASSEMBLER__extern register_t __cpu_logical_map[];
Signature · 1 line
2.34.1
Re: [PATCH v4 1/3] arm/mpu: implement setup_virt_paging for MPU systems
Quoted 114 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
Implement
setup_virt_pagingfor AArch64 MPU systems, taking care of stage 2 address translation regime, IPA bits, supported VMID length configuration and VTCR_EL2/VSTCR_EL2 register programming.Implement also the Armv8-R specific changes to
ID_AA64MMFR0_EL1, related to the supported memory system architecture (PMSA/VMSA) and check that when MPU is built, the underlying HW is compatible with PMSA. By default MPU at EL2 and EL1 is required.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]>---
v4:
- Fixed typo in the comments
- Fixed typo in the commit title and message
- movedp2m_vmid_allocator_init()after write of
VTCR_EL2
- Fixed printf format specifier %d -> %u
v3:
- Refactor unused code to more relevant commits.
- Add P2M print information
- Formatting issues
- Update commit message
v2:
- Separate commit into multiple commits--- xen/arch/arm/arm64/mpu/p2m.c | 80 +++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 4 ++ xen/arch/arm/include/asm/cpufeature.h | 13 +++- xen/arch/arm/include/asm/processor.h | 8 +++ 4 files changed, 101 insertions(+), 4 deletions(-)xen/arch/arm/arm64/mpu/p2m.c +64
-1@@ -2,11 +2,89 @@#include <xen/bug.h> #include <xen/init.h> +#include <xen/lib.h> #include <asm/p2m.h> void __init setup_virt_paging (void ) { -BUG_ON ("unimplemented" ); +register_t vtcr_el2 =READ_SYSREG (VTCR_EL2 ); +register_t 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 PA size. +*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* +* 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_PMSA_SUPPORT ) && + (system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) ) + goto fault; + +/* Stage 1 EL1&0 translation regime uses PMSAv8 by default */ + vtcr_el2 &= ~VTCR_MSA ; + +/* +* Clear VTCR_EL2.NSA bit to configure non-secure stage 2 translation output +* address space to access the Secure PA space as Armv8-R only implements +* secure state. +*/ + vtcr_el2 &= ~VTCR_NSA ; + +/* +* cpuinfo sanitization makes sure we support 16-bits VMID only if all cores +* are supporting it. +* +* Set the VS bit only if 16 bit VMID is supported. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + { + vtcr_el2 |=VTCR_VS ; + max_vmid =MAX_VMID_16_BIT ; + } +else + vtcr_el2 &= ~VTCR_VS ; + +WRITE_SYSREG (vtcr_el2,VTCR_EL2 ); + +p2m_vmid_allocator_init (); + +/* +* 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
xen/arch/arm/arm64/mpu/p2m.c line 82
Quoted 10 lines
xen/arch/arm/arm64/mpu/p2m.c +10
-0+* are different, we set SC bit 1. +*/ + vstcr_el2 &= ~VSTCR_EL2_SA ; + vstcr_el2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (vstcr_el2,VSTCR_EL2 ); + +printk ("P2M: %u-bit IPA with %u-bit PA and %u-bit VMID\n" , + p2m_ipa_bits, + pa_range_info[system_cpuinfo.mm64.pa_range], + (MAX_VMID ==MAX_VMID_16_BIT ) ?16 :8 );
NIT: No need for spaces between ().
~Michal
PATCH v4 2/3 arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
In reply to Luca FancelluFrom: Harry Ramsey <[email protected]>
Add a new device tree property v8r_el1_msa to select the MSA (memory system architecture) at EL1 for Armv8-R architecture: MPU or MMU, the former is the default if the property is not passed.
The check and setting of this new input parameter for the guest configuration is performed in arch_domain_create() instead of the more usual arch_sanitise_domain_config() because the former has access to the Xen internal guest creation flags which are required to ensure PMSA can work (domain requires static allocation and direct mapping).
The property is valid only when used on MPU systems and will result in a panic on MMU ones.
Bumped XEN_DOMCTL_INTERFACE_VERSION because of the new domctl input parameter.
---
v4:
- Rework the patch to have the v8r_el1_msa input parameter more enclosed in the Armv8-A (mmu)/Armv8-R (mpu) space.
v3:
- Improve commit message and device tree property description
- Remove macro protection
- Remove unused function is_mpu_domain
- Code formatting
--- docs/misc/arm/device-tree/booting.txt | 14 ++++ xen/arch/arm/dom0less-build.c | 3 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/include/asm/domain.h | 4 ++ xen/arch/arm/include/asm/domain_build.h | 8 +++ xen/arch/arm/include/asm/mmu/domain-build.h | 46 +++++++++++++ xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/include/asm/mpu/domain-build.h | 27 ++++++++ xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 5 ++ xen/arch/arm/mpu/arm64/mm.c | 5 ++ xen/arch/arm/mpu/domain-build.c | 76 +++++++++++++++++++++ xen/include/public/arch-arm.h | 7 ++ xen/include/public/domctl.h | 4 +- 14 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/domain-build.h create mode 100644 xen/arch/arm/include/asm/mpu/domain-build.h create mode 100644 xen/arch/arm/mpu/domain-build.c
docs/misc/arm/device-tree/booting.txt +14 -0
@@ -322,6 +322,20 @@ 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 systems, a domain + should use PMSAv8 (MPU) at EL1 or VMSAv8 (MMU) at EL1. + + - "mmu" + Enables VMSAv8 at EL1. This requires hardware support and is only + optionally available on AArch64. + + - "mpu" + Enables PMSAv8 at EL1. This is the default behaviour when the property is + not passed. This configuration requires static allocation (xen,static-mem) + and direct mapping (direct-map). + 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 +3 -0
@@ -24,6 +24,7 @@#include <asm/domain_build.h> #include <asm/firmware/sci.h> #include <asm/grant_table.h> +#include <asm/mpu.h> #include <asm/setup.h> #ifdef CONFIG_VGICV2
@@ -322,6 +323,8 @@ 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" ); +arch_dt_v8r_el1_msa_parse (node, d_cfg); +if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;
xen/arch/arm/domain.c +4 -0
@@ -18,6 +18,7 @@#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> +#include <asm/domain_build.h> #include <asm/event.h> #include <asm/gic.h> #include <asm/guest_atomics.h>
@@ -725,6 +726,9 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +if ( (rc =arch_set_v8r_el1_msa (d, config, flags)) !=0 ) + goto fail; +return 0 ; fail:
xen/arch/arm/include/asm/domain.h +4 -0
@@ -128,6 +128,10 @@ struct arch_domain#endif struct resume_info resume_ctx; + +#ifdef CONFIG_MPU +uint8_t v8r_el1_msa; +#endif } __cacheline_aligned;struct arch_vcpu
xen/arch/arm/include/asm/domain_build.h +8 -0
@@ -4,6 +4,14 @@#include <xen/fdt-kernel.h> #include <xen/sched.h> +#if defined(CONFIG_MMU ) +#include <asm/mmu/domain-build.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/domain-build.h> +#else +# error "Unknown memory management layout" +#endif +typedef __be32 gic_interrupt_t [3 ];int make_psci_node (void *fdt);void evtchn_allocate (struct domain *d);
xen/arch/arm/include/asm/mmu/domain-build.h new file +46 -0
46 lines not on this page · raw message
xen/arch/arm/include/asm/mpu.h +5 -0
@@ -27,6 +27,11 @@#ifndef __ASSEMBLER__ +/* +* Utility function to determine if an Armv8-R processor supports VMSA. +*/ +bool has_v8r_vmsa_support (void ); +/* * Set base address of MPU protection region. *
xen/arch/arm/include/asm/mpu/domain-build.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_DOMAIN_BUILD_H__ +#define __ARM_MPU_DOMAIN_BUILD_H__ + +#include <xen/device_tree.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <public/domctl.h> + +void arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg); + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags); + +#endif /* __ARM_MPU_DOMAIN_BUILD_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/mpu/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_ARM_32) += arm32/ obj-$(CONFIG_ARM_64) += arm64/ +obj-y += domain-build.o obj-y += domain-page.o obj-y += mm.o obj-y += p2m.o
xen/arch/arm/mpu/arm32/mm.c +5 -0
@@ -38,6 +38,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return false; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers:
xen/arch/arm/mpu/arm64/mm.c +5 -0
@@ -32,6 +32,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_VMSA_SUPPORT ; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers:
xen/arch/arm/mpu/domain-build.c new file +76 -0
76 lines not on this page · raw message
xen/include/public/arch-arm.h +7 -0
@@ -330,6 +330,10 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_ARM_SCI_NONE 0#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE 0 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA 2 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;
@@ -355,6 +359,9 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ uint8_t arm_sci_type; +/* IN */ +uint8_t v8r_el1_msa; + uint16_t pad; };#endif /* __XEN__ || __XEN_TOOLS__ */
xen/include/public/domctl.h +2 -2
@@ -30,9 +30,9 @@* fields) don't require a change of the version. * Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION! * -* Last version bump: Xen 4.19 +* Last version bump: Xen 4.22 */ -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000018/* * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
Signature · 1 line
2.34.1
Re: [PATCH v4 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Quoted 54 lines · Luca Fancellu
From: Harry Ramsey <[email protected]>
Add a new device tree property
v8r_el1_msato select the MSA (memory system architecture) at EL1 for Armv8-R architecture: MPU or MMU, the former is the default if the property is not passed.The check and setting of this new input parameter for the guest configuration is performed in
arch_domain_create()instead of the more usualarch_sanitise_domain_config()because the former has access to the Xen internal guest creation flags which are required to ensure PMSA can work (domain requires static allocation and direct mapping).The property is valid only when used on MPU systems and will result in a panic on MMU ones.
Bumped
XEN_DOMCTL_INTERFACE_VERSIONbecause of the new domctl input parameter.Signed-off-by Harry Ramsey <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v4:
- Rework the patch to have thev8r_el1_msainput parameter more enclosed in the Armv8-A (mmu)/Armv8-R (mpu) space.
v3:
- Improve commit message and device tree property description
- Remove macro protection
- Remove unused functionis_mpu_domain
- Code formatting--- docs/misc/arm/device-tree/booting.txt | 14 ++++ xen/arch/arm/dom0less-build.c | 3 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/include/asm/domain.h | 4 ++ xen/arch/arm/include/asm/domain_build.h | 8 +++ xen/arch/arm/include/asm/mmu/domain-build.h | 46 +++++++++++++ xen/arch/arm/include/asm/mpu.h | 5 ++ xen/arch/arm/include/asm/mpu/domain-build.h | 27 ++++++++ xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/arm32/mm.c | 5 ++ xen/arch/arm/mpu/arm64/mm.c | 5 ++ xen/arch/arm/mpu/domain-build.c | 76 +++++++++++++++++++++ xen/include/public/arch-arm.h | 7 ++ xen/include/public/domctl.h | 4 +- 14 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/domain-build.h create mode 100644 xen/arch/arm/include/asm/mpu/domain-build.h create mode 100644 xen/arch/arm/mpu/domain-build.cdocs/misc/arm/device-tree/booting.txt +0
-0
docs/misc/arm/device-tree/booting.txt with the following properties: · line 328
Quoted 7 lines
docs/misc/arm/device-tree/booting.txt +4
-0@@ -322,6 +322,20 @@ 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 systems, a domain + should use PMSAv8 (MPU) at EL1 or VMSAv8 (MMU) at EL1.
Instead of repeating at EL1 you could move it next to "on Armv8R systems"
docs/misc/arm/device-tree/booting.txt with the following properties: · line 332
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+ + - "mmu" + Enables VMSAv8 at EL1. This requires hardware support and is only + optionally available on AArch64.
Maybe it's due to the combination of words but it does not immediately tell that it's not present on AArch32. I would add: "Not supported on AArch32".
Quoted 22 lines
docs/misc/arm/device-tree/booting.txt +6
-0+ + - "mpu" + Enables PMSAv8 at EL1. This is the default behaviour when the property is + not passed. This configuration requires static allocation (xen,static-mem) + and direct mapping (direct-map). + 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@@ -24,6 +24,7 @@#include <asm/domain_build.h> #include <asm/firmware/sci.h> #include <asm/grant_table.h> +#include <asm/mpu.h> #include <asm/setup.h> #ifdef CONFIG_VGICV2
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 326
Quoted 4 lines
xen/arch/arm/dom0less-build.c +1
-0@@ -322,6 +323,8 @@ 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" ); +arch_dt_v8r_el1_msa_parse (node, d_cfg);
"arch" prefix should be used by functions called from the common code that have arch-specific implementation. This is not the case for functions you're introducing here, so please drop this prefix.
Also, I would continue using the SCI approach e.g. call it domu_dt_msa_parse() and decide to panic at the call site rather than making this decision in the function itself.
Quoted 46 lines
xen/arch/arm/dom0less-build.c +1
-0+if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;xen/arch/arm/domain.c +4
-0@@ -18,6 +18,7 @@#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> +#include <asm/domain_build.h> #include <asm/event.h> #include <asm/gic.h> #include <asm/guest_atomics.h> @@ -725,6 +726,9 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +if ( (rc =arch_set_v8r_el1_msa (d, config, flags)) !=0 ) + goto fail; +return 0 ; fail:xen/arch/arm/include/asm/domain.h +4
-0@@ -128,6 +128,10 @@ struct arch_domain#endif struct resume_info resume_ctx; + +#ifdef CONFIG_MPU +uint8_t v8r_el1_msa; +#endif } __cacheline_aligned;struct arch_vcpu xen/arch/arm/include/asm/domain_build.h +0
-0
xen/arch/arm/include/asm/domain_build.h line 12
Quoted 9 lines
xen/arch/arm/include/asm/domain_build.h +6
-0@@ -4,6 +4,14 @@#include <xen/fdt-kernel.h> #include <xen/sched.h> +#if defined(CONFIG_MMU ) +#include <asm/mmu/domain-build.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/domain-build.h> +#else +# error "Unknown memory management layout"
I don't think that this error msg is correct for domain build.
Quoted 62 lines
xen/arch/arm/include/asm/domain_build.h +2
-0+#endif +typedef __be32 gic_interrupt_t [3 ];int make_psci_node (void *fdt);void evtchn_allocate (struct domain *d);xen/arch/arm/include/asm/mmu/domain-build.h new file +46
-0@@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MMU_DOMAIN_BUILD_H__ +#define __ARM_MMU_DOMAIN_BUILD_H__ + +#include <xen/device_tree.h> +#include <xen/errno.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <public/domctl.h> + +static inline +void arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg) +{ +const char *v8r_el1_msa; + +if ( !dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa) ) +panic ("'v8r_el1_msa' property found, but CONFIG_MPU not selected\n" ); +} + +static inline +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags) +{ +if ( config->arch.v8r_el1_msa ) + { +dprintk (XENLOG_INFO , +"arch.v8r_el1_msa set, but CONFIG_MPU not selected\n" ); +return -EINVAL ; + } + +return 0 ; +} + +#endif /* __ARM_MMU_DOMAIN_BUILD_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/include/asm/mpu.h +0
-0
xen/arch/arm/include/asm/mpu.h line 32
Quoted 6 lines
xen/arch/arm/include/asm/mpu.h +3
-0@@ -27,6 +27,11 @@#ifndef __ASSEMBLER__ +/* +* Utility function to determine if an Armv8-R processor supports VMSA. +*/
NIT: No need for multi-line comment for a single sentence that can fit in one line.
Quoted 139 lines
xen/arch/arm/include/asm/mpu.h +2
-0+bool has_v8r_vmsa_support (void ); +/* * Set base address of MPU protection region. * xen/arch/arm/include/asm/mpu/domain-build.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_DOMAIN_BUILD_H__ +#define __ARM_MPU_DOMAIN_BUILD_H__ + +#include <xen/device_tree.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <public/domctl.h> + +void arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg); + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags); + +#endif /* __ARM_MPU_DOMAIN_BUILD_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/mpu/Makefile +1
-0@@ -1,5 +1,6 @@ obj-$(CONFIG_ARM_32) += arm32/ obj-$(CONFIG_ARM_64) += arm64/ +obj-y += domain-build.o obj-y += domain-page.o obj-y += mm.o obj-y += p2m.oxen/arch/arm/mpu/arm32/mm.c +5
-0@@ -38,6 +38,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return false; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/arm64/mm.c +5
-0@@ -32,6 +32,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_VMSA_SUPPORT ; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/domain-build.c new file +52
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/device_tree.h> +#include <xen/domain.h> +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/types.h> +#include <xen/sched.h> +#include <asm/mpu.h> +#include <asm/mpu/domain-build.h> +#include <public/arch-arm.h> +#include <public/domctl.h> + +void __init arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg) +{ +const char *v8r_el1_msa; + + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE ; + +if ( !dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa) ) + { +if ( !strcmp (v8r_el1_msa,"mmu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA ; +else if ( !strcmp (v8r_el1_msa,"mpu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA ; +else +panic ("Invalid device tree option for v8r_el1_msa\n" ); + } +} + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags) +{ +switch ( config->arch.v8r_el1_msa ) + { +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE : + fallthrough; +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA : +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) + { +dprintk (XENLOG_INFO , +"PMSA is not valid for domain without static allocation and direct map (v8r_el1_msa)\n" ); +return -EINVAL ; + } +break ; + +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA : +if ( !has_v8r_vmsa_support () ) + { + dprintk(XENLOG_INFO,
xen/arch/arm/mpu/domain-build.c line 62
Quoted 10 lines
xen/arch/arm/mpu/domain-build.c new file +10
-0+ "Platform does not support VMSA at EL1 (v8r_el1_msa)\n"); +return -EINVAL ; + } +break ; + +default : +dprintk (XENLOG_INFO ,"Unsupported arch.v8r_el1_msa value (%u)\n" , + config->arch.v8r_el1_msa); +return -EINVAL ; + }
Why do we even need this split. It seems like all the above checks could be done in arch_dt_v8r_el1_msa_parse given that it is called after static-mem,direct-map are set. This would simplify this file and we would not even need to introduce new domain-build split for one function.
Quoted 30 lines
xen/arch/arm/mpu/domain-build.c new file +14
-0+ + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +4
-0@@ -330,6 +330,10 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_ARM_SCI_NONE 0#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE 0 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA 2 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;
xen/include/public/arch-arm.h struct xen_arch_domainconfig { · line 364
Quoted 6 lines
xen/include/public/arch-arm.h +3
-0@@ -355,6 +359,9 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ uint8_t arm_sci_type; +/* IN */ +uint8_t v8r_el1_msa; +uint16_t pad;
Before this change there were 3B of implicit padding. Now you added 1B of data and 2B of explicit padding. The struct size is the same, so why bumping the interface version? I don't see it necessary here. Also, why explicit padding? With explicit padding I do think you need to now check that it's 0.
Quoted 9 lines
xen/include/public/arch-arm.h +0
-0};#endif /* __XEN__ || __XEN_TOOLS__ */ xen/include/public/domctl.h +0
-0@@ -30,9 +30,9 @@* fields) don't require a change of the version.
xen/include/public/domctl.h line 38
Quoted 10 lines
xen/include/public/domctl.h +2
-2* Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION! * -* Last version bump: Xen 4.19 +* Last version bump: Xen 4.22 */ -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000018/* * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
~Michal
Re: [PATCH v4 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Hi Michal,
thanks for your review,
Quoted 9 lines
Quoted 9 lines
docs/misc/arm/device-tree/booting.txt +0
-0@@ -322,6 +322,20 @@ with the following properties: Should be used together with scmi-smc-passthrough Xen command line option.
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt with the following properties: · line 328
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+- v8r_el1_msa + + A string property specifying whether, on Armv8-R systems, a domain + should use PMSAv8 (MPU) at EL1 or VMSAv8 (MMU) at EL1.Instead of repeating at EL1 you could move it next to "on Armv8R systems"
ok
Quoted 7 lines
docs/misc/arm/device-tree/booting.txt with the following properties: · line 332
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt +4
-0+ + - "mmu" + Enables VMSAv8 at EL1. This requires hardware support and is only + optionally available on AArch64.Maybe it's due to the combination of words but it does not immediately tell that it's not present on AArch32. I would add: "Not supported on AArch32".
Ok
Quoted 26 lines
Quoted 26 lines
docs/misc/arm/device-tree/booting.txt +6
-0+ + - "mpu" + Enables PMSAv8 at EL1. This is the default behaviour when the property is + not passed. This configuration requires static allocation (xen,static-mem) + and direct mapping (direct-map). +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@@ -24,6 +24,7 @@#include <asm/domain_build.h> #include <asm/firmware/sci.h> #include <asm/grant_table.h> +#include <asm/mpu.h> #include <asm/setup.h> #ifdef CONFIG_VGICV2 @@ -322,6 +323,8 @@ 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" );
Quoted 8 lines
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 326
Quoted 1 line
xen/arch/arm/dom0less-build.c +1
-0+arch_dt_v8r_el1_msa_parse (node, d_cfg);"arch" prefix should be used by functions called from the common code that have arch-specific implementation. This is not the case for functions you're introducing here, so please drop this prefix.
Also, I would continue using the SCI approach e.g. call it
domu_dt_msa_parse()and decide to panic at the call site rather than making this decision in the function itself.
sounds good
Quoted 50 lines
Quoted 50 lines
xen/arch/arm/dom0less-build.c +1
-0+if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;xen/arch/arm/domain.c +4
-0@@ -18,6 +18,7 @@#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> +#include <asm/domain_build.h> #include <asm/event.h> #include <asm/gic.h> #include <asm/guest_atomics.h> @@ -725,6 +726,9 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +if ( (rc =arch_set_v8r_el1_msa (d, config, flags)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/include/asm/domain.h +4
-0@@ -128,6 +128,10 @@ struct arch_domain#endif struct resume_info resume_ctx; + +#ifdef CONFIG_MPU +uint8_t v8r_el1_msa; +#endif } __cacheline_aligned;struct
arch_vcpuxen/arch/arm/include/asm/domain_build.h +0
-0@@ -4,6 +4,14 @@#include <xen/fdt-kernel.h> #include <xen/sched.h>
Quoted 7 lines
xen/arch/arm/include/asm/domain_build.h line 12
Quoted 6 lines
xen/arch/arm/include/asm/domain_build.h +6
-0+#if defined(CONFIG_MMU ) +#include <asm/mmu/domain-build.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/domain-build.h> +#else +# error "Unknown memory management layout"I don't think that this error msg is correct for domain build.
are you suggesting dropping the error or modifying the message?
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/include/asm/mpu.h +0
-0@@ -27,6 +27,11 @@
Quoted 6 lines
xen/arch/arm/include/asm/mpu.h line 32
Quoted 5 lines
xen/arch/arm/include/asm/mpu.h +3
-0#ifndef __ASSEMBLER__ +/* +* Utility function to determine if an Armv8-R processor supports VMSA. +*/ NIT: No need for multi-line comment for a single sentence that can fit in one line.
ok
Quoted 146 lines
Quoted 146 lines
xen/arch/arm/include/asm/mpu.h +2
-0+bool has_v8r_vmsa_support (void ); +/* * Set base address of MPU protection region. * xen/arch/arm/include/asm/mpu/domain-build.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_DOMAIN_BUILD_H__ +#define __ARM_MPU_DOMAIN_BUILD_H__ + +#include <xen/device_tree.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <public/domctl.h> + +void arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg); + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags); + +#endif /* __ARM_MPU_DOMAIN_BUILD_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/mpu/Makefile +0
-0@@ -1,5 +1,6 @@obj-$(CONFIG_ARM_32) += arm32/
obj-$(CONFIG_ARM_64) += arm64/
+obj-y += domain-build.o
obj-y += domain-page.o
obj-y += mm.o
obj-y += p2m.oxen/arch/arm/mpu/arm32/mm.c +5
-0@@ -38,6 +38,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return false; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/arm64/mm.c +5
-0@@ -32,6 +32,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_VMSA_SUPPORT ; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/domain-build.c new file +58
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/device_tree.h> +#include <xen/domain.h> +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/types.h> +#include <xen/sched.h> +#include <asm/mpu.h> +#include <asm/mpu/domain-build.h> +#include <public/arch-arm.h> +#include <public/domctl.h> + +void __init arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg) +{ +const char *v8r_el1_msa; + + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE ; + +if ( !dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa) ) + { +if ( !strcmp (v8r_el1_msa,"mmu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA ; +else if ( !strcmp (v8r_el1_msa,"mpu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA ; +else +panic ("Invalid device tree option for v8r_el1_msa\n" ); + } +} + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags) +{ +switch ( config->arch.v8r_el1_msa ) + { +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE : + fallthrough; +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA : +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) + { +dprintk (XENLOG_INFO , +"PMSA is not valid for domain without static allocation and direct map (v8r_el1_msa)\n" ); +return -EINVAL ; + } +break ; + +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA : +if ( !has_v8r_vmsa_support () ) + { +dprintk (XENLOG_INFO , +"Platform does not support VMSA at EL1 (v8r_el1_msa)\n" ); +return -EINVAL ; + } +break ; + +default :
Quoted 8 lines
xen/arch/arm/mpu/domain-build.c line 62
Quoted 4 lines
xen/arch/arm/mpu/domain-build.c new file +4
-0+dprintk (XENLOG_INFO ,"Unsupported arch.v8r_el1_msa value (%u)\n" , + config->arch.v8r_el1_msa); +return -EINVAL ; + }Why do we even need this split. It seems like all the above checks could be done in
arch_dt_v8r_el1_msa_parsegiven that it is called after static-mem,direct-map are set. This would simplify this file and we would not even need to introduce new domain-build split for one function.
Please correct me if I’m wrong, if I move the checks in arch_dt_v8r_el1_msa_parse() they will be handled only on dom0less domain creation only.
If I have it in the current way it will be handled by dom0less and XL toolstack creation. I understand that for now the toolstack path is not implemented, but it felt better to do this now rather than change it later.
Let me know what you think.
Quoted 33 lines
Quoted 33 lines
xen/arch/arm/mpu/domain-build.c new file +14
-0+ + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +4
-0@@ -330,6 +330,10 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_ARM_SCI_NONE 0#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE 0 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA 2 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;@@ -355,6 +359,9 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */
Quoted 8 lines
xen/include/public/arch-arm.h struct xen_arch_domainconfig { · line 364
Quoted 4 lines
xen/include/public/arch-arm.h +3
-0uint8_t arm_sci_type; +/* IN */ +uint8_t v8r_el1_msa; +uint16_t pad;Before this change there were 3B of implicit padding. Now you added 1B of data and 2B of explicit padding. The struct size is the same, so why bumping the interface version? I don't see it necessary here. Also, why explicit padding? With explicit padding I do think you need to now check that it's 0.
I’ve bumped because if an older toolstack is passing something that is not zero in the v8r_el1_msa we would return an error and stop the domain creation by the above:
---
Quoted 6 lines
Quoted 6 lines
static inline
xen/include/public/arch-arm.h +5
-0+int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags) +{ +if ( config->arch.v8r_el1_msa )
Quoted 8 lines
xen/include/public/arch-arm.h
Quoted 8 lines
xen/include/public/arch-arm.h +8
-0+ { +dprintk (XENLOG_INFO , +"arch.v8r_el1_msa set, but CONFIG_MPU not selected\n" ); +return -EINVAL ; + } + +return 0 ; +}
---
So I thought this was a breaking change on it’s own, regarless of checking that the padding is zero.
Let me know what you think, I would drop the explicit padding and version bump if you say that adding v8r_el1_msa is not breaking the interface.
Quoted 18 lines
Quoted 18 lines
};
#endif /*__XEN__||__XEN_TOOLS__*/xen/include/public/domctl.h +2
-2@@ -30,9 +30,9 @@* fields) don't require a change of the version. * Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION! * -* Last version bump: Xen 4.19 +* Last version bump: Xen 4.22 */ -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000018
Quoted 5 lines
xen/include/public/domctl.h line 38
Quoted 2 lines
xen/include/public/domctl.h +0
-0/* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. ~Michal
Cheers,
Luca
Re: [PATCH v4 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains
Quoted 126 lines · Luca Fancellu
Hi Michal,
thanks for your review,
Quoted 9 lines
Quoted 9 lines
docs/misc/arm/device-tree/booting.txt +0
-0@@ -322,6 +322,20 @@ with the following properties: Should be used together with scmi-smc-passthrough Xen command line option.Quoted 5 lines
docs/misc/arm/device-tree/booting.txt with the following properties: · line 328
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+- v8r_el1_msa + + A string property specifying whether, on Armv8-R systems, a domain + should use PMSAv8 (MPU) at EL1 or VMSAv8 (MMU) at EL1.Instead of repeating at EL1 you could move it next to "on Armv8R systems"
ok
Quoted 7 lines
docs/misc/arm/device-tree/booting.txt with the following properties: · line 332
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt +4
-0+ + - "mmu" + Enables VMSAv8 at EL1. This requires hardware support and is only + optionally available on AArch64.Maybe it's due to the combination of words but it does not immediately tell that it's not present on AArch32. I would add: "Not supported on AArch32".
Ok
Quoted 26 lines
Quoted 26 lines
docs/misc/arm/device-tree/booting.txt +6
-0+ + - "mpu" + Enables PMSAv8 at EL1. This is the default behaviour when the property is + not passed. This configuration requires static allocation (xen,static-mem) + and direct mapping (direct-map). +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@@ -24,6 +24,7 @@#include <asm/domain_build.h> #include <asm/firmware/sci.h> #include <asm/grant_table.h> +#include <asm/mpu.h> #include <asm/setup.h> #ifdef CONFIG_VGICV2 @@ -322,6 +323,8 @@ 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" );Quoted 8 lines
xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 326
Quoted 1 line
xen/arch/arm/dom0less-build.c +1
-0+arch_dt_v8r_el1_msa_parse (node, d_cfg);"arch" prefix should be used by functions called from the common code that have arch-specific implementation. This is not the case for functions you're introducing here, so please drop this prefix.
Also, I would continue using the SCI approach e.g. call it
domu_dt_msa_parse()and decide to panic at the call site rather than making this decision in the function itself.sounds good
Quoted 50 lines
Quoted 50 lines
xen/arch/arm/dom0less-build.c +1
-0+if ( !dt_property_read_u32 (node,"nr_spis" , &d_cfg->arch.nr_spis) ) {int vpl011_virq =GUEST_VPL011_SPI ;xen/arch/arm/domain.c +4
-0@@ -18,6 +18,7 @@#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> +#include <asm/domain_build.h> #include <asm/event.h> #include <asm/gic.h> #include <asm/guest_atomics.h> @@ -725,6 +726,9 @@ int arch_domain_create(struct domain *d,if ( (rc =sci_domain_init (d, config)) !=0 ) goto fail; +if ( (rc =arch_set_v8r_el1_msa (d, config, flags)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/include/asm/domain.h +4
-0@@ -128,6 +128,10 @@ struct arch_domain#endif struct resume_info resume_ctx; + +#ifdef CONFIG_MPU +uint8_t v8r_el1_msa; +#endif } __cacheline_aligned;struct
arch_vcpuxen/arch/arm/include/asm/domain_build.h +0
-0@@ -4,6 +4,14 @@#include <xen/fdt-kernel.h> #include <xen/sched.h> Quoted 7 lines
xen/arch/arm/include/asm/domain_build.h line 12
Quoted 6 lines
xen/arch/arm/include/asm/domain_build.h +6
-0+#if defined(CONFIG_MMU ) +#include <asm/mmu/domain-build.h> +#elif defined(CONFIG_MPU ) +#include <asm/mpu/domain-build.h> +#else +# error "Unknown memory management layout"I don't think that this error msg is correct for domain build.
Quoted 1 line
are you suggesting dropping the error or modifying the message?
modifying the message
Quoted 172 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/mpu.h +0
-0@@ -27,6 +27,11 @@Quoted 6 lines
xen/arch/arm/include/asm/mpu.h line 32
Quoted 5 lines
xen/arch/arm/include/asm/mpu.h +3
-0#ifndef __ASSEMBLER__ +/* +* Utility function to determine if an Armv8-R processor supports VMSA. +*/ NIT: No need for multi-line comment for a single sentence that can fit in one line.
ok
Quoted 146 lines
Quoted 146 lines
xen/arch/arm/include/asm/mpu.h +2
-0+bool has_v8r_vmsa_support (void ); +/* * Set base address of MPU protection region. * xen/arch/arm/include/asm/mpu/domain-build.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_DOMAIN_BUILD_H__ +#define __ARM_MPU_DOMAIN_BUILD_H__ + +#include <xen/device_tree.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <public/domctl.h> + +void arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg); + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags); + +#endif /* __ARM_MPU_DOMAIN_BUILD_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/mpu/Makefile +0
-0@@ -1,5 +1,6 @@obj-$(CONFIG_ARM_32) += arm32/
obj-$(CONFIG_ARM_64) += arm64/
+obj-y += domain-build.o
obj-y += domain-page.o
obj-y += mm.o
obj-y += p2m.oxen/arch/arm/mpu/arm32/mm.c +5
-0@@ -38,6 +38,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return false; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/arm64/mm.c +5
-0@@ -32,6 +32,11 @@break ; \ } +bool has_v8r_vmsa_support (void ) +{ +return system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_VMSA_SUPPORT ; +} +/* * Armv8-R supports direct access and indirect access to the MPU regions through * registers: xen/arch/arm/mpu/domain-build.c new file +58
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/device_tree.h> +#include <xen/domain.h> +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/types.h> +#include <xen/sched.h> +#include <asm/mpu.h> +#include <asm/mpu/domain-build.h> +#include <public/arch-arm.h> +#include <public/domctl.h> + +void __init arch_dt_v8r_el1_msa_parse (struct dt_device_node *node, +struct xen_domctl_createdomain *d_cfg) +{ +const char *v8r_el1_msa; + + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE ; + +if ( !dt_property_read_string (node,"v8r_el1_msa" , &v8r_el1_msa) ) + { +if ( !strcmp (v8r_el1_msa,"mmu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA ; +else if ( !strcmp (v8r_el1_msa,"mpu" ) ) + d_cfg->arch.v8r_el1_msa =XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA ; +else +panic ("Invalid device tree option for v8r_el1_msa\n" ); + } +} + +int arch_set_v8r_el1_msa (struct domain *d, +const struct xen_domctl_createdomain *config, +unsigned int flags) +{ +switch ( config->arch.v8r_el1_msa ) + { +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE : + fallthrough; +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA : +if ( !(flags & CDF_staticmem) || !(flags & CDF_directmap) ) + { +dprintk (XENLOG_INFO , +"PMSA is not valid for domain without static allocation and direct map (v8r_el1_msa)\n" ); +return -EINVAL ; + } +break ; + +case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA : +if ( !has_v8r_vmsa_support () ) + { +dprintk (XENLOG_INFO , +"Platform does not support VMSA at EL1 (v8r_el1_msa)\n" ); +return -EINVAL ; + } +break ; + +default :Quoted 8 lines
xen/arch/arm/mpu/domain-build.c line 62
Quoted 4 lines
xen/arch/arm/mpu/domain-build.c new file +4
-0+dprintk (XENLOG_INFO ,"Unsupported arch.v8r_el1_msa value (%u)\n" , + config->arch.v8r_el1_msa); +return -EINVAL ; + }Why do we even need this split. It seems like all the above checks could be done in
arch_dt_v8r_el1_msa_parsegiven that it is called after static-mem,direct-map are set. This would simplify this file and we would not even need to introduce new domain-build split for one function.
Quoted 7 lines
Please correct me if I’m wrong, if I move the checks in
arch_dt_v8r_el1_msa_parse()they will be handled only on dom0less domain creation only.
If I have it in the current way it will be handled by dom0less and XL toolstack creation. I understand that for now the toolstack path is not implemented, but it felt better to do this now rather than change it later.Let me know what you think.
MPU == everything static, so I'm not sure how dynamic domain creation via libxl would come into play here.
Quoted 43 lines
Quoted 34 lines
Quoted 34 lines
xen/arch/arm/mpu/domain-build.c new file +14
-0+ + d->arch.v8r_el1_msa = config->arch.v8r_el1_msa; + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +4
-0@@ -330,6 +330,10 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_ARM_SCI_NONE 0#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE 0 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA 1 +#define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA 2 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;@@ -355,6 +359,9 @@ struct xen_arch_domainconfig {uint32_t clock_frequency;/* IN */ Quoted 8 lines
xen/include/public/arch-arm.h struct xen_arch_domainconfig { · line 364
Quoted 4 lines
xen/include/public/arch-arm.h +3
-0uint8_t arm_sci_type; +/* IN */ +uint8_t v8r_el1_msa; +uint16_t pad;Before this change there were 3B of implicit padding. Now you added 1B of data and 2B of explicit padding. The struct size is the same, so why bumping the interface version? I don't see it necessary here. Also, why explicit padding? With explicit padding I do think you need to now check that it's 0.
Quoted 3 lines
I’ve bumped because if an older toolstack is passing something that is not zero in the
v8r_el1_msawe would return an error and stop the domain creation by the above:
I guess we won't have this issue if we drop arch_set_v8r_el1_msa as suggested above.
~Michal
PATCH v4 3/3 arm/mpu: Implement p2m tables
In reply to Luca FancelluFrom: Harry Ramsey <[email protected]>
Implement p2m_alloc_table, p2m_init and p2m_final_teardown for MPU systems.
---
v4:
- no changes
v3:
- Check for alloc_xenheap_pages allocation
- Clear additional page allocated for ARM64
- Add check for INVALID_VCPU_ID
- Remove unnecessary function generate_vsctlr
- Code formatting fixes
--- xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/mpu/p2m.h | 12 +++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/mpu/p2m.c | 78 ++++++++++++++++++++++++++-- 5 files changed, 96 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/p2m.h +12 -0
@@ -3,8 +3,20 @@#ifndef __ARM_MPU_P2M_H__#define __ARM_MPU_P2M_H__ +#include <xen/bitops.h> +#include <xen/macros.h> +#include <xen/page-size.h> +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). +*/ +#define P2M_ROOT_PAGES DIV_ROUND_UP(255 * sizeof(pr_t), PAGE_SIZE) +#define P2M_ROOT_ORDER get_count_order(P2M_ROOT_PAGES) +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/mpu/p2m.c +75 -3
92 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v4 3/3] arm/mpu: Implement p2m tables
Quoted 58 lines · Luca Fancellu
From: Harry Ramsey <[email protected]>
Implement
p2m_alloc_table,p2m_initandp2m_final_teardownfor MPU systems.Signed-off-by Harry Ramsey <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v4:
- no changes
v3:
- Check foralloc_xenheap_pagesallocation
- Clear additional page allocated for ARM64
- Add check forINVALID_VCPU_ID
- Remove unnecessary functiongenerate_vsctlr
- Code formatting fixes--- xen/arch/arm/include/asm/arm32/mpu.h | 2 + xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/mpu/p2m.h | 12 +++++ xen/arch/arm/include/asm/p2m.h | 5 ++ xen/arch/arm/mpu/p2m.c | 78 ++++++++++++++++++++++++++-- 5 files changed, 96 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/p2m.h +0
-0@@ -3,8 +3,20 @@#ifndef __ARM_MPU_P2M_H__#define __ARM_MPU_P2M_H__
xen/arch/arm/include/asm/mpu/p2m.h line 15
Quoted 10 lines
xen/arch/arm/include/asm/mpu/p2m.h +8
-0+#include <xen/bitops.h> +#include <xen/macros.h> +#include <xen/page-size.h> +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).
This comment may go stale if we add something to pr_t. I don't think it's super useful.
xen/arch/arm/include/asm/mpu/p2m.h line 17
Quoted 2 lines
xen/arch/arm/include/asm/mpu/p2m.h +2
-0+*/ +#define P2M_ROOT_PAGES DIV_ROUND_UP(255 * sizeof(pr_t), PAGE_SIZE)
Please don't opencode max number of regions. Instead use MAX_MPU_REGION_NR
Quoted 36 lines
xen/arch/arm/include/asm/mpu/p2m.h +2
-0+#define P2M_ROOT_ORDER get_count_order(P2M_ROOT_PAGES) +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/mpu/p2m.c +5
-0@@ -28,10 +28,69 @@ void p2m_dump_info(struct domain *d)BUG_ON ("unimplemented" ); } +static int p2m_alloc_table (struct domain *d) +{ +struct p2m_domain *p2m =p2m_get_hostp2m (d); +void *table =alloc_xenheap_pages (P2M_ROOT_ORDER ,0 ); +
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 45
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10
-0+if ( !table ) + { +printk (XENLOG_G_ERR "%pd: p2m: unable to allocate P2M MPU mapping table\n" , + d); +return -ENOMEM ; + } + + p2m->root =virt_to_page (table); + +for (int i =0 ; i <P2M_ROOT_PAGES ; i++)
unsigned int and we usually declare it at the top
Also, missing spaces around brackets
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 46
Quoted 1 line
xen/arch/arm/mpu/p2m.c +1
-0+clear_page (page_to_virt (p2m->root + i));
Instead of the conversion, you should use table here which is already a VA.
Quoted 35 lines
xen/arch/arm/mpu/p2m.c +31
-2+ +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); + + 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 ); +BUILD_BUG_ON ((1 << (sizeof (p2m->last_vcpu_ran[0 ]) *8 )) <INVALID_VCPU_ID ); + +for_each_possible_cpu (cpu) + p2m->last_vcpu_ran[cpu] =INVALID_VCPU_ID ; + +/* +* "Trivial" initialization is now complete. Set the backpointer so that +* p2m_teardown() and related functions know to do something. +*/ + p2m->domain = d; +
xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 89
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10
-0+ rc =p2m_alloc_vmid (d); +if ( rc ) +return rc; + + p2m->vsctlr = ((register_t )p2m->vmid <<VSCTLR_VMID_SHIFT ); + + rc =p2m_alloc_table (d); +if ( rc ) + { +p2m_free_vmid (d);
You should not free it because you risk double free given that it is also freed in p2m_final_teardown. That's why on MMU we don't do it.
Quoted 19 lines
xen/arch/arm/mpu/p2m.c +11
-1+return rc; + } + +return 0 ; }void p2m_save_state (struct vcpu *p)@@ -46,7 +105,20 @@ void p2m_restore_state(struct vcpu *n)void p2m_final_teardown (struct domain *d) { -BUG_ON ("unimplemented" ); +struct p2m_domain *p2m =p2m_get_hostp2m (d); + +/* p2m not actually initialized */ +if ( !p2m->domain ) +return ; + +if ( p2m->root )
xen/arch/arm/mpu/p2m.c void p2m_restore_state(struct vcpu *n) · line 124
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +7
-0+free_xenheap_pages (page_to_virt (p2m->root),P2M_ROOT_ORDER ); + + p2m->root =NULL ; + +p2m_free_vmid (d); + + p2m->domain =NULL ; }bool p2m_resolve_translation_fault (struct domain *d,gfn_t gfn)
~Michal