aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkos Chandras <markos.chandras@imgtec.com>2015-01-26 08:04:33 -0500
committerRalf Baechle <ralf@linux-mips.org>2015-02-16 04:55:26 -0500
commited4cbc81addbc076b016c5b979fd1a02f0897f0a (patch)
treeab240d2c8f5bcd7eacbde7a3f46744ebb99b3995
parentfde3538a8a711aedf1173ecb2d45aed868f51c97 (diff)
MIPS: HTW: Prevent accidental HTW start due to nested htw_{start, stop}
activate_mm() and switch_mm() call get_new_mmu_context() which in turn can enable the HTW before the entryhi is changed with the new ASID. Since the latter will enable the HTW in local_flush_tlb_all(), then there is a small timing window where the HTW is running with the new ASID but with an old pgd since the TLBMISS_HANDLER_SETUP_PGD hasn't assigned a new one yet. In order to prevent that, we introduce a simple htw counter to avoid starting HTW accidentally due to nested htw_{start,stop}() sequences. Moreover, since various IPI calls can enforce TLB flushing operations on a different core, such an operation may interrupt another htw_{stop,start} in progress leading inconsistent updates of the htw_seq variable. In order to avoid that, we disable the interrupts whenever we update that variable. Signed-off-by: Markos Chandras <markos.chandras@imgtec.com> Cc: <stable@vger.kernel.org> # 3.17+ Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/9118/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/include/asm/cpu-info.h5
-rw-r--r--arch/mips/include/asm/mmu_context.h7
-rw-r--r--arch/mips/include/asm/pgtable.h24
-rw-r--r--arch/mips/kernel/cpu-probe.c4
4 files changed, 32 insertions, 8 deletions
diff --git a/arch/mips/include/asm/cpu-info.h b/arch/mips/include/asm/cpu-info.h
index a6c9ccb33c5c..c3f4f2d2e108 100644
--- a/arch/mips/include/asm/cpu-info.h
+++ b/arch/mips/include/asm/cpu-info.h
@@ -84,6 +84,11 @@ struct cpuinfo_mips {
84 * (shifted by _CACHE_SHIFT) 84 * (shifted by _CACHE_SHIFT)
85 */ 85 */
86 unsigned int writecombine; 86 unsigned int writecombine;
87 /*
88 * Simple counter to prevent enabling HTW in nested
89 * htw_start/htw_stop calls
90 */
91 unsigned int htw_seq;
87} __attribute__((aligned(SMP_CACHE_BYTES))); 92} __attribute__((aligned(SMP_CACHE_BYTES)));
88 93
89extern struct cpuinfo_mips cpu_data[]; 94extern struct cpuinfo_mips cpu_data[];
diff --git a/arch/mips/include/asm/mmu_context.h b/arch/mips/include/asm/mmu_context.h
index 87f11072f557..45914b59824c 100644
--- a/arch/mips/include/asm/mmu_context.h
+++ b/arch/mips/include/asm/mmu_context.h
@@ -25,7 +25,6 @@ do { \
25 if (cpu_has_htw) { \ 25 if (cpu_has_htw) { \
26 write_c0_pwbase(pgd); \ 26 write_c0_pwbase(pgd); \
27 back_to_back_c0_hazard(); \ 27 back_to_back_c0_hazard(); \
28 htw_reset(); \
29 } \ 28 } \
30} while (0) 29} while (0)
31 30
@@ -144,6 +143,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
144 unsigned long flags; 143 unsigned long flags;
145 local_irq_save(flags); 144 local_irq_save(flags);
146 145
146 htw_stop();
147 /* Check if our ASID is of an older version and thus invalid */ 147 /* Check if our ASID is of an older version and thus invalid */
148 if ((cpu_context(cpu, next) ^ asid_cache(cpu)) & ASID_VERSION_MASK) 148 if ((cpu_context(cpu, next) ^ asid_cache(cpu)) & ASID_VERSION_MASK)
149 get_new_mmu_context(next, cpu); 149 get_new_mmu_context(next, cpu);
@@ -156,6 +156,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
156 */ 156 */
157 cpumask_clear_cpu(cpu, mm_cpumask(prev)); 157 cpumask_clear_cpu(cpu, mm_cpumask(prev));
158 cpumask_set_cpu(cpu, mm_cpumask(next)); 158 cpumask_set_cpu(cpu, mm_cpumask(next));
159 htw_start();
159 160
160 local_irq_restore(flags); 161 local_irq_restore(flags);
161} 162}
@@ -182,6 +183,7 @@ activate_mm(struct mm_struct *prev, struct mm_struct *next)
182 183
183 local_irq_save(flags); 184 local_irq_save(flags);
184 185
186 htw_stop();
185 /* Unconditionally get a new ASID. */ 187 /* Unconditionally get a new ASID. */
186 get_new_mmu_context(next, cpu); 188 get_new_mmu_context(next, cpu);
187 189
@@ -191,6 +193,7 @@ activate_mm(struct mm_struct *prev, struct mm_struct *next)
191 /* mark mmu ownership change */ 193 /* mark mmu ownership change */
192 cpumask_clear_cpu(cpu, mm_cpumask(prev)); 194 cpumask_clear_cpu(cpu, mm_cpumask(prev));
193 cpumask_set_cpu(cpu, mm_cpumask(next)); 195 cpumask_set_cpu(cpu, mm_cpumask(next));
196 htw_start();
194 197
195 local_irq_restore(flags); 198 local_irq_restore(flags);
196} 199}
@@ -205,6 +208,7 @@ drop_mmu_context(struct mm_struct *mm, unsigned cpu)
205 unsigned long flags; 208 unsigned long flags;
206 209
207 local_irq_save(flags); 210 local_irq_save(flags);
211 htw_stop();
208 212
209 if (cpumask_test_cpu(cpu, mm_cpumask(mm))) { 213 if (cpumask_test_cpu(cpu, mm_cpumask(mm))) {
210 get_new_mmu_context(mm, cpu); 214 get_new_mmu_context(mm, cpu);
@@ -213,6 +217,7 @@ drop_mmu_context(struct mm_struct *mm, unsigned cpu)
213 /* will get a new context next time */ 217 /* will get a new context next time */
214 cpu_context(cpu, mm) = 0; 218 cpu_context(cpu, mm) = 0;
215 } 219 }
220 htw_start();
216 local_irq_restore(flags); 221 local_irq_restore(flags);
217} 222}
218 223
diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
index 3aa982b50a10..845016d1cdbd 100644
--- a/arch/mips/include/asm/pgtable.h
+++ b/arch/mips/include/asm/pgtable.h
@@ -99,19 +99,31 @@ extern void paging_init(void);
99 99
100#define htw_stop() \ 100#define htw_stop() \
101do { \ 101do { \
102 unsigned long flags; \
103 \
102 if (cpu_has_htw) { \ 104 if (cpu_has_htw) { \
103 write_c0_pwctl(read_c0_pwctl() & \ 105 local_irq_save(flags); \
104 ~(1 << MIPS_PWCTL_PWEN_SHIFT)); \ 106 if(!raw_current_cpu_data.htw_seq++) { \
105 back_to_back_c0_hazard(); \ 107 write_c0_pwctl(read_c0_pwctl() & \
108 ~(1 << MIPS_PWCTL_PWEN_SHIFT)); \
109 back_to_back_c0_hazard(); \
110 } \
111 local_irq_restore(flags); \
106 } \ 112 } \
107} while(0) 113} while(0)
108 114
109#define htw_start() \ 115#define htw_start() \
110do { \ 116do { \
117 unsigned long flags; \
118 \
111 if (cpu_has_htw) { \ 119 if (cpu_has_htw) { \
112 write_c0_pwctl(read_c0_pwctl() | \ 120 local_irq_save(flags); \
113 (1 << MIPS_PWCTL_PWEN_SHIFT)); \ 121 if (!--raw_current_cpu_data.htw_seq) { \
114 back_to_back_c0_hazard(); \ 122 write_c0_pwctl(read_c0_pwctl() | \
123 (1 << MIPS_PWCTL_PWEN_SHIFT)); \
124 back_to_back_c0_hazard(); \
125 } \
126 local_irq_restore(flags); \
115 } \ 127 } \
116} while(0) 128} while(0)
117 129
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 5342674842f5..228ae864c92e 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -424,8 +424,10 @@ static inline unsigned int decode_config3(struct cpuinfo_mips *c)
424 if (config3 & MIPS_CONF3_MSA) 424 if (config3 & MIPS_CONF3_MSA)
425 c->ases |= MIPS_ASE_MSA; 425 c->ases |= MIPS_ASE_MSA;
426 /* Only tested on 32-bit cores */ 426 /* Only tested on 32-bit cores */
427 if ((config3 & MIPS_CONF3_PW) && config_enabled(CONFIG_32BIT)) 427 if ((config3 & MIPS_CONF3_PW) && config_enabled(CONFIG_32BIT)) {
428 c->htw_seq = 0;
428 c->options |= MIPS_CPU_HTW; 429 c->options |= MIPS_CPU_HTW;
430 }
429 431
430 return config3 & MIPS_CONF_M; 432 return config3 & MIPS_CONF_M;
431} 433}