perf/x86: Fix offcore_rsp valid mask for SNB/IVB

The valid mask for both offcore_response_0 and
offcore_response_1 was wrong for SNB/SNB-EP,
IVB/IVB-EP. It was possible to write to
reserved bit and cause a GP fault crashing
the kernel.

This patch fixes the problem by correctly marking the
reserved bits in the valid mask for all the processors
mentioned above.

A distinction between desktop and server parts is introduced
because bits 24-30 are only available on the server parts.

This version of the patch is just a rebase to perf/urgent tree
and should apply to older kernels as well.

Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: peterz@infradead.org
Cc: jolsa@redhat.com
Cc: gregkh@linuxfoundation.org
Cc: security@kernel.org
Cc: ak@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by Stephane Eranian and committed by Ingo Molnar f1923820 8176cced

Changed files
+16 -4
arch
x86
kernel
+16 -4
arch/x86/kernel/cpu/perf_event_intel.c
··· 153 153 }; 154 154 155 155 static struct extra_reg intel_snb_extra_regs[] __read_mostly = { 156 - INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0x3fffffffffull, RSP_0), 157 - INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0x3fffffffffull, RSP_1), 156 + INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0x3f807f8fffull, RSP_0), 157 + INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0x3f807f8fffull, RSP_1), 158 + EVENT_EXTRA_END 159 + }; 160 + 161 + static struct extra_reg intel_snbep_extra_regs[] __read_mostly = { 162 + INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0x3fffff8fffull, RSP_0), 163 + INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0x3fffff8fffull, RSP_1), 158 164 EVENT_EXTRA_END 159 165 }; 160 166 ··· 2103 2097 x86_pmu.event_constraints = intel_snb_event_constraints; 2104 2098 x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints; 2105 2099 x86_pmu.pebs_aliases = intel_pebs_aliases_snb; 2106 - x86_pmu.extra_regs = intel_snb_extra_regs; 2100 + if (boot_cpu_data.x86_model == 45) 2101 + x86_pmu.extra_regs = intel_snbep_extra_regs; 2102 + else 2103 + x86_pmu.extra_regs = intel_snb_extra_regs; 2107 2104 /* all extra regs are per-cpu when HT is on */ 2108 2105 x86_pmu.er_flags |= ERF_HAS_RSP_1; 2109 2106 x86_pmu.er_flags |= ERF_NO_HT_SHARING; ··· 2132 2123 x86_pmu.event_constraints = intel_ivb_event_constraints; 2133 2124 x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints; 2134 2125 x86_pmu.pebs_aliases = intel_pebs_aliases_snb; 2135 - x86_pmu.extra_regs = intel_snb_extra_regs; 2126 + if (boot_cpu_data.x86_model == 62) 2127 + x86_pmu.extra_regs = intel_snbep_extra_regs; 2128 + else 2129 + x86_pmu.extra_regs = intel_snb_extra_regs; 2136 2130 /* all extra regs are per-cpu when HT is on */ 2137 2131 x86_pmu.er_flags |= ERF_HAS_RSP_1; 2138 2132 x86_pmu.er_flags |= ERF_NO_HT_SHARING;