aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sparc64/mmu_context.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sparc64/mmu_context.h')
-rw-r--r--include/asm-sparc64/mmu_context.h167
1 files changed, 86 insertions, 81 deletions
diff --git a/include/asm-sparc64/mmu_context.h b/include/asm-sparc64/mmu_context.h
index 57ee7b306189..2337eb487719 100644
--- a/include/asm-sparc64/mmu_context.h
+++ b/include/asm-sparc64/mmu_context.h
@@ -19,96 +19,103 @@ extern unsigned long tlb_context_cache;
19extern unsigned long mmu_context_bmap[]; 19extern unsigned long mmu_context_bmap[];
20 20
21extern void get_new_mmu_context(struct mm_struct *mm); 21extern void get_new_mmu_context(struct mm_struct *mm);
22#ifdef CONFIG_SMP
23extern void smp_new_mmu_context_version(void);
24#else
25#define smp_new_mmu_context_version() do { } while (0)
26#endif
22 27
23/* Initialize a new mmu context. This is invoked when a new 28extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
24 * address space instance (unique or shared) is instantiated. 29extern void destroy_context(struct mm_struct *mm);
25 * This just needs to set mm->context to an invalid context. 30
26 */ 31extern void __tsb_context_switch(unsigned long pgd_pa,
27#define init_new_context(__tsk, __mm) \ 32 struct tsb_config *tsb_base,
28 (((__mm)->context.sparc64_ctx_val = 0UL), 0) 33 struct tsb_config *tsb_huge,
29 34 unsigned long tsb_descr_pa);
30/* Destroy a dead context. This occurs when mmput drops the 35
31 * mm_users count to zero, the mmaps have been released, and 36static inline void tsb_context_switch(struct mm_struct *mm)
32 * all the page tables have been flushed. Our job is to destroy 37{
33 * any remaining processor-specific state, and in the sparc64 38 __tsb_context_switch(__pa(mm->pgd),
34 * case this just means freeing up the mmu context ID held by 39 &mm->context.tsb_block[0],
35 * this task if valid. 40#ifdef CONFIG_HUGETLB_PAGE
36 */ 41 (mm->context.tsb_block[1].tsb ?
37#define destroy_context(__mm) \ 42 &mm->context.tsb_block[1] :
38do { spin_lock(&ctx_alloc_lock); \ 43 NULL)
39 if (CTX_VALID((__mm)->context)) { \ 44#else
40 unsigned long nr = CTX_NRBITS((__mm)->context); \ 45 NULL
41 mmu_context_bmap[nr>>6] &= ~(1UL << (nr & 63)); \ 46#endif
42 } \ 47 , __pa(&mm->context.tsb_descr[0]));
43 spin_unlock(&ctx_alloc_lock); \ 48}
44} while(0) 49
45 50extern void tsb_grow(struct mm_struct *mm, unsigned long tsb_index, unsigned long mm_rss);
46/* Reload the two core values used by TLB miss handler 51#ifdef CONFIG_SMP
47 * processing on sparc64. They are: 52extern void smp_tsb_sync(struct mm_struct *mm);
48 * 1) The physical address of mm->pgd, when full page 53#else
49 * table walks are necessary, this is where the 54#define smp_tsb_sync(__mm) do { } while (0)
50 * search begins. 55#endif
51 * 2) A "PGD cache". For 32-bit tasks only pgd[0] is
52 * ever used since that maps the entire low 4GB
53 * completely. To speed up TLB miss processing we
54 * make this value available to the handlers. This
55 * decreases the amount of memory traffic incurred.
56 */
57#define reload_tlbmiss_state(__tsk, __mm) \
58do { \
59 register unsigned long paddr asm("o5"); \
60 register unsigned long pgd_cache asm("o4"); \
61 paddr = __pa((__mm)->pgd); \
62 pgd_cache = 0UL; \
63 if (task_thread_info(__tsk)->flags & _TIF_32BIT) \
64 pgd_cache = get_pgd_cache((__mm)->pgd); \
65 __asm__ __volatile__("wrpr %%g0, 0x494, %%pstate\n\t" \
66 "mov %3, %%g4\n\t" \
67 "mov %0, %%g7\n\t" \
68 "stxa %1, [%%g4] %2\n\t" \
69 "membar #Sync\n\t" \
70 "wrpr %%g0, 0x096, %%pstate" \
71 : /* no outputs */ \
72 : "r" (paddr), "r" (pgd_cache),\
73 "i" (ASI_DMMU), "i" (TSB_REG)); \
74} while(0)
75 56
76/* Set MMU context in the actual hardware. */ 57/* Set MMU context in the actual hardware. */
77#define load_secondary_context(__mm) \ 58#define load_secondary_context(__mm) \
78 __asm__ __volatile__("stxa %0, [%1] %2\n\t" \ 59 __asm__ __volatile__( \
79 "flush %%g6" \ 60 "\n661: stxa %0, [%1] %2\n" \
80 : /* No outputs */ \ 61 " .section .sun4v_1insn_patch, \"ax\"\n" \
81 : "r" (CTX_HWBITS((__mm)->context)), \ 62 " .word 661b\n" \
82 "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU)) 63 " stxa %0, [%1] %3\n" \
64 " .previous\n" \
65 " flush %%g6\n" \
66 : /* No outputs */ \
67 : "r" (CTX_HWBITS((__mm)->context)), \
68 "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU), "i" (ASI_MMU))
83 69
84extern void __flush_tlb_mm(unsigned long, unsigned long); 70extern void __flush_tlb_mm(unsigned long, unsigned long);
85 71
86/* Switch the current MM context. */ 72/* Switch the current MM context. Interrupts are disabled. */
87static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk) 73static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
88{ 74{
89 unsigned long ctx_valid; 75 unsigned long ctx_valid, flags;
90 int cpu; 76 int cpu;
91 77
92 /* Note: page_table_lock is used here to serialize switch_mm 78 spin_lock_irqsave(&mm->context.lock, flags);
93 * and activate_mm, and their calls to get_new_mmu_context.
94 * This use of page_table_lock is unrelated to its other uses.
95 */
96 spin_lock(&mm->page_table_lock);
97 ctx_valid = CTX_VALID(mm->context); 79 ctx_valid = CTX_VALID(mm->context);
98 if (!ctx_valid) 80 if (!ctx_valid)
99 get_new_mmu_context(mm); 81 get_new_mmu_context(mm);
100 spin_unlock(&mm->page_table_lock);
101 82
102 if (!ctx_valid || (old_mm != mm)) { 83 /* We have to be extremely careful here or else we will miss
103 load_secondary_context(mm); 84 * a TSB grow if we switch back and forth between a kernel
104 reload_tlbmiss_state(tsk, mm); 85 * thread and an address space which has it's TSB size increased
105 } 86 * on another processor.
87 *
88 * It is possible to play some games in order to optimize the
89 * switch, but the safest thing to do is to unconditionally
90 * perform the secondary context load and the TSB context switch.
91 *
92 * For reference the bad case is, for address space "A":
93 *
94 * CPU 0 CPU 1
95 * run address space A
96 * set cpu0's bits in cpu_vm_mask
97 * switch to kernel thread, borrow
98 * address space A via entry_lazy_tlb
99 * run address space A
100 * set cpu1's bit in cpu_vm_mask
101 * flush_tlb_pending()
102 * reset cpu_vm_mask to just cpu1
103 * TSB grow
104 * run address space A
105 * context was valid, so skip
106 * TSB context switch
107 *
108 * At that point cpu0 continues to use a stale TSB, the one from
109 * before the TSB grow performed on cpu1. cpu1 did not cross-call
110 * cpu0 to update it's TSB because at that point the cpu_vm_mask
111 * only had cpu1 set in it.
112 */
113 load_secondary_context(mm);
114 tsb_context_switch(mm);
106 115
107 /* Even if (mm == old_mm) we _must_ check 116 /* Any time a processor runs a context on an address space
108 * the cpu_vm_mask. If we do not we could 117 * for the first time, we must flush that context out of the
109 * corrupt the TLB state because of how 118 * local TLB.
110 * smp_flush_tlb_{page,range,mm} on sparc64
111 * and lazy tlb switches work. -DaveM
112 */ 119 */
113 cpu = smp_processor_id(); 120 cpu = smp_processor_id();
114 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) { 121 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
@@ -116,6 +123,7 @@ static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, str
116 __flush_tlb_mm(CTX_HWBITS(mm->context), 123 __flush_tlb_mm(CTX_HWBITS(mm->context),
117 SECONDARY_CONTEXT); 124 SECONDARY_CONTEXT);
118 } 125 }
126 spin_unlock_irqrestore(&mm->context.lock, flags);
119} 127}
120 128
121#define deactivate_mm(tsk,mm) do { } while (0) 129#define deactivate_mm(tsk,mm) do { } while (0)
@@ -123,23 +131,20 @@ static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, str
123/* Activate a new MM instance for the current task. */ 131/* Activate a new MM instance for the current task. */
124static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm) 132static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
125{ 133{
134 unsigned long flags;
126 int cpu; 135 int cpu;
127 136
128 /* Note: page_table_lock is used here to serialize switch_mm 137 spin_lock_irqsave(&mm->context.lock, flags);
129 * and activate_mm, and their calls to get_new_mmu_context.
130 * This use of page_table_lock is unrelated to its other uses.
131 */
132 spin_lock(&mm->page_table_lock);
133 if (!CTX_VALID(mm->context)) 138 if (!CTX_VALID(mm->context))
134 get_new_mmu_context(mm); 139 get_new_mmu_context(mm);
135 cpu = smp_processor_id(); 140 cpu = smp_processor_id();
136 if (!cpu_isset(cpu, mm->cpu_vm_mask)) 141 if (!cpu_isset(cpu, mm->cpu_vm_mask))
137 cpu_set(cpu, mm->cpu_vm_mask); 142 cpu_set(cpu, mm->cpu_vm_mask);
138 spin_unlock(&mm->page_table_lock);
139 143
140 load_secondary_context(mm); 144 load_secondary_context(mm);
141 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT); 145 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
142 reload_tlbmiss_state(current, mm); 146 tsb_context_switch(mm);
147 spin_unlock_irqrestore(&mm->context.lock, flags);
143} 148}
144 149
145#endif /* !(__ASSEMBLY__) */ 150#endif /* !(__ASSEMBLY__) */