powerpc/perf: Add mtmmcr0(FC) after ppc_set_pmu_inuse(1)
Madhavan Srinivasan
maintainerPATCH 1/2 powerpc/perf: Add mtmmcr0(FC) after ppc_set_pmu_inuse(1)
pmu_inuse flag is part of lppaca struct which notifies the hypervisor whether guest/partition is using PMUs. This provides a hint incase of save/restore of PMU registers. And in power_pmu_enable(), linux sets the pmu_inuse flag and then updates the PMU registers. Current sequence in power_pmu_enable() is 1) update pmc_inuse flag 2)update MMCRA, MMCR1, MMCR0 and so on. But with this sequence, there is a window where when updating MMCRA, hypersior could load stale value to MMCR0 which could cause a PMI exception. Patch add a mtmmcr0 with freeze counter bit set right after updating the pmu_inuse flag to avoid any overflow scenarios.
--- arch/powerpc/perf/core-book3s.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/perf/core-book3s.c +1 -0
@@ -1343,6 +1343,7 @@ static void power_pmu_enable(struct pmu *pmu)* Then unfreeze the events. */ ppc_set_pmu_inuse (1 ); +mtspr (SPRN_MMCR0 ,MMCR0_FC );mtspr (SPRN_MMCRA , cpuhw->mmcr[2 ] & ~MMCRA_SAMPLE_ENABLE );mtspr (SPRN_MMCR1 , cpuhw->mmcr[1 ]); mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
Signature · 1 line
2.21.1
Madhavan Srinivasan
maintainerPATCH v2 2/2 powerpc/perf: Check pmus_inuse flag in perf_event_print_debug()
pmu_inuse flag is part of lppaca struct which notifies the hypervisor whether guest/partition is using PMUs. This provides a hint for save/restore of PMU registers. Currently perf_event_print_debug() does not check for pmu_inuse flag and it is not safe to use it to dump PMU SPRs in a CONFIG_PSERIES.
Patch adds two things here. 1) An inline ppc_get_pmu_inuse() to get the pmu_inuse value and 2)check in perf_event_print_debug() before dumping the PMU SPRs.
ppc_get_pmu_inuse() is based on ppc_set_pmu_inuse() and includes same CONFIG_ checks.
---
Changelog v1:
- Fixed pmac32_deconfig build break
- Fixed errors reported by checkpatch.pl
arch/powerpc/include/asm/pmc.h | 15 +++++++++++++++ arch/powerpc/perf/core-book3s.c | 9 +++++++++ 2 files changed, 24 insertions(+)
arch/powerpc/include/asm/pmc.h +15 -0
@@ -34,11 +34,26 @@ static inline void ppc_set_pmu_inuse(int inuse) #endif } +static inline u8 ppc_get_pmu_inuse (void ) +{ +#if defined(CONFIG_PPC_PSERIES ) || defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE ) +if (firmware_has_feature (FW_FEATURE_LPAR )) { +#ifdef CONFIG_PPC_PSERIES +return get_lppaca ()->pmcregs_in_use; +#endif + } +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +return get_paca ()->pmcregs_in_use; +#endif +#endif +} +extern void power4_enable_pmcs (void );#else /* CONFIG_PPC64 */ static inline void ppc_set_pmu_inuse (int inuse) { } +static inline u8 ppc_get_pmu_inuse (void ) {return 0 ; }#endif
arch/powerpc/perf/core-book3s.c +9 -0
@@ -808,6 +808,15 @@ void perf_event_print_debug(void)if (!ppmu->n_counter)return ; +/* +* Check pmu_inuse flag. As per PAPR spec, hypersivor +* will save/restore the PMU regs only if pmu_inuse is +* set. If its not enable, values dumped from these SPRs +* may not be valid or useful. +*/ +if (!ppc_get_pmu_inuse ()) +return ; +local_irq_save (flags); pr_info("CPU: %d PMU registers, ppmu = %s n_counters = %d",
Signature · 1 line
2.21.1