Repository navigation
feat(runtime): support nested virtualization on Windows x86_64 hosts - #10
olebhansen wants to merge 3 commits into
Conversation
29be50d to
9e43b12
Compare
msb_krun 0.1.42 can enable nested virtualization in WHP partitions, which Windows hosts need before a sandbox can opt in to it. It also changes Windows x86_64 full snapshots: WHP execution state now carries the emulated PIT and uses backend state ABI 2. This runtime refuses earlier Windows full snapshots with libkrun's missing-PIT error, and earlier runtimes refuse the new ABI; disk-only snapshots and other hosts are unchanged. Windows guests also boot with tsc_early_khz from the WHP processor clock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50eb730 to
ba6de0e
Compare
The Windows host check now accepts Windows x86_64 when the Windows Hypervisor Platform sets up a one-vCPU partition with nesting and xAPIC emulation enabled, the configuration libkrun uses. WHP refuses nesting at setup without the local APIC emulation. WinHvPlatform.dll is loaded at run time, as Hypervisor.framework is on macOS, so processes that link the runtime still start on hosts without the optional feature. Sandboxes on Windows 11 can then opt in to nested virtualization; the launch key, record field and runtime capability are unchanged. An older Windows runtime already advertises the capability but refuses nesting when the VM starts, so a current SDK that resolves such a runtime fails at start instead of at admission. Runtimes ship with the SDK, so this is accepted rather than guarded by another capability. The Windows CI job runs the host check tests, which accept either result on hosted runners. MSB_TEST_EXPECT_NESTED_VIRT now also makes the unit test fail when a host expected to nest is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…away The SDK starts a detached runtime with CREATE_BREAKAWAY_FROM_JOB so that it outlives the launcher's job object. When the launcher is in a job without JOB_OBJECT_LIMIT_BREAKAWAY_OK, CreateProcess refuses with ERROR_ACCESS_DENIED and the SDK reported a bare permission error that looked like a file problem. This hits `cargo test`, whose kill-on-close job breaks create_detached() and modify().restart(), and agentd started from sandboxed tool shells. Retry without the breakaway flag when the first attempt is refused, and log a warning. If the retry also fails, the error names the process start and both causes. Trade-off: a runtime started this way stays in the launcher's job, so it ends when that job is terminated or closed with kill-on-close, for example when the test run or the shell exits. The alternative is not starting at all, since such a job lets no child escape. Launchers in no job, or in a job that allows breakaway, behave as before. The launch contract is unchanged; COMPATIBILITY.md records the lifecycle change. The new test reproduces the refusal in a kill-on-close job without breakaway and checks that the detached process starts inside that job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ba6de0e to
1727197
Compare
|
@martinothamar This is ready for the QA round. Per your comment, The QA checklist per platform is in the description under QA. On Windows 11 with Intel, both |
|
Back to draft. Investigating if this can be superseeded by upstream, now that superradcompany#823 is merged. |
|
@martinothamar, I'm closing this one. Upstream merged its nested virtualization work into What that means here:
|
Brings nested virtualization (
nested_virt) to Windows x86_64 hosts in the fork, sonestedSandboxesworks for digdir-agents on Windows before the next agentctl release instead of waiting for upstream (digdir/digdir-agents#173). Upstream's own nested virtualization work also covers Windows onmsb_krun0.1.42 and adds nested snapshots. When the fork syncs to an upstream release that contains it, these commits should drop out of the queue. This PR keeps to the singlenested_virtcapability that upstream is likely to keep.Commits
chore(deps): bump libkrun to 0.1.42.msb_krun0.1.42 setsWHvPartitionPropertyCodeNestedVirtualizationon WHP partitions when nesting is enabled. 0.1.41 only left VMX/SVM in the guest CPUID. The bump also brings libkrun's nested-snapshot and timer work, changes Windows x86_64 full snapshots (see Compatibility), and boots Windows guests withtsc_early_khzfrom the WHP clock.feat(runtime): support nested virtualization on Windows x86_64 hosts.host_support()on Windows x86_64 creates a one-vCPU WHP partition with nesting and xAPIC emulation, sets it up and deletes it. That is the configuration libkrun uses, and WHP refuses nesting at setup without the local APIC emulation.WinHvPlatform.dllis loaded at run time, asHypervisor.frameworkis on macOS. The commit also updates the docs andCOMPATIBILITY.md, and adds a Windows CI step for the host-check tests.fix(spawn): start detached Windows runtimes in jobs that forbid breakaway. The SDK starts detached runtimes withCREATE_BREAKAWAY_FROM_JOB. Inside a job object without breakaway, such ascargo testor some sandboxed tool shells, that failed with a barePermissionDenied(os error 5). The SDK now retries without breakaway and logs a warning; the runtime then stays in the caller's job. It is independent of nesting, but without it the Windows integration tests cannot run undercargo test.The guest kernel needs no change. The released
libkrunfw-windows-x86_64.dllis built from the Linux x86_64 config and already haskvm_intelandkvm_amdbuilt in.Compatibility
nested_virtbut refuses nesting when the VM starts. A current SDK that resolves such a runtime therefore fails at start, afterreplaceor amodifyrestart has changed the sandbox. That is accepted because the runtime ships with the SDK.QA
Suggested round before the next agentctl release. Run the integration tests with
MSB_TEST_EXPECT_NESTED_VIRT=1on hosts that support nesting:modify().restart().nested_virthas no/dev/kvm.nested_virtexposes/dev/kvm, andmsbinside the guest boots its own sandbox.0.7.11-digdir.1is refused with the missing-PIT message.cargo test(not only nextest) runs the integration tests.nestedSandboxes: requiredreports theNestedSandboxescondition as available on Windows. It can then run nested Agents.Evidence so far
On Windows 11 Enterprise 26200, Intel Core Ultra 7 155H, VBS/HVCI on:
MSB_TEST_EXPECT_NESTED_VIRT=1 cargo test -p microsandbox-runtime --lib nested_virtpasses.nested_virtandruntime::spawn::tests::windows_tests.cargo clippy -p microsandbox-cli -p microsandbox-runtime -p microsandbox -- -D warningsis clean.sdk/rust/tests/nested_virt.rspass under plaincargo test, which exercises the breakaway fallback. They ran against themsb.exebuilt from this branch, with thelibkrunfw-windows-x86_64.dllfromv0.7.11-digdir.1andMSB_TEST_EXPECT_NESTED_VIRT=1. Before commit 3,nested_virt_can_be_modified_on_an_existing_sandboxfailed undercargo testwith os error 5.msbfromv0.7.8-digdir.2ranmsb run alpinein about 3 s.nestedSandboxes: required. T3 Code created nested worker Agents throughagentctlin it and connected to one over SSH.Not covered here: AMD Windows, macOS and Linux, and real Windows full snapshots across versions. Hosted CI runners probably lack nesting, so CI only exercises the probe.
🤖 Generated with Claude Code