public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@elte.hu>,
	Stephane Eranian <eranian@google.com>,
	"robert.richter" <robert.richter@amd.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Arjan Van De Ven <arjan@linux.intel.com>,
	"H. Peter Anvin" <hpa@linux.kernel.org>
Subject: [PATCH] perf, x86: Disable perf if the BIOS got its grubby paws on the PMU
Date: Fri, 03 Sep 2010 11:13:47 +0200	[thread overview]
Message-ID: <1283505227.1783.224.camel@laptop> (raw)

Disable all of perf if we find any active PMCs on boot.

It has been reported that some BIOSes access the PMU, for obscure things
better done by the OS. Come down hard on this practice and fully disable
the PMU.

[ Boot tested on a westmere system with a sane BIOS -- I don't actually
  have an affected system to test this on. ]

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---

Robert, do you know if any AMD system BIOSes carry similar
Feat^H^H^H^HFailureAdd?

 arch/x86/kernel/cpu/perf_event_intel.c |   35 ++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index ee05c90..6849653 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -923,6 +923,19 @@ static void intel_clovertown_quirks(void)
 	x86_pmu.pebs_constraints = NULL;
 }
 
+static void print_BIOS_fail(void)
+{
+	printk(KERN_ERR "\n");
+	printk(KERN_ERR "=============================================\n");
+	printk(KERN_ERR "It appears the BIOS is actively using the PMU\n");
+	printk(KERN_ERR "this avoids Linux from using it, please de-  \n");
+	printk(KERN_ERR "activate this BIOS feature or request a BIOS \n");
+	printk(KERN_ERR "update from your vendor.                     \n");
+	printk(KERN_ERR "=============================================\n");
+
+	memset(&x86_pmu, 0, sizeof(x86_pmu));
+}
+
 static __init int intel_pmu_init(void)
 {
 	union cpuid10_edx edx;
@@ -930,6 +943,8 @@ static __init int intel_pmu_init(void)
 	unsigned int unused;
 	unsigned int ebx;
 	int version;
+	u64 val;
+	int i;
 
 	if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
 		switch (boot_cpu_data.x86) {
@@ -968,6 +983,26 @@ static __init int intel_pmu_init(void)
 		x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
 
 	/*
+	 * Check to see if the BIOS enabled any of the counters, if so
+	 * complain and bail.
+	 */
+	for (i = 0; i < x86_pmu.num_counters; i++) {
+		rdmsrl(x86_pmu.eventsel + i, val);
+		if (val & ARCH_PERFMON_EVENTSEL_ENABLE) {
+			print_BIOS_fail();
+			return -EBUSY;
+		}
+	}
+
+	for (i = 0; i < x86_pmu.num_counters_fixed; i++) {
+		rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, val);
+		if (val & (0x03 << i*4)) {
+			print_BIOS_fail();
+			return -EBUSY;
+		}
+	}
+
+	/*
 	 * v2 and above have a perf capabilities MSR
 	 */
 	if (version > 1) {


             reply	other threads:[~2010-09-03  9:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-03  9:13 Peter Zijlstra [this message]
2010-09-03 13:53 ` [PATCH] perf, x86: Disable perf if the BIOS got its grubby paws on the PMU Arjan van de Ven
2010-09-03 14:32   ` Matt Domsch
2010-09-03 14:46     ` Peter Zijlstra
2010-09-07 15:15       ` Robert Richter
2010-09-07 16:51         ` Robert Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283505227.1783.224.camel@laptop \
    --to=peterz@infradead.org \
    --cc=arjan@linux.intel.com \
    --cc=eranian@google.com \
    --cc=hpa@linux.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=robert.richter@amd.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox