Commit 2968314094d8db0af32de20ad51349a30ea54a01
Committed by
Greg Kroah-Hartman
1 parent
763e95c4ac
Exists in
ti-linux-3.14.y
and in
2 other branches
perf/x86/intel: Use rdmsrl_safe() when initializing RAPL PMU
commit 24223657806a0ebd0ae5c9caaf7b021091889cf2 upstream. CPUs which should support the RAPL counters according to Family/Model/Stepping may still issue #GP when attempting to access the RAPL MSRs. This may happen when Linux is running under KVM and we are passing-through host F/M/S data, for example. Use rdmsrl_safe to first access the RAPL_POWER_UNIT MSR; if this fails, do not attempt to use this PMU. Signed-off-by: Venkatesh Srinivas <venkateshs@google.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1394739386-22260-1-git-send-email-venkateshs@google.com Cc: zheng.z.yan@intel.com Cc: eranian@google.com Cc: ak@linux.intel.com Cc: linux-kernel@vger.kernel.org [ The patch also silently fixes another bug: rapl_pmu_init() didn't handle the memory alloc failure case previously. ] Signed-off-by: Ingo Molnar <mingo@kernel.org> [backport by whissi] Cc: Thomas D <whissi@whissi.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 9 additions and 3 deletions Side-by-side Diff
arch/x86/kernel/cpu/perf_event_intel_rapl.c
... | ... | @@ -511,6 +511,7 @@ |
511 | 511 | struct rapl_pmu *pmu = per_cpu(rapl_pmu, cpu); |
512 | 512 | int phys_id = topology_physical_package_id(cpu); |
513 | 513 | u64 ms; |
514 | + u64 msr_rapl_power_unit_bits; | |
514 | 515 | |
515 | 516 | if (pmu) |
516 | 517 | return 0; |
... | ... | @@ -518,6 +519,9 @@ |
518 | 519 | if (phys_id < 0) |
519 | 520 | return -1; |
520 | 521 | |
522 | + if (!rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits)) | |
523 | + return -1; | |
524 | + | |
521 | 525 | pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu)); |
522 | 526 | if (!pmu) |
523 | 527 | return -1; |
... | ... | @@ -531,8 +535,7 @@ |
531 | 535 | * |
532 | 536 | * we cache in local PMU instance |
533 | 537 | */ |
534 | - rdmsrl(MSR_RAPL_POWER_UNIT, pmu->hw_unit); | |
535 | - pmu->hw_unit = (pmu->hw_unit >> 8) & 0x1FULL; | |
538 | + pmu->hw_unit = (msr_rapl_power_unit_bits >> 8) & 0x1FULL; | |
536 | 539 | pmu->pmu = &rapl_pmu_class; |
537 | 540 | |
538 | 541 | /* |
... | ... | @@ -649,7 +652,9 @@ |
649 | 652 | get_online_cpus(); |
650 | 653 | |
651 | 654 | for_each_online_cpu(cpu) { |
652 | - rapl_cpu_prepare(cpu); | |
655 | + ret = rapl_cpu_prepare(cpu); | |
656 | + if (ret) | |
657 | + goto out; | |
653 | 658 | rapl_cpu_init(cpu); |
654 | 659 | } |
655 | 660 | |
... | ... | @@ -672,6 +677,7 @@ |
672 | 677 | hweight32(rapl_cntr_mask), |
673 | 678 | ktime_to_ms(pmu->timer_interval)); |
674 | 679 | |
680 | +out: | |
675 | 681 | put_online_cpus(); |
676 | 682 | |
677 | 683 | return 0; |