blob: 29b0301c18aab26f2a613d397da9856a8d1eec3b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __UM_TLB_H
2#define __UM_TLB_H
3
WANG Cong1f4deba2008-04-15 14:34:38 -07004#include <linux/pagemap.h>
Jeff Dike0b4e2732008-02-04 22:31:07 -08005#include <linux/swap.h>
6#include <asm/percpu.h>
7#include <asm/pgalloc.h>
8#include <asm/tlbflush.h>
9
10#define tlb_start_vma(tlb, vma) do { } while (0)
11#define tlb_end_vma(tlb, vma) do { } while (0)
12#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
13
14/* struct mmu_gather is an opaque type used by the mm code for passing around
15 * any data needed by arch specific code for tlb_remove_page.
16 */
17struct mmu_gather {
18 struct mm_struct *mm;
19 unsigned int need_flush; /* Really unmapped some ptes? */
20 unsigned long start;
21 unsigned long end;
22 unsigned int fullmm; /* non-zero means full mm flush */
23};
24
Jeff Dike0b4e2732008-02-04 22:31:07 -080025static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
26 unsigned long address)
27{
28 if (tlb->start > address)
29 tlb->start = address;
30 if (tlb->end < address + PAGE_SIZE)
31 tlb->end = address + PAGE_SIZE;
32}
33
34static inline void init_tlb_gather(struct mmu_gather *tlb)
35{
36 tlb->need_flush = 0;
37
38 tlb->start = TASK_SIZE;
39 tlb->end = 0;
40
41 if (tlb->fullmm) {
42 tlb->start = 0;
43 tlb->end = TASK_SIZE;
44 }
45}
46
Peter Zijlstraff075d602011-05-24 17:11:57 -070047static inline void
Linus Torvalds2b047252013-08-15 11:42:25 -070048tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
Jeff Dike0b4e2732008-02-04 22:31:07 -080049{
Jeff Dike0b4e2732008-02-04 22:31:07 -080050 tlb->mm = mm;
Linus Torvalds2b047252013-08-15 11:42:25 -070051 tlb->start = start;
52 tlb->end = end;
53 tlb->fullmm = !(start | (end+1));
Jeff Dike0b4e2732008-02-04 22:31:07 -080054
55 init_tlb_gather(tlb);
Jeff Dike0b4e2732008-02-04 22:31:07 -080056}
57
58extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
59 unsigned long end);
60
61static inline void
Peter Zijlstraff075d602011-05-24 17:11:57 -070062tlb_flush_mmu(struct mmu_gather *tlb)
Jeff Dike0b4e2732008-02-04 22:31:07 -080063{
64 if (!tlb->need_flush)
65 return;
66
67 flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end);
68 init_tlb_gather(tlb);
69}
70
71/* tlb_finish_mmu
72 * Called at the end of the shootdown operation to free up any resources
73 * that were required.
74 */
75static inline void
76tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
77{
Peter Zijlstraff075d602011-05-24 17:11:57 -070078 tlb_flush_mmu(tlb);
Jeff Dike0b4e2732008-02-04 22:31:07 -080079
80 /* keep the page table cache within bounds */
81 check_pgt_cache();
Jeff Dike0b4e2732008-02-04 22:31:07 -080082}
83
84/* tlb_remove_page
85 * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)),
86 * while handling the additional races in SMP caused by other CPUs
87 * caching valid mappings in their TLBs.
88 */
Peter Zijlstraff075d602011-05-24 17:11:57 -070089static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
Jeff Dike0b4e2732008-02-04 22:31:07 -080090{
91 tlb->need_flush = 1;
92 free_page_and_swap_cache(page);
Peter Zijlstraff075d602011-05-24 17:11:57 -070093 return 1; /* avoid calling tlb_flush_mmu */
94}
95
96static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
97{
98 __tlb_remove_page(tlb, page);
Jeff Dike0b4e2732008-02-04 22:31:07 -080099}
100
101/**
102 * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
103 *
104 * Record the fact that pte's were really umapped in ->need_flush, so we can
105 * later optimise away the tlb invalidate. This helps when userspace is
106 * unmapping already-unmapped pages, which happens quite a lot.
107 */
108#define tlb_remove_tlb_entry(tlb, ptep, address) \
109 do { \
110 tlb->need_flush = 1; \
111 __tlb_remove_tlb_entry(tlb, ptep, address); \
112 } while (0)
113
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000114#define pte_free_tlb(tlb, ptep, addr) __pte_free_tlb(tlb, ptep, addr)
Jeff Dike0b4e2732008-02-04 22:31:07 -0800115
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000116#define pud_free_tlb(tlb, pudp, addr) __pud_free_tlb(tlb, pudp, addr)
Jeff Dike0b4e2732008-02-04 22:31:07 -0800117
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000118#define pmd_free_tlb(tlb, pmdp, addr) __pmd_free_tlb(tlb, pmdp, addr)
Jeff Dike0b4e2732008-02-04 22:31:07 -0800119
120#define tlb_migrate_finish(mm) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122#endif