perf/x86/amd/core: Fix overflow reset on hotplug
authorSandipan Das <sandipan.das@amd.com>
Thu, 14 Sep 2023 14:06:04 +0000 (19:36 +0530)
committerIngo Molnar <mingo@kernel.org>
Fri, 22 Sep 2023 10:05:14 +0000 (12:05 +0200)
commit23d2626b841c2adccdeb477665313c02dff02dc3
treed35c51166a07dece9a8d4ee412193e3f2f632271
parentce9ecca0238b140b88f43859b211c9fdfd8e5b70
perf/x86/amd/core: Fix overflow reset on hotplug

Kernels older than v5.19 do not support PerfMonV2 and the PMI handler
does not clear the overflow bits of the PerfCntrGlobalStatus register.
Because of this, loading a recent kernel using kexec from an older
kernel can result in inconsistent register states on Zen 4 systems.

The PMI handler of the new kernel gets confused and shows a warning when
an overflow occurs because some of the overflow bits are set even if the
corresponding counters are inactive. These are remnants from overflows
that were handled by the older kernel.

During CPU hotplug, the PerfCntrGlobalCtl and PerfCntrGlobalStatus
registers should always be cleared for PerfMonV2-capable processors.
However, a condition used for NB event constaints applicable only to
older processors currently prevents this from happening. Move the reset
sequence to an appropriate place and also clear the LBR Freeze bit.

Fixes: 21d59e3e2c40 ("perf/x86/amd/core: Detect PerfMonV2 support")
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/882a87511af40792ba69bb0e9026f19a2e71e8a3.1694696888.git.sandipan.das@amd.com
arch/x86/events/amd/core.c