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

Re: [PATCH v3 1/3] arm/mpu: implement setup_virt_paging for MPU system


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Mon, 13 Apr 2026 12:28:01 +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=H/z2OmdoXPcAEd3PIyGujSBvqgVOqgg6qrZm7JIsj0E=; b=AhbPHkeKzF8nnnJbx3BJK8pa9GlAgs5gUUdN0zPH106E4uHTAXkvK7x4MTslbRrL3z7PPumqHUddA0wlUoAdrtaFApi8HJBgWiUe5I96Z+kKzJzDA4z/5s8/jy9FutXqj5jUMfo0KqdHPR40CXVZyEfF1RmmIeVEhxJe0UUwubB8h4fkzv8nDYWNQdp2GL0s/d5QN5BxUSG+8TMZwH3W4lygODRjZh05LE4Vx5ZZy1YnsQEk1I55CAvSTHgmmBW0b8H/dngg4Mi8Y/MeXC+X1uxkB/Vadw41a+hzocU6TGuUs/M/btwxKH6Gkd7ioCSWbaOTPUYAvux2Fw2JlYldOw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RcIjd+Y1DP7bIOiUtF06Rg39zvHdl0Vyxzz5yXyOoWh/t+7S/fF7BT+1W3QUOkPJ1MifZ6IrY1eqsDiq+qe1elrr8Tlj5GwKg9+dQ8T2iLEBnpa5Na+8xX4je25InlQh/oXkAJE9M0xqyfvx3KI02lkUaKXoIb6kOLjNKN0d9hlJ6sGfdSJCtJIU2STkj3T9TAdXZf/hzxHRg5Vd36LXrxDRuQ42FFx0O6rc1v5KnyhjxNHgezct7jfJgt50ciXckrBOaqDLafDeSyQZqK17H5zoIe9nsS8qbip6qwo2HrpKc9u1lXdS5SeuX9MVqOCV1Bax/gG6wn/FeC6z0PFRmg==
  • 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: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "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: Mon, 13 Apr 2026 10:32:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 13/04/2026 11:54, Luca Fancellu wrote:
> Hi Michal,
> 
>>>
>>> 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 "pabits".
>>> +     */
>>> +    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 Armv8r only 
>>> implements
>>> +     * secure state.
>>> +     */
>>> +    vtcr_el2 &= ~VTCR_NSA;
>>> +
>>> +    /*
>>> +     * cpuinfo sanitization makes sure we support 16bits VMID only if all 
>>> cores
>>> +     * are supporting it.
>>> +     *
>>> +     * Set the VS bit only if 16 bit VIMD 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;
>> This is the last change to vtcr_el2. Why do you put p2m_vmid_allocator_init()
>> in-between this and write to vtcr_el2 register? It looks odd.
> 
> ok I can have the write to the register before calling 
> p2m_vmid_allocator_init, in the
> end what matters is only to call p2m_vmid_allocator_init() after setting 
> max_vmid.
> 
>>
>>> +
>>> +    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);
>>> +
>>> +    printk("P2M: %d-bit IPA with %d-bit PA and %d-bit VMID\n",
>> All these are unsigned, so %u.
> 
> Oops, blindly copying from MMU code, I realise we have the issue also there
There are many other places in Xen using incorrect printk identifiers but for
the new code we should use the correct ones.

~Michal




 


Rackspace

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