msm: perf: Do not allocate new hw_event if event is duplicate.

During a perf_event_enable, kernel/events/core.c calls pmu->add() which
is platform implementation(arch/arm/kernel/perf_event.c). Due to the
duplicate constraints, arch/arm/mach-msm/perf_event_msm_krait_l2.c
drivers marks the event as OFF but returns TRUE to perf_event.c which
goes ahead and allocates the hw_event and enables it.
Since event is marked OFF, kernel events core will try to enable this event
again during next perf_event_enable. Which results in same event enabled
on multiple hw_events. But during the perf_release, event struct is freed
and only one hw_event is released. This results in dereferencing the
invalid pointer and hence the crash.
Fix this by returning error in case of constraint event duplicate. Hence
avoiding the same event programmed on multiple hw event counters.

Change-Id: Ia3360be027dfe87ac753191ffe7e0bc947e72455
Signed-off-by: Arun KS <arunks@codeaurora.org>
Signed-off-by: Veena Sambasivan <veenas@codeaurora.org>
This commit is contained in:
Veena Sambasivan 2016-05-19 18:47:15 -07:00 committed by Gilad Avidov
parent dc901a50d5
commit 8afa5f8798
3 changed files with 7 additions and 2 deletions

View file

@ -300,6 +300,7 @@ armpmu_add(struct perf_event *event, int flags)
pr_err("Event: %llx failed constraint check.\n",
event->attr.config);
event->state = PERF_EVENT_STATE_OFF;
err = -EPERM;
goto out;
}

View file

@ -503,8 +503,10 @@ static int msm_l2_test_set_ev_constraint(struct perf_event *event)
* This sets the event OFF on all but one
* CPU.
*/
if (!(event->cpu < 0))
if (!(event->cpu < 0)) {
event->state = PERF_EVENT_STATE_OFF;
err = -EPERM;
}
}
out:
raw_spin_unlock_irqrestore(&l2_pmu_constraints.lock, flags);

View file

@ -836,8 +836,10 @@ static int msm_l2_test_set_ev_constraint(struct perf_event *event)
* This sets the event OFF on all but one
* CPU.
*/
if (!(event->cpu < 0))
if (!(event->cpu < 0)) {
event->state = PERF_EVENT_STATE_OFF;
err = -EPERM;
}
}
out: