Skip to content

fix(kvm): do not lose vCPU kicks outside of KVM_RUN - #547

Merged
Lencerf merged 1 commit into
google:mainfrom
Lencerf:push-vvuzvvoxrxzs
Nov 11, 2026
Merged

Lencerf merged 1 commit into
google:mainfrom
Lencerf:push-vvuzvvoxrxzs

Conversation

@Lencerf

@Lencerf Lencerf commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

stop_vcpu() kicks a vCPU with SIGRTMIN, which only interrupts a vCPU inside KVM_RUN. A vCPU outside KVM_RUN, e.g. one still initializing or emulating an MMIO access, misses the kick and enters the guest again. If the guest then halts, the vCPU never notices the request to pause, shut down, or reboot the VM.

As suggested by the KVM API documentation, let the signal handler set immediate_exit of the vCPU of the current thread, so that the next KVM_RUN returns immediately, and clear it when KVM_RUN returns EINTR. The handler finds the vCPU through a thread-local variable, so a vCPU stays on the thread that created it.

`stop_vcpu()` kicks a vCPU with SIGRTMIN, which only interrupts a vCPU
inside KVM_RUN. A vCPU outside KVM_RUN, e.g. one still initializing or
emulating an MMIO access, misses the kick and enters the guest again.
If the guest then halts, the vCPU never notices the request to pause,
shut down, or reboot the VM.

As suggested by the KVM API documentation, let the signal handler set
`immediate_exit` of the vCPU of the current thread, so that the next
KVM_RUN returns immediately, and clear it when KVM_RUN returns EINTR.
The handler finds the vCPU through a thread-local variable, so a vCPU
stays on the thread that created it.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42980979607

Coverage decreased (-0.03%) to 43.8%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: 27 uncovered changes across 2 files (0 of 27 lines covered, 0.0%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
alioth/src/hv/kvm/vcpu/vcpu.rs 24 0 0.0%
alioth/src/hv/kvm/kvm.rs 3 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
alioth/src/hv/kvm/vcpu/vcpu.rs 1 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 16457
Covered Lines: 6997
Line Coverage: 42.52%
Relevant Branches: 1760
Covered Branches: 982
Branch Coverage: 55.8%
Branches in Coverage %: Yes
Coverage Strength: 905.1 hits per line

💛 - Coveralls

@Lencerf
Lencerf added this pull request to the merge queue Nov 11, 2026
Merged via the queue into google:main with commit bf57612 Nov 11, 2026
20 checks passed
@Lencerf
Lencerf deleted the push-vvuzvvoxrxzs branch November 11, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants