Skip to content

Commit 08ec97b

Browse files
committed
whp: implement safe wrappers for VM, vCPU, and instruction emulation
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>
1 parent 391409d commit 08ec97b

4 files changed

Lines changed: 954 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"src/vmm",
1616
"src/aws_nitro",
1717
"src/rutabaga_gfx",
18+
"src/whp",
1819
]
1920
exclude = ["examples/gtk_display"]
2021
resolver = "2"

src/whp/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "krun-whp"
3+
version = "0.1.0-1.18.0"
4+
authors = ["The libkrun Authors"]
5+
edition = "2021"
6+
description = "Windows Hypervisor Platform backend for libkrun"
7+
license = "Apache-2.0"
8+
repository = "https://github.com/containers/libkrun"
9+
10+
[dependencies]
11+
log = "0.4.0"
12+
13+
[target.'cfg(target_os = "windows")'.dependencies]
14+
windows-sys = { version = "0.61.2", features = [
15+
"Win32_Foundation",
16+
"Win32_System_Hypervisor",
17+
"Win32_System_Performance",
18+
] }

0 commit comments

Comments
 (0)