Skip to content

Commit f4b4b45

Browse files
author
Peter Zijlstra
committed
perf/x86: Fix out of bound MSR access
On Wed, Jul 28, 2021 at 12:49:43PM -0400, Vince Weaver wrote: > [32694.087403] unchecked MSR access error: WRMSR to 0x318 (tried to write 0x0000000000000000) at rIP: 0xffffffff8106f854 (native_write_msr+0x4/0x20) > [32694.101374] Call Trace: > [32694.103974] perf_clear_dirty_counters+0x86/0x100 The problem being that it doesn't filter out all fake counters, in specific the above (erroneously) tries to use FIXED_BTS. Limit the fixed counters indexes to the hardware supplied number. Reported-by: Vince Weaver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Vince Weaver <[email protected]> Tested-by: Like Xu <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b068fc0 commit f4b4b45

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arch/x86/events/core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,13 +2489,15 @@ void perf_clear_dirty_counters(void)
24892489
return;
24902490

24912491
for_each_set_bit(i, cpuc->dirty, X86_PMC_IDX_MAX) {
2492-
/* Metrics and fake events don't have corresponding HW counters. */
2493-
if (is_metric_idx(i) || (i == INTEL_PMC_IDX_FIXED_VLBR))
2494-
continue;
2495-
else if (i >= INTEL_PMC_IDX_FIXED)
2492+
if (i >= INTEL_PMC_IDX_FIXED) {
2493+
/* Metrics and fake events don't have corresponding HW counters. */
2494+
if ((i - INTEL_PMC_IDX_FIXED) >= hybrid(cpuc->pmu, num_counters_fixed))
2495+
continue;
2496+
24962497
wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + (i - INTEL_PMC_IDX_FIXED), 0);
2497-
else
2498+
} else {
24982499
wrmsrl(x86_pmu_event_addr(i), 0);
2500+
}
24992501
}
25002502

25012503
bitmap_zero(cpuc->dirty, X86_PMC_IDX_MAX);

0 commit comments

Comments
 (0)