Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9f97721 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

perf/core: Fix perf_pmu_unregister() locking



When we unregister a PMU, we fail to serialize the @pmu_idr properly.
Fix that by doing the entire thing under pmu_lock.

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>
Fixes: 2e80a82a ("perf: Dynamic pmu types")
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 291d0e5d
Loading
Loading
Loading
Loading
+2 −7
Original line number Original line Diff line number Diff line
@@ -9431,9 +9431,7 @@ static void free_pmu_context(struct pmu *pmu)
	if (pmu->task_ctx_nr > perf_invalid_context)
	if (pmu->task_ctx_nr > perf_invalid_context)
		return;
		return;


	mutex_lock(&pmus_lock);
	free_percpu(pmu->pmu_cpu_context);
	free_percpu(pmu->pmu_cpu_context);
	mutex_unlock(&pmus_lock);
}
}


/*
/*
@@ -9689,12 +9687,8 @@ EXPORT_SYMBOL_GPL(perf_pmu_register);


void perf_pmu_unregister(struct pmu *pmu)
void perf_pmu_unregister(struct pmu *pmu)
{
{
	int remove_device;

	mutex_lock(&pmus_lock);
	mutex_lock(&pmus_lock);
	remove_device = pmu_bus_running;
	list_del_rcu(&pmu->entry);
	list_del_rcu(&pmu->entry);
	mutex_unlock(&pmus_lock);


	/*
	/*
	 * We dereference the pmu list under both SRCU and regular RCU, so
	 * We dereference the pmu list under both SRCU and regular RCU, so
@@ -9706,13 +9700,14 @@ void perf_pmu_unregister(struct pmu *pmu)
	free_percpu(pmu->pmu_disable_count);
	free_percpu(pmu->pmu_disable_count);
	if (pmu->type >= PERF_TYPE_MAX)
	if (pmu->type >= PERF_TYPE_MAX)
		idr_remove(&pmu_idr, pmu->type);
		idr_remove(&pmu_idr, pmu->type);
	if (remove_device) {
	if (pmu_bus_running) {
		if (pmu->nr_addr_filters)
		if (pmu->nr_addr_filters)
			device_remove_file(pmu->dev, &dev_attr_nr_addr_filters);
			device_remove_file(pmu->dev, &dev_attr_nr_addr_filters);
		device_del(pmu->dev);
		device_del(pmu->dev);
		put_device(pmu->dev);
		put_device(pmu->dev);
	}
	}
	free_pmu_context(pmu);
	free_pmu_context(pmu);
	mutex_unlock(&pmus_lock);
}
}
EXPORT_SYMBOL_GPL(perf_pmu_unregister);
EXPORT_SYMBOL_GPL(perf_pmu_unregister);