-
Notifications
You must be signed in to change notification settings - Fork 9
Join worker vCPU threads before tearing down guest memory #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
|
|
||
| #include "runtime/forkipc.h" | ||
| #include "runtime/proctitle.h" | ||
| #include "runtime/thread.h" | ||
|
|
||
| #include "syscall/fuse.h" | ||
| #include "syscall/path.h" | ||
|
|
@@ -510,6 +511,16 @@ int main(int argc, char **argv) | |
| */ | ||
| int exit_code = vcpu_run_loop(vcpu, vexit, &g, verbose, timeout_sec); | ||
|
|
||
| /* Wait for worker vCPU threads to stop before tearing down guest memory. | ||
| * The main thread leaves the run loop as soon as it observes the | ||
| * exit_group flag, but sibling vCPU threads may still be mid-iteration in | ||
| * their own run loops (e.g. touching shim_globals). cleanup_main_resources | ||
| * unmaps the guest slab via guest_destroy, so a still-running worker would | ||
| * fault on freed guest memory and crash the host with SIGSEGV, masking the | ||
| * real exit code. thread_join_workers() is a no-op once the workers have | ||
| * already wound down (the common single-threaded case). */ | ||
| thread_join_workers(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Cleaner: drop the |
||
|
|
||
| /* Tear down debugger state before freeing guest/vCPU resources. */ | ||
| gdb_stub_shutdown(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering vs
gdb_stub_shutdown()at the next line leaves a residual race.gdb_stub_shutdown()(gdbstub.c:1435-1440) broadcastsresume_condto release any GDB-paused workers so they can exit. A worker stuck ingdb_stub_handle_stophasactive=1(paused in ptrace-stop, not deactivated), so the new join here polls 100ms, sees no deactivation, and detaches. Thengdb_stub_shutdownreleases the worker, it resumes execution, and main proceeds toshim_globals_counters_dump/cleanup_main_resources-- same SIGSEGV pattern the PR is fixing, just gated on a GDB session.Move the join one line down so the GDB-paused case is also covered: