Skip to content

[nanvix] Add Linux/KVM Support#445

Merged
huzaifa-d merged 2 commits into
mainfrom
user/ppenna/nanvix-kvm-support
May 28, 2026
Merged

[nanvix] Add Linux/KVM Support#445
huzaifa-d merged 2 commits into
mainfrom
user/ppenna/nanvix-kvm-support

Conversation

@ppenna

@ppenna ppenna commented May 28, 2026

Copy link
Copy Markdown
Contributor

📖 Description

Extends the Nanvix MicroVM containment backend to Linux via KVM, mirroring the existing Windows/WHP implementation, and adds a Linux E2E test suite to cover it.

Runtime (wxc_common/src/nanvix_runner.rs)

  • Split runner internals along target_os: Windows keeps the WHP snapshot warm-start; Linux cold-boots the VM via KVM on every invocation (no snapshot, no -snapshot/-bin-dir args; cwd set to exe dir).
  • Generalize the watchdog: usize carries a duplicated process HANDLE on Windows and the child PID on Linux; on timeout, Linux delivers SIGKILL via libc::kill instead of TerminateProcess.
  • Gate snapshot resolution, NANVIX_HOME, DEFAULT_HOME_LEAF, and SNAPSHOT_CBOR behind cfg(target_os = "windows").
  • Use nanvix_common::NANVIXD_BINARY for the platform-correct daemon name (nanvixd.exe / nanvixd.elf).
  • New unit tests: signal-killed copyback skip, platform constant check, total-timeout sentinel/overflow, NanVixError display variants.

Staging (wxc_common/src/microvm_staging.rs)

  • Fix host_path_to_guest_relative to strip leading slashes so Linux absolute paths (/tmp/xyz) become guest-relative (tmp/xyz).
  • Update existing rewrite test for the Linux case where the host path is a substring of the guest path; add two new tests covering leading-slash stripping.

lxc binary (src/lxc)

  • Add microvm cargo feature that enables wxc_common/microvm and depends on nanvix_binaries so KVM artifacts are downloaded/staged.
  • New build.rs copies staged Nanvix artifacts next to lxc-exec using nanvix_common::copy_artifacts_to_target and DEP_NANVIX_BINARIES_BIN_DIR.
  • Wire ContainmentBackend::MicroVm in main.rs: gated by --experimental, returns NanVixScriptRunner when compiled with microvm, otherwise exits with a clear error.

nanvix_binaries (src/nanvix_binaries)

  • Build script now handles target_os = "linux" in addition to Windows: downloads microvm-standalone-256mb.tar.gz, extracts flat binaries from <prefix>/ and kernel files from <prefix>/bin/ via tar --strip-components, and verifies SHA256 sums via sha256sum. Snapshot pre-generation remains Windows-only.
  • versions.json: bump tag to 3.12.3-nanvix-0.15.19-9558cff and add asset_linux / binaries_linux fields.
  • checksums.json: restructured into per-platform { "windows": .., "linux": .. } sub-maps with new hashes for both targets.

nanvix_common (src/nanvix_common)

  • REQUIRED_BINARIES and new NANVIXD_BINARY are cfg-gated per target_os so both daemons can be referenced symbolically.
  • RepoConfig gains optional asset_linux / binaries_linux fields (serde default).
  • load_checksums accepts either the legacy flat map or the new platform-keyed form, selected by a platform: &str argument.

wxc_common (Cargo.toml + lib.rs)

  • Move nanvix_common and uuid out of the Windows-only target section so the microvm feature works on Linux; add a Linux-only libc dep used by the watchdog SIGKILL path.
  • Drop the target_os = "windows" gate from microvm_staging and nanvix_runner module declarations (the runner now compiles on Linux too).

Build & docs

  • build.sh: add --with-microvm flag, composed with --with-hyperlight via a FEATURES_LIST array.
  • docs/nanvix-microvm/nanvix.md: document Linux prerequisites (/dev/kvm, lxc-exec, --with-microvm) and note that warm-start via snapshots is Windows-only.

E2E tests (tests/e2e_linux_microvm.rs + test_configs/microvm_*_linux.json)

  • Mirrors the Windows MicroVM E2E suite, invoking lxc-exec directly with containment=microvm.
  • Adds skip guards (has_lxc_exe, has_lxc_nanvix_binaries, has_kvm), a full-suite test with per-case timing emitted to microvm-perf-results-linux.json, and an #[ignore] repeat-stress test.
  • Adds 7 new test_configs/microvm_*_linux.json covering hello, exit code, multiline, stdlib, large output, exception, and timeout cases.

No schema or SDK changes — backend selection still uses "containment": "microvm".

🔗 References

None.

🔍 Validation

  • cargo build --release -p lxc --features microvm on Linux x86_64.
  • cargo test -p wxc_common — new unit tests for the watchdog signal-kill skip, platform constants, timeout sentinel/overflow, NanVixError display, and the staging leading-slash stripping all pass.
  • cargo test -p wxc_e2e_tests --test e2e_linux_microvm against a host with /dev/kvm and a built lxc-exec — all 7 cases pass and microvm-perf-results-linux.json is emitted.
  • Existing Windows MicroVM path unchanged; Windows behavior verified to still cold-resolve snapshot + warm-start via WHP.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

@ppenna ppenna self-assigned this May 28, 2026
Copilot AI review requested due to automatic review settings May 28, 2026 03:45
@ppenna
ppenna force-pushed the user/ppenna/nanvix-kvm-support branch from fd59aa6 to d05e1b1 Compare May 28, 2026 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Linux/KVM support for the NanVix MicroVM backend, aligning the Rust runtime and build/staging pipeline with the existing Windows/WHP implementation, and introduces a Linux-focused E2E test suite plus new test configs.

Changes:

  • Extends NanVixScriptRunner and staging logic to compile/run on Linux (cold-boot via KVM; Windows keeps snapshot warm-start).
  • Adds Linux E2E tests that invoke lxc-exec with containment=microvm, along with new Linux microvm test_configs/.
  • Updates build + binary acquisition to support Linux NanVix artifacts (new versions/checksums layout) and adds a --with-microvm option to build.sh.
Show a summary per file
File Description
test_configs/microvm_hello_linux.json New Linux MicroVM “hello” config.
test_configs/microvm_exit_code_linux.json New Linux MicroVM exit-code propagation config.
test_configs/microvm_multiline_linux.json New Linux MicroVM multi-line script config.
test_configs/microvm_stdlib_linux.json New Linux MicroVM stdlib import/use config.
test_configs/microvm_large_output_linux.json New Linux MicroVM large-output config.
test_configs/microvm_error_linux.json New Linux MicroVM exception config.
test_configs/microvm_timeout_linux.json New Linux MicroVM timeout config.
src/wxc_e2e_tests/tests/e2e_linux_microvm.rs Adds a Linux MicroVM E2E suite + perf output + stress test.
src/wxc_e2e_tests/src/lib.rs Adds Linux target triples and helpers to locate/run lxc-exec + prerequisites (/dev/kvm, staged NanVix binaries).
src/wxc_common/src/nanvix_runner.rs Splits Windows vs Linux runner behavior; Linux KVM cold-boot; Linux watchdog uses SIGKILL. Adds unit tests.
src/wxc_common/src/microvm_staging.rs Fixes Linux absolute-path handling by stripping leading slashes; updates/adds tests.
src/wxc_common/src/lib.rs Builds microvm modules when feature="microvm" is enabled (now not Windows-only).
src/wxc_common/Cargo.toml Moves microvm deps out of Windows-only section; adds Linux-only libc dep.
src/nanvix_common/src/lib.rs Adds platform-conditional REQUIRED_BINARIES + NANVIXD_BINARY; extends repo config for Linux; updates checksum loader to accept platform-keyed format.
src/nanvix_binaries/versions.json Bumps pinned tag; adds Linux asset/binaries fields.
src/nanvix_binaries/checksums.json Restructures checksums into { windows: {...}, linux: {...} } with updated hashes.
src/nanvix_binaries/build.rs Adds Linux download/extract/verify flow for tar.gz assets; retains Windows snapshot pre-generation behavior.
src/lxc/src/main.rs Wires ContainmentBackend::MicroVm for lxc-exec behind --experimental and the microvm feature.
src/lxc/Cargo.toml Adds microvm feature (pulls in wxc_common/microvm + nanvix_binaries) and a build-dependency on nanvix_common.
src/lxc/build.rs Copies staged NanVix artifacts next to the built lxc-exec when microvm is enabled.
src/Cargo.lock Updates dependency graph for new feature/deps.
docs/nanvix-microvm/nanvix.md Documents Linux/KVM prerequisites and clarifies Windows-only snapshot warm-start.
build.sh Adds --with-microvm and composes features with --with-hyperlight.

Copilot's findings

Comments suppressed due to low confidence (1)

src/wxc_common/Cargo.toml:48

  • On Linux, libc is only used by the MicroVM watchdog path (nanvix_runner), but it is currently an unconditional dependency for all Linux builds of wxc_common. Making it an optional dependency enabled by the microvm feature would avoid pulling libc into non-microvm builds.
[target.'cfg(target_os = "linux")'.dependencies]
libc = { workspace = true }

  • Files reviewed: 22/23 changed files
  • Comments generated: 3

Comment thread src/wxc_common/src/lib.rs Outdated
Comment thread docs/nanvix-microvm/nanvix.md Outdated
Comment thread src/wxc_common/src/nanvix_runner.rs
@ppenna
ppenna marked this pull request as draft May 28, 2026 03:54
@ppenna ppenna closed this May 28, 2026
@ppenna
ppenna deleted the user/ppenna/nanvix-kvm-support branch May 28, 2026 05:10
@ppenna ppenna reopened this May 28, 2026
@ppenna
ppenna force-pushed the user/ppenna/nanvix-kvm-support branch 2 times, most recently from 8910e8f to 8e98fd0 Compare May 28, 2026 06:25
@ppenna
ppenna marked this pull request as ready for review May 28, 2026 15:18
Comment thread src/nanvix_common/src/lib.rs Outdated
Comment thread src/wxc_common/src/nanvix_runner.rs Outdated
ppenna added 2 commits May 28, 2026 11:54
Extends the Nanvix MicroVM containment backend to run on Linux via KVM,
mirroring the existing Windows/WHP implementation. The `lxc-exec` binary
gains a `microvm` containment option behind the `microvm` cargo feature
and the `--experimental` runtime flag.

Runtime (src/wxc_common/src/nanvix_runner.rs)
- Split runner internals along target_os: Windows keeps WHP snapshot
  warm-start; Linux cold-boots the VM via KVM on every invocation
  (no snapshot, no `-snapshot`/`-bin-dir` args; cwd set to exe dir).
- Generalize watchdog: `usize` carries a duplicated process HANDLE on
  Windows and the child PID on Linux; on timeout, Linux delivers
  SIGKILL via `libc::kill` instead of `TerminateProcess`.
- Gate snapshot resolution, `NANVIX_HOME`, `DEFAULT_HOME_LEAF`, and
  `SNAPSHOT_CBOR` behind `cfg(target_os = "windows")`.
- Use `nanvix_common::NANVIXD_BINARY` for the platform-correct daemon
  name (`nanvixd.exe` / `nanvixd.elf`).
- New unit tests: signal-killed copyback skip, platform constant check,
  total_timeout sentinel/overflow, NanVixError display variants.

Staging (src/wxc_common/src/microvm_staging.rs)
- Fix `host_path_to_guest_relative` to strip leading slashes so Linux
  absolute paths (`/tmp/xyz`) become guest-relative (`tmp/xyz`).
- Update existing rewrite test to handle the Linux case where the host
  path is a substring of the guest path; add two new tests covering
  leading-slash stripping.

lxc binary (src/lxc)
- Add `microvm` feature that enables `wxc_common/microvm` and depends
  on `nanvix_binaries` so KVM artifacts are downloaded/staged.
- New `build.rs` copies the staged Nanvix artifacts next to `lxc-exec`
  using `nanvix_common::copy_artifacts_to_target` and
  `DEP_NANVIX_BINARIES_BIN_DIR`.
- Wire `ContainmentBackend::MicroVm` in main.rs: gated by
  `--experimental`, returns `NanVixScriptRunner` when compiled with
  `microvm`, otherwise exits with a clear error.

nanvix_binaries (src/nanvix_binaries)
- Build script now handles `target_os = "linux"` in addition to
  Windows: downloads `microvm-standalone-256mb.tar.gz`, extracts flat
  binaries from `<prefix>/` and kernel files from `<prefix>/bin/` via
  `tar --strip-components`, and verifies SHA256 sums using
  `sha256sum`. Snapshot pre-generation is Windows-only.
- versions.json: add `asset_linux` / `binaries_linux` fields for
  the Linux tar.gz asset (Windows tag/asset unchanged).
- checksums.json: restructured into per-platform `{ "windows": ..,
  "linux": .. }` sub-maps; new Linux hashes added, Windows hashes
  unchanged.

nanvix_common (src/nanvix_common)
- `REQUIRED_BINARIES` and new `NANVIXD_BINARY` are now cfg-gated per
  target_os so both daemons can be referenced symbolically.
- `RepoConfig` gains optional `asset_linux` / `binaries_linux` fields
  (serde default).
- `load_checksums` accepts either the legacy flat map or the new
  platform-keyed form, selected by a `platform: &str` argument.

wxc_common (src/wxc_common/Cargo.toml + src/lib.rs)
- Move `nanvix_common` and `uuid` out of the Windows-only target
  section so the `microvm` feature works on Linux; add Linux-only
  `libc` dep used by the watchdog SIGKILL path.
- Drop `target_os = "windows"` gate from `microvm_staging` and
  `nanvix_runner` module declarations (the runner now compiles on
  Linux too).

Build & docs
- build.sh: add `--with-microvm` flag, composed with `--with-hyperlight`
  via a `FEATURES_LIST` array.
- docs/nanvix-microvm/nanvix.md: document Linux prerequisites
  (`/dev/kvm`, `lxc-exec`, `--with-microvm`) and note that warm-start
  via snapshots is Windows-only.

No schema or SDK changes; backend selection still uses
`"containment": "microvm"`.
Mirrors the Windows MicroVM E2E suite in `tests/e2e_linux_microvm.rs`,
invoking `lxc-exec` directly with `containment=microvm`. Adds skip
guards (`has_lxc_exe`, `has_lxc_nanvix_binaries`, `has_kvm`), a
full-suite test with per-case timing emitted to
`microvm-perf-results-linux.json`, and an `#[ignore]` repeat-stress
test. Includes 7 new `test_configs/microvm_*_linux.json` covering
hello, exit code, multiline, stdlib, large output, exception, and
timeout cases.
@ppenna
ppenna force-pushed the user/ppenna/nanvix-kvm-support branch from b473954 to 9f3c274 Compare May 28, 2026 18:54
@bbonaby

bbonaby commented May 28, 2026

Copy link
Copy Markdown
Collaborator

closing and reopening to see if that updates the ADO status syncing

@bbonaby bbonaby closed this May 28, 2026
@bbonaby bbonaby reopened this May 28, 2026
@huzaifa-d

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@huzaifa-d
huzaifa-d merged commit a8cd650 into main May 28, 2026
22 checks passed
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.

4 participants