Skip to content

Commit 5001bcf

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Restore guest PMU if it is enabled
On LoongArch system, guest PMU hardware is shared by guest and host but PMU interrupt is separated. PMU is pass-through to VM, and there is PMU context switch when exit to host and return to guest. There is optimiation to check whether PMU is enabled by guest. If not, it is not necessary to return to guest. However, if it is enabled, PMU context for guest need switch on. Now KVM_REQ_PMU notification is set on vCPU context switch, but it is missing if there is no vCPU context switch while PMU is used by guest VM, so fix it. Cc: <stable@vger.kernel.org> Fixes: f4e40ea ("LoongArch: KVM: Add PMU support for guest") Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent d3c9515 commit 5001bcf

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

arch/loongarch/kvm/vcpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,18 @@ static void kvm_lose_pmu(struct kvm_vcpu *vcpu)
132132
* Clear KVM_LARCH_PMU if the guest is not using PMU CSRs when
133133
* exiting the guest, so that the next time trap into the guest.
134134
* We don't need to deal with PMU CSRs contexts.
135+
*
136+
* Otherwise set the request bit KVM_REQ_PMU to restore guest PMU
137+
* before entering guest VM
135138
*/
136139
val = kvm_read_sw_gcsr(csr, LOONGARCH_CSR_PERFCTRL0);
137140
val |= kvm_read_sw_gcsr(csr, LOONGARCH_CSR_PERFCTRL1);
138141
val |= kvm_read_sw_gcsr(csr, LOONGARCH_CSR_PERFCTRL2);
139142
val |= kvm_read_sw_gcsr(csr, LOONGARCH_CSR_PERFCTRL3);
140143
if (!(val & KVM_PMU_EVENT_ENABLED))
141144
vcpu->arch.aux_inuse &= ~KVM_LARCH_PMU;
145+
else
146+
kvm_make_request(KVM_REQ_PMU, vcpu);
142147

143148
kvm_restore_host_pmu(vcpu);
144149
}

0 commit comments

Comments
 (0)