|
238 | 238 |
|
239 | 239 | /* |
240 | 240 | * Some Loongson 3 CPUs have a bug wherein execution of a memory access (load, |
241 | | - * store or pref) in between an ll & sc can cause the sc instruction to |
| 241 | + * store or prefetch) in between an LL & SC can cause the SC instruction to |
242 | 242 | * erroneously succeed, breaking atomicity. Whilst it's unusual to write code |
243 | 243 | * containing such sequences, this bug bites harder than we might otherwise |
244 | 244 | * expect due to reordering & speculation: |
245 | 245 | * |
246 | | - * 1) A memory access appearing prior to the ll in program order may actually |
247 | | - * be executed after the ll - this is the reordering case. |
| 246 | + * 1) A memory access appearing prior to the LL in program order may actually |
| 247 | + * be executed after the LL - this is the reordering case. |
248 | 248 | * |
249 | | - * In order to avoid this we need to place a memory barrier (ie. a sync |
250 | | - * instruction) prior to every ll instruction, in between it & any earlier |
251 | | - * memory access instructions. Many of these cases are already covered by |
252 | | - * smp_mb__before_llsc() but for the remaining cases, typically ones in |
253 | | - * which multiple CPUs may operate on a memory location but ordering is not |
254 | | - * usually guaranteed, we use loongson_llsc_mb() below. |
| 249 | + * In order to avoid this we need to place a memory barrier (ie. a SYNC |
| 250 | + * instruction) prior to every LL instruction, in between it and any earlier |
| 251 | + * memory access instructions. |
255 | 252 | * |
256 | 253 | * This reordering case is fixed by 3A R2 CPUs, ie. 3A2000 models and later. |
257 | 254 | * |
258 | | - * 2) If a conditional branch exists between an ll & sc with a target outside |
259 | | - * of the ll-sc loop, for example an exit upon value mismatch in cmpxchg() |
| 255 | + * 2) If a conditional branch exists between an LL & SC with a target outside |
| 256 | + * of the LL-SC loop, for example an exit upon value mismatch in cmpxchg() |
260 | 257 | * or similar, then misprediction of the branch may allow speculative |
261 | | - * execution of memory accesses from outside of the ll-sc loop. |
| 258 | + * execution of memory accesses from outside of the LL-SC loop. |
262 | 259 | * |
263 | | - * In order to avoid this we need a memory barrier (ie. a sync instruction) |
| 260 | + * In order to avoid this we need a memory barrier (ie. a SYNC instruction) |
264 | 261 | * at each affected branch target, for which we also use loongson_llsc_mb() |
265 | 262 | * defined below. |
266 | 263 | * |
267 | 264 | * This case affects all current Loongson 3 CPUs. |
| 265 | + * |
| 266 | + * The above described cases cause an error in the cache coherence protocol; |
| 267 | + * such that the Invalidate of a competing LL-SC goes 'missing' and SC |
| 268 | + * erroneously observes its core still has Exclusive state and lets the SC |
| 269 | + * proceed. |
| 270 | + * |
| 271 | + * Therefore the error only occurs on SMP systems. |
268 | 272 | */ |
269 | 273 | #ifdef CONFIG_CPU_LOONGSON3_WORKAROUNDS /* Loongson-3's LLSC workaround */ |
270 | | -#define loongson_llsc_mb() __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory") |
| 274 | +#define loongson_llsc_mb() __asm__ __volatile__("sync" : : :"memory") |
271 | 275 | #else |
272 | 276 | #define loongson_llsc_mb() do { } while (0) |
273 | 277 | #endif |
|
0 commit comments