0271-x86-feature-Enable-the-x86-feature-to-control-Specul.patch 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Tim Chen <[email protected]>
  3. Date: Thu, 24 Aug 2017 09:34:41 -0700
  4. Subject: [PATCH] x86/feature: Enable the x86 feature to control Speculation
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5753
  9. CVE-2017-5715
  10. cpuid ax=0x7, return rdx bit 26 to indicate presence of this feature
  11. IA32_SPEC_CTRL (0x48) and IA32_PRED_CMD (0x49)
  12. IA32_SPEC_CTRL, bit0 – Indirect Branch Restricted Speculation (IBRS)
  13. IA32_PRED_CMD, bit0 – Indirect Branch Prediction Barrier (IBPB)
  14. Signed-off-by: Tim Chen <[email protected]>
  15. Signed-off-by: Andy Whitcroft <[email protected]>
  16. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  17. (cherry picked from commit f1f160a92b70c25d6e6e76788463bbec86a73313)
  18. Signed-off-by: Fabian Grünbichler <[email protected]>
  19. ---
  20. arch/x86/include/asm/cpufeatures.h | 1 +
  21. arch/x86/include/asm/msr-index.h | 5 +++++
  22. arch/x86/kernel/cpu/scattered.c | 1 +
  23. 3 files changed, 7 insertions(+)
  24. diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
  25. index 3928050b51b0..44be8fd069bf 100644
  26. --- a/arch/x86/include/asm/cpufeatures.h
  27. +++ b/arch/x86/include/asm/cpufeatures.h
  28. @@ -208,6 +208,7 @@
  29. #define X86_FEATURE_AVX512_4FMAPS ( 7*32+17) /* AVX-512 Multiply Accumulation Single precision */
  30. #define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
  31. +#define X86_FEATURE_SPEC_CTRL ( 7*32+19) /* Control Speculation Control */
  32. /* Virtualization flags: Linux defined, word 8 */
  33. #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
  34. diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
  35. index db88b7f852b4..4e3438a00a50 100644
  36. --- a/arch/x86/include/asm/msr-index.h
  37. +++ b/arch/x86/include/asm/msr-index.h
  38. @@ -41,6 +41,9 @@
  39. #define MSR_PPIN_CTL 0x0000004e
  40. #define MSR_PPIN 0x0000004f
  41. +#define MSR_IA32_SPEC_CTRL 0x00000048
  42. +#define MSR_IA32_PRED_CMD 0x00000049
  43. +
  44. #define MSR_IA32_PERFCTR0 0x000000c1
  45. #define MSR_IA32_PERFCTR1 0x000000c2
  46. #define MSR_FSB_FREQ 0x000000cd
  47. @@ -437,6 +440,8 @@
  48. #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)
  49. #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
  50. #define FEATURE_CONTROL_LMCE (1<<20)
  51. +#define FEATURE_ENABLE_IBRS (1<<0)
  52. +#define FEATURE_SET_IBPB (1<<0)
  53. #define MSR_IA32_APICBASE 0x0000001b
  54. #define MSR_IA32_APICBASE_BSP (1<<8)
  55. diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
  56. index 23c23508c012..9651ea395812 100644
  57. --- a/arch/x86/kernel/cpu/scattered.c
  58. +++ b/arch/x86/kernel/cpu/scattered.c
  59. @@ -24,6 +24,7 @@ static const struct cpuid_bit cpuid_bits[] = {
  60. { X86_FEATURE_INTEL_PT, CPUID_EBX, 25, 0x00000007, 0 },
  61. { X86_FEATURE_AVX512_4VNNIW, CPUID_EDX, 2, 0x00000007, 0 },
  62. { X86_FEATURE_AVX512_4FMAPS, CPUID_EDX, 3, 0x00000007, 0 },
  63. + { X86_FEATURE_SPEC_CTRL, CPUID_EDX, 26, 0x00000007, 0 },
  64. { X86_FEATURE_CAT_L3, CPUID_EBX, 1, 0x00000010, 0 },
  65. { X86_FEATURE_CAT_L2, CPUID_EBX, 2, 0x00000010, 0 },
  66. { X86_FEATURE_CDP_L3, CPUID_ECX, 2, 0x00000010, 1 },
  67. --
  68. 2.14.2