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

[email protected]
Newsgroups dev.linux.lists.kvmarm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] `kvm_handle_gcs` uses `vcpu_has_nv(vcpu)` instead of `is_nested_ctxt(vcpu)` to forward GCS exceptions, bypassing safety warnings and misrouting unexpected L1 traps.
--

--- Patch [7]: [PATCH v19 07/14] KVM: arm64: Forward GCS exceptions to nested guests ---
commit f418917369df0c1bc3138d818288366ea3e842e1
Author: Mark Brown <[email protected]>

KVM: arm64: Forward GCS exceptions to nested guests

This commit adds handling to forward GCS exceptions to nested guests when
HFGITR_EL2.nGCSSTR_EL1 is clear or for GCS data check exceptions in an L2
guest.

> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> index 54aedf93c78b6..63dcc4a0e69a8 100644
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
[ ... ]
> +/*
> + * 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)) {

[Severity: Medium]
Does this code use the correct check for nested execution here?

By checking vcpu_has_nv() instead of is_nested_ctxt(), if an unexpected GCS
trap occurs while executing the L1 guest, KVM will erroneously forward the
trap to the L1 virtual EL2.

Should this check be is_nested_ctxt(vcpu) so that unexpected L1 traps fall
through to the host WARN_ON_ONCE and correctly inject an UNDEF?

> +		kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
> +		return 1;
> +	}
> +
> +	WARN_ON_ONCE(1);
>  	kvm_inject_undefined(vcpu);
>  	return 1;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.