]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - arch/powerpc/perf/core-book3s.c
powerpc/perf: Fix crashes with generic_compat_pmu & BHRB
[mirror_ubuntu-hirsute-kernel.git] / arch / powerpc / perf / core-book3s.c
index 93d20e1ed845148391a0a891877c5883707227c8..08643cba1494822f7585906c3b3b39aab4cb1a90 100644 (file)
@@ -1557,9 +1557,16 @@ nocheck:
        ret = 0;
  out:
        if (has_branch_stack(event)) {
-               power_pmu_bhrb_enable(event);
-               cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
-                                       event->attr.branch_sample_type);
+               u64 bhrb_filter = -1;
+
+               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);
@@ -1881,7 +1888,6 @@ static int power_pmu_event_init(struct perf_event *event)
        int n;
        int err;
        struct cpu_hw_events *cpuhw;
-       u64 bhrb_filter;
 
        if (!ppmu)
                return -ENOENT;
@@ -1987,7 +1993,10 @@ static int power_pmu_event_init(struct perf_event *event)
        err = power_check_constraints(cpuhw, events, cflags, n + 1);
 
        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);
 
                if (bhrb_filter == -1) {