Commit 547e9fd7 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf: Annotate cpuctx->ctx.mutex to avoid a lockdep splat

Lockdep spotted:

	loop_1b_instruc/1899 is trying to acquire lock:
	 (event_mutex){+.+.+.}, at: [<ffffffff810e1908>] perf_trace_init+0x3b/0x2f7

	but task is already holding lock:
	 (&ctx->mutex){+.+.+.}, at: [<ffffffff810eb45b>] perf_event_init_context+0xc0/0x218

	which lock already depends on the new lock.

	the existing dependency chain (in reverse order) is:

	-> #3 (&ctx->mutex){+.+.+.}:
	-> #2 (cpu_hotplug.lock){+.+.+.}:
	-> #1 (module_mutex){+.+...}:
	-> #0 (event_mutex){+.+.+.}:

But because the deadlock would be cpuhotplug (cpu-event) vs fork
(task-event) it cannot, in fact, happen. We can annotate this by giving the
perf_event_context used for the cpuctx a different lock class from those
used by tasks.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 8c8a9b25
...@@ -5380,6 +5380,8 @@ static int pmu_dev_alloc(struct pmu *pmu) ...@@ -5380,6 +5380,8 @@ static int pmu_dev_alloc(struct pmu *pmu)
goto out; goto out;
} }
static struct lock_class_key cpuctx_mutex;
int perf_pmu_register(struct pmu *pmu, char *name, int type) int perf_pmu_register(struct pmu *pmu, char *name, int type)
{ {
int cpu, ret; int cpu, ret;
...@@ -5428,6 +5430,7 @@ int perf_pmu_register(struct pmu *pmu, char *name, int type) ...@@ -5428,6 +5430,7 @@ int perf_pmu_register(struct pmu *pmu, char *name, int type)
cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu); cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
__perf_event_init_context(&cpuctx->ctx); __perf_event_init_context(&cpuctx->ctx);
lockdep_set_class(&cpuctx->ctx.mutex, &cpuctx_mutex);
cpuctx->ctx.type = cpu_context; cpuctx->ctx.type = cpu_context;
cpuctx->ctx.pmu = pmu; cpuctx->ctx.pmu = pmu;
cpuctx->jiffies_interval = 1; cpuctx->jiffies_interval = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment