Skip to content

Commit 3a38c57

Browse files
committed
Merge tag 'perf-urgent-2023-10-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf event fixes from Ingo Molnar: "Misc fixes: work around an AMD microcode bug on certain models, and fix kexec kernel PMI handlers on AMD systems that get loaded on older kernels that have an unexpected register state" * tag 'perf-urgent-2023-10-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/amd: Do not WARN() on every IRQ perf/x86/amd/core: Fix overflow reset on hotplug
2 parents e402b08 + 599522d commit 3a38c57

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

arch/x86/events/amd/core.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,12 @@ static void amd_pmu_cpu_reset(int cpu)
534534
/* Clear enable bits i.e. PerfCntrGlobalCtl.PerfCntrEn */
535535
wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_CTL, 0);
536536

537-
/* Clear overflow bits i.e. PerfCntrGLobalStatus.PerfCntrOvfl */
538-
wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR, amd_pmu_global_cntr_mask);
537+
/*
538+
* Clear freeze and overflow bits i.e. PerfCntrGLobalStatus.LbrFreeze
539+
* and PerfCntrGLobalStatus.PerfCntrOvfl
540+
*/
541+
wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR,
542+
GLOBAL_STATUS_LBRS_FROZEN | amd_pmu_global_cntr_mask);
539543
}
540544

541545
static int amd_pmu_cpu_prepare(int cpu)
@@ -570,6 +574,7 @@ static void amd_pmu_cpu_starting(int cpu)
570574
int i, nb_id;
571575

572576
cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY;
577+
amd_pmu_cpu_reset(cpu);
573578

574579
if (!x86_pmu.amd_nb_constraints)
575580
return;
@@ -591,8 +596,6 @@ static void amd_pmu_cpu_starting(int cpu)
591596

592597
cpuc->amd_nb->nb_id = nb_id;
593598
cpuc->amd_nb->refcnt++;
594-
595-
amd_pmu_cpu_reset(cpu);
596599
}
597600

598601
static void amd_pmu_cpu_dead(int cpu)
@@ -601,6 +604,7 @@ static void amd_pmu_cpu_dead(int cpu)
601604

602605
kfree(cpuhw->lbr_sel);
603606
cpuhw->lbr_sel = NULL;
607+
amd_pmu_cpu_reset(cpu);
604608

605609
if (!x86_pmu.amd_nb_constraints)
606610
return;
@@ -613,8 +617,6 @@ static void amd_pmu_cpu_dead(int cpu)
613617

614618
cpuhw->amd_nb = NULL;
615619
}
616-
617-
amd_pmu_cpu_reset(cpu);
618620
}
619621

620622
static inline void amd_pmu_set_global_ctl(u64 ctl)
@@ -884,7 +886,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
884886
struct hw_perf_event *hwc;
885887
struct perf_event *event;
886888
int handled = 0, idx;
887-
u64 status, mask;
889+
u64 reserved, status, mask;
888890
bool pmu_enabled;
889891

890892
/*
@@ -909,6 +911,14 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
909911
status &= ~GLOBAL_STATUS_LBRS_FROZEN;
910912
}
911913

914+
reserved = status & ~amd_pmu_global_cntr_mask;
915+
if (reserved)
916+
pr_warn_once("Reserved PerfCntrGlobalStatus bits are set (0x%llx), please consider updating microcode\n",
917+
reserved);
918+
919+
/* Clear any reserved bits set by buggy microcode */
920+
status &= amd_pmu_global_cntr_mask;
921+
912922
for (idx = 0; idx < x86_pmu.num_counters; idx++) {
913923
if (!test_bit(idx, cpuc->active_mask))
914924
continue;

0 commit comments

Comments
 (0)