tlb_nohash.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. struct tlb_flush_param {
  79. unsigned long addr;
  80. unsigned int pid;
  81. };
  82. static void do_flush_tlb_mm_ipi(void *param)
  83. {
  84. struct tlb_flush_param *p = param;
  85. _tlbil_pid(p ? p->pid : 0);
  86. }
  87. static void do_flush_tlb_page_ipi(void *param)
  88. {
  89. struct tlb_flush_param *p = param;
  90. _tlbil_va(p->addr, p->pid);
  91. }
  92. /* Note on invalidations and PID:
  93. *
  94. * We snapshot the PID with preempt disabled. At this point, it can still
  95. * change either because:
  96. * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
  97. * - we are invaliating some target that isn't currently running here
  98. * and is concurrently acquiring a new PID on another CPU
  99. * - some other CPU is re-acquiring a lost PID for this mm
  100. * etc...
  101. *
  102. * However, this shouldn't be a problem as we only guarantee
  103. * invalidation of TLB entries present prior to this call, so we
  104. * don't care about the PID changing, and invalidating a stale PID
  105. * is generally harmless.
  106. */
  107. void flush_tlb_mm(struct mm_struct *mm)
  108. {
  109. cpumask_t cpu_mask;
  110. unsigned int pid;
  111. preempt_disable();
  112. pid = mm->context.id;
  113. if (unlikely(pid == MMU_NO_CONTEXT))
  114. goto no_context;
  115. if (!cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
  116. struct tlb_flush_param p = { .pid = pid };
  117. /* Ignores smp_processor_id() even if set. */
  118. smp_call_function_many(mm_cpumask(mm),
  119. do_flush_tlb_mm_ipi, &p, 1);
  120. }
  121. _tlbil_pid(pid);
  122. no_context:
  123. preempt_enable();
  124. }
  125. EXPORT_SYMBOL(flush_tlb_mm);
  126. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  127. {
  128. struct cpumask *cpu_mask;
  129. unsigned int pid;
  130. preempt_disable();
  131. pid = vma ? vma->vm_mm->context.id : 0;
  132. if (unlikely(pid == MMU_NO_CONTEXT))
  133. goto bail;
  134. cpu_mask = mm_cpumask(vma->vm_mm);
  135. if (!cpumask_equal(cpu_mask, cpumask_of(smp_processor_id()))) {
  136. /* If broadcast tlbivax is supported, use it */
  137. if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
  138. int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
  139. if (lock)
  140. spin_lock(&tlbivax_lock);
  141. _tlbivax_bcast(vmaddr, pid);
  142. if (lock)
  143. spin_unlock(&tlbivax_lock);
  144. goto bail;
  145. } else {
  146. struct tlb_flush_param p = { .pid = pid, .addr = vmaddr };
  147. /* Ignores smp_processor_id() even if set in cpu_mask */
  148. smp_call_function_many(cpu_mask,
  149. do_flush_tlb_page_ipi, &p, 1);
  150. }
  151. }
  152. _tlbil_va(vmaddr, pid);
  153. bail:
  154. preempt_enable();
  155. }
  156. EXPORT_SYMBOL(flush_tlb_page);
  157. #endif /* CONFIG_SMP */
  158. /*
  159. * Flush kernel TLB entries in the given range
  160. */
  161. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  162. {
  163. #ifdef CONFIG_SMP
  164. preempt_disable();
  165. smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
  166. _tlbil_pid(0);
  167. preempt_enable();
  168. #else
  169. _tlbil_pid(0);
  170. #endif
  171. }
  172. EXPORT_SYMBOL(flush_tlb_kernel_range);
  173. /*
  174. * Currently, for range flushing, we just do a full mm flush. This should
  175. * be optimized based on a threshold on the size of the range, since
  176. * some implementation can stack multiple tlbivax before a tlbsync but
  177. * for now, we keep it that way
  178. */
  179. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  180. unsigned long end)
  181. {
  182. flush_tlb_mm(vma->vm_mm);
  183. }
  184. EXPORT_SYMBOL(flush_tlb_range);