diff mbox series

[v12,25/31] LoongArch: KVM: Implement handle fpu exception

Message ID 20230530015223.147755-26-zhaotianrui@loongson.cn (mailing list archive)
State New, archived
Headers show
Series Add KVM LoongArch support | expand

Commit Message

zhaotianrui May 30, 2023, 1:52 a.m. UTC
Implement handle fpu exception, using kvm_own_fpu to enable fpu for
guest.

Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
 arch/loongarch/kvm/exit.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

maobibo June 6, 2023, 1:42 a.m. UTC | #1
Reviewed-by: Bibo, Mao <maobibo@loongson.cn>

在 2023/5/30 09:52, Tianrui Zhao 写道:
> Implement handle fpu exception, using kvm_own_fpu to enable fpu for
> guest.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>  arch/loongarch/kvm/exit.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
> index 1237ceb06d0c..10f9922a7e76 100644
> --- a/arch/loongarch/kvm/exit.c
> +++ b/arch/loongarch/kvm/exit.c
> @@ -631,3 +631,29 @@ static int _kvm_handle_read_fault(struct kvm_vcpu *vcpu)
>  {
>  	return _kvm_handle_mmu_fault(vcpu, false);
>  }
> +
> +/**
> + * _kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host
> + * @vcpu:	Virtual CPU context.
> + *
> + * Handle when the guest attempts to use fpu which hasn't been allowed
> + * by the root context.
> + */
> +static int _kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
> +{
> +	struct kvm_run *run = vcpu->run;
> +
> +	/*
> +	 * If guest FPU not present, the FPU operation should have been
> +	 * treated as a reserved instruction!
> +	 * If FPU already in use, we shouldn't get this at all.
> +	 */
> +	if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) {
> +		kvm_err("%s internal error\n", __func__);
> +		run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> +		return RESUME_HOST;
> +	}
> +
> +	kvm_own_fpu(vcpu);
> +	return RESUME_GUEST;
> +}
diff mbox series

Patch

diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 1237ceb06d0c..10f9922a7e76 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -631,3 +631,29 @@  static int _kvm_handle_read_fault(struct kvm_vcpu *vcpu)
 {
 	return _kvm_handle_mmu_fault(vcpu, false);
 }
+
+/**
+ * _kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host
+ * @vcpu:	Virtual CPU context.
+ *
+ * Handle when the guest attempts to use fpu which hasn't been allowed
+ * by the root context.
+ */
+static int _kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
+{
+	struct kvm_run *run = vcpu->run;
+
+	/*
+	 * If guest FPU not present, the FPU operation should have been
+	 * treated as a reserved instruction!
+	 * If FPU already in use, we shouldn't get this at all.
+	 */
+	if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) {
+		kvm_err("%s internal error\n", __func__);
+		run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		return RESUME_HOST;
+	}
+
+	kvm_own_fpu(vcpu);
+	return RESUME_GUEST;
+}