Re: [PATCH 2/3] perf_events: fix validation of events using an extrareg (v4)

From: Stephane Eranian
Date: Thu Jun 09 2011 - 16:36:21 EST


On Thu, Jun 9, 2011 at 8:40 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> On Mon, 2011-06-06 at 16:57 +0200, Stephane Eranian wrote:
>> +static struct cpu_hw_events *allocate_fake_cpuc(void)
>> +{
>> + Â Â Â struct cpu_hw_events *cpuc;
>> + Â Â Â int cpu = smp_processor_id();
>
> That's a boo-boo, clearly we are in a preemptible context here (see the
> GFP_KERNEL allocation on the next line), so using smp_processor_id()
> isn't valid.
>
Good point. I missed that.

> Now since all that allocate_shared_regs() does with it is pick a NUMA
> node, we should probably use raw_smp_processor_id() and leave it at
> that, right?
>
Yeah, for what we do with fake_cpuc, it does not really matter where
it comes from. This is not on any critical path. The simplest allocator
will do it.


>> + Â Â Â cpuc = kzalloc(sizeof(*cpuc), GFP_KERNEL);
>> + Â Â Â if (!cpuc)
>> + Â Â Â Â Â Â Â return ERR_PTR(-ENOMEM);
>> +
>> + Â Â Â /* only needed, if we have extra_regs */
>> + Â Â Â if (x86_pmu.extra_regs) {
>> + Â Â Â Â Â Â Â cpuc->shared_regs = allocate_shared_regs(cpu);
>> + Â Â Â Â Â Â Â if (!cpuc->shared_regs)
>> + Â Â Â Â Â Â Â Â Â Â Â goto error;
>> + Â Â Â }
>> + Â Â Â return cpuc;
>> +error:
>> + Â Â Â free_fake_cpuc(cpuc);
>> + Â Â Â return ERR_PTR(-ENOMEM);
>> +}
>
>
--
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/