forked fromtorvalds/linux
- Notifications
You must be signed in to change notification settings - Fork0
Commite45cdc7
membarrier: Execute SYNC_CORE on the calling thread
membarrier()'s MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE is documented assyncing the core on all sibling threads but not necessarily the callingthread. This behavior is fundamentally buggy and cannot be used safely.Suppose a user program has two threads. Thread A is on CPU 0 and thread Bis on CPU 1. Thread A modifies some text and callsmembarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE).Then thread B executes the modified code. If, at any point aftermembarrier() decides which CPUs to target, thread A could be preempted andreplaced by thread B on CPU 0. This could even happen on exit from themembarrier() syscall. If this happens, thread B will end up running on CPU0 without having synced.In principle, this could be fixed by arranging for the scheduler to issuesync_core_before_usermode() whenever switching between two threads in thesame mm if there is any possibility of a concurrent membarrier() call, butthis would have considerable overhead. Instead, make membarrier() sync thecalling CPU as well.As an optimization, this avoids an extra smp_mb() in the defaultbarrier-only mode and an extra rseq preempt on the caller.Fixes:70216e1 ("membarrier: Provide core serializing command, *_SYNC_CORE")Signed-off-by: Andy Lutomirski <luto@kernel.org>Signed-off-by: Thomas Gleixner <tglx@linutronix.de>Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>Link:https://lore.kernel.org/r/250ded637696d490c69bef1877148db86066881c.1607058304.git.luto@kernel.org1 parent758c937 commite45cdc7
1 file changed
+33
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
216 | | - | |
217 | | - | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
| |||
229 | 228 | | |
230 | 229 | | |
231 | 230 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | 231 | | |
243 | 232 | | |
244 | 233 | | |
245 | 234 | | |
246 | 235 | | |
247 | 236 | | |
248 | 237 | | |
249 | | - | |
250 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
251 | 243 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
255 | 270 | | |
256 | 271 | | |
257 | 272 | | |
| |||
0 commit comments
Comments
(0)