From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
x86@kernel.org, Stephane Eranian <eranian@google.com>,
Borislav Petkov <bp@suse.de>, Kan Liang <kan.liang@intel.com>
Subject: Re: [patch 0/4] x86/perf/intel/cstate: Fix cpu hotplug handling and make it modular
Date: Mon, 21 Mar 2016 16:01:27 +0100 [thread overview]
Message-ID: <20160321150127.GY6344@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20160320185527.763205536@linutronix.de>
On Sun, Mar 20, 2016 at 06:59:01PM -0000, Thomas Gleixner wrote:
> The perf cstate driver is yet another trainwreck vs. cpu hotplug handling. The
> hotplug code is not only disfunctional, it's also a uncomprehensible mess.
>
> The following series fixes the hotplug functionality, sanitizes error handling
> and makes the driver modular.
>
I needed the below to not make it insta explode with perf_fuzzer.
At cstate_pmu_event_init() event->cpu can still be -1, that results in
funny masks being dereferenced.
With the probe thing, we need to clear msr[].attr for all those that are
not available, other event_init() will happily still select them
(they're just not visible in sysfs, and guess how much the fuzzer cares
about that.. :-).
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -267,7 +267,7 @@ static ssize_t cstate_get_attr_cpumask(s
static int cstate_pmu_event_init(struct perf_event *event)
{
u64 cfg = event->attr.config;
- unsigned int cpu;
+ int cpu;
if (event->attr.type != event->pmu->type)
return -ENOENT;
@@ -282,6 +282,9 @@ static int cstate_pmu_event_init(struct
event->attr.sample_period) /* no sampling */
return -EINVAL;
+ if (event->cpu < 0)
+ return -EINVAL;
+
if (event->pmu == &cstate_core_pmu) {
if (cfg >= PERF_CSTATE_CORE_EVENT_MAX)
return -EINVAL;
@@ -547,22 +550,24 @@ MODULE_DEVICE_TABLE(x86cpu, intel_cstate
* Probe the cstate events and insert the available one into sysfs attrs
* Return false if there are no available events.
*/
-static bool __init cstate_probe_msr(const unsigned long evmsk,
- struct perf_cstate_msr *msr,
- struct attribute **attrs)
+static bool __init cstate_probe_msr(const unsigned long evmsk, int max,
+ struct perf_cstate_msr *msr,
+ struct attribute **attrs)
{
bool found = false;
unsigned int bit;
u64 val;
- for_each_set_bit(bit, &evmsk, sizeof(evmsk) * BITS_PER_BYTE) {
- /* Verify whether the MSR is accessible */
- if (!rdmsrl_safe(msr[bit].msr, &val)) {
+ for (bit = 0; bit < max; bit++) {
+ if (test_bit(bit, &evmsk) && !rdmsrl_safe(msr[bit].msr, &val)) {
*attrs++ = &msr[bit].attr->attr.attr;
found = true;
+ } else {
+ msr[bit].attr = NULL;
}
}
*attrs = NULL;
+
return found;
}
@@ -572,11 +577,13 @@ static int __init cstate_probe(const str
if (cm->quirks & SLM_PKG_C6_USE_C7_MSR)
pkg_msr[PERF_CSTATE_PKG_C6_RES].msr = MSR_PKG_C7_RESIDENCY;
- has_cstate_core = cstate_probe_msr(cm->core_events, core_msr,
- core_events_attrs);
-
- has_cstate_pkg = cstate_probe_msr(cm->pkg_events, pkg_msr,
- pkg_events_attrs);
+ has_cstate_core = cstate_probe_msr(cm->core_events,
+ PERF_CSTATE_CORE_EVENT_MAX,
+ core_msr, core_events_attrs);
+
+ has_cstate_pkg = cstate_probe_msr(cm->pkg_events,
+ PERF_CSTATE_PKG_EVENT_MAX,
+ pkg_msr, pkg_events_attrs);
return (has_cstate_core || has_cstate_pkg) ? 0 : -ENODEV;
}
prev parent reply other threads:[~2016-03-21 15:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-20 18:59 [patch 0/4] x86/perf/intel/cstate: Fix cpu hotplug handling and make it modular Thomas Gleixner
2016-03-20 18:59 ` [patch 1/4] x86/perf/intel/cstate: Make hotplug handling actually work Thomas Gleixner
2016-03-31 9:20 ` [tip:perf/core] x86/perf/intel/cstate: Make cstate " tip-bot for Thomas Gleixner
2016-03-20 18:59 ` [patch 2/4] x86/perf/intel/cstate: Sanitize probing Thomas Gleixner
2016-03-21 14:19 ` Liang, Kan
2016-03-21 14:42 ` Peter Zijlstra
2016-03-21 15:03 ` Thomas Gleixner
2016-03-21 15:04 ` Thomas Gleixner
2016-03-31 9:21 ` [tip:perf/core] " tip-bot for Thomas Gleixner
2016-03-20 18:59 ` [patch 3/4] x86/perf/intel/cstate: Sanitize error handling Thomas Gleixner
2016-03-31 9:21 ` [tip:perf/core] " tip-bot for Thomas Gleixner
2016-03-20 18:59 ` [patch 4/4] x86/perf/intel/cstate: Modularize driver Thomas Gleixner
2016-03-31 9:21 ` [tip:perf/core] " tip-bot for Thomas Gleixner
2016-03-21 15:01 ` Peter Zijlstra [this message]
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=20160321150127.GY6344@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@suse.de \
--cc=eranian@google.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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