Skip to content

Commit 37cdfc6

Browse files
zhaotianrui-loongsonchenhuacai
authored andcommitted
LoongArch: KVM: Implement handle fpu exception
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]>
1 parent d5b6588 commit 37cdfc6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,30 @@ static int kvm_handle_write_fault(struct kvm_vcpu *vcpu)
631631
{
632632
return kvm_handle_rdwr_fault(vcpu, true);
633633
}
634+
635+
/**
636+
* kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host
637+
* @vcpu: Virtual CPU context.
638+
*
639+
* Handle when the guest attempts to use fpu which hasn't been allowed
640+
* by the root context.
641+
*/
642+
static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
643+
{
644+
struct kvm_run *run = vcpu->run;
645+
646+
/*
647+
* If guest FPU not present, the FPU operation should have been
648+
* treated as a reserved instruction!
649+
* If FPU already in use, we shouldn't get this at all.
650+
*/
651+
if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) {
652+
kvm_err("%s internal error\n", __func__);
653+
run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
654+
return RESUME_HOST;
655+
}
656+
657+
kvm_own_fpu(vcpu);
658+
659+
return RESUME_GUEST;
660+
}

0 commit comments

Comments
 (0)