Commit 2c7724b
fix: SMP priority inheritance race condition in mutex lock chain
In SMP environments, the priority inheritance (PI) lock chain traversal
in inner_pend_for has a race condition where:
1. Thread A captures priority value (e.g., 6)
2. Thread A releases its lock, acquires the scanned thread's lock
3. During this window, Thread B promotes Thread A's priority (from 6 to 0)
4. Thread A uses the stale value (6) for comparison, causing incorrect
priority promotion decisions
The fix:
- Re-read current_priority after acquiring scanning_thread's lock to get
the most up-to-date value
- Use conditional promotion instead of forced promotion to avoid
overwriting already-promoted priorities
- Continue traversing the lock chain even if adjust_wait_queue_position_by
fails, since the thread may still need PI from other waiting threads
Test: test_blocking_mutex_chain_basic now passes 50000 iterations
consistently on qemu_virt64_aarch64.debug.swi (SMP 8-core).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent edf4176 commit 2c7724b
1 file changed
Lines changed: 25 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
207 | 206 | | |
208 | 207 | | |
209 | 208 | | |
| |||
224 | 223 | | |
225 | 224 | | |
226 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
227 | 237 | | |
228 | 238 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
238 | 247 | | |
239 | 248 | | |
240 | 249 | | |
| |||
249 | 258 | | |
250 | 259 | | |
251 | 260 | | |
252 | | - | |
253 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
254 | 266 | | |
255 | 267 | | |
256 | 268 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 269 | + | |
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
| |||
0 commit comments