All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vince Weaver <vweaver1@eecs.utk.edu>
To: <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Subject: Re: [perf] enable raw OFFCORE_EVENTS for non-perf userspace
Date: Wed, 3 Aug 2011 13:00:12 -0400	[thread overview]
Message-ID: <alpine.DEB.2.00.1108031254120.4627@cl320.eecs.utk.edu> (raw)
In-Reply-To: <alpine.DEB.2.00.1108031200390.703@cl320.eecs.utk.edu>


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);


  reply	other threads:[~2011-08-03 17:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 16:05 [perf] enable raw OFFCORE_EVENTS for non-perf userspace Vince Weaver
2011-08-03 17:00 ` Vince Weaver [this message]
2011-08-04 15:55 ` Peter Zijlstra
2011-08-05  2:24   ` Vince Weaver
2011-08-05  9:49   ` Ingo Molnar
2011-11-07 18:30   ` Vince Weaver
2011-11-18 23:34 ` [tip:perf/urgent] perf/x86: Enable raw event access to Intel offcore events tip-bot for Peter Zijlstra
2011-11-21 18:24   ` Vince Weaver
2011-11-21 18:52     ` Peter Zijlstra
2011-11-21 19:01       ` Vince Weaver
2011-11-21 19:04         ` Stephane Eranian
2011-11-21 21:04           ` Vince Weaver
2011-11-21 21:39             ` Stephane Eranian
2011-11-21 21:42               ` Peter Zijlstra
2011-11-21 21:45                 ` Stephane Eranian
2011-11-21 21:48                   ` Peter Zijlstra
2011-11-21 22:05             ` Peter Zijlstra

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=alpine.DEB.2.00.1108031254120.4627@cl320.eecs.utk.edu \
    --to=vweaver1@eecs.utk.edu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.