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

[XEN][PATCH 5/8] xen/arm64: make aarch32 support optional


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Wed, 23 Jul 2025 07:58:39 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • 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=YqsjkOZrnLjGC4gte2okg6lfmiavBrMr3K6zQx5JWPc=; b=oQYJpcqvzbjuHZqUMb51KJHtrlsJMPuBHg7FzLzQT+jCcmLqBJ1pmeag02rit+JxIz2tyAUBtjmqP0BgIT4zyKc61aXea5LoWH2FlbsIrq2RYtFITCPSpy94qPF/v7t2taqtYfPNMglnZITbhHqO6nMmJDvaqGrALvbI3I3kAnZM0JIqh/IpZzQFmRpwmjF9hBGyhfFSE5RYRpCcLU0/y75GkJMKs3fH3Rr5if9n9nktNlmunS2kUnBjYbkhK7L30M5cGIqjPJaDEzysVCVYDQuoS1bhdbkhnmNQRR9YpPwgOAG6tLWz8M1FatpBIKW4HL3PBQO1J8w4QnDx/Rvecg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FX130+oJ+KIlyC85aIM7m2POkGQCtHm7zjYa39lSwIy1r+XtqLpxuH89dHFgnKR7aa4BF7A09Hn808O4tpZPGzj8IfCn153db/Os6XDfAY/naRudc6SU3Z9U5Ynea9NY8BI1pH4FkwTf8Wk+qEQsES4+onzhO90btym7aRLg68kBTfSxxhCqqARlwO0OEc/n2eMc5gMhOxq8Djlz+Ii9AIABodotWKdqfa9H4Iy7ockQWbbeuEzxy8puOqTykZyneqTz/1aikUi3w8WSDbFVn7mAgjM8m7M+ICVF20NXHqCjrMRU482+LIpYmzdYGjjJgoI62SxVnelDMjCTJ6hawg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Delivery-date: Wed, 23 Jul 2025 07:58:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHb+6eZv33sEf/jFk+oo2yrINbPuA==
  • Thread-topic: [XEN][PATCH 5/8] xen/arm64: make aarch32 support optional

From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

Now Arm64 AArch32 guest support is always enabled and built-in while not
all Arm64 platforms supports AArch32 or this support might not be needed.

Hence, this patch introduces basic support for disabling Arm64 AArch32
guest support. The following changes are introduced:

- Introduce Kconfig option CONFIG_ARM64_AARCH32 to allow enable/disable
  Arm64 AArch32 guest support (default y)

- Introduce is_aarch32_enabled() helper which accounts Arm64 HW capability
  and CONFIG_ARM64_AARCH32 setting

- Set Arm64 domain type to DOMAIN_64BIT by default

- Introduce arm64_set_domain_type() to configure Arm64 domain type in
  unified way instead of open coding (d)->arch.type, and account
  CONFIG_ARM64_AARCH32 configuration.

- toolstack: do not advertise "xen-3.0-armv7l " capability if
  CONFIG_ARM64_AARCH32=n

- toolstack: reduce XEN_DOMCTL_set_address_size hypercall handler to a
  simple sanity check if CONFIG_ARM64_AARCH32=n

With CONFIG_ARM64_AARCH32=n the Xen will reject AArch32 guests (kernels) if
configured by user in the following way:
- Xen boot will fail with panic during dom0 or dom0less domains creation
- toolstack domain creation will be rejected due to xc_dom_compat_check()
  failure.

Making Arm64 AArch32 guest support open further possibilities for build
optimizations of Arm64 AArch32 guest support code.

Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
---
 xen/arch/arm/Kconfig                    |  7 ++++
 xen/arch/arm/arm64/domain-build.c       | 45 +++++++++++++++++++++++--
 xen/arch/arm/arm64/domctl.c             |  6 ++++
 xen/arch/arm/domain.c                   |  1 +
 xen/arch/arm/domain_build.c             | 24 +++----------
 xen/arch/arm/include/asm/arm32/domain.h |  6 ++++
 xen/arch/arm/include/asm/arm64/domain.h | 27 +++++++++++++++
 xen/arch/arm/setup.c                    |  2 +-
 8 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 17df147b2555..d41076143d81 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -267,6 +267,13 @@ config PCI_PASSTHROUGH
        help
          This option enables PCI device passthrough
 
+config ARM64_AARCH32
+       bool "AArch32 Guests support on on ARM64 (UNSUPPORTED)" if UNSUPPORTED
+       depends on ARM_64
+       default y
+       help
+         This option enables AArch32 Guests on ARM64.
+
 endmenu
 
 menu "ARM errata workaround via the alternative framework"
diff --git a/xen/arch/arm/arm64/domain-build.c 
b/xen/arch/arm/arm64/domain-build.c
index 3a89ee46b8c6..aa8c616dd92e 100644
--- a/xen/arch/arm/arm64/domain-build.c
+++ b/xen/arch/arm/arm64/domain-build.c
@@ -4,13 +4,54 @@
 #include <xen/sched.h>
 
 #include <asm/domain.h>
+#include <asm/arm64/sve.h>
+
+int __init arm64_set_domain_type(struct domain *d, struct kernel_info *kinfo)
+{
+    enum domain_type type;
+
+    ASSERT(d);
+    ASSERT(kinfo);
+
+    type = kinfo->arch.type;
+
+    if ( !is_aarch32_enabled() )
+    {
+        ASSERT(d->arch.type == DOMAIN_64BIT);
+
+        if ( type == DOMAIN_32BIT )
+        {
+            const char *str = "not available";
+
+            if ( !IS_ENABLED(CONFIG_ARM64_AARCH32) )
+                str = "disabled";
+            printk("aarch32 guests support is %s\n", str);
+            return -EINVAL;
+        }
+
+        return 0;
+    }
+
+    if ( is_sve_domain(d) && type == DOMAIN_32BIT )
+    {
+        printk("SVE is not available for 32-bit domain\n");
+        return -EINVAL;
+    }
+
+    d->arch.type = type;
+
+    return 0;
+}
 
 #ifdef CONFIG_DOM0LESS_BOOT
 /* TODO: make arch.type generic ? */
 void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
 {
-    /* type must be set before allocate memory */
-    d->arch.type = kinfo->arch.type;
+    int rc;
+
+    rc = arm64_set_domain_type(d, kinfo);
+    if ( rc < 0 )
+        panic("Unsupported guest type\n");
 }
 #endif
 
diff --git a/xen/arch/arm/arm64/domctl.c b/xen/arch/arm/arm64/domctl.c
index 8720d126c97d..8a243d3fbd15 100644
--- a/xen/arch/arm/arm64/domctl.c
+++ b/xen/arch/arm/arm64/domctl.c
@@ -13,6 +13,7 @@
 #include <asm/arm64/sve.h>
 #include <asm/cpufeature.h>
 
+#if defined(CONFIG_ARM64_AARCH32)
 static long switch_mode(struct domain *d, enum domain_type type)
 {
     struct vcpu *v;
@@ -50,6 +51,7 @@ static long set_address_size(struct domain *d, uint32_t 
address_size)
         return -EINVAL;
     }
 }
+#endif /* CONFIG_ARM64_AARCH32 */
 
 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
@@ -57,7 +59,11 @@ long subarch_do_domctl(struct xen_domctl *domctl, struct 
domain *d,
     switch ( domctl->cmd )
     {
     case XEN_DOMCTL_set_address_size:
+#if defined(CONFIG_ARM64_AARCH32)
         return set_address_size(d, domctl->u.address_size.size);
+#else
+        return domctl->u.address_size.size == 32 ? -EINVAL : 0;
+#endif /* CONFIG_ARM64_AARCH32 */
 
     default:
         return -ENOSYS;
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index e785278cdbd7..d08ca458a15c 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -788,6 +788,7 @@ int arch_domain_create(struct domain *d,
     /* Copy the encoded vector length sve_vl from the domain configuration */
     d->arch.sve_vl = config->arch.sve_vl;
 #endif
+    domain_set_type_default(d);
 
     return 0;
 
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index af7e9d830ae1..06dfd5bedd14 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1872,21 +1872,6 @@ int __init construct_domain(struct domain *d, struct 
kernel_info *kinfo)
     BUG_ON(d->vcpu[0] == NULL);
     BUG_ON(v->is_initialised);
 
-#ifdef CONFIG_ARM_64
-    /* if aarch32 mode is not supported at EL1 do not allow 32-bit domain */
-    if ( !(cpu_has_el1_32) && kinfo->arch.type == DOMAIN_32BIT )
-    {
-        printk("Platform does not support 32-bit domain\n");
-        return -EINVAL;
-    }
-
-    if ( is_sve_domain(d) && (kinfo->arch.type == DOMAIN_32BIT) )
-    {
-        printk("SVE is not available for 32-bit domain\n");
-        return -EINVAL;
-    }
-#endif
-
     /*
      * kernel_load will determine the placement of the kernel as well
      * as the initrd & fdt in RAM, so call it first.
@@ -1976,6 +1961,10 @@ static int __init construct_dom0(struct domain *d)
     if ( rc < 0 )
         return rc;
 
+    rc = arm64_set_domain_type(d, &kinfo);
+    if ( rc < 0 )
+        return rc;
+
     return construct_hwdom(&kinfo, NULL);
 }
 
@@ -1987,11 +1976,6 @@ int __init construct_hwdom(struct kernel_info *kinfo,
 
     iommu_hwdom_init(d);
 
-#ifdef CONFIG_ARM_64
-    /* type must be set before allocate_memory or create cpu */
-    d->arch.type = kinfo->arch.type;
-#endif
-
     if ( vcpu_create(d, 0) == NULL )
         panic("Error creating domain 0 vcpu0\n");
 
diff --git a/xen/arch/arm/include/asm/arm32/domain.h 
b/xen/arch/arm/include/asm/arm32/domain.h
index c0a7fc35f38b..bdbb9e3cad47 100644
--- a/xen/arch/arm/include/asm/arm32/domain.h
+++ b/xen/arch/arm/include/asm/arm32/domain.h
@@ -10,6 +10,12 @@
 
 #define vcpu_switch_to_aarch64_mode(v)
 
+#define is_aarch32_enabled() (true)
+
+#define domain_set_type_default(d)
+
+#define arm64_set_domain_type(d, kinfo) (0)
+
 #endif /* ARM_ARM32_DOMAIN_H */
 
 /*
diff --git a/xen/arch/arm/include/asm/arm64/domain.h 
b/xen/arch/arm/include/asm/arm64/domain.h
index 7a51ceedf25d..18402ae3ca0d 100644
--- a/xen/arch/arm/include/asm/arm64/domain.h
+++ b/xen/arch/arm/include/asm/arm64/domain.h
@@ -3,6 +3,10 @@
 #ifndef ARM_ARM64_DOMAIN_H
 #define ARM_ARM64_DOMAIN_H
 
+#include <asm/cpufeature.h>
+
+struct kernel_info;
+
 /*
  * Returns true if guest execution state is AArch32
  *
@@ -24,6 +28,29 @@
  */
 void vcpu_switch_to_aarch64_mode(struct vcpu *v);
 
+/*
+ * Arm64 declares AArch32 (32bit) Execution State support in the
+ * Processor Feature Registers (PFR0), but also can be disabled manually.
+ */
+#define is_aarch32_enabled()                                                   
\
+        (IS_ENABLED(CONFIG_ARM64_AARCH32) && cpu_has_aarch32)
+
+/*
+ * Set default Execution State to AArch64 (64bit) during domain creation.
+ */
+#define domain_set_type_default(d) ((d)->arch.type = DOMAIN_64BIT)
+
+/*
+ * Set domain type from struct kernel_info which defines guest Execution
+ * State AArch32/AArch64 during regular dom0 or predefined (dom0less)
+ * domains creation .
+ * Type must be set before allocate_memory or create vcpus.
+ *
+ * @d: pointer to the domain structure.
+ * @kinfo: pointer to the kinfo structure.
+ */
+int arm64_set_domain_type(struct domain *d, struct kernel_info *kinfo);
+
 #endif /* ARM_ARM64_DOMAIN_H */
 
 /*
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 8abc1d641df0..368350226973 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -530,7 +530,7 @@ static int __init init_xen_cap_info(void)
 #ifdef CONFIG_ARM_64
     safe_strcat(xen_cap_info, "xen-3.0-aarch64 ");
 #endif
-    if ( cpu_has_aarch32 )
+    if ( is_aarch32_enabled() )
         safe_strcat(xen_cap_info, "xen-3.0-armv7l ");
 
     return 0;
-- 
2.34.1



 


Rackspace

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