0123-perf-x86-Enable-free-running-PEBS-for-REGS_USER-INTR.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. From 6e502c25e8279d5c02db5b59e081a5415e1734fe Mon Sep 17 00:00:00 2001
  2. From: Andi Kleen <[email protected]>
  3. Date: Thu, 31 Aug 2017 14:46:30 -0700
  4. Subject: [PATCH 123/242] perf/x86: Enable free running PEBS for REGS_USER/INTR
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. [ Note, this is a Git cherry-pick of the following commit:
  10. a47ba4d77e12 ("perf/x86: Enable free running PEBS for REGS_USER/INTR")
  11. ... for easier x86 PTI code testing and back-porting. ]
  12. Currently free running PEBS is disabled when user or interrupt
  13. registers are requested. Most of the registers are actually
  14. available in the PEBS record and can be supported.
  15. So we just need to check for the supported registers and then
  16. allow it: it is all except for the segment register.
  17. For user registers this only works when the counter is limited
  18. to ring 3 only, so this also needs to be checked.
  19. Signed-off-by: Andi Kleen <[email protected]>
  20. Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
  21. Cc: Linus Torvalds <[email protected]>
  22. Cc: Peter Zijlstra <[email protected]>
  23. Cc: Thomas Gleixner <[email protected]>
  24. Link: http://lkml.kernel.org/r/[email protected]
  25. Signed-off-by: Ingo Molnar <[email protected]>
  26. (backported from commit 2fe1bc1f501d55e5925b4035bcd85781adc76c63)
  27. Signed-off-by: Andy Whitcroft <[email protected]>
  28. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  29. (cherry picked from commit 06c6715f5b78b9976e72467b6bba510e243e5aad)
  30. Signed-off-by: Fabian Grünbichler <[email protected]>
  31. ---
  32. arch/x86/events/perf_event.h | 24 +++++++++++++++++++++++-
  33. arch/x86/events/intel/core.c | 4 ++++
  34. 2 files changed, 27 insertions(+), 1 deletion(-)
  35. diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
  36. index 0f7dad8bd358..590eaf7c2c3e 100644
  37. --- a/arch/x86/events/perf_event.h
  38. +++ b/arch/x86/events/perf_event.h
  39. @@ -85,13 +85,15 @@ struct amd_nb {
  40. * Flags PEBS can handle without an PMI.
  41. *
  42. * TID can only be handled by flushing at context switch.
  43. + * REGS_USER can be handled for events limited to ring 3.
  44. *
  45. */
  46. #define PEBS_FREERUNNING_FLAGS \
  47. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | \
  48. PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | \
  49. PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | \
  50. - PERF_SAMPLE_TRANSACTION)
  51. + PERF_SAMPLE_TRANSACTION | \
  52. + PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER)
  53. /*
  54. * A debug store configuration.
  55. @@ -110,6 +112,26 @@ struct debug_store {
  56. u64 pebs_event_reset[MAX_PEBS_EVENTS];
  57. };
  58. +#define PEBS_REGS \
  59. + (PERF_REG_X86_AX | \
  60. + PERF_REG_X86_BX | \
  61. + PERF_REG_X86_CX | \
  62. + PERF_REG_X86_DX | \
  63. + PERF_REG_X86_DI | \
  64. + PERF_REG_X86_SI | \
  65. + PERF_REG_X86_SP | \
  66. + PERF_REG_X86_BP | \
  67. + PERF_REG_X86_IP | \
  68. + PERF_REG_X86_FLAGS | \
  69. + PERF_REG_X86_R8 | \
  70. + PERF_REG_X86_R9 | \
  71. + PERF_REG_X86_R10 | \
  72. + PERF_REG_X86_R11 | \
  73. + PERF_REG_X86_R12 | \
  74. + PERF_REG_X86_R13 | \
  75. + PERF_REG_X86_R14 | \
  76. + PERF_REG_X86_R15)
  77. +
  78. /*
  79. * Per register state.
  80. */
  81. diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
  82. index 6f342001ec6a..7f3afbf928bb 100644
  83. --- a/arch/x86/events/intel/core.c
  84. +++ b/arch/x86/events/intel/core.c
  85. @@ -2958,6 +2958,10 @@ static unsigned long intel_pmu_free_running_flags(struct perf_event *event)
  86. if (event->attr.use_clockid)
  87. flags &= ~PERF_SAMPLE_TIME;
  88. + if (!event->attr.exclude_kernel)
  89. + flags &= ~PERF_SAMPLE_REGS_USER;
  90. + if (event->attr.sample_regs_user & ~PEBS_REGS)
  91. + flags &= ~(PERF_SAMPLE_REGS_USER | PERF_SAMPLE_REGS_INTR);
  92. return flags;
  93. }
  94. --
  95. 2.14.2