[XEN][PATCH 1/7] xen/arm64: domctl: set_address_size add check for vcpus not initialized

Grygorii Strashko posted 7 patches 3 months ago
[XEN][PATCH 1/7] xen/arm64: domctl: set_address_size add check for vcpus not initialized
Posted by Grygorii Strashko 3 months ago
From: Grygorii Strashko <grygorii_strashko@epam.com>

The vcpu ctx initialization (arch_set_info_guest()) is depends on proper
domain type (32/64bit) configuration, so check that vcpus are not
initialized when toolstack issues XEN_DOMCTL_set_address_size hypercall.

Signed-off-by: Grygorii Strashko <grygorii_strashko@epam.com>
---
 xen/arch/arm/arm64/domctl.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xen/arch/arm/arm64/domctl.c b/xen/arch/arm/arm64/domctl.c
index 8720d126c97d..82eff26fb0d1 100644
--- a/xen/arch/arm/arm64/domctl.c
+++ b/xen/arch/arm/arm64/domctl.c
@@ -13,6 +13,19 @@
 #include <asm/arm64/sve.h>
 #include <asm/cpufeature.h>
 
+static bool vcpus_check_initialised(struct domain *d)
+{
+    struct vcpu *v;
+
+    for_each_vcpu(d, v)
+    {
+        if ( v->is_initialised )
+            return true;
+    }
+
+    return false;
+}
+
 static long switch_mode(struct domain *d, enum domain_type type)
 {
     struct vcpu *v;
@@ -21,6 +34,8 @@ static long switch_mode(struct domain *d, enum domain_type type)
         return -EINVAL;
     if ( domain_tot_pages(d) != 0 )
         return -EBUSY;
+    if ( vcpus_check_initialised(d) )
+        return -EBUSY;
     if ( d->arch.type == type )
         return 0;
 
-- 
2.34.1
Re: [XEN][PATCH 1/7] xen/arm64: domctl: set_address_size add check for vcpus not initialized
Posted by Alejandro Vallejo 3 months ago
On Thu Jul 31, 2025 at 11:42 AM CEST, Grygorii Strashko wrote:
> From: Grygorii Strashko <grygorii_strashko@epam.com>
>
> The vcpu ctx initialization (arch_set_info_guest()) is depends on proper
                                                       ^
                                                   stray "is"

> domain type (32/64bit) configuration, so check that vcpus are not
> initialized when toolstack issues XEN_DOMCTL_set_address_size hypercall.
>
> Signed-off-by: Grygorii Strashko <grygorii_strashko@epam.com>
> ---
>  xen/arch/arm/arm64/domctl.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/xen/arch/arm/arm64/domctl.c b/xen/arch/arm/arm64/domctl.c
> index 8720d126c97d..82eff26fb0d1 100644
> --- a/xen/arch/arm/arm64/domctl.c
> +++ b/xen/arch/arm/arm64/domctl.c
> @@ -13,6 +13,19 @@
>  #include <asm/arm64/sve.h>
>  #include <asm/cpufeature.h>
>  
> +static bool vcpus_check_initialised(struct domain *d)

nit: I'd call it vcpus_any_initialised(), that way it's far easier to
     see what it does without jumping into the implementation.

> +{
> +    struct vcpu *v;
> +
> +    for_each_vcpu(d, v)
> +    {
> +        if ( v->is_initialised )
> +            return true;
> +    }
> +
> +    return false;
> +}
> +
>  static long switch_mode(struct domain *d, enum domain_type type)
>  {
>      struct vcpu *v;
> @@ -21,6 +34,8 @@ static long switch_mode(struct domain *d, enum domain_type type)
>          return -EINVAL;
>      if ( domain_tot_pages(d) != 0 )
>          return -EBUSY;
> +    if ( vcpus_check_initialised(d) )
> +        return -EBUSY;
>      if ( d->arch.type == type )
>          return 0;
>