[PATCH v3 24/36] KVM: arm64: gic-v5: Create, init vgic_v5

Jonathan Cameron jonathan.cameron at huawei.com
Mon Jan 12 08:20:33 PST 2026


On Fri, 9 Jan 2026 17:04:47 +0000
Sascha Bischoff <Sascha.Bischoff at arm.com> wrote:

> Update kvm_vgic_create to create a vgic_v5 device. When creating a
> vgic, FEAT_GCIE in the ID_AA64PFR2 is only exposed to vgic_v5-based
> guests, and is hidden otherwise. GIC in ~ID_AA64PFR0_EL1 is never
> exposed for a vgic_v5 guest.
> 
> When initialising a vgic_v5, skip kvm_vgic_dist_init as GICv5 doesn't
> support one. The current vgic_v5 implementation only supports PPIs, so
> no SPIs are initialised either.
> 
> The current vgic_v5 support doesn't extend to nested guests. Therefore,
> the init of vgic_v5 for a nested guest is failed in vgic_v5_init.
> 
> As the current vgic_v5 doesn't require any resources to be mapped,
> vgic_v5_map_resources is simply used to check that the vgic has indeed
> been initialised. Again, this will change as more GICv5 support is
> merged in.
> 
> Signed-off-by: Sascha Bischoff <sascha.bischoff at arm.com>
> Reviewed-by: Jonathan Cameron <jonathan.cameron at huawei.com>
Minor patch break up comment below. No need to change unless
maintainers ask for it I think.

Jonathan


> ---
>  arch/arm64/kvm/vgic/vgic-init.c | 60 +++++++++++++++++++++------------
>  arch/arm64/kvm/vgic/vgic-v5.c   | 26 ++++++++++++++
>  arch/arm64/kvm/vgic/vgic.h      |  2 ++
>  include/kvm/arm_vgic.h          |  1 +
>  4 files changed, 68 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
> index 973bbbe56062c..bde5544b58b09 100644
> --- a/arch/arm64/kvm/vgic/vgic-init.c
> +++ b/arch/arm64/kvm/vgic/vgic-init.c

> @@ -418,22 +425,28 @@ int vgic_init(struct kvm *kvm)
>  	if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
>  		return -EBUSY;
>  
> -	/* freeze the number of spis */
> -	if (!dist->nr_spis)
> -		dist->nr_spis = VGIC_NR_IRQS_LEGACY - VGIC_NR_PRIVATE_IRQS;
> +	if (!vgic_is_v5(kvm)) {
> +		/* freeze the number of spis */
> +		if (!dist->nr_spis)
> +			dist->nr_spis = VGIC_NR_IRQS_LEGACY - VGIC_NR_PRIVATE_IRQS;
>  
> -	ret = kvm_vgic_dist_init(kvm, dist->nr_spis);
> -	if (ret)
> -		goto out;
> +		ret = kvm_vgic_dist_init(kvm, dist->nr_spis);
> +		if (ret)
> +			return ret;
>  
> -	/*
> -	 * Ensure vPEs are allocated if direct IRQ injection (e.g. vSGIs,
> -	 * vLPIs) is supported.
> -	 */
> -	if (vgic_supports_direct_irqs(kvm)) {
> -		ret = vgic_v4_init(kvm);
> +		/*
> +		 * Ensure vPEs are allocated if direct IRQ injection (e.g. vSGIs,
> +		 * vLPIs) is supported.
> +		 */
> +		if (vgic_supports_direct_irqs(kvm)) {
> +			ret = vgic_v4_init(kvm);
> +			if (ret)
> +				return ret;
> +		}
> +	} else {
> +		ret = vgic_v5_init(kvm);
>  		if (ret)
> -			goto out;
> +			return ret;
>  	}
>  
>  	kvm_for_each_vcpu(idx, vcpu, kvm)
> @@ -441,11 +454,11 @@ int vgic_init(struct kvm *kvm)
>  
>  	ret = kvm_vgic_setup_default_irq_routing(kvm);
>  	if (ret)
> -		goto out;
> +		return ret;
>  
>  	vgic_debug_init(kvm);
>  	dist->initialized = true;
> -out:

It is a bit marginal on whether it is worth the effort but I think
this would been slightly clearer if a precursor patch had dealt with the
early returns.

> +
>  	return ret;

return 0;

Always nice to be explicit when it is a good exit path.

>  }
>  





More information about the linux-arm-kernel mailing list