public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@googlemail.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, paulus@samba.org,
	perfmon2-devel@lists.sf.net, Stephane Eranian <eranian@gmail.com>
Subject: Re: [PATCH] perf_events: fix validate_event bug
Date: Wed, 18 Nov 2009 17:46:25 +0100	[thread overview]
Message-ID: <1258562785.3918.685.camel@laptop> (raw)
In-Reply-To: <1256223091-6002-1-git-send-email-eranian@gmail.com>

On Thu, 2009-10-22 at 16:51 +0200, Stephane Eranian wrote:
> 	The validate_event() was failing on valid event
> 	combinations. The function was assuming that if
> 	x86_schedule_event() returned 0, it meant error.
> 	But x86_schedule_event() returns the counter index
> 	and 0 is a perfectly valid value. An error is returned
> 	if the function returns a negative value.

Good point.

> 	Furthermore, validate_event() was also failing for
> 	event groups because the event->pmu was not set until
> 	after hw_perf_pmu_init().

(hw_perf_event_init, right?)

Won't this give very funny results for mixed pmu groups?

How about something like:

 if (event->pmu && event->pmu != &pmu)
	return 0;

That should deal with new events, who do not yet have their pmu set and
for those we know they're for us, but exclude events for other PMUs.

> 	Signed-off-by: Stephane Eranian <eranian@gmail.com>
> --
>  arch/x86/kernel/cpu/perf_event.c |    5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
> index 2e20bca..d321ff7 100644
> --- a/arch/x86/kernel/cpu/perf_event.c
> +++ b/arch/x86/kernel/cpu/perf_event.c
> @@ -2229,10 +2229,7 @@ validate_event(struct cpu_hw_events *cpuc, struct perf_event *event)
>  {
>  	struct hw_perf_event fake_event = event->hw;
>  
> -	if (event->pmu != &pmu)
> -		return 0;
> -
> -	return x86_schedule_event(cpuc, &fake_event);
> +	return x86_schedule_event(cpuc, &fake_event) >= 0;
>  }
>  
>  static int validate_group(struct perf_event *event)



  reply	other threads:[~2009-11-18 16:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-22 14:51 [PATCH] perf_events: fix validate_event bug Stephane Eranian
2009-11-18 16:46 ` Peter Zijlstra [this message]
2009-11-23 13:34   ` stephane eranian
2009-11-23 13:45     ` Peter Zijlstra
2009-11-24 13:18       ` stephane eranian
2009-11-24 22:00         ` Paul Mackerras
2009-11-25  5:47           ` stephane eranian
2009-11-25  7:55             ` Peter Zijlstra
2009-11-24 13:27 ` Stephane Eranian
2009-11-24 19:03   ` [tip:perf/core] perf_events, x86: Fix " tip-bot for Stephane Eranian

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=1258562785.3918.685.camel@laptop \
    --to=peterz@infradead.org \
    --cc=eranian@gmail.com \
    --cc=eranian@googlemail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=perfmon2-devel@lists.sf.net \
    /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