Skip to content

feat: Support smp on kvm/x86-64 - #187

Merged
junyu0312 merged 1 commit into
mainfrom
dev
Jul 14, 2026
Merged

junyu0312 merged 1 commit into
mainfrom
dev

Conversation

@junyu0312

@junyu0312 junyu0312 commented Jul 14, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Secondary virtual CPUs can now start automatically during virtual machine boot when supported by the virtualization platform.
    • Boot behavior is tailored for KVM and Apple Hypervisor environments.
  • Bug Fixes

    • Improved virtual CPU startup handling by retrying temporary availability errors, helping boot sequences proceed more reliably.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The VM interface now exposes platform-specific secondary CPU boot policy. KVM enables secondary vCPU booting, Apple Hypervisor disables it, and the VMM conditionally boots secondary vCPUs. KVM vCPU execution also retries EAGAIN errors.

Changes

Secondary vCPU boot behavior

Layer / File(s) Summary
Hypervisor boot policy
crates/vm-core/src/virtualization/vm.rs, crates/vm-core/src/virtualization/kvm/vm.rs, crates/vm-core/src/virtualization/hvp/vm.rs
HypervisorVm requires a secondary CPU boot decision; KVM returns true and Apple Hypervisor returns false.
KVM vCPU retry handling
Cargo.toml, crates/vm-core/Cargo.toml, crates/vm-core/src/virtualization/kvm/vcpu.rs
Adds Linux libc support and retries vcpu_fd.run() on EAGAIN, while panicking on other errors.
VMM secondary CPU startup
crates/vm-vmm/src/vm.rs, crates/vm-vmm/src/vm/config.rs, crates/vm-vmm/src/vm/snapshot.rs
Renames the stored hypervisor field and conditionally boots active secondary vCPUs during Vm::boot. Construction from configuration and snapshots uses the renamed field.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Vm
  participant HypervisorVm
  participant SecondaryVcpu
  Vm->>HypervisorVm: secondary_cpu_should_run_on_booting()
  HypervisorVm-->>Vm: return boot policy
  Vm->>SecondaryVcpu: boot each active vCPU ID starting at 1
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: enabling SMP/secondary CPU booting on KVM x86-64.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@junyu0312
junyu0312 merged commit 9b6da30 into main Jul 14, 2026
11 of 12 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/vm-core/src/virtualization/kvm/vcpu.rs`:
- Around line 107-113: Update the `vcpu_fd.run()` error handling in the vCPU
execution loop to retry both `libc::EAGAIN` and `libc::EINTR` with `continue`.
Replace the fallback `panic!` for other errors with returning
`VcpuError::KvmError`, preserving the existing vCPU error propagation path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdb87d14-ddd8-4c7e-b441-2bcd30543c70

📥 Commits

Reviewing files that changed from the base of the PR and between 11ed545 and e45a499.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • Cargo.toml
  • crates/vm-core/Cargo.toml
  • crates/vm-core/src/virtualization/hvp/vm.rs
  • crates/vm-core/src/virtualization/kvm/vcpu.rs
  • crates/vm-core/src/virtualization/kvm/vm.rs
  • crates/vm-core/src/virtualization/vm.rs
  • crates/vm-vmm/src/vm.rs
  • crates/vm-vmm/src/vm/config.rs
  • crates/vm-vmm/src/vm/snapshot.rs

Comment on lines +107 to +113
let vm_exit = match vcpu_fd.run() {
Ok(vm_exit) => vm_exit,
Err(err) => match err.errno() {
libc::EAGAIN => continue,
_ => panic!("{err}"),
},
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if VcpuError can wrap a kvm run error and look at the error enum.
rg -A 10 'enum VcpuError' crates/vm-core/src/
# Check for EINTR occurrences in similar kvm runs in other projects or this one.
rg 'EINTR' crates/vm-core/

Repository: junyu0312/rust-vm

Length of output: 983


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map relevant files and inspect the vCPU error type and KVM run loop.
git ls-files crates/vm-core/src/virtualization/kvm/vcpu.rs crates/vm-core/src/virtualization/vcpu/error.rs

echo '--- error.rs ---'
cat -n crates/vm-core/src/virtualization/vcpu/error.rs

echo '--- kvm/vcpu.rs (around run loop) ---'
sed -n '1,220p' crates/vm-core/src/virtualization/kvm/vcpu.rs

Repository: junyu0312/rust-vm

Length of output: 6721


🏁 Script executed:

#!/bin/bash
set -euo pipefail

git ls-files crates/vm-core/src/virtualization/kvm/vcpu.rs crates/vm-core/src/virtualization/vcpu/error.rs

echo '--- error.rs ---'
cat -n crates/vm-core/src/virtualization/vcpu/error.rs

echo '--- kvm/vcpu.rs (around run loop) ---'
sed -n '1,220p' crates/vm-core/src/virtualization/kvm/vcpu.rs

Repository: junyu0312/rust-vm

Length of output: 6721


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- error.rs ---'
cat -n crates/vm-core/src/virtualization/vcpu/error.rs

echo '--- kvm/vcpu.rs (around run loop) ---'
sed -n '1,220p' crates/vm-core/src/virtualization/kvm/vcpu.rs

Repository: junyu0312/rust-vm

Length of output: 6627


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the KVM vCPU run loop and its return type / error plumbing.
rg -n -A 4 -B 4 'vcpu_fd\.run\(\)|fn .*vcpu|Result<.*, VcpuError>|VcpuError' crates/vm-core/src/virtualization/kvm crates/vm-core/src/virtualization/vcpu

Repository: junyu0312/rust-vm

Length of output: 19580


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- EINTR in repo ---'
rg -n 'EINTR|EAGAIN|errno\(\)' crates/vm-core/src crates -g '!target' || true

echo '--- kvm_ioctls dependency versions ---'
rg -n 'kvm_ioctls|kvm-bindings' Cargo.toml Cargo.lock crates/**/Cargo.toml || true

Repository: junyu0312/rust-vm

Length of output: 1121


Retry EINTR and avoid panicking on KVM run errors. Treat EINTR like EAGAIN here, and return the remaining run() errors via VcpuError::KvmError instead of aborting the vCPU thread.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/vm-core/src/virtualization/kvm/vcpu.rs` around lines 107 - 113, Update
the `vcpu_fd.run()` error handling in the vCPU execution loop to retry both
`libc::EAGAIN` and `libc::EINTR` with `continue`. Replace the fallback `panic!`
for other errors with returning `VcpuError::KvmError`, preserving the existing
vCPU error propagation path.

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.

1 participant