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

Re: [for-4.22][PATCH] xen/arm: Fail domain construction if a secondary vCPU cannot be created


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Wed, 8 Jul 2026 13:40:27 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.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=15GRzMNsqIbB/evT3tBPJrK/H7jL8Rhe9uVvGwFg798=; b=izntbHwSzpHiVAMWxarSIHgfLxVtYr3pVcuxX+C8+ed2CQFOazBWR80811BJ23rFm4W1PpD4m7703ScnqlkPEeZxsH6YxeXwmUijBoLUKglrr2tdFBjt9ffaGvQAqDVqrwoFksGUcTjwgiXLM6Et2D7qk1aLJ7IudYwO/oVS/98xHn4POoTsL1Kj/KadWR2g8CeKp3TIAUd2xPVcyCNyq6dohibrF51S+gJPz3Yu4945HVPxfbSsZ7MhXcJ//Ip29UYEy9n2YlEN7HTMwlsbOp+HOHDokzgR9pmDwALgcWuNFM1bZWGtRtcCqCaRmjBLY6baEISglCpK2HA9xc7yuw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ptmCN9zLpo+fQINeLgSnwlx926ueDzp1sm+jJYVSSK8tYt7eZ5XuuPtIP/8JH7oenYLcVELxlG3SLJJkgvZlYH/uBUqshbnZro7nKOnZ9Z0kjNwTG3VFsNzHlhfBdQDhaLGq8pjT8Xr9GoXwriJom0XMYBMwKl5I4IsMS059paBLsEfyWPgKBZ7LNnmi8PRR9NX6nDqZlQV6fXjUhwqxJbLU77dTlwZDUgaL+fW5L7QIJmYqg/IMO3i5Mg3JCiTptuFs5EuCpwVVvOckq6cXvk4y7NabeikoZJoOyJZ5X+TMl5H5sLkBu9kYflImjTB/o2L4PYCKMJCnd+6c8ySASg==
  • 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: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>, <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Wed, 08 Jul 2026 11:40:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 08-Jul-26 13:30, Andrew Cooper wrote:
> On 08/07/2026 8:49 am, Michal Orzel wrote:
>> construct_domain() creates the secondary vCPUs in a loop, but on a
>> vcpu_create() failure it only prints a message and breaks out of the
>> loop returning success. As a result the domain can be constructed
>> with fewer vCPUs than d->max_vcpus, leaving NULL holes in d->vcpu[]
>> below max_vcpus.
> 
> I'd suggest phrasing this as "partially constructed".  "holes" isn't
> really what's going on, given the linear nature of allocation.
> 
> Because of the object visibility, and because constructing vCPUs isn't
> atomic, all code needs to cope with d->vcpu[] having no, some or all of
> d->max_vcpus constructed.
> 
>>
>> When the guest probes the redistributor of a vCPU that was never created,
>> get_vcpu_from_rdist() only checks vcpu_id against d->max_vcpus and then
>> dereferences the NULL d->vcpu[vcpu_id], resulting in a data abort.
> 
> That's unsafe, especially as vcpu_id is calculated from an MMIO access.
> 
> diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c
> index c1c4d6f71ea8..c01cc596d593 100644
> --- a/xen/arch/arm/vgic-v3.c
> +++ b/xen/arch/arm/vgic-v3.c
> @@ -1111,10 +1111,10 @@ static struct vcpu *get_vcpu_from_rdist(struct
> domain *d,
>      unsigned int vcpu_id;
>  
>      vcpu_id = region->first_cpu + ((gpa - region->base) / GICV3_GICR_SIZE);
> -    if ( unlikely(vcpu_id >= d->max_vcpus) )
> -        return NULL;
>  
> -    v = d->vcpu[vcpu_id];
> +    v = domain_vcpu(d, vcpu_id);
> +    if ( !v )
> +        return NULL;
>  
>      *offset = gpa - v->arch.vgic.rdist_base;
>  
> 
> Do you want me to submit this separately?
If you have time, yes. Otherwise I can do that too tomorrow.

> 
> 
>>
>> Return an error instead of breaking out of the loop. Both callers
>> (construct_domU() and construct_hwdom()) already propagate a negative
>> return value and fail domain construction, which is the correct
>> behaviour: a domain that cannot provide the requested number of vCPUs
>> should not be brought up.
>>
>> Fixes: 6b0e8e43348a ("xen/arm: allocate secondaries dom0 vcpus")
>> Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
>> ---
>>  xen/arch/arm/domain_build.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>> index 550617f152bb..b46574fd32aa 100644
>> --- a/xen/arch/arm/domain_build.c
>> +++ b/xen/arch/arm/domain_build.c
>> @@ -1847,7 +1847,7 @@ int __init construct_domain(struct domain *d, struct 
>> kernel_info *kinfo)
>>          if ( vcpu_create(d, i) == NULL )
>>          {
>>              printk("Failed to allocate d%dv%d\n", d->domain_id, i);
>> -            break;
>> +            return -EINVAL;
>>          }
>>  
>>          if ( is_64bit_domain(d) )
> 
> On x86, we explicitly tolerate a failure to build all of dom0's CPUs, if
> at least one did get constructed.  This is to increase the chances that
> the server can boot and at least let an admin in to look at things.
> 
> However, I can see why such a behaviour is not wanted in a "single
> pre-packaged system" as used by automotive.
Yes, that is a known difference in behavior between x86 and Arm. We decided to
bail out asap.

~Michal




 


Rackspace

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