Re: [PATCH] perf_events: fix validate_event bug

From: stephane eranian
Date: Mon Nov 23 2009 - 08:34:12 EST


Hi,

Sorry for the delay,

On Wed, Nov 18, 2009 at 5:46 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> 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?)
>
Yes.

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

What do you mean by '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@xxxxxxxxx>
>> --
>> Â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)
>
>
>
--
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/