]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0048-x86-tracing-Introduce-a-static-key-for-exception-tra.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0048-x86-tracing-Introduce-a-static-key-for-exception-tra.patch
CommitLineData
321d628a
FG
1From 179faefa769caa263bc88b1f7292be7a60df4298 Mon Sep 17 00:00:00 2001
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Mon, 28 Aug 2017 08:47:21 +0200
e4cdf2a5 4Subject: [PATCH 048/241] x86/tracing: Introduce a static key for exception
321d628a
FG
5 tracing
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10CVE-2017-5754
11
12Switching the IDT just for avoiding tracepoints creates a completely
13impenetrable macro/inline/ifdef mess.
14
15There is no point in avoiding tracepoints for most of the traps/exceptions.
16For the more expensive tracepoints, like pagefaults, this can be handled with
17an explicit static key.
18
19Preparatory patch to remove the tracing IDT.
20
21Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
22Cc: Andy Lutomirski <luto@kernel.org>
23Cc: Borislav Petkov <bp@alien8.de>
24Cc: Linus Torvalds <torvalds@linux-foundation.org>
25Cc: Peter Zijlstra <peterz@infradead.org>
26Cc: Steven Rostedt <rostedt@goodmis.org>
27Link: http://lkml.kernel.org/r/20170828064956.593094539@linutronix.de
28Signed-off-by: Ingo Molnar <mingo@kernel.org>
29(cherry picked from commit 2feb1b316d48004d905278c02a55902cab0be8be)
30Signed-off-by: Andy Whitcroft <apw@kathleen.maas>
31(cherry picked from commit 15e0ff2a63fdd93f8881e2ebba5c048c5b601e57)
32Signed-off-by: Andy Whitcroft <apw@canonical.com>
33Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
34(cherry picked from commit d58a56e851c339d8d9d311dc9b4fad6abbf8bf19)
35Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
36---
37 arch/x86/include/asm/trace/common.h | 15 +++++++++++++++
38 arch/x86/include/asm/trace/exceptions.h | 4 +---
39 arch/x86/include/asm/trace/irq_vectors.h | 4 +---
40 arch/x86/kernel/tracepoint.c | 9 ++++++++-
41 4 files changed, 25 insertions(+), 7 deletions(-)
42 create mode 100644 arch/x86/include/asm/trace/common.h
43
44diff --git a/arch/x86/include/asm/trace/common.h b/arch/x86/include/asm/trace/common.h
45new file mode 100644
46index 000000000000..b1eb7b18ee8a
47--- /dev/null
48+++ b/arch/x86/include/asm/trace/common.h
49@@ -0,0 +1,15 @@
50+#ifndef _ASM_TRACE_COMMON_H
51+#define _ASM_TRACE_COMMON_H
52+
53+extern int trace_irq_vector_regfunc(void);
54+extern void trace_irq_vector_unregfunc(void);
55+
56+#ifdef CONFIG_TRACING
57+DECLARE_STATIC_KEY_FALSE(trace_irqvectors_key);
58+#define trace_irqvectors_enabled() \
59+ static_branch_unlikely(&trace_irqvectors_key)
60+#else
61+static inline bool trace_irqvectors_enabled(void) { return false; }
62+#endif
63+
64+#endif
65diff --git a/arch/x86/include/asm/trace/exceptions.h b/arch/x86/include/asm/trace/exceptions.h
66index 2422b14c50a7..960a5b50ac3b 100644
67--- a/arch/x86/include/asm/trace/exceptions.h
68+++ b/arch/x86/include/asm/trace/exceptions.h
69@@ -5,9 +5,7 @@
70 #define _TRACE_PAGE_FAULT_H
71
72 #include <linux/tracepoint.h>
73-
74-extern int trace_irq_vector_regfunc(void);
75-extern void trace_irq_vector_unregfunc(void);
76+#include <asm/trace/common.h>
77
78 DECLARE_EVENT_CLASS(x86_exceptions,
79
80diff --git a/arch/x86/include/asm/trace/irq_vectors.h b/arch/x86/include/asm/trace/irq_vectors.h
81index 32dd6a9e343c..7825b4426e7e 100644
82--- a/arch/x86/include/asm/trace/irq_vectors.h
83+++ b/arch/x86/include/asm/trace/irq_vectors.h
84@@ -5,9 +5,7 @@
85 #define _TRACE_IRQ_VECTORS_H
86
87 #include <linux/tracepoint.h>
88-
89-extern int trace_irq_vector_regfunc(void);
90-extern void trace_irq_vector_unregfunc(void);
91+#include <asm/trace/common.h>
92
93 DECLARE_EVENT_CLASS(x86_irq_vector,
94
95diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
96index 15515132bf0d..dd4aa04bb95c 100644
97--- a/arch/x86/kernel/tracepoint.c
98+++ b/arch/x86/kernel/tracepoint.c
99@@ -4,9 +4,11 @@
100 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
101 *
102 */
103+#include <linux/jump_label.h>
104+#include <linux/atomic.h>
105+
106 #include <asm/hw_irq.h>
107 #include <asm/desc.h>
108-#include <linux/atomic.h>
109
110 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
111 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
112@@ -15,6 +17,7 @@ struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
113 /* No need to be aligned, but done to keep all IDTs defined the same way. */
114 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
115
116+DEFINE_STATIC_KEY_FALSE(trace_irqvectors_key);
117 static int trace_irq_vector_refcount;
118 static DEFINE_MUTEX(irq_vector_mutex);
119
120@@ -36,6 +39,8 @@ static void switch_idt(void *arg)
121
122 int trace_irq_vector_regfunc(void)
123 {
124+ static_branch_inc(&trace_irqvectors_key);
125+
126 mutex_lock(&irq_vector_mutex);
127 if (!trace_irq_vector_refcount) {
128 set_trace_idt_ctr(1);
129@@ -49,6 +54,8 @@ int trace_irq_vector_regfunc(void)
130
131 void trace_irq_vector_unregfunc(void)
132 {
133+ static_branch_dec(&trace_irqvectors_key);
134+
135 mutex_lock(&irq_vector_mutex);
136 trace_irq_vector_refcount--;
137 if (!trace_irq_vector_refcount) {
138--
1392.14.2
140