perf, x86, uncore: Fix minor race in box set up
Subsystems (2)
PATCH 1/1 perf, x86, uncore: Fix minor race in box set up
From: Andi Kleen <[email protected]>
I was looking for the trinity oops cause in the uncore driver. (so far didn't found it)
However I found this tiny race: when a box is set up two threads on the same CPU, they may be setting up the box in parallel (e.g. with kernel preemption). This could lead to the reference count being increasing too much. Always recheck there is no existing cpu reference inside the lock.
--- arch/x86/kernel/cpu/perf_event_intel_uncore.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_uncore.c +4 -0
@@ -42,6 +42,9 @@ struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpureturn box;raw_spin_lock (&uncore_box_lock); +/* Recheck in lock to handle races. */ +if (*per_cpu_ptr (pmu->box, cpu)) + goto out;list_for_each_entry (box, &pmu->box_list, list) {if (box->phys_id ==topology_physical_package_id (cpu)) {atomic_inc (&box->refcnt);
@@ -49,6 +52,7 @@ struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpubreak ; } } +out:raw_spin_unlock (&uncore_box_lock);return *per_cpu_ptr (pmu->box, cpu);
Signature · 1 line
1.9.3
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf/x86/intel/uncore: Fix minor race in box set up
perf/x86/intel/uncore: Fix minor race in box set up
Commit-ID: 4f971248bc6ad2bb2a89a25a072ebfec5757d298 Gitweb: http://git.kernel.org/tip/4f971248bc6ad2bb2a89a25a072ebfec5757d298 Author: Andi Kleen <[email protected]> AuthorDate: Mon, 22 Sep 2014 15:27:06 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 3 Oct 2014 06:02:49 +0200
perf/x86/intel/uncore: Fix minor race in box set up
I was looking for the trinity oops cause in the uncore driver. (so far didn't found it)
However I found this tiny race: when a box is set up two threads on the same CPU, they may be setting up the box in parallel (e.g. with kernel preemption). This could lead to the reference count being increasing too much. Always recheck there is no existing cpu reference inside the lock.
--- arch/x86/kernel/cpu/perf_event_intel_uncore.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_uncore.c +4 -0
@@ -42,6 +42,9 @@ struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpureturn box;raw_spin_lock (&uncore_box_lock); +/* Recheck in lock to handle races. */ +if (*per_cpu_ptr (pmu->box, cpu)) + goto out;list_for_each_entry (box, &pmu->box_list, list) {if (box->phys_id ==topology_physical_package_id (cpu)) {atomic_inc (&box->refcnt);
@@ -49,6 +52,7 @@ struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpubreak ; } } +out:raw_spin_unlock (&uncore_box_lock);return *per_cpu_ptr (pmu->box, cpu);