fix(vmm): fix KVM smoke test for nested virtualization#421
Merged
Conversation
95351a2 to
ffcb938
Compare
The smoke test from #417 failed on EC2 c8i instances because it didn't initialize vCPU registers before KVM_RUN. Without setting CS base=0 and RIP=0, the CPU starts at the x86 reset vector (0xFFFFFFF0) which is unmapped, causing KVM_EXIT_UNKNOWN on nested KVM. This was misdiagnosed as "broken nested virtualization on Amazon Linux 2023 / EC2 c8i". In fact, both Amazon Linux 2023 (kernel 6.1) and Ubuntu 24.04 (kernel 6.17) work correctly on c8i when the vCPU is properly initialized. The fix: - Move smoke test to C (kvm_smoke.c) — Rust's libc::ioctl() variadic FFI has ABI issues with KVM ioctls on some platforms - Properly init vCPU state: CS base=0, selector=0, RIP=0, RFLAGS=0x2 - Verified on EC2 c8i with both AL2023 and Ubuntu 24.04 References: - LWN "Using the KVM API": https://lwn.net/Articles/658511/ - dpw/kvm-hello-world: https://github.com/dpw/kvm-hello-world Fixes the false positive from #417.
ffcb938 to
90f11b6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KVM_RUNlibc::ioctl()variadic FFI ABI issuesRoot Cause
The smoke test from #417 didn't set up vCPU registers (CS, RIP, RFLAGS) before calling
KVM_RUN. Without initialization, the x86 CPU starts at the reset vector (0xFFFFFFF0) which has no memory mapped in the test VM.KVM_EXIT_HLTby coincidenceKVM_EXIT_UNKNOWN(0) orKVM_EXIT_SHUTDOWN(17)This was misdiagnosed as "broken nested virtualization on Amazon Linux 2023". Both AL2023 (kernel 6.1) and Ubuntu 24.04 (kernel 6.17) work correctly on c8i when the vCPU is properly initialized.
The Fix
libc::ioctl()variadic FFI has ABI issues with KVM ioctls on some platforms. The smoke test is now inkvm_smoke.ccalled via FFI.Test Results
References