whp: implement safe wrappers for VM, vCPU, and instruction emulation#665
Open
lstocchi wants to merge 1 commit intocontainers:mainfrom
Open
whp: implement safe wrappers for VM, vCPU, and instruction emulation#665lstocchi wants to merge 1 commit intocontainers:mainfrom
lstocchi wants to merge 1 commit intocontainers:mainfrom
Conversation
This commit introduces the foundational Rust abstractions for the Windows Hypervisor Platform (WHP) backend. It encapsulates the raw C FFI bindings into safe, idiomatic Rust structs (`WhpVm`, `WhpVcpu`, and `WhpEmulator`). Key features include: - Partition & vCPU Management: Safe wrappers for partition configuration, CPUID masking, memory mapping, and `WHvRunVirtualProcessor` exit routing. - High-Performance Register I/O: Introduces const-generic helpers (`get_registers<N>` and `set_registers<N>`) to guarantee stack-allocated, zero-overhead register reads/writes on the VM-exit hot path. - Robust TSC Calibration: Implements accurate host TSC frequency detection via CPUID 0x15/0x16, with a reliable `QueryPerformanceCounter` (QPC) calibration fallback for AMD/older hardware. - Emulation: Integrates WHP's built-in x86 emulator for MMIO and PIO handling. - Undocumented WHP Workarounds: Implements the `clear_halt_suspend` workaround using `WHvRegisterInternalActivityState`. This ports a known QEMU/crosvm fix that manually clears the `HaltSuspend` bit, preventing vCPUs from freezing when interrupts are injected via `WHvRequestInterrupt` while in a HLT state. Signed-off-by: lstocchi <lstocchi@redhat.com>
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.
This commit introduces the foundational Rust abstractions for the Windows Hypervisor Platform (WHP) backend. I took inspiration from the hvf crate (you'll find
WhpVm,WhpVcpu, andWhpEmulator).Key features include:
WHvRunVirtualProcessorexit routing.get_registers<N>andset_registers<N>) to guarantee stack-allocated, zero-overhead register reads/writes on the VM-exit hot path.QueryPerformanceCounter(QPC) calibration fallback for AMD/older hardware.clear_halt_suspendworkaround usingWHvRegisterInternalActivityState. This ports a known QEMU/crosvm fix that manually clears theHaltSuspendbit, preventing vCPUs from freezing when interrupts are injected viaWHvRequestInterruptwhile in a HLT state.In a follow-up PR i'll add the hyper-v enlightements as this is already a big one.