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