Commit 06e67bb
authored
vmop: add VMOP_KILL_THREAD and VMOP_KILL_CHILD (#65)
* vmop: fix killed-thread escape races and add VMOP_KILL_THREAD/KILL_CHILD
Fixes the v68/opt pi-test hang (and the underlying correctness hole it
exposed) and wires up a proper cross-thread kill API.
## Root cause
A thread marked for death (KILL|VMWORK set by kill_thread_locked) could
still be on its way into a blocking syscall. While it spun for the BKL
it was still RUNNING, so the per-state kill action had already fired.
Once it took the BKL the gate in futex_classic/futex_pi checked
VMWORK&&IE — not VMWORK alone. Kill leaves IE alone, so with IE clear
the thread sailed past, set STATUS_BLOCKED, and parked in a wait ring.
Nobody reaped it; num_cpus never drained; the booter (no timer fallback)
slept forever.
A second bug: after h2_vmkill(VMOP_KILL_VM_SELF) some siblings died
mid-cleanup holding pthread_exit_lock. The main thread's pthread_exit
tried to acquire it and blocked forever (num_cpus stuck at 1) because
the original kill loop skipped the caller with "if (target == me)
continue".
## Changes
vmop.ref.c / vmop.h / h2_vm.h
- Add VMOP_KILL_THREAD and VMOP_KILL_CHILD operations. KILL_THREAD
sets KILL+VMWORK on a target and forces it out of every state
(VMWAIT, RUNNING, INTBLOCKED, BLOCKED, READY) ignoring guest IE.
KILL_CHILD iterates a child VM's contexts[] under one BKL section.
- Remove the "if (target == me) continue" skip in the kill_vm loop so
the caller also receives KILL|VMWORK+IPI; the IPI fires before any
mutex can be acquired after vmkill returns.
futex_classic / futex_pi (ref + v4opt.S)
- Change the VMWORK gate from VMWORK&&IE to VMWORK alone, matching
what H2K_switch already does. Gate calls vm_do_work_withlock (BKL
held), which handles KILL (never returns) or clears VMWORK and
returns -1 so the caller retries.
popup.ref.c / intpool.ref.c
- Add the same VMWORK gate (these had no check at all).
- popup.v4opt.S: add allocframe(#0) to make the function non-leaf,
add vmstatus load + bitsset after k0lock, jump to fail label that
calls vm_do_work_withlock; change jumpr r31 → dealloc_return at all
early-return paths.
- Note: h2_intwait (trap 11) routes to H2K_popup_wait; covered here.
vmwork.ref.c
- Remove the IE guard around the VMWORK clear. The interrupt
controller retains the pending interrupt, so clearing VMWORK with IE
disabled cannot lose work — it is re-discovered when the guest
re-enables IE.
pthread_thread.ref.c
- Add h2_thread_stop_trap in the last==true branch of pthread_exit as
defense-in-depth (now redundant given the kill-loop fix above, but
kept as a hard guarantee).
specs and docs
- vmdefs.spec: document VMWORK contract ("reconsider before blocking").
- vmwork.spec: drop "and interrupts are enabled" from the clear rule.
- futex_classic.spec, futex_pi.spec, popup.spec, intpool.spec: state
the spurious-failure / retry contract for all block primitives.
tests
- futex/test/tests/vmwork: new directed unit test; cases B (VMWORK
alone, no IE) and C (VMWORK|KILL) fail pre-fix, pass post-fix for
both ref and opt builds.
- vmwork/test: assert VMWORK is cleared after every non-KILL call,
including the IE-disabled path.
- vmop/test: updated assertions for new caller-kill behavior;
KILL_THREAD and KILL_CHILD coverage.
- popup/test, intpool/test: cases B and C mirroring the futex pattern.
- libs/posix/pthread/test_h2: new pthread test suite covering join,
detach, barriers, condvars, rwlocks, semaphores, TLS, and stuck-thread
scenarios that exercise the vmkill path end-to-end.
Verified: 1224 passed, 0 failed across all 9 variants
(v68/v73/v81 x opt/ref/opt_si). Previously v68/opt and v81/opt_si
pi-test hung on every run.
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
* vmwork: remove H2K_vm_do_work wrapper; callers acquire BKL directly
H2K_vm_do_work was a thin BKL acquire/call-withlock/release wrapper
with a single call site (vmipi.ref.c). Inline the lock pair there
and delete the wrapper, leaving H2K_vm_do_work_withlock as the sole
public entry point.
- vmipi.ref.c: inline BKL_LOCK/UNLOCK around _withlock call; drop
duplicate #include <hw.h>
- vmipi/test: stub H2K_vm_do_work_withlock instead of H2K_vm_do_work
- vmwork.ref.c: remove wrapper; drop now-unused #include <hw.h>
- vmwork.h: remove H2K_vm_do_work declaration
- vmwork.spec: remove H2K_vm_do_work section; update description
1224/1224 tests pass across 9 variants.
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
* popup,vmop: fix popup_cancel <<#2 typo and add dispatcher/cancel coverage tests
popup.v4opt.S: H2K_popup_cancel used <<#2 (4-byte stride) when indexing
inthandlers[], which is an array of 8-byte H2K_inthandler_t entries.
For any intnum != 0 the wrong slot was cleared (e.g. cancelling intnum=2
cleared intnum=1's handler) and odd intnums produced a misaligned 64-bit
store in the opt build. Fix to <<#3 to match H2K_popup_int and
H2K_popup_wait which already use the correct stride.
vmop/test: add dispatcher coverage -- OOB op codes (including -1, 100,
and VMOP_MAX) must return -1, and VMOP_KILL_THREAD / VMOP_KILL_VM must
dispatch correctly through H2K_vmop(). Declare H2K_vmop() in vmop.h so
the test can call the dispatcher directly.
popup/test: add H2K_popup_cancel coverage -- simulate the INTBLOCKED
state left by popup_wait (handler registered, r00=intnum) and verify
that cancel clears the handler slot and resets r00 to -1.
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
* build: fix two bugs that broke make cov
Makefile.inc.test: try_gmon_out is PHONY so it re-runs on every cov
invocation, but hexagon-gmon-merge refuses to overwrite an existing
gmon.out (exits 255). If a previous run left gmon.out behind (e.g.
after a partial cov run following testall), subsequent cov runs would
fail for every affected test. Fix by removing gmon.out at the top of
try_gmon_out before the merge.
makefile: the build recipe wrote "v$(ARCHV) $@ ..." to the ver file,
so a plain "make build" produced "v81 build ..." instead of "v81 opt ...".
merge_cov.py expects the second token to be "opt" or "ref" and exits
with an error otherwise, preventing the merged cov.txt/cov.rpt from
being generated. Fix by using $(TARGET) instead of $@.
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
* build: don't symlink cov.txt from source tree into cov build dir
The cov.txt rule symlinked all non-Makefile.inc files from the source
directory into the per-test build directory. If a stale cov.txt
happened to exist in the source tree (e.g. from a previous cov run that
wrote through an earlier symlink), it would be linked in, causing the
build-dir cov.txt target to write back through it into the source tree.
On the next run, try_gmon_out would find gmon.out already present (from
the previous testall run) and hexagon-gmon-merge would exit 255 with
"gmon.out: File exists."
Fix by excluding cov.txt and cov-*.txt from the symlink step, matching
how generated_tests.dat and scenarios.h are already excluded.
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
---------
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>1 parent 364219e commit 06e67bb
154 files changed
Lines changed: 4791 additions & 97 deletions
File tree
- kernel
- event
- intpool
- test
- popup
- test
- futex
- futex_classic
- futex_pi
- futex/test/tests/vmwork
- sched/switch
- thread/stop
- util/vmdefs
- vm
- vmfuncs
- test
- vmipi
- test
- vmop
- test
- vmwork
- test
- libs
- h2
- common
- vm
- posix/pthread
- test_h2
- attr_roundtrip
- barrier_basic
- cond_signal_broadcast
- detach_states
- exit1_detached_worker_with_stuck
- exit1_main_cond_wait
- exit1_main_mutex
- exit1_worker_cond_wait
- join_basic
- join_invalid
- mutex_recursive
- mutex_trylock
- neg_attr_setstacksize_zero
- neg_barrier_init_zero
- neg_cond_wait_no_mutex
- neg_create_invalid_routine
- neg_join_self
- neg_mutex_destroy_held
- neg_mutex_unlock_unowned
- neg_rwlock_unlock_unheld
- neg_sem_overflow_post
- neg_tls_use_after_delete
- pthread_exit_main
- pthread_workers_return
- rwlock_readers_writers
- sem_corner
- stuck_in_barrier
- stuck_in_cond_timedwait
- stuck_in_cond_wait
- stuck_in_join
- stuck_in_mutex
- stuck_in_pthread_exit_joined
- stuck_in_rwlock_rd
- stuck_in_rwlock_wr
- stuck_in_sem_timedwait
- stuck_in_sem_wait
- tls_keys
- thread
- syscall/angel/src
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| |||
358 | 367 | | |
359 | 368 | | |
360 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
361 | 392 | | |
362 | 393 | | |
363 | 394 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
143 | 147 | | |
144 | 148 | | |
145 | | - | |
146 | 149 | | |
147 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
148 | 161 | | |
149 | 162 | | |
150 | 163 | | |
| |||
199 | 212 | | |
200 | 213 | | |
201 | 214 | | |
202 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
203 | 226 | | |
204 | 227 | | |
205 | 228 | | |
| |||
230 | 253 | | |
231 | 254 | | |
232 | 255 | | |
233 | | - | |
| 256 | + | |
234 | 257 | | |
235 | 258 | | |
236 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
| |||
312 | 321 | | |
313 | 322 | | |
314 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
315 | 372 | | |
316 | 373 | | |
317 | 374 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
27 | | - | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
49 | | - | |
50 | | - | |
| 60 | + | |
| 61 | + | |
51 | 62 | | |
52 | 63 | | |
53 | | - | |
54 | | - | |
| 64 | + | |
| 65 | + | |
55 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
56 | 71 | | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
60 | | - | |
61 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
62 | 93 | | |
63 | 94 | | |
64 | 95 | | |
65 | | - | |
66 | | - | |
| 96 | + | |
| 97 | + | |
67 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
68 | 103 | | |
69 | 104 | | |
70 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | | - | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
0 commit comments