Skip to contentSkip to conversation

perf/x86: fix RAPL rdmsrl_safe() usage

PATCH In review Stephane Eranian 5 participants 5 messages Apr 23, 2014 – Apr 24, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/x86: fix RAPL rdmsrl_safe() usage

This patch fixes a bug introduced by commit 24223657.

The rdmsrl_safe() function returns 0 on success. The current code was failing to detect the RAPL PMU on real hardware (missing /sys/devices/power) because the return value of rdmsrl_safe() was misinterpreted.

arch/x86/kernel/cpu/perf_event_intel_rapl.c +2 -1
index 7c87424..619f769 100644
@@ -543,7 +543,8 @@ static int rapl_cpu_prepare(int cpu)
 	if (phys_id < 0)
 		return -1;
 
-	if (!rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits))
+	/* protect rdmsrl() to handle virtualization */
+	if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits))
 		return -1;
 
 	pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Stephane Eranian

This patch fixes a bug introduced by commit 24223657.

Maybe add

Fixes <commit-id>

tag?

Quoted 6 lines

The rdmsrl_safe() function returns 0 on success. The current code was failing to detect the RAPL PMU on real hardware (missing /sys/devices/power) because the return value of rdmsrl_safe() was misinterpreted.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#2 lore raw
Quoted 10 lines · Borislav Petkov
Quoted 2 lines · Stephane Eranian

This patch fixes a bug introduced by commit 24223657.

Maybe add

Fixes <commit-id>

tag?

Quoted 8 lines
Quoted 6 lines

The rdmsrl_safe() function returns 0 on success. The current code was failing to detect the RAPL PMU on real hardware (missing /sys/devices/power) because the return value of rdmsrl_safe() was misinterpreted.

-- vs;

#3 lore raw
Quoted 3 lines
Quoted 1 line

Again the bug is really in KVM. We wouldn't need all this crap if KVM didn't throw the bogus #GPs. I'm sure you missed plenty of MSR accesses elsewhere, and it's a ticking time bomb.

If the VM lies to the kernel with the family-model you need to at least limit the consequences. KVM is spectacularly failing to do that by throwing bogus #GPs.

The brown paper bad needs to be employed on the KVM code (or better the bug be fixed there, by defaulting to not #GP on unknown MSRs)

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#4 lore raw

[tip:perf/urgent] perf/x86: Fix RAPL rdmsrl_safe() usage

In reply to Stephane Eranian
perf/x86: Fix RAPL rdmsrl_safe() usage
Commit-ID:  9f7ff8931e3c5ddc8535476971ec9501e9555c05
Gitweb:     http://git.kernel.org/tip/9f7ff8931e3c5ddc8535476971ec9501e9555c05
Author:     Stephane Eranian <[email protected]>
AuthorDate: Wed, 23 Apr 2014 19:04:19 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 24 Apr 2014 08:12:41 +0200

perf/x86: Fix RAPL rdmsrl_safe() usage

This patch fixes a bug introduced by:

24223657806a ("perf/x86/intel: Use rdmsrl_safe() when initializing RAPL PMU")

The rdmsrl_safe() function returns 0 on success. The current code was failing to detect the RAPL PMU on real hardware (missing /sys/devices/power) because the return value of rdmsrl_safe() was misinterpreted.

---
 arch/x86/kernel/cpu/perf_event_intel_rapl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_intel_rapl.c +2 -1
index 7c87424..619f769 100644
@@ -543,7 +543,8 @@ static int rapl_cpu_prepare(int cpu)
 	if (phys_id < 0)
 		return -1;
 
-	if (!rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits))
+	/* protect rdmsrl() to handle virtualization */
+	if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits))
 		return -1;
 
 	pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));