Skip to content

Commit b460b51

Browse files
aikmpe
authored andcommitted
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: be80e75 ("powerpc/perf: Add generic compat mode pmu driver") Cc: stable@vger.kernel.org # v5.2+ Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Madhavan Srinivasan <maddy@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200602025612.62707-1-aik@ozlabs.ru
1 parent b91eb51 commit b460b51

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

arch/powerpc/perf/core-book3s.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,16 @@ static int power_pmu_add(struct perf_event *event, int ef_flags)
15571557
ret = 0;
15581558
out:
15591559
if (has_branch_stack(event)) {
1560-
power_pmu_bhrb_enable(event);
1561-
cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
1562-
event->attr.branch_sample_type);
1560+
u64 bhrb_filter = -1;
1561+
1562+
if (ppmu->bhrb_filter_map)
1563+
bhrb_filter = ppmu->bhrb_filter_map(
1564+
event->attr.branch_sample_type);
1565+
1566+
if (bhrb_filter != -1) {
1567+
cpuhw->bhrb_filter = bhrb_filter;
1568+
power_pmu_bhrb_enable(event);
1569+
}
15631570
}
15641571

15651572
perf_pmu_enable(event->pmu);
@@ -1881,7 +1888,6 @@ static int power_pmu_event_init(struct perf_event *event)
18811888
int n;
18821889
int err;
18831890
struct cpu_hw_events *cpuhw;
1884-
u64 bhrb_filter;
18851891

18861892
if (!ppmu)
18871893
return -ENOENT;
@@ -1987,7 +1993,10 @@ static int power_pmu_event_init(struct perf_event *event)
19871993
err = power_check_constraints(cpuhw, events, cflags, n + 1);
19881994

19891995
if (has_branch_stack(event)) {
1990-
bhrb_filter = ppmu->bhrb_filter_map(
1996+
u64 bhrb_filter = -1;
1997+
1998+
if (ppmu->bhrb_filter_map)
1999+
bhrb_filter = ppmu->bhrb_filter_map(
19912000
event->attr.branch_sample_type);
19922001

19932002
if (bhrb_filter == -1) {

0 commit comments

Comments
 (0)