Re: [PATCH] perf_events: fix validate_event bug

From: stephane eranian
Date: Tue Nov 24 2009 - 08:18:16 EST


On Mon, Nov 23, 2009 at 2:45 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> On Mon, 2009-11-23 at 14:34 +0100, stephane eranian wrote:
>
>> > Won't this give very funny results for mixed pmu groups?
>> >
>>
>> What do you mean by 'mixed pmu groups'?
>
> We currently have a number of struct pmu objects:
>
> Âperf_ops_generic
> Âperf_ops_cpu_clock
> Âperf_ops_task_clock
>
> which are all software based PMUs, and one of:
>
> Âpmu    Â(arch/x86/kernel/cpu/perf_event.c)
> Âpower_pmu Â(arch/powerpc/kernel/perf_event.c)
>
> To represent the hardware PMU.
>
> Now say you mix software events and hardware events into a single group,
> the loop in validate_group:
>
> Âlist_for_each_entry(sibling, &leader->sibling_list, group_entry) {
> Â Â Â Âif (!validate_event(&fake_pmu, sibling))
> Â Â Â Â Â Â Â Â Â Â Â Âreturn -ENOSPC;
> Â}
>
> could pass a !hardware event into validate_event(), which currently
> ignores it because event->pmu won't be &pmu, however if you remove that
> check, it'll try and call x86 routines on a software event, which is
> bound to go funny.
>
Ok, so it seems the only valid test to check if the event is related to the
HW PMU is to compare event->pmu with pmu (arch/x86/.../perf_event.c).

In that case you first suggestion is fine.

> Now Frederic is going to make things more interesting by representing HW
> breakpoints as another HW PMU (the distinction between hw/sw pmu is in
> scheduling, you can always schedule a software event).
>
> This weakens the !is_software_event(), in that !software doesn't tell
> you which hardware event it is -- something which needs mending in your
> more complex x86 constraints scheduling patch.
>
That means we can drop is_software_event() in this code and instead
define locally
in x86 a is_hw_pmu_event() function as event->pmu == &pmu.
--
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/