xen/arm: handle Dom0 vCPU limits from GICv3 redistributors
cover xen/arm: handle Dom0 vCPU limits from GICv3 redistributors
From: Mykola Kvach <[email protected]>
This series fixes and documents a Dom0 construction corner case on Arm GICv3 systems where Dom0 uses the host redistributor layout.
When the requested Dom0 vCPU count exceeds the number of virtual redistributor frames covered by the exposed host-layout GICR regions, the vGICv3 per-vCPU init path rejects the first uncovered vCPU. However, the generic vGIC init path ignored that error, so vcpu_create() could succeed with an invalid per-vCPU vGIC state. Dom0 could then observe more possible CPUs than Xen can back with emulated redistributors and hang during secondary CPU bring-up.
The first patch propagates the per-vCPU vGIC init failure and fixes the host-layout redistributor region count when all hardware regions have been consumed. With the fix, Dom0 construction stops creating secondary vCPUs at the first vCPU whose redistributor frame is not covered, while preserving the existing best-effort Dom0 policy and allowing Dom0 to boot with the vCPUs created before the failure.
The second patch documents the resulting Arm GICv3 constraint for dom0_max_vcpus.
Mykola Kvach (2):
xen/arm: propagate vGIC vCPU init failures
docs: Document Arm GICv3 limit for dom0_max_vcpus
docs/misc/xen-command-line.pandoc | 8 ++++++++ xen/arch/arm/vgic-v3.c | 3 ++- xen/arch/arm/vgic.c | 10 +++++++--- 3 files changed, 17 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 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 best-effort Dom0 policy: a failure to create a secondary vCPU stops the secondary vCPU creation loop, but does not fail the whole Dom0 boot.
--- xen/arch/arm/vgic-v3.c | 3 ++- xen/arch/arm/vgic.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
xen/arch/arm/vgic-v3.c +2 -1
@@ -1834,7 +1834,8 @@ 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 = (i == vgic_v3_hw.nr_rdist_regions) ? + i : i +1 ; d->arch.vgic.intid_bits = vgic_v3_hw.intid_bits; }
xen/arch/arm/vgic.c +7 -3
@@ -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++)
@@ -944,4 +949,3 @@ void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_* indent-tabs-mode: nil * End: */ -
Signature · 1 line
2.43.0
Re: [PATCH 1/2] xen/arm: propagate vGIC vCPU init failures
Quoted 64 lines · Mykola Kvach
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=64The host GICv3 redistributor range is:
region 0: 0x0000002f100000 - 0x0000002f300000With 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 63but 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 ICACTIVER0Propagate 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, butXFREE()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:
Quoted 7 lines
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 best-effort Dom0 policy: a failure to create a secondary vCPU stops the secondary vCPU creation loop, but does not fail the whole Dom0 boot.
This is the construct_domain() policy that is used for both dom0 and dom0less domUs. I must say I don't really like this policy and it's against our *generic* Arm policy to fail the domain creation on any error especially if this belongs to unsatisfied user requests. This is not really related to your series, but I would like to ask other Arm maintainers about their opinion.
Quoted 14 lines
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")Signed-off-by Mykola Kvach <[email protected]>--- xen/arch/arm/vgic-v3.c | 3 ++- xen/arch/arm/vgic.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)xen/arch/arm/vgic-v3.c +0
-0
xen/arch/arm/vgic-v3.c static int vgic_v3_domain_init(struct domain *d) · line 1838
Quoted 6 lines
xen/arch/arm/vgic-v3.c +2
-1@@ -1834,7 +1834,8 @@ 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 = (i == vgic_v3_hw.nr_rdist_regions) ? + i : i +1 ;
Wouldn't min(i+1,vgic_v3_hw.nr_rdist_regions) be cleaner?
Quoted 31 lines
xen/arch/arm/vgic-v3.c +0
-0d->arch.vgic.intid_bits = vgic_v3_hw.intid_bits; }xen/arch/arm/vgic.c +7
-2@@ -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++)
xen/arch/arm/vgic.c void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_ · line 947
Quoted 4 lines
xen/arch/arm/vgic.c +0
-1@@ -944,4 +949,3 @@ void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_* indent-tabs-mode: nil * End: */ -
Stray change, please drop.
~Michal
Re: [PATCH 1/2] xen/arm: propagate vGIC vCPU init failures
Hi Michal,
Thank you for the feedback.
Quoted 72 lines · Michal
Quoted 68 lines · Mykola Kvach
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=64The host GICv3 redistributor range is:
region 0: 0x0000002f100000 - 0x0000002f300000With 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 63but 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 ICACTIVER0Propagate 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, butXFREE()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!
Quoted 8 lines
Quoted 3 lines
Keep the existing best-effort Dom0 policy: a failure to create a secondary vCPU stops the secondary vCPU creation loop, but does not fail the whole Dom0 boot.
This is the
construct_domain()policy that is used for both dom0 and dom0less domUs. I must say I don't really like this policy and it's against our *generic* Arm policy to fail the domain creation on any error especially if this belongs to unsatisfied user requests. This is not really related to your series, but I would like to ask other Arm maintainers about their opinion.
Yes, I agree this is a broader construct_domain() policy question. I kept the existing behaviour in this patch, but I am fine with adjusting it if the maintainers decide that domain creation should fail in this case.
In any case, I will reword the commit message so it does not describe this as a Dom0-only policy, since the same construct_domain() path is also used for dom0less domains.
Quoted 10 lines
Quoted 10 lines
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")Signed-off-by Mykola Kvach <[email protected]>--- xen/arch/arm/vgic-v3.c | 3 ++- xen/arch/arm/vgic.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
Quoted 12 lines
xen/arch/arm/vgic-v3.c static int vgic_v3_domain_init(struct domain *d) · line 1838
Quoted 11 lines
xen/arch/arm/vgic-v3.c +2
-1@@ -1834,7 +1834,8 @@ 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 = (i == vgic_v3_hw.nr_rdist_regions) ? + i : i +1 ;Wouldn't
min(i+1,vgic_v3_hw.nr_rdist_regions)be cleaner?
Ack, I will change this in v2.
Quoted 29 lines
Quoted 29 lines
xen/arch/arm/vgic-v3.c +0
-0d->arch.vgic.intid_bits = vgic_v3_hw.intid_bits; }xen/arch/arm/vgic.c +7
-2@@ -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; + }
Quoted 8 lines
xen/arch/arm/vgic.c void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_ · line 947
Quoted 7 lines
xen/arch/arm/vgic.c +0
-1memset (&v->arch.vgic.pending_irqs,0 ,sizeof (v->arch.vgic.pending_irqs));for (i =0 ; i <32 ; i++)@@ -944,4 +949,3 @@ void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_* indent-tabs-mode: nil * End: */ -Stray change, please drop.
Ack.
Best regards,
Mykola
PATCH 2/2 docs: Document Arm GICv3 limit for dom0_max_vcpus
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
On Arm GICv3 systems, Dom0 may use the host GIC layout, for example when it is the hardware domain. In that case the effective Dom0 vCPU count is not only bounded by the requested dom0_max_vcpus value and Xen's generic vCPU limits. It is also bounded by the redistributor MMIO regions that can be exposed for the host layout.
Document that Xen can only create Dom0 vCPUs whose virtual redistributor frame is covered by those regions, and that secondary vCPU creation stops at the first vCPU whose virtual redistributor frame is not covered.
--- docs/misc/xen-command-line.pandoc | 8 ++++++++ 1 file changed, 8 insertions(+)
docs/misc/xen-command-line.pandoc +8 -0
@@ -981,6 +981,14 @@ The number of VCPUs to give to dom0. This number of VCPUs can be more than the number of PCPUs on the host. The default is the number of PCPUs. +On Arm systems using GICv3, Dom0 may use the host GIC layout, for example +when it is the hardware domain. In this case, this value is also limited +by the redistributor MMIO regions that can be exposed for that layout. +Xen can only create Dom0 VCPUs whose virtual redistributor frame is +covered by those regions. If the requested number of VCPUs exceeds that +limit, secondary VCPU creation stops at the first VCPU whose virtual +redistributor frame is not covered. + Or: > `= <min>-<max>` where `<min>` and `<max>` are integers.
Signature · 1 line
2.43.0
Re: [PATCH 2/2] docs: Document Arm GICv3 limit for dom0_max_vcpus
Quoted 22 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
On Arm GICv3 systems, Dom0 may use the host GIC layout, for example when it is the hardware domain. In that case the effective Dom0 vCPU count is not only bounded by the requested
dom0_max_vcpusvalue and Xen's generic vCPU limits. It is also bounded by the redistributor MMIO regions that can be exposed for the host layout.Document that Xen can only create Dom0 vCPUs whose virtual redistributor frame is covered by those regions, and that secondary vCPU creation stops at the first vCPU whose virtual redistributor frame is not covered.
Signed-off-by Mykola Kvach <[email protected]>--- docs/misc/xen-command-line.pandoc | 8 ++++++++ 1 file changed, 8 insertions(+)docs/misc/xen-command-line.pandoc +0
-0
docs/misc/xen-command-line.pandoc The number of VCPUs to give to dom0. This number of VCPUs can be more · line 984
Quoted 4 lines
docs/misc/xen-command-line.pandoc +1
-0@@ -981,6 +981,14 @@ The number of VCPUs to give to dom0. This number of VCPUs can be more than the number of PCPUs on the host. The default is the number of PCPUs. +On Arm systems using GICv3, Dom0 may use the host GIC layout, for example
It's not dom0 specific. It can by any domain using host memory layout meaning dom0, hwdom, domU direct mapped, in which case I'm not sure if such comment should belong here given that this behavior is not dom0_max_vcpus specific (same could be triggered on your setup with dom0less domU, direct-mapped and 17 vCPUs).
docs/misc/xen-command-line.pandoc The number of VCPUs to give to dom0. This number of VCPUs can be more · line 994
Quoted 10 lines
docs/misc/xen-command-line.pandoc +7
-0+when it is the hardware domain. In this case, this value is also limited +by the redistributor MMIO regions that can be exposed for that layout. +Xen can only create Dom0 VCPUs whose virtual redistributor frame is +covered by those regions. If the requested number of VCPUs exceeds that +limit, secondary VCPU creation stops at the first VCPU whose virtual +redistributor frame is not covered. + Or: > `= <min>-<max>` where `<min>` and `<max>` are integers.
~Michal
Re: [PATCH 2/2] docs: Document Arm GICv3 limit for dom0_max_vcpus
Hi Michal,
Thank you for the review.
Quoted 29 lines · Michal
Quoted 25 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
On Arm GICv3 systems, Dom0 may use the host GIC layout, for example when it is the hardware domain. In that case the effective Dom0 vCPU count is not only bounded by the requested
dom0_max_vcpusvalue and Xen's generic vCPU limits. It is also bounded by the redistributor MMIO regions that can be exposed for the host layout.Document that Xen can only create Dom0 vCPUs whose virtual redistributor frame is covered by those regions, and that secondary vCPU creation stops at the first vCPU whose virtual redistributor frame is not covered.
Signed-off-by Mykola Kvach <[email protected]>--- docs/misc/xen-command-line.pandoc | 8 ++++++++ 1 file changed, 8 insertions(+)docs/misc/xen-command-line.pandoc +0
-0@@ -981,6 +981,14 @@ The number of VCPUs to give to dom0. This number of VCPUs can be more than the number of PCPUs on the host. The default is the number of PCPUs.
Quoted 5 lines
docs/misc/xen-command-line.pandoc The number of VCPUs to give to dom0. This number of VCPUs can be more · line 984
Quoted 1 line
docs/misc/xen-command-line.pandoc +1
-0+On Arm systems using GICv3, Dom0 may use the host GIC layout, for exampleIt's not dom0 specific. It can by any domain using host memory layout meaning dom0, hwdom, domU direct mapped, in which case I'm not sure if such comment should belong here given that this behavior is not
dom0_max_vcpusspecific (same could be triggered on your setup with dom0less domU, direct-mapped and 17 vCPUs).
You are right that the redistributor coverage limit is not specific to dom0_max_vcpus. It applies to Arm GICv3 domains using the host layout, such as the hardware domain or a direct-mapped domain.
My reason for touching dom0_max_vcpus was that this option is where users are told how many Dom0 VCPUs Xen will try to create. However, the GICv3-specific details would fit better in a more generic Arm device-tree/domain description section, around the cpus/direct-map properties.
For dom0_max_vcpus, I can keep only a short generic note, for example:
The resulting number of Dom0 VCPUs is still subject to Xen's generic and architecture-specific domain limits.
~Mykola