Re: [RFC PATCH 5/6] perf: Fix race in callchains

From: Frederic Weisbecker
Date: Thu Jul 01 2010 - 11:42:40 EST


On Thu, Jul 01, 2010 at 05:36:01PM +0200, Frederic Weisbecker wrote:
> +static struct perf_callchain_entry *get_callchain_entry(int *rctx)
> +{
> + struct perf_callchain_entry_cpus *cpu_entries;
> +
> + *rctx = get_recursion_context(&__get_cpu_var(callchain_recursion));
> + if (*rctx == -1)
> + return NULL;
> +
> + cpu_entries = rcu_dereference(callchain_entries[*rctx]);
> + if (!cpu_entries)
> + return NULL;
> +
> + return this_cpu_ptr(cpu_entries->entries);
> +}
> +
> +static void
> +put_callchain_entry(int rctx)
> +{
> + put_recursion_context(&__get_cpu_var(callchain_recursion), rctx);
> +}
> +
> +static struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
> +{
> + int rctx;
> + struct perf_callchain_entry *entry;
> +
> +
> + entry = get_callchain_entry(&rctx);
> + if (!entry)
> + goto exit_put;


I realize this should only call put_callchain_entry() if rctx == -1, but you
got the idea...



> +
> + entry->nr = 0;
> +
> + if (!user_mode(regs)) {
> + perf_callchain_store(entry, PERF_CONTEXT_KERNEL);
> + perf_callchain_kernel(entry, regs);
> + if (current->mm)
> + regs = task_pt_regs(current);
> + else
> + regs = NULL;
> + }
> +
> + if (regs) {
> + perf_callchain_store(entry, PERF_CONTEXT_USER);
> + perf_callchain_user(entry, regs);
> + }
> +
> +exit_put:
> + put_callchain_entry(rctx);
> +
> + return entry;
> +}

--
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/