[PATCH v20 07/14] KVM: arm64: Forward GCS exceptions to nested guests

Leonardo Bras leo.bras at arm.com
Wed Sep 9 06:00:06 PDT 2026


On Tue, Sep 01, 2026 at 10:47:05PM +0100, Mark Brown wrote:
> For nested guests where HFGITR_EL2.nGCSSTR_EL1 is clear or when there are
> L2 GCS data check exceptions we need to forward the exception to the guest.
> Add handling to do so.
> 
> Signed-off-by: Mark Brown <broonie at kernel.org>
> ---
>  arch/arm64/kvm/handle_exit.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> index db37678dcb05..a8198e96fcb4 100644
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
> @@ -304,12 +304,24 @@ static int handle_svc(struct kvm_vcpu *vcpu)
>  	return 1;
>  }
>  
> +/*
> + * We might get GCS exceptions that need to be forwarded to the
> + * hypervisor when a nested guest has HFGITR_EL2.nGCSSTR_EL1 clear, or
> + * for a GCS data check exception for a L2 guest.
> + */
>  static int kvm_handle_gcs(struct kvm_vcpu *vcpu)
>  {
> -	/* We don't expect GCS, so treat it with contempt */
> -	if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, GCS, IMP))
> -		WARN_ON_ONCE(1);
> +	if (!kvm_has_gcs(vcpu->kvm)) {
> +		kvm_inject_undefined(vcpu);
> +		return 1;
> +	}
>  
> +	if (vcpu_has_nv(vcpu)) {
> +		kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
> +		return 1;
> +	}
> +
> +	WARN_ON_ONCE(1);
>  	kvm_inject_undefined(vcpu);
>  	return 1;
>  }

Oh handle_gcs, if kvm_has_gcs() && kvm_has_nv() -> Inject synchronous 
exception. Makes sense.

(it kept bothering me that the !gcs and the gcs case do the same thing, 
except for a warn_once. So I thougt on suggesting:

+	if (!kvm_has_gcs(vcpu->kvm))
+		goto inject_undef;
[...]
+	WARN_ON_ONCE(1);
+inject_undef:
>       kvm_inject_undefined(vcpu);
>       return 1;

But after it was done it did not look better.)


So, FWIW:
Reviewed-by: Leonardo Bras <leo.bras at arm.com>

Thanks!
Leo



More information about the linux-arm-kernel mailing list