]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.19/powerpc-perf-fix-mmcra-corruption-by-bhrb_filter.patch
fixes for 4.19
[thirdparty/kernel/stable-queue.git] / queue-4.19 / powerpc-perf-fix-mmcra-corruption-by-bhrb_filter.patch
CommitLineData
c0a62f2b
GKH
1From 3202e35ec1c8fc19cea24253ff83edf702a60a02 Mon Sep 17 00:00:00 2001
2From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
3Date: Sat, 11 May 2019 08:12:17 +0530
4Subject: powerpc/perf: Fix MMCRA corruption by bhrb_filter
5
6From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
7
8commit 3202e35ec1c8fc19cea24253ff83edf702a60a02 upstream.
9
10Consider a scenario where user creates two events:
11
12 1st event:
13 attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
14 attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY;
15 fd = perf_event_open(attr, 0, 1, -1, 0);
16
17 This sets cpuhw->bhrb_filter to 0 and returns valid fd.
18
19 2nd event:
20 attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
21 attr.branch_sample_type = PERF_SAMPLE_BRANCH_CALL;
22 fd = perf_event_open(attr, 0, 1, -1, 0);
23
24 It overrides cpuhw->bhrb_filter to -1 and returns with error.
25
26Now if power_pmu_enable() gets called by any path other than
27power_pmu_add(), ppmu->config_bhrb(-1) will set MMCRA to -1.
28
29Fixes: 3925f46bb590 ("powerpc/perf: Enable branch stack sampling framework")
30Cc: stable@vger.kernel.org # v3.10+
31Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
32Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
33Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
34Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36---
37 arch/powerpc/perf/core-book3s.c | 6 ++++--
38 arch/powerpc/perf/power8-pmu.c | 3 +++
39 arch/powerpc/perf/power9-pmu.c | 3 +++
40 3 files changed, 10 insertions(+), 2 deletions(-)
41
42--- a/arch/powerpc/perf/core-book3s.c
43+++ b/arch/powerpc/perf/core-book3s.c
44@@ -1827,6 +1827,7 @@ static int power_pmu_event_init(struct p
45 int n;
46 int err;
47 struct cpu_hw_events *cpuhw;
48+ u64 bhrb_filter;
49
50 if (!ppmu)
51 return -ENOENT;
52@@ -1932,13 +1933,14 @@ static int power_pmu_event_init(struct p
53 err = power_check_constraints(cpuhw, events, cflags, n + 1);
54
55 if (has_branch_stack(event)) {
56- cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
57+ bhrb_filter = ppmu->bhrb_filter_map(
58 event->attr.branch_sample_type);
59
60- if (cpuhw->bhrb_filter == -1) {
61+ if (bhrb_filter == -1) {
62 put_cpu_var(cpu_hw_events);
63 return -EOPNOTSUPP;
64 }
65+ cpuhw->bhrb_filter = bhrb_filter;
66 }
67
68 put_cpu_var(cpu_hw_events);
69--- a/arch/powerpc/perf/power8-pmu.c
70+++ b/arch/powerpc/perf/power8-pmu.c
71@@ -29,6 +29,7 @@ enum {
72 #define POWER8_MMCRA_IFM1 0x0000000040000000UL
73 #define POWER8_MMCRA_IFM2 0x0000000080000000UL
74 #define POWER8_MMCRA_IFM3 0x00000000C0000000UL
75+#define POWER8_MMCRA_BHRB_MASK 0x00000000C0000000UL
76
77 /*
78 * Raw event encoding for PowerISA v2.07 (Power8):
79@@ -243,6 +244,8 @@ static u64 power8_bhrb_filter_map(u64 br
80
81 static void power8_config_bhrb(u64 pmu_bhrb_filter)
82 {
83+ pmu_bhrb_filter &= POWER8_MMCRA_BHRB_MASK;
84+
85 /* Enable BHRB filter in PMU */
86 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
87 }
88--- a/arch/powerpc/perf/power9-pmu.c
89+++ b/arch/powerpc/perf/power9-pmu.c
90@@ -100,6 +100,7 @@ enum {
91 #define POWER9_MMCRA_IFM1 0x0000000040000000UL
92 #define POWER9_MMCRA_IFM2 0x0000000080000000UL
93 #define POWER9_MMCRA_IFM3 0x00000000C0000000UL
94+#define POWER9_MMCRA_BHRB_MASK 0x00000000C0000000UL
95
96 /* Nasty Power9 specific hack */
97 #define PVR_POWER9_CUMULUS 0x00002000
98@@ -308,6 +309,8 @@ static u64 power9_bhrb_filter_map(u64 br
99
100 static void power9_config_bhrb(u64 pmu_bhrb_filter)
101 {
102+ pmu_bhrb_filter &= POWER9_MMCRA_BHRB_MASK;
103+
104 /* Enable BHRB filter in PMU */
105 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
106 }