perf/x86: Fix perf,x86,cpuhp deadlock
authorPeter Zijlstra <peterz@infradead.org>
Wed, 10 Jan 2018 18:23:08 +0000 (19:23 +0100)
committerIngo Molnar <mingo@kernel.org>
Thu, 25 Jan 2018 13:48:30 +0000 (14:48 +0100)
commitefe951d3de9141626a494bcb1efb0650eaef6491
tree700b1669ac70b2fb6ddc854ac931e2cc6c8b0105
parent0c7296cad651a3a40286d70ff37e73bd6fa4e4da
perf/x86: Fix perf,x86,cpuhp deadlock

More lockdep gifts, a 5-way lockup race:

perf_event_create_kernel_counter()
  perf_event_alloc()
    perf_try_init_event()
      x86_pmu_event_init()
__x86_pmu_event_init()
  x86_reserve_hardware()
 #0     mutex_lock(&pmc_reserve_mutex);
    reserve_ds_buffer()
 #1       get_online_cpus()

perf_event_release_kernel()
  _free_event()
    hw_perf_event_destroy()
      x86_release_hardware()
 #0 mutex_lock(&pmc_reserve_mutex)
release_ds_buffer()
 #1   get_online_cpus()

 #1 do_cpu_up()
  perf_event_init_cpu()
 #2     mutex_lock(&pmus_lock)
 #3     mutex_lock(&ctx->mutex)

sys_perf_event_open()
  mutex_lock_double()
 #3     mutex_lock(ctx->mutex)
 #4     mutex_lock_nested(ctx->mutex, 1);

perf_try_init_event()
 #4   mutex_lock_nested(ctx->mutex, 1)
  x86_pmu_event_init()
    intel_pmu_hw_config()
      x86_add_exclusive()
 #0 mutex_lock(&pmc_reserve_mutex)

Fix it by using ordering constructs instead of locking.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/events/intel/ds.c