]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Skip PMU checking on vCPU context switch
authorBibo Mao <maobibo@loongson.cn>
Sun, 9 Nov 2025 08:02:09 +0000 (16:02 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Mon, 10 Nov 2025 00:37:07 +0000 (08:37 +0800)
PMU hardware about VM is switched on VM exit to host rather than vCPU
context sched off, PMU is checked and restored on return to VM. It is
not necessary to check PMU on vCPU context sched on callback, since the
request is made on the VM exit entry or VM PMU CSR access abort routine
already.

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

index b3995ff4b17eceb9627799e536df140b7fed8301..1245a6b358966f47025cf775a2925cb31ea32bbb 100644 (file)
@@ -148,12 +148,6 @@ static void kvm_lose_pmu(struct kvm_vcpu *vcpu)
        kvm_restore_host_pmu(vcpu);
 }
 
-static void kvm_restore_pmu(struct kvm_vcpu *vcpu)
-{
-       if ((vcpu->arch.aux_inuse & KVM_LARCH_PMU))
-               kvm_make_request(KVM_REQ_PMU, vcpu);
-}
-
 static void kvm_check_pmu(struct kvm_vcpu *vcpu)
 {
        if (kvm_check_request(KVM_REQ_PMU, vcpu)) {
@@ -304,7 +298,10 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
                vcpu->arch.aux_inuse &= ~KVM_LARCH_SWCSR_LATEST;
 
                if (kvm_request_pending(vcpu) || xfer_to_guest_mode_work_pending()) {
-                       kvm_lose_pmu(vcpu);
+                       if (vcpu->arch.aux_inuse & KVM_LARCH_PMU) {
+                               kvm_lose_pmu(vcpu);
+                               kvm_make_request(KVM_REQ_PMU, vcpu);
+                       }
                        /* make sure the vcpu mode has been written */
                        smp_store_mb(vcpu->mode, OUTSIDE_GUEST_MODE);
                        local_irq_enable();
@@ -1609,9 +1606,6 @@ static int _kvm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
        kvm_restore_timer(vcpu);
        kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
 
-       /* Restore hardware PMU CSRs */
-       kvm_restore_pmu(vcpu);
-
        /* Don't bother restoring registers multiple times unless necessary */
        if (vcpu->arch.aux_inuse & KVM_LARCH_HWCSR_USABLE)
                return 0;