tlb_nohash.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. unsigned int pid;
  110. preempt_disable();
  111. pid = mm->context.id;
  112. if (unlikely(pid == MMU_NO_CONTEXT))
  113. goto no_context;
  114. if (!cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
  115. struct tlb_flush_param p = { .pid = pid };
  116. /* Ignores smp_processor_id() even if set. */
  117. smp_call_function_many(mm_cpumask(mm),
  118. do_flush_tlb_mm_ipi, &p, 1);
  119. }
  120. _tlbil_pid(pid);
  121. no_context:
  122. preempt_enable();
  123. }
  124. EXPORT_SYMBOL(flush_tlb_mm);
  125. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  126. {
  127. struct cpumask *cpu_mask;
  128. unsigned int pid;
  129. preempt_disable();
  130. pid = vma ? vma->vm_mm->context.id : 0;
  131. if (unlikely(pid == MMU_NO_CONTEXT))
  132. goto bail;
  133. cpu_mask = mm_cpumask(vma->vm_mm);
  134. if (!cpumask_equal(cpu_mask, cpumask_of(smp_processor_id()))) {
  135. /* If broadcast tlbivax is supported, use it */
  136. if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
  137. int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
  138. if (lock)
  139. spin_lock(&tlbivax_lock);
  140. _tlbivax_bcast(vmaddr, pid);
  141. if (lock)
  142. spin_unlock(&tlbivax_lock);
  143. goto bail;
  144. } else {
  145. struct tlb_flush_param p = { .pid = pid, .addr = vmaddr };
  146. /* Ignores smp_processor_id() even if set in cpu_mask */
  147. smp_call_function_many(cpu_mask,
  148. do_flush_tlb_page_ipi, &p, 1);
  149. }
  150. }
  151. _tlbil_va(vmaddr, pid);
  152. bail:
  153. preempt_enable();
  154. }
  155. EXPORT_SYMBOL(flush_tlb_page);
  156. #endif /* CONFIG_SMP */
  157. /*
  158. * Flush kernel TLB entries in the given range
  159. */
  160. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  161. {
  162. #ifdef CONFIG_SMP
  163. preempt_disable();
  164. smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
  165. _tlbil_pid(0);
  166. preempt_enable();
  167. #else
  168. _tlbil_pid(0);
  169. #endif
  170. }
  171. EXPORT_SYMBOL(flush_tlb_kernel_range);
  172. /*
  173. * Currently, for range flushing, we just do a full mm flush. This should
  174. * be optimized based on a threshold on the size of the range, since
  175. * some implementation can stack multiple tlbivax before a tlbsync but
  176. * for now, we keep it that way
  177. */
  178. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  179. unsigned long end)
  180. {
  181. flush_tlb_mm(vma->vm_mm);
  182. }
  183. EXPORT_SYMBOL(flush_tlb_range);