tlb_nohash.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * This file contains the routines for TLB flushing.
  3. * On machines where the MMU does not use a hash table to store virtual to
  4. * physical translations (ie, SW loaded TLBs or Book3E compilant processors,
  5. * this does -not- include 603 however which shares the implementation with
  6. * hash based processors)
  7. *
  8. * -- BenH
  9. *
  10. * Copyright 2008 Ben Herrenschmidt <benh@kernel.crashing.org>
  11. * IBM Corp.
  12. *
  13. * Derived from arch/ppc/mm/init.c:
  14. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  15. *
  16. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  17. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  18. * Copyright (C) 1996 Paul Mackerras
  19. *
  20. * Derived from "arch/i386/mm/init.c"
  21. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  22. *
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public License
  25. * as published by the Free Software Foundation; either version
  26. * 2 of the License, or (at your option) any later version.
  27. *
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/mm.h>
  31. #include <linux/init.h>
  32. #include <linux/highmem.h>
  33. #include <linux/pagemap.h>
  34. #include <linux/preempt.h>
  35. #include <linux/spinlock.h>
  36. #include <asm/tlbflush.h>
  37. #include <asm/tlb.h>
  38. #include "mmu_decl.h"
  39. /*
  40. * Base TLB flushing operations:
  41. *
  42. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  43. * - flush_tlb_page(vma, vmaddr) flushes one page
  44. * - flush_tlb_range(vma, start, end) flushes a range of pages
  45. * - flush_tlb_kernel_range(start, end) flushes kernel pages
  46. *
  47. * - local_* variants of page and mm only apply to the current
  48. * processor
  49. */
  50. /*
  51. * These are the base non-SMP variants of page and mm flushing
  52. */
  53. void local_flush_tlb_mm(struct mm_struct *mm)
  54. {
  55. unsigned int pid;
  56. preempt_disable();
  57. pid = mm->context.id;
  58. if (pid != MMU_NO_CONTEXT)
  59. _tlbil_pid(pid);
  60. preempt_enable();
  61. }
  62. EXPORT_SYMBOL(local_flush_tlb_mm);
  63. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  64. {
  65. unsigned int pid;
  66. preempt_disable();
  67. pid = vma ? vma->vm_mm->context.id : 0;
  68. if (pid != MMU_NO_CONTEXT)
  69. _tlbil_va(vmaddr, pid);
  70. preempt_enable();
  71. }
  72. EXPORT_SYMBOL(local_flush_tlb_page);
  73. /*
  74. * And here are the SMP non-local implementations
  75. */
  76. #ifdef CONFIG_SMP
  77. static DEFINE_SPINLOCK(tlbivax_lock);
  78. static int mm_is_core_local(struct mm_struct *mm)
  79. {
  80. return cpumask_subset(mm_cpumask(mm),
  81. topology_thread_cpumask(smp_processor_id()));
  82. }
  83. struct tlb_flush_param {
  84. unsigned long addr;
  85. unsigned int pid;
  86. };
  87. static void do_flush_tlb_mm_ipi(void *param)
  88. {
  89. struct tlb_flush_param *p = param;
  90. _tlbil_pid(p ? p->pid : 0);
  91. }
  92. static void do_flush_tlb_page_ipi(void *param)
  93. {
  94. struct tlb_flush_param *p = param;
  95. _tlbil_va(p->addr, p->pid);
  96. }
  97. /* Note on invalidations and PID:
  98. *
  99. * We snapshot the PID with preempt disabled. At this point, it can still
  100. * change either because:
  101. * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
  102. * - we are invaliating some target that isn't currently running here
  103. * and is concurrently acquiring a new PID on another CPU
  104. * - some other CPU is re-acquiring a lost PID for this mm
  105. * etc...
  106. *
  107. * However, this shouldn't be a problem as we only guarantee
  108. * invalidation of TLB entries present prior to this call, so we
  109. * don't care about the PID changing, and invalidating a stale PID
  110. * is generally harmless.
  111. */
  112. void flush_tlb_mm(struct mm_struct *mm)
  113. {
  114. unsigned int pid;
  115. preempt_disable();
  116. pid = mm->context.id;
  117. if (unlikely(pid == MMU_NO_CONTEXT))
  118. goto no_context;
  119. if (!mm_is_core_local(mm)) {
  120. struct tlb_flush_param p = { .pid = pid };
  121. /* Ignores smp_processor_id() even if set. */
  122. smp_call_function_many(mm_cpumask(mm),
  123. do_flush_tlb_mm_ipi, &p, 1);
  124. }
  125. _tlbil_pid(pid);
  126. no_context:
  127. preempt_enable();
  128. }
  129. EXPORT_SYMBOL(flush_tlb_mm);
  130. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  131. {
  132. struct cpumask *cpu_mask;
  133. unsigned int pid;
  134. preempt_disable();
  135. pid = vma ? vma->vm_mm->context.id : 0;
  136. if (unlikely(pid == MMU_NO_CONTEXT))
  137. goto bail;
  138. cpu_mask = mm_cpumask(vma->vm_mm);
  139. if (!mm_is_core_local(mm)) {
  140. /* If broadcast tlbivax is supported, use it */
  141. if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
  142. int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
  143. if (lock)
  144. spin_lock(&tlbivax_lock);
  145. _tlbivax_bcast(vmaddr, pid);
  146. if (lock)
  147. spin_unlock(&tlbivax_lock);
  148. goto bail;
  149. } else {
  150. struct tlb_flush_param p = { .pid = pid, .addr = vmaddr };
  151. /* Ignores smp_processor_id() even if set in cpu_mask */
  152. smp_call_function_many(cpu_mask,
  153. do_flush_tlb_page_ipi, &p, 1);
  154. }
  155. }
  156. _tlbil_va(vmaddr, pid);
  157. bail:
  158. preempt_enable();
  159. }
  160. EXPORT_SYMBOL(flush_tlb_page);
  161. #endif /* CONFIG_SMP */
  162. /*
  163. * Flush kernel TLB entries in the given range
  164. */
  165. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  166. {
  167. #ifdef CONFIG_SMP
  168. preempt_disable();
  169. smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
  170. _tlbil_pid(0);
  171. preempt_enable();
  172. #else
  173. _tlbil_pid(0);
  174. #endif
  175. }
  176. EXPORT_SYMBOL(flush_tlb_kernel_range);
  177. /*
  178. * Currently, for range flushing, we just do a full mm flush. This should
  179. * be optimized based on a threshold on the size of the range, since
  180. * some implementation can stack multiple tlbivax before a tlbsync but
  181. * for now, we keep it that way
  182. */
  183. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  184. unsigned long end)
  185. {
  186. flush_tlb_mm(vma->vm_mm);
  187. }
  188. EXPORT_SYMBOL(flush_tlb_range);