]> Git Repo - linux.git/commitdiff
LoongArch: KVM: Implement handle fpu exception
authorTianrui Zhao <[email protected]>
Mon, 2 Oct 2023 02:01:29 +0000 (10:01 +0800)
committerHuacai Chen <[email protected]>
Mon, 2 Oct 2023 02:01:29 +0000 (10:01 +0800)
Implement handle fpu exception, using kvm_own_fpu() to enable fpu for
guest.

Reviewed-by: Bibo Mao <[email protected]>
Tested-by: Huacai Chen <[email protected]>
Signed-off-by: Tianrui Zhao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
arch/loongarch/kvm/exit.c

index c31894b75b0757299fb04e7eda21f5d0b449f841..e855ab9099b2411c896bd81655dff7d6c5df9370 100644 (file)
@@ -631,3 +631,30 @@ static int kvm_handle_write_fault(struct kvm_vcpu *vcpu)
 {
        return kvm_handle_rdwr_fault(vcpu, true);
 }
+
+/**
+ * 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;
+}
This page took 0.070707 seconds and 4 git commands to generate.