]>
Commit | Line | Data |
---|---|---|
59d5af67 | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
321d628a FG |
2 | From: Thomas Gleixner <tglx@linutronix.de> |
3 | Date: Mon, 28 Aug 2017 08:47:21 +0200 | |
59d5af67 | 4 | Subject: [PATCH] x86/tracing: Introduce a static key for exception tracing |
321d628a FG |
5 | MIME-Version: 1.0 |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | CVE-2017-5754 | |
10 | ||
11 | Switching the IDT just for avoiding tracepoints creates a completely | |
12 | impenetrable macro/inline/ifdef mess. | |
13 | ||
14 | There is no point in avoiding tracepoints for most of the traps/exceptions. | |
15 | For the more expensive tracepoints, like pagefaults, this can be handled with | |
16 | an explicit static key. | |
17 | ||
18 | Preparatory patch to remove the tracing IDT. | |
19 | ||
20 | Signed-off-by: Thomas Gleixner <tglx@linutronix.de> | |
21 | Cc: Andy Lutomirski <luto@kernel.org> | |
22 | Cc: Borislav Petkov <bp@alien8.de> | |
23 | Cc: Linus Torvalds <torvalds@linux-foundation.org> | |
24 | Cc: Peter Zijlstra <peterz@infradead.org> | |
25 | Cc: Steven Rostedt <rostedt@goodmis.org> | |
26 | Link: http://lkml.kernel.org/r/20170828064956.593094539@linutronix.de | |
27 | Signed-off-by: Ingo Molnar <mingo@kernel.org> | |
28 | (cherry picked from commit 2feb1b316d48004d905278c02a55902cab0be8be) | |
29 | Signed-off-by: Andy Whitcroft <apw@kathleen.maas> | |
30 | (cherry picked from commit 15e0ff2a63fdd93f8881e2ebba5c048c5b601e57) | |
31 | Signed-off-by: Andy Whitcroft <apw@canonical.com> | |
32 | Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com> | |
33 | (cherry picked from commit d58a56e851c339d8d9d311dc9b4fad6abbf8bf19) | |
34 | Signed-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 | ||
43 | diff --git a/arch/x86/include/asm/trace/common.h b/arch/x86/include/asm/trace/common.h | |
44 | new file mode 100644 | |
45 | index 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 | |
64 | diff --git a/arch/x86/include/asm/trace/exceptions.h b/arch/x86/include/asm/trace/exceptions.h | |
65 | index 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 | ||
79 | diff --git a/arch/x86/include/asm/trace/irq_vectors.h b/arch/x86/include/asm/trace/irq_vectors.h | |
80 | index 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 | ||
94 | diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c | |
95 | index 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 | -- | |
138 | 2.14.2 | |
139 |