0048-x86-tracing-Introduce-a-static-key-for-exception-tra.patch 4.6 KB

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