aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-10-24 18:58:13 -0400
committerIngo Molnar <mingo@kernel.org>2015-02-04 06:10:49 -0500
commita66734297f78707ce39d756b656bfae861d53f62 (patch)
treec58ac7f3a43522fd5f40527ee69eb0057cce41b0 /arch/x86/kernel
parent7911d3f7af14a614617e38245fedf98a724e46a9 (diff)
perf/x86: Add /sys/devices/cpu/rdpmc=2 to allow rdpmc for all tasks
While perfmon2 is a sufficiently evil library (it pokes MSRs directly) that breaking it is fair game, it's still useful, so we might as well try to support it. This allows users to write 2 to /sys/devices/cpu/rdpmc to disable all rdpmc protection so that hack like perfmon2 can continue to work. At some point, if perf_event becomes fast enough to replace perfmon2, then this can go. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Vince Weaver <vince@deater.net> Cc: "hillf.zj" <hillf.zj@alibaba-inc.com> Cc: Valdis Kletnieks <Valdis.Kletnieks@vt.edu> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/caac3c1c707dcca48ecbc35f4def21495856f479.1414190806.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r--arch/x86/kernel/cpu/perf_event.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index bec5cff7dc80..b71a7f86d68a 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -45,6 +45,8 @@ DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
45 .enabled = 1, 45 .enabled = 1,
46}; 46};
47 47
48struct static_key rdpmc_always_available = STATIC_KEY_INIT_FALSE;
49
48u64 __read_mostly hw_cache_event_ids 50u64 __read_mostly hw_cache_event_ids
49 [PERF_COUNT_HW_CACHE_MAX] 51 [PERF_COUNT_HW_CACHE_MAX]
50 [PERF_COUNT_HW_CACHE_OP_MAX] 52 [PERF_COUNT_HW_CACHE_OP_MAX]
@@ -1870,10 +1872,27 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
1870 if (ret) 1872 if (ret)
1871 return ret; 1873 return ret;
1872 1874
1875 if (val > 2)
1876 return -EINVAL;
1877
1873 if (x86_pmu.attr_rdpmc_broken) 1878 if (x86_pmu.attr_rdpmc_broken)
1874 return -ENOTSUPP; 1879 return -ENOTSUPP;
1875 1880
1876 x86_pmu.attr_rdpmc = !!val; 1881 if ((val == 2) != (x86_pmu.attr_rdpmc == 2)) {
1882 /*
1883 * Changing into or out of always available, aka
1884 * perf-event-bypassing mode. This path is extremely slow,
1885 * but only root can trigger it, so it's okay.
1886 */
1887 if (val == 2)
1888 static_key_slow_inc(&rdpmc_always_available);
1889 else
1890 static_key_slow_dec(&rdpmc_always_available);
1891 on_each_cpu(refresh_pce, NULL, 1);
1892 }
1893
1894 x86_pmu.attr_rdpmc = val;
1895
1877 return count; 1896 return count;
1878} 1897}
1879 1898