Skip to content

Commit 86aa94c

Browse files
Dapeng MiIngo Molnar
authored andcommitted
perf/x86/intel: Fix incorrect MSR index calculations in intel_pmu_config_acr()
The MSR offset calculations in intel_pmu_config_acr() are buggy. To calculate fixed counter MSR addresses in intel_pmu_config_acr(), the HW counter index "idx" is subtracted by INTEL_PMC_IDX_FIXED. This leads to the ACR mask value of fixed counters to be incorrectly saved to the positions of GP counters in acr_cfg_b[], e.g. For fixed counter 0, its ACR counter mask should be saved to acr_cfg_b[32], but it's saved to acr_cfg_b[0] incorrectly. Fix this issue. [ mingo: Clarified & improved the changelog. ] Fixes: ec980e4 ("perf/x86/intel: Support auto counter reload") Signed-off-by: Dapeng Mi <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dd3922c commit 86aa94c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/x86/events/intel/core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,26 +2900,28 @@ static void intel_pmu_config_acr(int idx, u64 mask, u32 reload)
29002900
{
29012901
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
29022902
int msr_b, msr_c;
2903+
int msr_offset;
29032904

29042905
if (!mask && !cpuc->acr_cfg_b[idx])
29052906
return;
29062907

29072908
if (idx < INTEL_PMC_IDX_FIXED) {
29082909
msr_b = MSR_IA32_PMC_V6_GP0_CFG_B;
29092910
msr_c = MSR_IA32_PMC_V6_GP0_CFG_C;
2911+
msr_offset = x86_pmu.addr_offset(idx, false);
29102912
} else {
29112913
msr_b = MSR_IA32_PMC_V6_FX0_CFG_B;
29122914
msr_c = MSR_IA32_PMC_V6_FX0_CFG_C;
2913-
idx -= INTEL_PMC_IDX_FIXED;
2915+
msr_offset = x86_pmu.addr_offset(idx - INTEL_PMC_IDX_FIXED, false);
29142916
}
29152917

29162918
if (cpuc->acr_cfg_b[idx] != mask) {
2917-
wrmsrl(msr_b + x86_pmu.addr_offset(idx, false), mask);
2919+
wrmsrl(msr_b + msr_offset, mask);
29182920
cpuc->acr_cfg_b[idx] = mask;
29192921
}
29202922
/* Only need to update the reload value when there is a valid config value. */
29212923
if (mask && cpuc->acr_cfg_c[idx] != reload) {
2922-
wrmsrl(msr_c + x86_pmu.addr_offset(idx, false), reload);
2924+
wrmsrl(msr_c + msr_offset, reload);
29232925
cpuc->acr_cfg_c[idx] = reload;
29242926
}
29252927
}

0 commit comments

Comments
 (0)