LoongArch: KVM: Add PMU support for guest
authorSong Gao <gaosong@loongson.cn>
Thu, 12 Sep 2024 12:53:40 +0000 (20:53 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 12 Sep 2024 12:53:40 +0000 (20:53 +0800)
commitf4e40ea9f78fed585e953bf38575e47d24922e1a
tree276a9131b25c79f8b8f1710c6ac4f145e2b710f4
parentacc7f20d54a3eeceec7602b11d6e3462e7fba862
LoongArch: KVM: Add PMU support for guest

On LoongArch, the host and guest have their own PMU CSRs registers and
they share PMU hardware resources. A set of PMU CSRs consists of a CTRL
register and a CNTR register. We can set which PMU CSRs are used by the
guest by writing to the GCFG register [24:26] bits.

On KVM side:
- Save the host PMU CSRs into structure kvm_context.
- If the host supports the PMU feature.
  - When entering guest mode, save the host PMU CSRs and restore the guest PMU CSRs.
  - When exiting guest mode, save the guest PMU CSRs and restore the host PMU CSRs.

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