[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d9471e38-1840-1f79-c028-8f78afc0d2c7@redhat.com>
Date: Wed, 10 Nov 2021 12:16:34 +0100
From: Eric Auger <eauger@...hat.com>
To: Gavin Shan <gshan@...hat.com>, kvmarm@...ts.cs.columbia.edu
Cc: maz@...nel.org, linux-kernel@...r.kernel.org,
Jonathan.Cameron@...wei.com, pbonzini@...hat.com, will@...nel.org
Subject: Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Gavin,
On 8/15/21 2:13 AM, Gavin Shan wrote:
> This supports SDEI_EVENT_CONTEXT hypercall. It's used by the guest
> to retrieved the original registers (R0 - R17) in its SDEI event
> handler. Those registers can be corrupted during the SDEI event
> delivery.
>
> Signed-off-by: Gavin Shan <gshan@...hat.com>
> ---
> arch/arm64/kvm/sdei.c | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
>
> diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c
> index b022ce0a202b..b4162efda470 100644
> --- a/arch/arm64/kvm/sdei.c
> +++ b/arch/arm64/kvm/sdei.c
> @@ -270,6 +270,44 @@ static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu,
> return ret;
> }
>
> +static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)
> +{
> + struct kvm *kvm = vcpu->kvm;
> + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;
> + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;
> + struct kvm_sdei_vcpu_regs *regs;
> + unsigned long index = smccc_get_arg1(vcpu);
s/index/param_id to match the spec?
> + unsigned long ret = SDEI_SUCCESS;
> +
> + /* Sanity check */
> + if (!(ksdei && vsdei)) {
> + ret = SDEI_NOT_SUPPORTED;
> + goto out;
> + }
> +
> + if (index > ARRAY_SIZE(vsdei->state.critical_regs.regs)) {
> + ret = SDEI_INVALID_PARAMETERS;
> + goto out;
> + }
I would move the above after regs = and use regs there (although the
regs ARRAY_SIZE of both is identifical)
> +
> + /* Check if the pending event exists */
> + spin_lock(&vsdei->lock);
> + if (!(vsdei->critical_event || vsdei->normal_event)) {
> + ret = SDEI_DENIED;
> + goto unlock;
> + }
> +
> + /* Fetch the requested register */
> + regs = vsdei->critical_event ? &vsdei->state.critical_regs :
> + &vsdei->state.normal_regs;
> + ret = regs->regs[index];
> +
> +unlock:
> + spin_unlock(&vsdei->lock);
> +out:
> + return ret;
> +}
> +
> int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
> {
> u32 func = smccc_get_function(vcpu);
> @@ -290,6 +328,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
> ret = kvm_sdei_hypercall_enable(vcpu, false);
> break;
> case SDEI_1_0_FN_SDEI_EVENT_CONTEXT:
> + ret = kvm_sdei_hypercall_context(vcpu);
> + break;
> case SDEI_1_0_FN_SDEI_EVENT_COMPLETE:
> case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
> case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER:
>
Eric
Powered by blists - more mailing lists