aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/include/asm/mmu_context.h5
-rw-r--r--arch/x86/kernel/cpu/perf_event.c21
2 files changed, 24 insertions, 2 deletions
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index 89c1fece224e..883f6b933fa4 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -19,9 +19,12 @@ static inline void paravirt_activate_mm(struct mm_struct *prev,
19#endif /* !CONFIG_PARAVIRT */ 19#endif /* !CONFIG_PARAVIRT */
20 20
21#ifdef CONFIG_PERF_EVENTS 21#ifdef CONFIG_PERF_EVENTS
22extern struct static_key rdpmc_always_available;
23
22static inline void load_mm_cr4(struct mm_struct *mm) 24static inline void load_mm_cr4(struct mm_struct *mm)
23{ 25{
24 if (atomic_read(&mm->context.perf_rdpmc_allowed)) 26 if (static_key_true(&rdpmc_always_available) ||
27 atomic_read(&mm->context.perf_rdpmc_allowed))
25 cr4_set_bits(X86_CR4_PCE); 28 cr4_set_bits(X86_CR4_PCE);
26 else 29 else
27 cr4_clear_bits(X86_CR4_PCE); 30 cr4_clear_bits(X86_CR4_PCE);
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