0208-x86-mm-Abstract-switching-CR3.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 7cc2d98148d5b5be191f4dbf4c29d4d6da93a9f8 Mon Sep 17 00:00:00 2001
  2. From: Dave Hansen <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:58 +0100
  4. Subject: [PATCH 208/242] x86/mm: Abstract switching CR3
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. In preparation to adding additional PCID flushing, abstract the
  10. loading of a new ASID into CR3.
  11. [ PeterZ: Split out from big combo patch ]
  12. Signed-off-by: Dave Hansen <[email protected]>
  13. Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
  14. Signed-off-by: Thomas Gleixner <[email protected]>
  15. Cc: Andy Lutomirski <[email protected]>
  16. Cc: Boris Ostrovsky <[email protected]>
  17. Cc: Borislav Petkov <[email protected]>
  18. Cc: Brian Gerst <[email protected]>
  19. Cc: David Laight <[email protected]>
  20. Cc: Denys Vlasenko <[email protected]>
  21. Cc: Eduardo Valentin <[email protected]>
  22. Cc: Greg KH <[email protected]>
  23. Cc: H. Peter Anvin <[email protected]>
  24. Cc: Josh Poimboeuf <[email protected]>
  25. Cc: Juergen Gross <[email protected]>
  26. Cc: Linus Torvalds <[email protected]>
  27. Cc: Peter Zijlstra <[email protected]>
  28. Cc: Will Deacon <[email protected]>
  29. Cc: [email protected]
  30. Cc: [email protected]
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Signed-off-by: Ingo Molnar <[email protected]>
  34. (cherry picked from commit 48e111982cda033fec832c6b0592c2acedd85d04)
  35. Signed-off-by: Andy Whitcroft <[email protected]>
  36. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  37. (cherry picked from commit 1e2affe2a79305b3a5f3ad65d3f61ad9d1f9e168)
  38. Signed-off-by: Fabian Grünbichler <[email protected]>
  39. ---
  40. arch/x86/mm/tlb.c | 22 ++++++++++++++++++++--
  41. 1 file changed, 20 insertions(+), 2 deletions(-)
  42. diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
  43. index ce87b69fb4e0..353f2f4e1d96 100644
  44. --- a/arch/x86/mm/tlb.c
  45. +++ b/arch/x86/mm/tlb.c
  46. @@ -101,6 +101,24 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen,
  47. *need_flush = true;
  48. }
  49. +static void load_new_mm_cr3(pgd_t *pgdir, u16 new_asid, bool need_flush)
  50. +{
  51. + unsigned long new_mm_cr3;
  52. +
  53. + if (need_flush) {
  54. + new_mm_cr3 = build_cr3(pgdir, new_asid);
  55. + } else {
  56. + new_mm_cr3 = build_cr3_noflush(pgdir, new_asid);
  57. + }
  58. +
  59. + /*
  60. + * Caution: many callers of this function expect
  61. + * that load_cr3() is serializing and orders TLB
  62. + * fills with respect to the mm_cpumask writes.
  63. + */
  64. + write_cr3(new_mm_cr3);
  65. +}
  66. +
  67. void leave_mm(int cpu)
  68. {
  69. struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
  70. @@ -228,7 +246,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
  71. if (need_flush) {
  72. this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id);
  73. this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen);
  74. - write_cr3(build_cr3(next->pgd, new_asid));
  75. + load_new_mm_cr3(next->pgd, new_asid, true);
  76. /*
  77. * NB: This gets called via leave_mm() in the idle path
  78. @@ -241,7 +259,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
  79. trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
  80. } else {
  81. /* The new ASID is already up to date. */
  82. - write_cr3(build_cr3_noflush(next->pgd, new_asid));
  83. + load_new_mm_cr3(next->pgd, new_asid, false);
  84. /* See above wrt _rcuidle. */
  85. trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0);
  86. --
  87. 2.14.2