powerpc/64s: Always set PMU control registers to frozen/disabled when not in use
authorNicholas Piggin <npiggin@gmail.com>
Tue, 23 Nov 2021 09:51:49 +0000 (19:51 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 24 Nov 2021 10:08:57 +0000 (21:08 +1100)
KVM PMU management code looks for particular frozen/disabled bits in
the PMU registers so it knows whether it must clear them when coming
out of a guest or not. Setting this up helps KVM make these optimisations
without getting confused. Longer term the better approach might be to
move guest/host PMU switching to the perf subsystem.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211123095231.1036501-12-npiggin@gmail.com
arch/powerpc/kernel/cpu_setup_power.c
arch/powerpc/kernel/dt_cpu_ftrs.c
arch/powerpc/kvm/book3s_hv.c

index a29dc83..3dc61e2 100644 (file)
@@ -109,7 +109,7 @@ static void init_PMU_HV_ISA207(void)
 static void init_PMU(void)
 {
        mtspr(SPRN_MMCRA, 0);
-       mtspr(SPRN_MMCR0, 0);
+       mtspr(SPRN_MMCR0, MMCR0_FC);
        mtspr(SPRN_MMCR1, 0);
        mtspr(SPRN_MMCR2, 0);
 }
@@ -123,7 +123,7 @@ static void init_PMU_ISA31(void)
 {
        mtspr(SPRN_MMCR3, 0);
        mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
-       mtspr(SPRN_MMCR0, MMCR0_PMCCEXT);
+       mtspr(SPRN_MMCR0, MMCR0_FC | MMCR0_PMCCEXT);
 }
 
 /*
index de59971..d2b35fb 100644 (file)
@@ -353,7 +353,7 @@ static void init_pmu_power8(void)
        }
 
        mtspr(SPRN_MMCRA, 0);
-       mtspr(SPRN_MMCR0, 0);
+       mtspr(SPRN_MMCR0, MMCR0_FC);
        mtspr(SPRN_MMCR1, 0);
        mtspr(SPRN_MMCR2, 0);
        mtspr(SPRN_MMCRS, 0);
@@ -392,7 +392,7 @@ static void init_pmu_power9(void)
                mtspr(SPRN_MMCRC, 0);
 
        mtspr(SPRN_MMCRA, 0);
-       mtspr(SPRN_MMCR0, 0);
+       mtspr(SPRN_MMCR0, MMCR0_FC);
        mtspr(SPRN_MMCR1, 0);
        mtspr(SPRN_MMCR2, 0);
 }
@@ -428,7 +428,7 @@ static void init_pmu_power10(void)
 
        mtspr(SPRN_MMCR3, 0);
        mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
-       mtspr(SPRN_MMCR0, MMCR0_PMCCEXT);
+       mtspr(SPRN_MMCR0, MMCR0_FC | MMCR0_PMCCEXT);
 }
 
 static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
index 6e760f4..8bf0f63 100644 (file)
@@ -2715,6 +2715,11 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
 #endif
 #endif
        vcpu->arch.mmcr[0] = MMCR0_FC;
+       if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+               vcpu->arch.mmcr[0] |= MMCR0_PMCCEXT;
+               vcpu->arch.mmcra = MMCRA_BHRB_DISABLE;
+       }
+
        vcpu->arch.ctrl = CTRL_RUNLATCH;
        /* default to host PVR, since we can't spoof it */
        kvmppc_set_pvr_hv(vcpu, mfspr(SPRN_PVR));