[PATCH 0/2] LoongArch: KVM: Restore guest PMU if it is enabled

Bibo Mao posted 2 patches 3 months, 2 weeks ago
arch/loongarch/kvm/vcpu.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
[PATCH 0/2] LoongArch: KVM: Restore guest PMU if it is enabled
Posted by Bibo Mao 3 months, 2 weeks ago
On LoongArch system, guest PMU hardware is shared by guest and host
and 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 it is enabled, PMU
context for guest need switch on. Now KVM_REQ_PMU notification is set
on vcpu context switch, however it is missing if there is no vcpu context
switch and PMU is used by guest VM.

Also there is code cleanup about PMU checking on vCPU sched-on callback,
since it is already checked on VM exit entry or VM PMU CSR access abort
routine.

Bibo Mao (2):
  LoongArch: KVM: Restore guest PMU if it is enabled
  LoongArch: KVM: Skip PMU checking on vCPU context switch

 arch/loongarch/kvm/vcpu.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)


base-commit: 6fab32bb6508abbb8b7b1c5498e44f0c32320ed5
-- 
2.39.3
Re: [PATCH 0/2] LoongArch: KVM: Restore guest PMU if it is enabled
Posted by Huacai Chen 3 months ago
Applied, thanks.

Huacai

On Fri, Oct 24, 2025 at 3:20 PM Bibo Mao <maobibo@loongson.cn> wrote:
>
> On LoongArch system, guest PMU hardware is shared by guest and host
> and 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 it is enabled, PMU
> context for guest need switch on. Now KVM_REQ_PMU notification is set
> on vcpu context switch, however it is missing if there is no vcpu context
> switch and PMU is used by guest VM.
>
> Also there is code cleanup about PMU checking on vCPU sched-on callback,
> since it is already checked on VM exit entry or VM PMU CSR access abort
> routine.
>
> Bibo Mao (2):
>   LoongArch: KVM: Restore guest PMU if it is enabled
>   LoongArch: KVM: Skip PMU checking on vCPU context switch
>
>  arch/loongarch/kvm/vcpu.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
>
>
> base-commit: 6fab32bb6508abbb8b7b1c5498e44f0c32320ed5
> --
> 2.39.3
>