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

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