• Peter Zijlstra's avatar
    perf/x86: Fix perf,x86,cpuhp deadlock · efe951d3
    Peter Zijlstra authored
    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: default avatarPeter 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: default avatarIngo Molnar <mingo@kernel.org>
    efe951d3
ds.c 42.5 KB