[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 1/3] arm/mpu: implement setup_virt_paging for MPU systems


  • To: Luca Fancellu <luca.fancellu@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Wed, 29 Apr 2026 13:11:58 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1OhkMHXducRriWhUH8Hmrl2Wr8sNaEW9VFkdIaPlvwY=; b=A3P0Usq/w8amGOUgodAMA+YNbSViEgAB8AdkNyMnUWdOdMYcq2+NXI8O8SZhGMSqXIYWLmhP7dulQxFx1oHW9CvlaGGztavZEVDpns1nYY5sS54S/ezUki5381OUk69bX4uOCZTMQeIwcHC5NlWc+dNPAf2CZYT9ChwaqNCPq0ijNwLjOxZ97q6qACN5x+xOBN8qz+/L4wtRGg0etd+pFnws0ZGrLNSxQZYusEGKjIdL6CrHQEAgckCorZwDqR2nvxkHy53jxdmjtFM+s4Bv60qL92udgRLzP2EXw/X5Pdz8dz/ZvmuYUI/E3MdQO9FOvyQGBzmwr6LzKNSNP9gnKA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JY2QU+Bv3d9eavG3kWFDtSbS1wfd/xftlcco9FD9n3MAZ7AOliO+u59VvMEBKbyFMRGgg9RQ/zjuujIpnLRTBxP8kzAa8RO3+Ex+zBlfGeCjuG5RxfZhKJmIwq9dzMyFpI1mJ6StRqviLuTtr8defX8fySOC6ORFw0MjI7V7pLTsq7sxUDYSzJij2gZRi0CEjp6hSGMtbOQ9+l/njVD81y6KRZ1S7GsHsVHivXxYb8JiyN1te7C6o51V/Seidq5yijrUrABQid8IN7HfWjwQXx4FW46MIofX3tomyLTH8AToEr2fkdYKeCVgm1zgQJcoPvj3ABT6/f3vgGGsswlbsw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: Penny Zheng <Penny.Zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <wei.chen@xxxxxxx>, Hari Limaye <hari.limaye@xxxxxxx>, Harry Ramsey <harry.ramsey@xxxxxxx>
  • Delivery-date: Wed, 29 Apr 2026 11:12:13 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 20-Apr-26 16:22, Luca Fancellu wrote:
> From: Penny Zheng <Penny.Zheng@xxxxxxx>
> 
> 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.
> 
> Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
> Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> Signed-off-by: Hari Limaye <hari.limaye@xxxxxxx>
> Signed-off-by: Harry Ramsey <harry.ramsey@xxxxxxx>
> ---
> 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(-)
> 
> diff --git a/xen/arch/arm/arm64/mpu/p2m.c b/xen/arch/arm/arm64/mpu/p2m.c
> index b6d8b2777b58..a39a1fc38946 100644
> --- a/xen/arch/arm/arm64/mpu/p2m.c
> +++ b/xen/arch/arm/arm64/mpu/p2m.c
> @@ -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);
NIT: No need for spaces between ().

Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.