]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Enable FPU with max supported FPU type
authorBibo Mao <maobibo@loongson.cn>
Thu, 11 Jun 2026 12:46:40 +0000 (20:46 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 11 Jun 2026 12:46:40 +0000 (20:46 +0800)
There are three FPU types FPU/LSX/LASX, which represents FPU64, FPU128
and FPU256, and now lazy FPU method is used with FPU enabling. There are
three different HW FPU exception code with different FPU type.

The exising method is to enable specified FPU type with responding FPU
exeception. Supposing application uses FPU64 and FPU256, there will be
FPU256 exception when FPU256 type is used.

Here enable FPU with the max VM supported type directly, so it can avoid
unnecessary FPU exception in future if further FPU type is used.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/include/asm/kvm_host.h
arch/loongarch/kvm/exit.c
arch/loongarch/kvm/vcpu.c

index e76a49d4233ba4cf29f5f52f5e61f34b47096c7f..bad16c5f963ca87fe137b942a0023efad13ed685 100644 (file)
@@ -204,7 +204,6 @@ struct kvm_vcpu_arch {
 
        /* Which auxiliary state is loaded (KVM_LARCH_*) */
        unsigned int aux_inuse;
-       unsigned int aux_ldtype;
 
        /* FPU state */
        struct loongarch_fpu fpu FPU_ALIGN;
index b839c989d3dc413c8d85f68b15f04652d1de259e..c8492670f169ed324b23a8b058db306e75deeb22 100644 (file)
@@ -755,7 +755,6 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu, int ecode)
                return RESUME_HOST;
        }
 
-       vcpu->arch.aux_ldtype = KVM_LARCH_FPU;
        kvm_make_request(KVM_REQ_FPU_LOAD, vcpu);
 
        return RESUME_GUEST;
@@ -796,10 +795,8 @@ static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu, int ecode)
 {
        if (!kvm_guest_has_lsx(&vcpu->arch))
                kvm_queue_exception(vcpu, EXCCODE_INE, 0);
-       else {
-               vcpu->arch.aux_ldtype = KVM_LARCH_LSX;
+       else
                kvm_make_request(KVM_REQ_FPU_LOAD, vcpu);
-       }
 
        return RESUME_GUEST;
 }
@@ -816,10 +813,8 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu, int ecode)
 {
        if (!kvm_guest_has_lasx(&vcpu->arch))
                kvm_queue_exception(vcpu, EXCCODE_INE, 0);
-       else {
-               vcpu->arch.aux_ldtype = KVM_LARCH_LASX;
+       else
                kvm_make_request(KVM_REQ_FPU_LOAD, vcpu);
-       }
 
        return RESUME_GUEST;
 }
index c28aa37f37a982728f1e174e8af0113192fd8061..c65518b4e18eefd189907c80ec439ec722ed428d 100644 (file)
@@ -240,21 +240,12 @@ static void kvm_late_check_requests(struct kvm_vcpu *vcpu)
                }
 
        if (kvm_check_request(KVM_REQ_FPU_LOAD, vcpu)) {
-               switch (vcpu->arch.aux_ldtype) {
-               case KVM_LARCH_FPU:
-                       kvm_own_fpu(vcpu);
-                       break;
-               case KVM_LARCH_LSX:
-                       kvm_own_lsx(vcpu);
-                       break;
-               case KVM_LARCH_LASX:
+               if (kvm_guest_has_lasx(&vcpu->arch))
                        kvm_own_lasx(vcpu);
-                       break;
-               default:
-                       break;
-               }
-
-               vcpu->arch.aux_ldtype = 0;
+               else if (kvm_guest_has_lsx(&vcpu->arch))
+                       kvm_own_lsx(vcpu);
+               else if (kvm_guest_has_fpu(&vcpu->arch))
+                       kvm_own_fpu(vcpu);
        }
 
        if (kvm_check_request(KVM_REQ_LBT_LOAD, vcpu))