Skip to contentSkip to conversation

Fifth MPU Series

PATCH Superseded Luca Fancellu 4 participants 19 messages May 8 – May 12

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 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 10d417b8b62efa5093707c1dfe9bd48e0abeb331.

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            | 74 ++++++++++++++++++++++
 xen/arch/arm/domain.c                    | 11 ++++
 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  | 21 +++++++
 xen/arch/arm/include/asm/mpu/p2m.h       |  7 +++
 xen/arch/arm/include/asm/p2m.h           |  5 ++
 xen/arch/arm/include/asm/processor.h     |  8 +++
 xen/arch/arm/mpu/arm32/mm.c              | 17 +++++
 xen/arch/arm/mpu/arm64/mm.c              | 18 ++++++
 xen/arch/arm/mpu/p2m.c                   | 72 ++++++++++++++++++++-
 xen/include/public/arch-arm.h            |  6 ++
 xen/include/public/domctl.h              |  4 +-
 18 files changed, 353 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 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.

---
v5:
- removed spaces in inline if condition
- Add Michal R-by
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
index b6d8b2777b58..4547417df97e 100644
@@ -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
index 19d409d3eb5a..f3c11d871e86 100644
@@ -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
index 13353c8e1ad1..bf902a397068 100644
@@ -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
index 1a48c9ff3b39..895d7cd50244 100644
@@ -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
#2 lore raw

PATCH v5 2/3 arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

In reply to Luca Fancellu

From: 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.

Implement the dom0less path to parse the new device tree property, add a new domctl hypercall input parameter v8r_el1_msa for arm and add the sanitisation in arch_sanitise_domain_config(), the parameter is intended to be used on CONFIG_MPU systems and returns an error if selected for MMU.

Given the breaking change, bump the XEN_DOMCTL_INTERFACE_VERSION.

---
v5:
- follow the way domu_dt_sci_parse and ARM_SCI is doing, but return error if property is present in MMU systems.
- Align the commit message on the new changes
- fix documentation
- fix multiline comment
- drop the explicit padding from struct xen_arch_domainconfig
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           | 74 +++++++++++++++++++++++++
 xen/arch/arm/domain.c                   | 11 ++++
 xen/arch/arm/include/asm/domain.h       |  4 ++
 xen/arch/arm/include/asm/domain_build.h | 21 +++++++
 xen/arch/arm/mpu/arm32/mm.c             | 17 ++++++
 xen/arch/arm/mpu/arm64/mm.c             | 18 ++++++
 xen/include/public/arch-arm.h           |  6 ++
 xen/include/public/domctl.h             |  4 +-
 9 files changed, 167 insertions(+), 2 deletions(-)
docs/misc/arm/device-tree/booting.txt +14 -0
index 977b4286082f..2389ae610963 100644
@@ -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 at EL1, a domain
+    should use PMSAv8 (MPU) or VMSAv8 (MMU).
+
+    - "mmu"
+    Enables VMSAv8 at EL1. This requires hardware support and is only
+    optionally available on AArch64. Not supported on AArch32.
+
+    - "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 +74 -0

86 lines not on this page · raw message

xen/arch/arm/domain.c +11 -0
index 26380a807cad..ac7d1abd9c7c 100644
@@ -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>
@@ -630,6 +631,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
+    if ( !v8r_el1_msa_domain_sanitise_config(config) )
+    {
+        dprintk(XENLOG_INFO, "Unsupported v8r_el1_msa value\n");
+        return -EINVAL;
+    }
+
     return sci_domain_sanitise_config(config);
 }
 
@@ -722,6 +729,10 @@ int arch_domain_create(struct domain *d,
     d->arch.sve_vl = config->arch.sve_vl;
 #endif
 
+#ifdef CONFIG_MPU
+    d->arch.v8r_el1_msa = config->arch.v8r_el1_msa;
+#endif
+
     if ( (rc = sci_domain_init(d, config)) != 0 )
         goto fail;
 
xen/arch/arm/include/asm/domain.h +4 -0
index b24f02d269be..ac7300e41fcd 100644
@@ -112,6 +112,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 +21 -0
index 6674dac5e2f8..50ddc0511e7e 100644
@@ -19,6 +19,27 @@ int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
 
 int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
 
+#ifdef CONFIG_MPU
+/* Utility function to determine if an Armv8-R processor supports VMSA. */
+bool has_v8r_vmsa_support(void);
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config);
+#else
+static inline bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)
+{
+    if ( config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE )
+        return false;
+
+    return true;
+}
+#endif /* CONFIG_MPU */
+
 #endif
 
 /*
xen/arch/arm/mpu/arm32/mm.c +17 -0
index a4673c351141..a759ebdfc124 100644
@@ -5,6 +5,8 @@
 #include <asm/mpu.h>
 #include <asm/sysregs.h>
 #include <asm/system.h>
+#include <public/arch-arm.h>
+#include <public/domctl.h>
 
 #define GENERATE_WRITE_PR_REG_CASE(num, pr)               \
     case num:                                             \
@@ -38,6 +40,21 @@
         break;                                            \
     }
 
+bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)
+{
+    if ( config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE &&
+         config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA )
+        return false;
+
+    return true;
+}
+
 /*
  * Armv8-R supports direct access and indirect access to the MPU regions through
  * registers:
xen/arch/arm/mpu/arm64/mm.c +18 -0
index ed643cad4073..441d209601c1 100644
@@ -5,6 +5,8 @@
 #include <asm/mpu.h>
 #include <asm/sysregs.h>
 #include <asm/system.h>
+#include <public/arch-arm.h>
+#include <public/domctl.h>
 
 /*
  * The following are needed for the cases: GENERATE_WRITE_PR_REG_CASE
@@ -32,6 +34,22 @@
         break;                                                  \
     }
 
+bool has_v8r_vmsa_support(void)
+{
+    return system_cpuinfo.mm64.msa_frac == MM64_MSA_FRAC_VMSA_SUPPORT;
+}
+
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)
+{
+    if ( config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE &&
+         config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA &&
+         config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA )
+        return false;
+
+    return true;
+}
+
 /*
  * Armv8-R supports direct access and indirect access to the MPU regions through
  * registers:
xen/include/public/arch-arm.h +6 -0
index cd563cf70684..6d222f15f6d5 100644
@@ -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,8 @@ struct xen_arch_domainconfig {
     uint32_t clock_frequency;
     /* IN */
     uint8_t arm_sci_type;
+    /* IN */
+    uint8_t v8r_el1_msa;
 };
 #endif /* __XEN__ || __XEN_TOOLS__ */
 
xen/include/public/domctl.h +2 -2
index 8f6708c0a7cd..23124547f347 100644
@@ -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
#3 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Quoted 14 lines · Luca Fancellu
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 +2 -0
@@ -355,6 +359,8 @@ struct xen_arch_domainconfig {
     uint32_t clock_frequency;
     /* IN */
     uint8_t arm_sci_type;
+    /* IN */
+    uint8_t v8r_el1_msa;
 };

Can you please take the opportunity and insert (and check) explicit padding, so that the next uint8_t field addition won't require ...

xen/include/public/domctl.h line 35

Quoted 11 lines
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

... such a bump?

Jan

#4 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Hi Jan,

Quoted 27 lines · Jan Beulich
Quoted 14 lines · Luca Fancellu
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 +2 -0
@@ -355,6 +359,8 @@ struct xen_arch_domainconfig {
    uint32_t clock_frequency;
    /* IN */
    uint8_t arm_sci_type;
+    /* IN */
+    uint8_t v8r_el1_msa;
 };

Can you please take the opportunity and insert (and check) explicit padding, so that the next uint8_t field addition won't require ...

Quoted 13 lines

xen/include/public/domctl.h line 35

Quoted 11 lines
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

... such a bump?

Yes, will be part of v6, thanks for your review.

Cheers,
Luca

#5 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

In reply to Luca Fancellu
Quoted 53 lines · Luca Fancellu

From: 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.

Implement the dom0less path to parse the new device tree property, add a new domctl hypercall input parameter v8r_el1_msa for arm and add the sanitisation in arch_sanitise_domain_config(), the parameter is intended to be used on CONFIG_MPU systems and returns an error if selected for MMU.

Given the breaking change, bump the XEN_DOMCTL_INTERFACE_VERSION.

---
v5:
- follow the way domu_dt_sci_parse and ARM_SCI is doing, but return error if property is present in MMU systems.
- Align the commit message on the new changes
- fix documentation
- fix multiline comment
- drop the explicit padding from struct xen_arch_domainconfig
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           | 74 +++++++++++++++++++++++++
 xen/arch/arm/domain.c                   | 11 ++++
 xen/arch/arm/include/asm/domain.h       |  4 ++
 xen/arch/arm/include/asm/domain_build.h | 21 +++++++
 xen/arch/arm/mpu/arm32/mm.c             | 17 ++++++
 xen/arch/arm/mpu/arm64/mm.c             | 18 ++++++
 xen/include/public/arch-arm.h           |  6 ++
 xen/include/public/domctl.h             |  4 +-
 9 files changed, 167 insertions(+), 2 deletions(-)
docs/misc/arm/device-tree/booting.txt +1 -0
index 977b4286082f..2389ae610963 100644
@@ -322,6 +322,20 @@ with the following properties:
     Should be used together with scmi-smc-passthrough Xen command line
     option.
 
+- v8r_el1_msa

docs/misc/arm/device-tree/booting.txt with the following properties: · line 335

Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +10 -0
+
+    A string property specifying whether, on Armv8-R systems at EL1, a domain
+    should use PMSAv8 (MPU) or VMSAv8 (MMU).
+
+    - "mmu"
+    Enables VMSAv8 at EL1. This requires hardware support and is only
+    optionally available on AArch64. Not supported on AArch32.
+
+    - "mpu"
+    Enables PMSAv8 at EL1. This is the default behaviour when the property is

s/behaviour/behavior/

Quoted 11 lines
docs/misc/arm/device-tree/booting.txt +3 -0
+    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 +0 -0
index 6f73c65e5151..2a0671bd0e8e 100644

xen/arch/arm/dom0less-build.c static int __init domu_dt_sci_parse(struct dt_device_node *node, · line 299

Quoted 5 lines
xen/arch/arm/dom0less-build.c +2 -0
@@ -295,6 +295,77 @@ static int __init domu_dt_sci_parse(struct dt_device_node *node,
     return 0;
 }
 
+static int __init
+domu_dt_v8r_el1_msa_parse(struct dt_device_node *node,

node can be const

Quoted 14 lines
xen/arch/arm/dom0less-build.c +14 -0
+                          struct xen_domctl_createdomain *d_cfg,
+                          unsigned int flags)
+{
+    bool property_present = dt_property_read_bool(node, "v8r_el1_msa");
+
+    if ( !property_present )
+        d_cfg->arch.v8r_el1_msa = XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE;
+    else
+    {
+        const char *v8r_el1_msa;
+        int ret = dt_property_read_string(node, "v8r_el1_msa", &v8r_el1_msa);
+
+        if ( ret )
+            return ret;

xen/arch/arm/dom0less-build.c static int __init domu_dt_sci_parse(struct dt_device_node *node, · line 323

Quoted 10 lines
xen/arch/arm/dom0less-build.c +10 -0
+
+        if ( !strcmp(v8r_el1_msa, "mpu") )
+            d_cfg->arch.v8r_el1_msa = XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA;
+        else if ( !strcmp(v8r_el1_msa, "mmu") )
+            d_cfg->arch.v8r_el1_msa = XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA;
+        else
+        {
+            printk(XENLOG_ERR
+                   "v8r_el1_msa value (%s) not valid for domain %s\n",
+                   v8r_el1_msa, dt_node_name(node));

dt_node_name can be any arbitrary name not necessarily denoting a domain in a meaningful way. Without a full path it can be misleading. Either print a full path or don't print it at all. Here and elsewhere.

Quoted 120 lines
xen/arch/arm/dom0less-build.c +48 -0
+            return -EINVAL;
+        }
+    }
+
+    if ( !IS_ENABLED(CONFIG_MPU) )
+    {
+        if ( !property_present )
+            return 0;
+
+        printk(XENLOG_ERR
+               "Not supported 'v8r_el1_msa' DT property found for domain %s\n",
+               dt_node_name(node));
+        return -EINVAL;
+    }
+
+    switch ( d_cfg->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) )
+        {
+            printk(XENLOG_ERR
+                   "PMSA is not valid for domain (%s) without static allocation and direct map (v8r_el1_msa)\n",
+                   dt_node_name(node));
+            return -EINVAL;
+        }
+        break;
+
+    case XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA:
+        if ( !has_v8r_vmsa_support() )
+        {
+            printk(XENLOG_ERR
+                   "Platform doesn't support VMSA at EL1 (v8r_el1_msa)\n");
+            return -EINVAL;
+        }
+        break;
+
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
 int __init arch_parse_dom0less_node(struct dt_device_node *node,
                                     struct boot_domain *bd)
 {
@@ -308,6 +379,9 @@ 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 ( domu_dt_v8r_el1_msa_parse(node, d_cfg, flags) )
+        panic("Error getting v8r_el1_msa configuration\n");
+
     if ( !dt_property_read_u32(node, "nr_spis", &d_cfg->arch.nr_spis) )
     {
         int vpl011_virq = GUEST_VPL011_SPI;
xen/arch/arm/domain.c +11 -0
index 26380a807cad..ac7d1abd9c7c 100644
@@ -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>
@@ -630,6 +631,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
+    if ( !v8r_el1_msa_domain_sanitise_config(config) )
+    {
+        dprintk(XENLOG_INFO, "Unsupported v8r_el1_msa value\n");
+        return -EINVAL;
+    }
+
     return sci_domain_sanitise_config(config);
 }
 
@@ -722,6 +729,10 @@ int arch_domain_create(struct domain *d,
     d->arch.sve_vl = config->arch.sve_vl;
 #endif
 
+#ifdef CONFIG_MPU
+    d->arch.v8r_el1_msa = config->arch.v8r_el1_msa;
+#endif
+
     if ( (rc = sci_domain_init(d, config)) != 0 )
         goto fail;
 
xen/arch/arm/include/asm/domain.h +4 -0
index b24f02d269be..ac7300e41fcd 100644
@@ -112,6 +112,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 +3 -0
index 6674dac5e2f8..50ddc0511e7e 100644
@@ -19,6 +19,27 @@ int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
 
 int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
 
+#ifdef CONFIG_MPU
+/* Utility function to determine if an Armv8-R processor supports VMSA. */
+bool has_v8r_vmsa_support(void);

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 10 lines
xen/arch/arm/include/asm/domain_build.h +10 -0
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config);
+#else
+static inline bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

Quoted 28 lines
xen/arch/arm/include/asm/domain_build.h +8 -0
+{
+    if ( config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE )
+        return false;
+
+    return true;
+}
+#endif /* CONFIG_MPU */
+
 #endif
 
 /*
xen/arch/arm/mpu/arm32/mm.c +2 -0
index a4673c351141..a759ebdfc124 100644
@@ -5,6 +5,8 @@
 #include <asm/mpu.h>
 #include <asm/sysregs.h>
 #include <asm/system.h>
+#include <public/arch-arm.h>
+#include <public/domctl.h>
 
 #define GENERATE_WRITE_PR_REG_CASE(num, pr)               \
     case num:                                             \
@@ -38,6 +40,21 @@
         break;                                            \
     }
 

xen/arch/arm/mpu/arm32/mm.c line 52

Quoted 10 lines
xen/arch/arm/mpu/arm32/mm.c +10 -0
+bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)
+{
+    if ( config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE &&
+         config->arch.v8r_el1_msa != XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA )

Please add brackets ( () && () )

~Michal

#6 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Hi Michal,

Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/domain_build.h +0 -0
index 6674dac5e2f8..50ddc0511e7e 100644
@@ -19,6 +19,27 @@ int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
 
 int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
 
Quoted 16 lines

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 13 lines
xen/arch/arm/include/asm/domain_build.h +13 -0
+#ifdef CONFIG_MPU
+/* Utility function to determine if an Armv8-R processor supports VMSA. */
+bool has_v8r_vmsa_support(void);
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config);
+#else
+static inline bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

I’ll fix all your other findings and I’ll address Jan comment on the explicit padding + check.

Cheers,
Luca

#7 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Quoted 27 lines · Luca Fancellu

Hi Michal,

Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/domain_build.h +0 -0
index 6674dac5e2f8..50ddc0511e7e 100644
@@ -19,6 +19,27 @@ int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
 
 int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
 
Quoted 16 lines

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 13 lines
xen/arch/arm/include/asm/domain_build.h +13 -0
+#ifdef CONFIG_MPU
+/* Utility function to determine if an Armv8-R processor supports VMSA. */
+bool has_v8r_vmsa_support(void);
+bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config);
+#else
+static inline bool has_v8r_vmsa_support(void)
+{
+    return false;
+}
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

Quoted 5 lines

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

~Michal

#8 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Hi Michal,

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 3 lines
xen/arch/arm/include/asm/domain_build.h +3 -0
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

Quoted 7 lines
Quoted 5 lines

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

We treat NONE as PMSA on Armv8-R, so either NONE and PMSA are valid and lead to PMSA at EL1

Cheers,
Luca

#9 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Quoted 11 lines · Luca Fancellu

Hi Michal,

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 3 lines
xen/arch/arm/include/asm/domain_build.h +3 -0
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

We treat NONE as PMSA on Armv8-R, so either NONE and PMSA are valid and lead to PMSA at EL1

NONE denotes property not set i.e. set a default. IMO at the place where we set a default, NONE should be switched to PMSA. This is a cleaner solution than giving two options the same meaning. Sanitization could then verify that indeed the default setting took place.

~Michal

#10 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Hi Michal,

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

xen/arch/arm/include/asm/domain_build.h int prepare_acpi(struct domain *d, struct kernel_info *kinfo); · line 34

Quoted 4 lines
xen/arch/arm/include/asm/domain_build.h +3 -0
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

We treat NONE as PMSA on Armv8-R, so either NONE and PMSA are valid and lead to PMSA at EL1

NONE denotes property not set i.e. set a default. IMO at the place where we set a default, NONE should be switched to PMSA. This is a cleaner solution than giving two options the same meaning. Sanitization could then verify that indeed the default setting took place.

Ok so this is a bit different from how all other *_NONE are handled currently (TEE and SCI).

So on MPU Arm32/64 now we will stop the domain creation if NONE is passed, is that the behaviour you are expecting for DOMCTL v8r_el1_msa? (Ideally we should not get this because we will switch during DT parse)

Cheers,
Luca

#11 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Quoted 24 lines · Luca Fancellu

Hi Michal,

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

We treat NONE as PMSA on Armv8-R, so either NONE and PMSA are valid and lead to PMSA at EL1

NONE denotes property not set i.e. set a default. IMO at the place where we set a default, NONE should be switched to PMSA. This is a cleaner solution than giving two options the same meaning. Sanitization could then verify that indeed the default setting took place.

Quoted 5 lines

Ok so this is a bit different from how all other *_NONE are handled currently (TEE and SCI).

So on MPU Arm32/64 now we will stop the domain creation if NONE is passed, is that the behaviour you are expecting for DOMCTL v8r_el1_msa? (Ideally we should not get this because we will switch during DT parse)

I think the confusion is that you are mixing the meaning of none (i.e. I don't want it) with not set. In case of TEE and SCI, none means you I don't want TEE or SCI, please disable them. Now, how would this look like for MPU. I don't want PMSA or VMSA? This does not make any sense because it's something impossible.

~Michal

#12 lore raw

Re: [PATCH v5 2/3] arm/mpu: Introduce `v8r_el1_msa` device tree property for domains

Quoted 25 lines
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +3 -0
+
+static inline bool v8r_el1_msa_domain_sanitise_config(
+    const struct xen_domctl_createdomain *config)

Why can't this function be common? I can see 3 definitions (Arm64 MPU, Arm32 MPU, MMU) but they do not have anything that would prevent from generalizing them in a single function.

I can do a common one I think, just to be aligned, should the common one behaves as the current implementation?

Arm64/32 MMU: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE allowed
Arm64: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA,VMSA} allowed
Arm32: Only v8r_el1_msa == XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{NONE,PMSA} allowed

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What's the reason for allowing NONE for MPU here? None denotes property not specified but at this point it should be set to a default.

We treat NONE as PMSA on Armv8-R, so either NONE and PMSA are valid and lead to PMSA at EL1

NONE denotes property not set i.e. set a default. IMO at the place where we set a default, NONE should be switched to PMSA. This is a cleaner solution than giving two options the same meaning. Sanitization could then verify that indeed the default setting took place.

Ok so this is a bit different from how all other *_NONE are handled currently (TEE and SCI).

Quoted 7 lines
Quoted 3 lines

So on MPU Arm32/64 now we will stop the domain creation if NONE is passed, is that the behaviour you are expecting for DOMCTL v8r_el1_msa? (Ideally we should not get this because we will switch during DT parse)

I think the confusion is that you are mixing the meaning of none (i.e. I don't want it) with not set. In case of TEE and SCI, none means you I don't want TEE or SCI, please disable them. Now, how would this look like for MPU. I don't want PMSA or VMSA? This does not make any sense because it's something impossible.

ok makes sense, I will then:

Arm 64/32 MMU: allow only XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE Arm 64 MPU: allow XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_{PMSA,VMSA} Arm 32 MPU: allow XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA

Cheers,
Luca

#13 lore raw

PATCH v5 3/3 arm/mpu: Implement p2m tables

In reply to Luca Fancellu

From: Harry Ramsey <[email protected]>

Implement p2m_alloc_table, p2m_init and p2m_final_teardown for MPU systems.

---
v5:
- removed comment for P2M_ROOT_PAGES/P2M_ROOT_ORDER
- used MAX_MPU_REGION_NR instead of opencoding 255
- use 'table' in p2m_alloc_table to clear pages
- remove p2m_free_vmid() from error path in p2m_init() which is already handled outside
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   |  7 +++
 xen/arch/arm/include/asm/p2m.h       |  5 ++
 xen/arch/arm/mpu/p2m.c               | 72 ++++++++++++++++++++++++++--
 5 files changed, 85 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/arm32/mpu.h +2 -0
index 2cf0f8cbacae..d565230f84ee 100644
@@ -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
index 4f694190a8a3..8b86a03fee44 100644
@@ -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 +7 -0
index e46d9e757a1d..0d4149c71987 100644
@@ -3,8 +3,15 @@
 #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;
 
+#define P2M_ROOT_PAGES DIV_ROUND_UP(MAX_MPU_REGION_NR * 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
index 010ce8c9ebbd..ed1b6dd40f40 100644
@@ -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 +69 -3

86 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v5 3/3
#14 lore raw

Re: [PATCH v5 3/3] arm/mpu: Implement p2m tables

Quoted 61 lines · Luca Fancellu

From: Harry Ramsey <[email protected]>

Implement p2m_alloc_table, p2m_init and p2m_final_teardown for MPU systems.

---
v5:
- removed comment for P2M_ROOT_PAGES/P2M_ROOT_ORDER
- used MAX_MPU_REGION_NR instead of opencoding 255
- use 'table' in p2m_alloc_table to clear pages
- remove p2m_free_vmid() from error path in p2m_init() which is already handled outside
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   |  7 +++
 xen/arch/arm/include/asm/p2m.h       |  5 ++
 xen/arch/arm/mpu/p2m.c               | 72 ++++++++++++++++++++++++++--
 5 files changed, 85 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/arm32/mpu.h +2 -0
index 2cf0f8cbacae..d565230f84ee 100644
@@ -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
index 4f694190a8a3..8b86a03fee44 100644
@@ -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
index e46d9e757a1d..0d4149c71987 100644

xen/arch/arm/include/asm/mpu/p2m.h line 12

Quoted 10 lines
xen/arch/arm/include/asm/mpu/p2m.h +5 -0
@@ -3,8 +3,15 @@
 #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;
 
+#define P2M_ROOT_PAGES DIV_ROUND_UP(MAX_MPU_REGION_NR * sizeof(pr_t), PAGE_SIZE)

You should include mpu.h for MAX_MPU_REGION_NR definition

Quoted 28 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
index 010ce8c9ebbd..ed1b6dd40f40 100644
@@ -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 +0 -0
index f7fb58ab6aa8..8d5c65b1003f 100644

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 34

Quoted 7 lines
xen/arch/arm/mpu/p2m.c +4 -0
@@ -28,10 +28,63 @@ 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);
+    char *table = alloc_xenheap_pages(P2M_ROOT_ORDER, 0);

Why char and not void? We use void and pointer arithmetic is done by treating the size of a void as 1.

Quoted 23 lines
xen/arch/arm/mpu/p2m.c +19 -2
+    unsigned int i;
+
+    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 ( i = 0; i < P2M_ROOT_PAGES; i++ )
+        clear_page(table + (i * PAGE_SIZE));
+
+    return 0;
+}
+
 int p2m_init(struct domain *d)
 {
-    BUG_ON("unimplemented");
-    return -EINVAL;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int rc = 0;

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 65

Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10 -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. */

s/in/on

With the above fixed:

~Michal

#15 lore raw

Re: [PATCH v5 3/3] arm/mpu: Implement p2m tables

Hi Michal,

Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/mpu/p2m.h +0 -0
index e46d9e757a1d..0d4149c71987 100644
@@ -3,8 +3,15 @@
 #ifndef __ARM_MPU_P2M_H__
 #define __ARM_MPU_P2M_H__
 
Quoted 8 lines

xen/arch/arm/include/asm/mpu/p2m.h line 12

Quoted 7 lines
xen/arch/arm/include/asm/mpu/p2m.h +5 -0
+#include <xen/bitops.h>
+#include <xen/macros.h>
+#include <xen/page-size.h>
+
 struct p2m_domain;
 
+#define P2M_ROOT_PAGES DIV_ROUND_UP(MAX_MPU_REGION_NR * sizeof(pr_t), PAGE_SIZE)

You should include mpu.h for MAX_MPU_REGION_NR definition

right, I’ll include

Quoted 32 lines
Quoted 32 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
index 010ce8c9ebbd..ed1b6dd40f40 100644
@@ -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 +0 -0
index f7fb58ab6aa8..8d5c65b1003f 100644
@@ -28,10 +28,63 @@ void p2m_dump_info(struct domain *d)
    BUG_ON("unimplemented");
 }
 
Quoted 6 lines

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 34

Quoted 4 lines
xen/arch/arm/mpu/p2m.c +4 -0
+static int p2m_alloc_table(struct domain *d)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    char *table = alloc_xenheap_pages(P2M_ROOT_ORDER, 0);

Why char and not void? We use void and pointer arithmetic is done by treating the size of a void as 1.

I did it on purpose since it’s a compiler extension, but if you say it’s ok I’ll change it to void.

Quoted 26 lines
Quoted 26 lines
xen/arch/arm/mpu/p2m.c +22 -2
+    unsigned int i;
+
+    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 ( i = 0; i < P2M_ROOT_PAGES; i++ )
+        clear_page(table + (i * PAGE_SIZE));
+
+    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);
Quoted 8 lines

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 65

Quoted 7 lines
xen/arch/arm/mpu/p2m.c +7 -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. */

s/in/on

will fix

Quoted 3 lines

With the above fixed:

Thanks!

Cheers,
Luca

#16 lore raw

Re: [PATCH v5 3/3] arm/mpu: Implement p2m tables

Quoted 54 lines · Luca Fancellu

Hi Michal,

Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/mpu/p2m.h +0 -0
index e46d9e757a1d..0d4149c71987 100644
@@ -3,8 +3,15 @@
 #ifndef __ARM_MPU_P2M_H__
 #define __ARM_MPU_P2M_H__
 
Quoted 8 lines

xen/arch/arm/include/asm/mpu/p2m.h line 12

Quoted 7 lines
xen/arch/arm/include/asm/mpu/p2m.h +5 -0
+#include <xen/bitops.h>
+#include <xen/macros.h>
+#include <xen/page-size.h>
+
 struct p2m_domain;
 
+#define P2M_ROOT_PAGES DIV_ROUND_UP(MAX_MPU_REGION_NR * sizeof(pr_t), PAGE_SIZE)

You should include mpu.h for MAX_MPU_REGION_NR definition

right, I’ll include

Quoted 32 lines
Quoted 32 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
index 010ce8c9ebbd..ed1b6dd40f40 100644
@@ -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 +0 -0
index f7fb58ab6aa8..8d5c65b1003f 100644
@@ -28,10 +28,63 @@ void p2m_dump_info(struct domain *d)
    BUG_ON("unimplemented");
 }
 
Quoted 8 lines
Quoted 6 lines

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 34

Quoted 4 lines
xen/arch/arm/mpu/p2m.c +4 -0
+static int p2m_alloc_table(struct domain *d)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    char *table = alloc_xenheap_pages(P2M_ROOT_ORDER, 0);

Why char and not void? We use void and pointer arithmetic is done by treating the size of a void as 1.

I did it on purpose since it’s a compiler extension, but if you say it’s ok I’ll change it to void.

Yes, this is a documented extension in our MISRA language toolchain and as you can see, we use it in our code base.

BTW, please also ...

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/arm/mpu/p2m.c +15 -0
+    unsigned int i;
+
+    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 ( i = 0; i < P2M_ROOT_PAGES; i++ )
+        clear_page(table + (i * PAGE_SIZE));
+
+    return 0;
Quoted 8 lines
Quoted 8 lines

xen/arch/arm/mpu/p2m.c void p2m_dump_info(struct domain *d) · line 55

Quoted 8 lines
xen/arch/arm/mpu/p2m.c +4 -2
+}
+
 int p2m_init(struct domain *d)
 {
-    BUG_ON("unimplemented");
-    return -EINVAL;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int rc = 0;

... drop this redundant assignment.

~Michal

#17 lore raw
In reply to Luca Fancellu

Hello Luca,

Quoted 25 lines · Luca Fancellu

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 10d417b8b62efa5093707c1dfe9bd48e0abeb331.

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            | 74 ++++++++++++++++++++++
  xen/arch/arm/domain.c                    | 11 ++++
  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  | 21 +++++++
  xen/arch/arm/include/asm/mpu/p2m.h       |  7 +++
Quoted 9 lines
  xen/arch/arm/include/asm/p2m.h           |  5 ++
  xen/arch/arm/include/asm/processor.h     |  8 +++
  xen/arch/arm/mpu/arm32/mm.c              | 17 +++++
  xen/arch/arm/mpu/arm64/mm.c              | 18 ++++++
  xen/arch/arm/mpu/p2m.c                   | 72 ++++++++++++++++++++-
  xen/include/public/arch-arm.h            |  6 ++
  xen/include/public/domctl.h              |  4 +-
  18 files changed, 353 insertions(+), 9 deletions(-)

I am okay to have this patch series in the current release:

Thanks.

~ Oleksii

#18 lore raw

Hi Oleksii,

Quoted 34 lines · Oleksii Kurochko

Hello Luca,

Quoted 20 lines · Luca Fancellu

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 10d417b8b62efa5093707c1dfe9bd48e0abeb331. 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            | 74 ++++++++++++++++++++++
 xen/arch/arm/domain.c                    | 11 ++++
 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  | 21 +++++++
 xen/arch/arm/include/asm/mpu/p2m.h       |  7 +++
Quoted 8 lines
 xen/arch/arm/include/asm/p2m.h           |  5 ++
 xen/arch/arm/include/asm/processor.h     |  8 +++
 xen/arch/arm/mpu/arm32/mm.c              | 17 +++++
 xen/arch/arm/mpu/arm64/mm.c              | 18 ++++++
 xen/arch/arm/mpu/p2m.c                   | 72 ++++++++++++++++++++-
 xen/include/public/arch-arm.h            |  6 ++
 xen/include/public/domctl.h              |  4 +-
 18 files changed, 353 insertions(+), 9 deletions(-)
Quoted 2 lines

I am okay to have this patch series in the current release:

Thanks, I will send the v6 shortly and CC you as well in the cover letter.

Cheers,
Luca