From ce1c5147fcfac7fb6fe96faaa76f3f46174b9709 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 12 May 2017 12:45:25 +0100 Subject: [PATCH] perf/core: Avoid removing shared pmu_context on unregister In commit 1fd7e4169954 ("perf/core: Remove perf_cpu_context::unique_pmu"), the search for another user of the pmu_cpu_context was removed, and so we unconditionally free it during perf_pmu_unregister. This leads to random corruption later and a BUG at mm/percpu.c:689. v2: Check for shared pmu_contexts under the mutex. Fixes: 1fd7e4169954 ("perf/core: Remove perf_cpu_context::unique_pmu") Signed-off-by: Chris Wilson Cc: David Carrillo-Cisneros Cc: Peter Zijlstra (Intel) Cc: Ingo Molnar Cc: # v4.11+ Link: http://patchwork.freedesktop.org/patch/msgid/20170512114525.17575-1-chris@chris-wilson.co.uk --- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 3cd13a30f73292..bac38d972bb2ee 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9737,7 +9737,8 @@ void perf_pmu_unregister(struct pmu *pmu) device_del(pmu->dev); put_device(pmu->dev); } - free_pmu_context(pmu); + if (!find_pmu_context(pmu->task_ctx_nr)) + free_pmu_context(pmu); mutex_unlock(&pmus_lock); } EXPORT_SYMBOL_GPL(perf_pmu_unregister);