Repository navigation
openvmm_entry: add VM operation gate to the ttrpc VmService - #4659
Manish Ranjan Mahanta (marma-dev) wants to merge 24 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Exclusive RPCs block request admission, and ungated Quit can hang during active topology work.
3 open findings
What changed in this PR
Adds a concurrency gate to prevent conflicting ttrpc VM mutations.
Changes:
- Introduces shared and exclusive operation gating.
- Applies gating to lifecycle, teardown, and topology RPCs.
- Documents concurrency behavior.
| File | Description |
|---|---|
operation_gate.rs |
Implements gate state and tests. |
mod.rs |
Integrates gating into VmService. |
grpc.md |
Documents operation concurrency. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Topology operations (device and resource hot add/remove) share the gate with each other; pause, resume and teardown are exclusive. A conflicting operation is rejected immediately with ABORTED. Topology RPCs are admitted before their request is processed, so a rejected call has no side effects, and the guard is released when the operation completes, fails, or is cancelled.
Describe which ttrpc operations are exclusive or shared, the ABORTED response for a conflicting request, and that a rejected request has no side effects.
Split the pause/resume gate kind into separate Pause and Resume kinds so a conflict names the operation that is actually running. Make Quit wait for in-flight device and resource changes before dropping the VM. Such a change can hold a clone of a device RPC channel, and a live channel keeps the worker from stopping, so Quit could otherwise hang. Correct the Guide: pause, resume, and teardown run to completion before the server reads its next request, so requests arriving meanwhile are processed afterwards rather than rejected; ABORTED applies when one of them arrives while a device or resource change is still in flight.
A device or resource change can stay in flight indefinitely. For example, a Consomme port change waits for the NIC's queue processing, which is stopped while the VM is paused. Such a change held the gate, so resume and teardown were rejected with ABORTED and Quit, which waited for it, hung. Teardown and Quit are now terminal: they cancel in-flight gated changes before proceeding, and the cancelled calls return CANCELLED. Only the service-side wait is cancelled; a request already delivered to the VM is completed or discarded when the worker stops. The server's own shutdown path does the same. Consomme port changes are also rejected with FAILED_PRECONDITION unless the VM is running, since they cannot complete otherwise.
229fb81 to
0ced5c4
Compare
|
Drop safety of gated operations when Teardown/Quit cancels them (re: the "needs a closer look" note) I checked every operation There are only two kinds of await point:
What this means:
Pre-existing and separate: if the worker is mid-hot-add when it stops, it can drop a running device. On Linux block devices, that triggers the io_uring abort on teardown. It reproduces on |
There was a problem hiding this comment.
🔵 Needs a closer look
The new running-VM precondition deterministically breaks existing paused-VM port-validation tests, requiring those cases to move to the running phase and a separate paused-state FAILED_PRECONDITION assertion.
Review effort: Balanced
Consomme port updates and removals now return FAILED_PRECONDITION unless the VM is running, since their requests are serviced by the NIC's queue processing, which is stopped while paused. test_ttrpc_interface sent malformed port requests while the VM was still paused after CreateVm and expected parse errors, so it now fails with FAILED_PRECONDITION instead. Assert FAILED_PRECONDITION for both update and removal while paused, run the malformed-port cases after ResumeVm, and check that a port change after PauseVm fails fast and doesn't block the teardown that follows.
# Conflicts: # openvmm/openvmm_entry/src/ttrpc/mod.rs
There was a problem hiding this comment.
🟡 Changes recommended
Integration tests still assume a reusable post-save process and fail under the new terminal lifecycle, while pending WaitVM requests remain blocked after saves that leave the service terminal.
3 open issues
Review effort: Balanced
# Conflicts: # openvmm/openvmm_entry/src/ttrpc/mod.rs
There was a problem hiding this comment.
🔵 Needs a closer look
Saving transitions the VM to Halted without completing or clearing a pending WaitVM response, leaving the original caller blocked until Quit and rejecting subsequent waiters.
3 open issues
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
After a cancelled SaveVM and worker stop, a fresh WaitVM incorrectly reports “VM not created yet” rather than succeeding because the missing-VM check precedes the halted snapshot-saved check.
1 open issue
4 resolved since last review
Review effort: Balanced



What this does
The ttrpc
VmServicelets mutating RPCs run in any order. Device and resource changes run as background tasks, so a client (or two clients) can pause, resume, save or tear down the VM while a hot-add is still waiting on its device. This PR adds a smallVmOperationGatethat admits each mutating RPC only if it cannot conflict with what is already in flight.Behavior
ModifyResource,AddPcieDevice,RemovePcieDevice,AddVpciDevice,RemoveVpciDevicePauseVM,ResumeVM,SaveVMABORTEDTeardownVMbefore Save,QuitCANCELLEDPauseVM,ResumeVM,SaveVMandTeardownVMrun inline in the request loop, so they cannot overlap each other. The gate arbitrates them against background changes.Haltedwith reasonsnapshot saved;PropertiesVM,WaitVM, andQuitremain available. Pause, resume, save, shutdown, topology changes, teardown, create and restore returnFAILED_PRECONDITION.Quit; the VMM must not allow process reuse after a possibly committed save.Quitremains available and terminates the process after releasing resources. A failed SaveVM, before publication, does not seal the gate and leaves the VM paused so the caller can resume or retry.Behavior changes
PauseVM/ResumeVM/SaveVMduring an in-flight device or resource change now fail withABORTEDinstead of running concurrently.TeardownVM/Quitcancel in-flight changes before the saved VM terminal state. Previously teardown could hang: an in-flight change holds a device RPC channel, which keeps the worker from stopping.TeardownVMcould clearsnapshot_savedand allow a later VM to run with the old snapshot aliasing its memory file.UPDATE/REMOVErequires a running VM before the request is parsed further, because the backend services these requests only while its queue runs.Why at the ttrpc layer
Device and resource changes are sent over per-device RPC channels, not the worker's request queue, so ordering has to be decided where requests are admitted. The CLI/REPL issues these sequentially from one caller and is unchanged here. A worker-level mutation fence remains separate Save/Restore work.
Why now
Save/Restore over the API (#4553) is in
main. A snapshot must capture a stable device set, and a published save permanently aliases the VM's memory backing file. Operation ordering and post-save process lifetime therefore need one enforceable service contract.Not in this PR
Testing
VmServicetests: hot-add ordering and cancellation, committed SaveVM terminal state,WaitVM, rejection of resume/pause/teardown/create/restore, cancelled-Save terminal behavior, and worker-stop sealing.cargo test -p openvmm_entry ttrpc:: --lib: 50 passed against currentmain.cargo clippy -p openvmm_entry --all-targets: passed.cargo doc -p openvmm_entry --no-deps: passed.cargo xtask fmt --fix: passed.Docs: the gRPC management reference now describes the terminal SaveVM/explicit-
Quitlifecycle and gate sealing.Live trpc::test_ttrpc_interface on KVM and MSHV at head 78df413b: passed, including Save -> terminal state -> Quit -> process exit -> cross-process Restore.
Latest review fix: pending WaitVM completes on terminal Save; proto/Guide require explicit Quit and process exit.