Re: [perf] enable raw OFFCORE_EVENTS for non-perf userspace
From: Vince Weaver
Date: Wed Aug 03 2011 - 13:00:25 EST
and in case we don't want to be nice to userspace and want to brutally
suppress anyone not using the "perf" tool, here's a patch that
returns EINVAL for any raw access that sets config1.
I actually tested to make sure the patch doesn't break PAPI, unlike my
last attempt.
Currently we "block" access to setting the config1 value from userspace
by silently failing. This can cause unexpected behavior (especially if
the kernel is using the OFFCORE_RSP_0 msr internally) and also makes it
impossible to test if OFFCORE_RESPONSE events are being blocked or not.
This hackish patch causes an EINVAL to propogate back to userspace
by setting an invalid value to the config1 field.
I personally think this patch is a step backward, and the right thing to
do is give users full access to their own hardware. But the current state
of affairs is bad for tools like PAPI too.
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 4ee3abf..72baf25 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -608,8 +608,11 @@ static int x86_setup_perfctr(struct perf_event *event)
* Do not allow config1 (extended registers) to propagate,
* there's no sane user-space generalization yet:
*/
- if (attr->type == PERF_TYPE_RAW)
- return 0;
+ if (attr->type == PERF_TYPE_RAW) {
+ /* I HATE THIS PATCH AND EVERYTHING IT STANDS FOR. -- VMW */
+ event->attr.config1=0xffffffff; /* invalid, will be caught */
+ return x86_pmu_extra_regs(event->attr.config, event);
+ }
if (attr->type == PERF_TYPE_HW_CACHE)
return set_ext_hw_attr(hwc, event);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/