Skip to contentSkip to conversation

xen/arm: handle vGIC vCPU init failures

PATCH In review Mykola Kvach 2 participants 4 messages May 27

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: handle vGIC vCPU init failures

From: Mykola Kvach <[email protected]>

This series fixes two related GICv3 host-layout issues exposed when a boot-time domain requests more vCPUs than the guest-visible redistributor MMIO regions can cover.

For domains using the host memory layout, Xen exposes GICv3 redistributor MMIO regions based on the host layout. Each vCPU needs a virtual redistributor frame covered by one of those regions. On FVP with a 2 MiB redistributor region, only 16 128 KiB guest redistributor frames are covered; a request for 64 vCPUs leaves vCPU16 and above without a corresponding redistributor frame.

The vGICv3 per-vCPU init path detects this and rejects the first uncovered vCPU, but the generic vGIC init path ignored that error. As a result, vcpu_create() could succeed with invalid per-vCPU vGIC state, and the guest could observe more possible CPUs than Xen can back with emulated redistributors.

There was also an off-by-one in the host-layout redistributor region count when all hardware regions had been consumed. That could make Xen describe a guest-visible GICR MMIO region beyond the populated redistributor region list. A guest access to that exposed window would then fail to match any emulated redistributor frame.

Patch 1 fixes the vCPU creation path by propagating per-vCPU vGIC init failures, and also fixes the related host-layout redistributor region count so Xen does not expose an unbacked GICR window.

Patch 2 documents the resulting Arm GICv3 host-layout constraint for boot-time domains and keeps dom0_max_vcpus documentation generic.

Changes in v2:
- use min(i + 1U, vgic_v3_hw.nr_rdist_regions) for the host-layout redistributor region count.
- keep the trailing blank line at the end of xen/arch/arm/vgic.c.
- move the detailed GICv3 host-layout documentation from dom0_max_vcpus to the Arm device-tree booting documentation.
- add Michal's Reviewed-by tag to patch 1.

Mykola Kvach (2):
xen/arm: propagate vGIC vCPU init failures docs/arm: Document GICv3 vCPU limit for host-layout domains

 docs/misc/arm/device-tree/booting.txt | 9 +++++++++
 docs/misc/xen-command-line.pandoc     | 3 +++
 xen/arch/arm/vgic-v3.c                | 2 +-
 xen/arch/arm/vgic.c                   | 9 +++++++--
 4 files changed, 20 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 xen/arm: propagate vGIC vCPU init failures

From: Mykola Kvach <[email protected]>

The vGIC per-vCPU init callback can fail. In particular, GICv3 rejects a vCPU when the domain's redistributor layout has no MMIO slot covering that vCPU. However, the generic vGIC init path ignored the callback return value, so vcpu_create() could succeed with an invalid vGICv3 per-vCPU state.

This can be reproduced on FVP Base RevC by exposing a 2 MiB GICv3 redistributor region to Dom0 and booting Xen with:

    maxcpus=1 dom0_max_vcpus=64

The host GICv3 redistributor range is:

    region 0: 0x0000002f100000 - 0x0000002f300000

With Xen's guest redistributor frame size of 128 KiB, that range covers 16 guest redistributors. vCPU16 and above have no corresponding redistributor slot.

Before this fix, Xen detected the missing redistributors:

d0: Unable to find a re-distributor for VCPU 16
...
d0: Unable to find a re-distributor for VCPU 63

but ignored the error and continued as if the secondary vCPUs had been created correctly. Dom0 then saw 64 possible CPUs and could hang during secondary CPU bring-up:

smp: Bringing up secondary CPUs ...
d0v15: vGICR: SGI: unhandled word write ... to ICACTIVER0

Propagate the vGIC vcpu_init() error so the caller can stop creating secondary vCPUs. With this fix, Dom0 construction reports:

d0: Unable to find a re-distributor for VCPU 16 Failed to allocate d0v16

and the guest continues booting with the vCPUs created before the failure:

smp: Brought up 1 node, 16 CPUs

Free the private IRQ rank allocated by vcpu_vgic_init() on this error path. The caller will still run the generic vCPU creation cleanup, but XFREE() clears the pointer so that cleanup remains idempotent.

Also fix the host-layout redistributor region count for the case where the requested vCPU count is larger than the capacity of all host redistributor regions. The old code always stored i + 1 after the loop. That is correct when the loop stops inside a valid region because the requested vCPU count is covered. If the loop exits after consuming all hardware regions, i is already equal to the number of allocated regions, so i + 1 records one region too many.

In the same FVP setup, that off-by-one made Xen describe host-layout GICR state beyond the populated redistributor region list. Dom0 then accessed the GICR MMIO window described in its device tree, but Xen could not match the access to a valid emulated redistributor frame. During debugging this was seen as an unexpected vGICR access followed by a guest panic:

    d0v0: vGICR: unknown gpa read address 000000002f10ffe8
    pc : gic_iterate_rdists+0x4c/0x104
    Kernel panic - not syncing: Attempted to kill the idle task!

Keep the existing construct_domain() policy used by Dom0 and dom0less domain construction: a failure to create a secondary vCPU stops the secondary vCPU creation loop, but does not fail the whole domain construction.

Fixes ea37fd21110b ("xen/arm: split vgic driver into generic and vgic-v2 driver")
Fixes 54ec59f6b0b3 ("xen/arm: vgic-v3: Don't create empty re-distributor regions")

---
Changes in v2:
- use min(i + 1U, vgic_v3_hw.nr_rdist_regions) when limiting the host-layout redistributor region count.
- keep the trailing blank line at the end of xen/arch/arm/vgic.c.
- clarify that the best-effort secondary vCPU allocation failure policy is the existing construct_domain() policy for Dom0 and dom0less domains.

---
 xen/arch/arm/vgic-v3.c | 2 +-
 xen/arch/arm/vgic.c    | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
xen/arch/arm/vgic-v3.c +1 -1
index 77517c3030..c1c4d6f71e 100644
@@ -1834,7 +1834,7 @@ static int vgic_v3_domain_init(struct domain *d)
          * not match the number of pCPUs). Update the number of regions to
          * avoid exposing unused region as they will not get emulated.
          */
-        d->arch.vgic.nr_regions = i + 1;
+        d->arch.vgic.nr_regions = min(i + 1U, vgic_v3_hw.nr_rdist_regions);
 
         d->arch.vgic.intid_bits = vgic_v3_hw.intid_bits;
     }
xen/arch/arm/vgic.c +7 -2
index 6647071ad4..e5aca17dcb 100644
@@ -368,7 +368,7 @@ void domain_vgic_free(struct domain *d)
 
 int vcpu_vgic_init(struct vcpu *v)
 {
-    int i;
+    int i, ret;
 
     v->arch.vgic.private_irqs = xzalloc(struct vgic_irq_rank);
     if ( v->arch.vgic.private_irqs == NULL )
@@ -377,7 +377,12 @@ int vcpu_vgic_init(struct vcpu *v)
     /* SGIs/PPIs are always routed to this VCPU */
     vgic_rank_init(v->arch.vgic.private_irqs, 0, v->vcpu_id);
 
-    v->domain->arch.vgic.handler->vcpu_init(v);
+    ret = v->domain->arch.vgic.handler->vcpu_init(v);
+    if ( ret )
+    {
+        XFREE(v->arch.vgic.private_irqs);
+        return ret;
+    }
 
     memset(&v->arch.vgic.pending_irqs, 0, sizeof(v->arch.vgic.pending_irqs));
     for (i = 0; i < 32; i++)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/2 docs/arm: Document GICv3 vCPU limit for host-layout domains

In reply to Mykola Kvach

From: Mykola Kvach <[email protected]>

The number of vCPUs requested for a boot-time Arm domain is not bounded solely by Xen's generic domain limits. For GICv3 domains using the host memory layout, Xen can only create vCPUs whose virtual redistributor frame is covered by redistributor MMIO regions exposed for that layout.

This can affect the hardware domain and direct-mapped domains. Document the GICv3-specific limit in the cpus property description in the Arm device-tree booting guide. Also add a generic domain-limit caveat to the dom0_max_vcpus command-line documentation.

---
Changes in v2:
- move the detailed GICv3 host-layout redistributor note from dom0_max_vcpus to the Arm device-tree booting documentation.
- keep only a generic domain-limit note under dom0_max_vcpus.

---
 docs/misc/arm/device-tree/booting.txt | 9 +++++++++
 docs/misc/xen-command-line.pandoc     | 3 +++
 2 files changed, 12 insertions(+)
docs/misc/arm/device-tree/booting.txt +9 -0
index f73839df09..bcb06bc796 100644
@@ -162,6 +162,15 @@ with the following properties:
 
     An integer specifying the number of vcpus to allocate to the guest.
 
+    The resulting number of vcpus is still subject to Xen's generic and
+    architecture-specific domain limits. On Arm GICv3 systems, each vcpu
+    needs a virtual redistributor frame. Domains using the host GIC layout,
+    such as the hardware domain or direct-mapped domains, can only use vcpus
+    whose virtual redistributor frame is covered by the redistributor MMIO
+    regions exposed for that layout. If the requested number of vcpus exceeds
+    that limit, Xen will create fewer vcpus than requested, stopping at the
+    first vcpu whose virtual redistributor frame is not covered.
+
 - llc-colors
     A string specifying the LLC color configuration for the guest.
     Refer to docs/misc/cache_coloring.rst for syntax. This option is applicable
docs/misc/xen-command-line.pandoc +3 -0
index d46d5b2152..8c89b7852c 100644
@@ -1000,6 +1000,9 @@ For example, with `dom0_max_vcpus=4-8`:
 >      8    |  8
 >     10    |  8
 
+The resulting number of Dom0 VCPUs is still subject to Xen's generic
+and architecture-specific domain limits.
+
 ### dom0_mem (ARM)
 > `= <size>`
 
Signature · 1 line
2.43.0
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH for-4.22 v2 2/2] docs/arm: Document GICv3 vCPU limit for host-layout domains

Quoted 7 lines · Mykola Kvach

From: Mykola Kvach <[email protected]>

The number of vCPUs requested for a boot-time Arm domain is not bounded solely by Xen's generic domain limits. For GICv3 domains using the host memory layout, Xen can only create vCPUs whose virtual redistributor frame is covered by redistributor MMIO regions exposed for that layout.

Quoted 6 lines

This can affect the hardware domain and direct-mapped domains. Document the GICv3-specific limit in the cpus property description in the Arm device-tree booting guide. Also add a generic domain-limit caveat to the dom0_max_vcpus command-line documentation.

~Michal