Commit b460b512 authored by Alexey Kardashevskiy's avatar Alexey Kardashevskiy Committed by Michael Ellerman

powerpc/perf: Fix crashes with generic_compat_pmu & BHRB

The bhrb_filter_map ("The Branch History Rolling Buffer") callback is
only defined in raw CPUs' power_pmu structs. The "architected" CPUs
use generic_compat_pmu, which does not have this callback, and crashes
occur if a user tries to enable branch stack for an event.

This add a NULL pointer check for bhrb_filter_map() which behaves as
if the callback returned an error.

This does not add the same check for config_bhrb() as the only caller
checks for cpuhw->bhrb_users which remains zero if bhrb_filter_map==0.

Fixes: be80e758 ("powerpc/perf: Add generic compat mode pmu driver")
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200602025612.62707-1-aik@ozlabs.ru
parent b91eb518
...@@ -1557,9 +1557,16 @@ static int power_pmu_add(struct perf_event *event, int ef_flags) ...@@ -1557,9 +1557,16 @@ static int power_pmu_add(struct perf_event *event, int ef_flags)
ret = 0; ret = 0;
out: out:
if (has_branch_stack(event)) { if (has_branch_stack(event)) {
power_pmu_bhrb_enable(event); u64 bhrb_filter = -1;
cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type); if (ppmu->bhrb_filter_map)
bhrb_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type);
if (bhrb_filter != -1) {
cpuhw->bhrb_filter = bhrb_filter;
power_pmu_bhrb_enable(event);
}
} }
perf_pmu_enable(event->pmu); perf_pmu_enable(event->pmu);
...@@ -1881,7 +1888,6 @@ static int power_pmu_event_init(struct perf_event *event) ...@@ -1881,7 +1888,6 @@ static int power_pmu_event_init(struct perf_event *event)
int n; int n;
int err; int err;
struct cpu_hw_events *cpuhw; struct cpu_hw_events *cpuhw;
u64 bhrb_filter;
if (!ppmu) if (!ppmu)
return -ENOENT; return -ENOENT;
...@@ -1987,7 +1993,10 @@ static int power_pmu_event_init(struct perf_event *event) ...@@ -1987,7 +1993,10 @@ static int power_pmu_event_init(struct perf_event *event)
err = power_check_constraints(cpuhw, events, cflags, n + 1); err = power_check_constraints(cpuhw, events, cflags, n + 1);
if (has_branch_stack(event)) { if (has_branch_stack(event)) {
bhrb_filter = ppmu->bhrb_filter_map( u64 bhrb_filter = -1;
if (ppmu->bhrb_filter_map)
bhrb_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type); event->attr.branch_sample_type);
if (bhrb_filter == -1) { if (bhrb_filter == -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment