]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Check kvm_request_pending() in kvm_late_check_requests()
authorBibo Mao <maobibo@loongson.cn>
Thu, 9 Apr 2026 10:56:36 +0000 (18:56 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 9 Apr 2026 10:56:36 +0000 (18:56 +0800)
Add kvm_request_pending() checking firstly in kvm_late_check_requests(),
at most time there is no pending request, then the following pending bit
checking can be skipped.

Also embed function kvm_check_pmu() in to kvm_late_check_requests(), and
put it after the kvm_request_pending() checking.

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

index ed2cfcd76f60738c2f6afabe00d2a5d033969574..fc8f7290cfed4067f52571cc524d8c01aecdf101 100644 (file)
@@ -149,14 +149,6 @@ static void kvm_lose_pmu(struct kvm_vcpu *vcpu)
        kvm_restore_host_pmu(vcpu);
 }
 
-static void kvm_check_pmu(struct kvm_vcpu *vcpu)
-{
-       if (kvm_check_request(KVM_REQ_PMU, vcpu)) {
-               kvm_own_pmu(vcpu);
-               vcpu->arch.aux_inuse |= KVM_LARCH_PMU;
-       }
-}
-
 static void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 {
        u32 version;
@@ -232,6 +224,15 @@ static int kvm_check_requests(struct kvm_vcpu *vcpu)
 static void kvm_late_check_requests(struct kvm_vcpu *vcpu)
 {
        lockdep_assert_irqs_disabled();
+
+       if (!kvm_request_pending(vcpu))
+               return;
+
+       if (kvm_check_request(KVM_REQ_PMU, vcpu)) {
+               kvm_own_pmu(vcpu);
+               vcpu->arch.aux_inuse |= KVM_LARCH_PMU;
+       }
+
        if (kvm_check_request(KVM_REQ_TLB_FLUSH_GPA, vcpu))
                if (vcpu->arch.flush_gpa != INVALID_GPA) {
                        kvm_flush_tlb_gpa(vcpu, vcpu->arch.flush_gpa);
@@ -312,7 +313,6 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
                /* Make sure the vcpu mode has been written */
                smp_store_mb(vcpu->mode, IN_GUEST_MODE);
                kvm_check_vpid(vcpu);
-               kvm_check_pmu(vcpu);
 
                /*
                 * Called after function kvm_check_vpid()