From: Peter Zijlstra <peterz@infradead.org>
To: Don Zickus <dzickus@redhat.com>
Cc: george.dunlap@eu.citrix.com, LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@elte.hu>,
konrad.wilk@oracle.com
Subject: Re: [PATCH] x86, perf: Tweak broken BIOS rules during check_hw_exists
Date: Tue, 19 May 2015 10:17:00 +0200 [thread overview]
Message-ID: <20150519081700.GF19282@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1431976608-56970-1-git-send-email-dzickus@redhat.com>
On Mon, May 18, 2015 at 03:16:48PM -0400, Don Zickus wrote:
> I stumbled upon an AMD box that had the BIOS using a hardware counter. Instead
> of printing out a warning and continuing, it failed and blocked further perf
> counter usage.
Hehe, which was the original behaviour iirc.
> Looking through the history, I found commit a5ebe0ba3dff had tweaked the rules
> for a xen guest on an almost identical box and now changed the behaviour.
>
> Unfortunately the rules were tweaked incorrectly and will always lead to msr
> failures even though the msrs are completely fine.
>
> What happens now is in arch/x86/kernel/cpu/perf_event.c::check_hw_exists:
>
> <snip>
> for (i = 0; i < x86_pmu.num_counters; i++) {
> reg = x86_pmu_config_addr(i);
> ret = rdmsrl_safe(reg, &val);
> if (ret)
> goto msr_fail;
> if (val & ARCH_PERFMON_EVENTSEL_ENABLE) {
> bios_fail = 1;
> val_fail = val;
> reg_fail = reg;
> }
> }
>
> <snip>
> /*
> * Read the current value, change it and read it back to see if it
> * matches, this is needed to detect certain hardware emulators
> * (qemu/kvm) that don't trap on the MSR access and always return 0s.
> */
> reg = x86_pmu_event_addr(0);
> ^^^^
>
> if the first perf counter is enabled, then this routine will always fail
> because the counter is running. :-(
>
> if (rdmsrl_safe(reg, &val))
> goto msr_fail;
> val ^= 0xffffUL;
> ret = wrmsrl_safe(reg, val);
> ret |= rdmsrl_safe(reg, &val_new);
> if (ret || val != val_new)
> goto msr_fail;
>
> The above bios_fail used to be a 'goto' which is why it worked in the past.
>
> Further, most vendors have migrated to using fixed counters to hide their
> evilness hence this problem rarely shows up now days except on a few old boxes.
>
> I fixed my problem and kept the spirit of the original Xen fix, by recording a
> safe non-enable register to be used safely for the reading/writing check.
> Because it is not enabled, this passes on bare metal boxes (like metal), but
> should continue to throw an msr_fail on Xen guests because the register isn't
> emulated yet.
>
> Now I get a proper bios_fail error message and Xen should still see their
> msr_fail message (untested).
Thanks!
next prev parent reply other threads:[~2015-05-19 8:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 19:16 [PATCH] x86, perf: Tweak broken BIOS rules during check_hw_exists Don Zickus
2015-05-19 8:17 ` Peter Zijlstra [this message]
2015-05-21 17:57 ` George Dunlap
2015-06-02 15:15 ` George Dunlap
2015-05-27 10:02 ` [tip:perf/core] perf/x86: Tweak broken BIOS rules during check_hw_exists() tip-bot for Don Zickus
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=20150519081700.GF19282@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dzickus@redhat.com \
--cc=george.dunlap@eu.citrix.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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