diff options
author | Song Gao <gaosong@loongson.cn> | 2024-09-12 14:53:40 +0200 |
---|---|---|
committer | Huacai Chen <chenhuacai@loongson.cn> | 2024-09-12 14:53:40 +0200 |
commit | f4e40ea9f78fed585e953bf38575e47d24922e1a (patch) | |
tree | 276a9131b25c79f8b8f1710c6ac4f145e2b710f4 /arch/loongarch/kvm/exit.c | |
parent | LoongArch: KVM: Add vm migration support for LBT registers (diff) | |
download | linux-f4e40ea9f78fed585e953bf38575e47d24922e1a.tar.xz linux-f4e40ea9f78fed585e953bf38575e47d24922e1a.zip |
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>
Diffstat (limited to 'arch/loongarch/kvm/exit.c')
-rw-r--r-- | arch/loongarch/kvm/exit.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index a3d550a34973..34e23a9ed07f 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -127,6 +127,14 @@ static int kvm_handle_csr(struct kvm_vcpu *vcpu, larch_inst inst) rj = inst.reg2csr_format.rj; csrid = inst.reg2csr_format.csr; + if (csrid >= LOONGARCH_CSR_PERFCTRL0 && csrid <= vcpu->arch.max_pmu_csrid) { + if (kvm_guest_has_pmu(&vcpu->arch)) { + vcpu->arch.pc -= 4; + kvm_make_request(KVM_REQ_PMU, vcpu); + return EMULATE_DONE; + } + } + /* Process CSR ops */ switch (rj) { case 0: /* process csrrd */ |