From d9623938d1fdc232524091058808d8daa44175dd Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:14:43 -0800 Subject: [PATCH 1/9] arm64: extend shared cold-runtime validation Run the maintained host/PE probes, cold scenario inventory, bounded same-provision repetitions and cold runtime-adapter tests on native ARM64/WHP while retaining x86 defaults and full snapshot tails. Carry architecture through existing artifact producers and CI callers, require upstream Windows ARM unit/VMM evidence in addition to x86 jobs, and preserve the existing workflow/repository trust filter. Export the real ARM counter warp helper and correct ISA-specific device, SMP, layered-bootstrap and console observations. Pin the published OpenVMM verifier without rewriting the Phase 1/2 prefix. Native functional evidence covers 45 cold CLI cells, 115 adapter tests and 128 repetition CLI invocations. H4/H7, full UTC qualification and actual CI service admission remain unqualified; no ARM release-catalog or snapshot qualification is claimed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../actions/build-guest-artifacts/action.yml | 111 +- .github/actions/build-openvmm/action.yml | 6 + .github/actions/validate-runner/action.yml | 95 +- .github/workflows/build-openvmm-binary.yml | 7 + .github/workflows/ci.yml | 401 ++++++- .github/workflows/run-nvx-microvm-tests.yml | 223 +++- doc/build.md | 19 +- doc/ci.md | 79 +- doc/openvmm-upstream-roadmap.md | 41 +- doc/usage.md | 108 +- .../arm64/0001-nvx-platform-mmio.patch | 26 +- nvx-rs/README.md | 7 +- nvx-rs/src/bin/nvx-time-probe.rs | 12 +- nvx-rs/src/guest/mod.rs | 2 +- nvx-rs/src/guest/parse.rs | 1 - nvx-rs/src/guest/status.rs | 3 - nvx-rs/src/guest/sys/clock.rs | 2 - nvx-rs/src/guest/sys/mod.rs | 6 +- nvx-rs/src/guest/sys/scheduler.rs | 3 - nvx-rs/src/guest/time_probe/format.rs | 7 + nvx-rs/src/guest/time_probe/format/tests.rs | 12 +- nvx-rs/src/guest/time_probe/mod.rs | 24 +- nvx-rs/src/guest/time_probe/support.rs | 60 +- nvx-rs/src/guest/time_probe/support/tests.rs | 13 +- nvx-rs/src/guest/time_probe/tests.rs | 45 + nvx-rs/src/guest/time_probe/warp.rs | 135 ++- nvx-rs/src/guest/time_probe/warp/tests.rs | 18 + nvx-rs/src/host/cli/cpu_generations.json | 26 + nvx-rs/src/host/cli/cpu_profile.rs | 15 +- nvx-rs/tests/guest_tools.rs | 23 +- nvx-rs/tests/openvmm_cpu_profiles.rs | 31 +- openvmm | 2 +- scripts/nvx_tools/benchmark.py | 12 +- .../benchmark_scripts/smp-probe.sh.in | 92 +- scripts/nvx_tools/ci.py | 43 + scripts/nvx_tools/common.py | 33 + scripts/nvx_tools/doctor.py | 244 +++- scripts/nvx_tools/guest_binaries.py | 4 +- scripts/nvx_tools/host_time_probe.rs | 89 +- scripts/nvx_tools/microvm_durations.py | 13 +- scripts/nvx_tools/microvm_shards.py | 2 + .../microvm_test_scripts/filesystem-shares.sh | 4 +- .../microvm_test_scripts/interrupt-map.sh.in | 39 +- .../microvm_test_scripts/lifecycle.sh | 31 +- .../microvm_test_scripts/sandbox-blocks.sh | 8 +- .../microvm_test_scripts/virtio-mmio.sh | 63 + .../microvm_test_scripts/virtio-net.sh | 2 +- scripts/nvx_tools/microvm_tests.py | 406 ++++++- scripts/nvx_tools/openvmm_ci.py | 25 +- scripts/nvx_tools/runtime_adapter_tests.py | 144 ++- scripts/nvx_tools/sandbox_lifecycle_tests.py | 35 +- scripts/nvx_tools/sandbox_ram_upper_tests.py | 61 +- scripts/nvx_tools/time_abi.py | 72 +- scripts/setup/README.md | 18 +- scripts/setup/setup-linux.sh | 2 +- scripts/setup/setup-windows-whp.ps1 | 114 +- scripts/setup/tool-versions.conf | 10 +- scripts/test-layout-allowlist.json | 8 +- scripts/test_guest_binaries.py | 19 +- scripts/test_microvm_tests.py | 588 +++++++++- scripts/test_nvx_tools.py | 1032 ++++++++++++++--- scripts/test_time_abi.py | 404 ++++++- scripts/test_tool_versions.py | 156 ++- tests/runtime-adapter/README.md | 20 +- 64 files changed, 4728 insertions(+), 628 deletions(-) create mode 100644 scripts/nvx_tools/microvm_test_scripts/virtio-mmio.sh diff --git a/.github/actions/build-guest-artifacts/action.yml b/.github/actions/build-guest-artifacts/action.yml index bb2ed0018..a0d875a68 100644 --- a/.github/actions/build-guest-artifacts/action.yml +++ b/.github/actions/build-guest-artifacts/action.yml @@ -2,6 +2,12 @@ name: Build guest artifacts description: Cache or build the pinned Linux kernel and guest images inputs: + architecture: + description: >- + Guest ISA. ARM uses fresh native Docker builds only, with no x86 cache, + artifact reuse, determinism, Azure Linux, or debug-kernel claim. + required: false + default: x86_64 components: description: >- Space-separated guest artifacts to cache or build, so that jobs beside @@ -43,6 +49,9 @@ inputs: default: "false" outputs: + artifact-directory: + description: Architecture-qualified output directory + value: ${{ steps.architecture.outputs.directory }} cache-keys: description: >- The exact cache keys of the guest artifacts, as a JSON object by name, @@ -72,6 +81,59 @@ outputs: runs: using: composite steps: + - name: Select native guest architecture + id: architecture + shell: bash + env: + ARCHITECTURE: ${{ inputs.architecture }} + COMPONENTS: ${{ inputs.components }} + RESTORE_ONLY: ${{ inputs.restore-only }} + SAVE_CACHE: ${{ inputs.save-cache }} + REUSE: ${{ inputs.reuse }} + RECORD: ${{ inputs.record-artifact }} + run: | + set -euo pipefail + case "${ARCHITECTURE}" in + x86_64) + echo "directory=build" >> "${GITHUB_OUTPUT}" + echo "platform=linux/amd64" >> "${GITHUB_OUTPUT}" + echo "kernel-target=kernel-artifacts" >> "${GITHUB_OUTPUT}" + echo "alpine-target=initramfs-artifacts" >> "${GITHUB_OUTPUT}" + echo "ubuntu-target=ubuntu-initramfs-artifacts" >> "${GITHUB_OUTPUT}" + echo "distro-target=ubuntu-distro-layer-artifacts" >> "${GITHUB_OUTPUT}" + ;; + aarch64) + if [[ "${RESTORE_ONLY}" != false || "${SAVE_CACHE}" != false || + "${REUSE}" != false || -n "${RECORD}" ]]; then + echo "::error::ARM guest artifacts require explicit fresh-only builds; x86 cache/reuse records are not ARM provenance" >&2 + exit 1 + fi + case " ${COMPONENTS} " in + *" azurelinux "* | *" debug-kernel "*) + echo "::error::ARM cold scope has no Azure Linux or debug-kernel component" >&2 + exit 1 + ;; + esac + engine=$(docker info --format '{{.Architecture}}') + case "${engine}" in + aarch64 | arm64) ;; + *) + echo "::error::ARM producers require a native ARM Docker engine, not ${engine} emulation" >&2 + exit 1 + ;; + esac + echo "directory=build/aarch64" >> "${GITHUB_OUTPUT}" + echo "platform=linux/arm64" >> "${GITHUB_OUTPUT}" + echo "kernel-target=arm64-kernel-artifacts" >> "${GITHUB_OUTPUT}" + echo "alpine-target=arm64-artifacts" >> "${GITHUB_OUTPUT}" + echo "ubuntu-target=arm64-ubuntu-artifacts" >> "${GITHUB_OUTPUT}" + echo "distro-target=arm64-ubuntu-distro-layer-artifacts" >> "${GITHUB_OUTPUT}" + ;; + *) + echo "::error::Unsupported guest architecture: ${ARCHITECTURE}" >&2 + exit 1 + ;; + esac # An unknown name fails here rather than silently selecting nothing. - name: Select guest artifact components id: components @@ -128,6 +190,7 @@ runs: - name: Resolve guest cache keys id: guest-cache-keys + if: inputs.architecture == 'x86_64' shell: bash env: KERNEL_VERSION: ${{ steps.guest-versions.outputs.kernel-version }} @@ -159,7 +222,7 @@ runs: - name: Restore Linux kernel (zstd) id: cache-linux-kernel-zstd - if: steps.components.outputs.kernel == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.kernel == 'true' uses: actions/cache/restore@v5 with: path: | @@ -171,7 +234,7 @@ runs: - name: Restore Alpine disk image (zstd) id: cache-alpine-image-zstd - if: steps.components.outputs.alpine == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.alpine == 'true' uses: actions/cache/restore@v5 with: path: | @@ -183,7 +246,7 @@ runs: - name: Restore Ubuntu initramfs (zstd) id: cache-ubuntu-initramfs-zstd - if: steps.components.outputs.ubuntu == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.ubuntu == 'true' uses: actions/cache/restore@v5 with: path: | @@ -194,7 +257,7 @@ runs: - name: Restore Ubuntu distro layer (zstd) id: cache-ubuntu-distro-zstd - if: steps.components.outputs.ubuntu == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.ubuntu == 'true' uses: actions/cache/restore@v5 with: path: | @@ -206,7 +269,7 @@ runs: - name: Restore Azure Linux initramfs (zstd) id: cache-azurelinux-initramfs-zstd - if: steps.components.outputs.azurelinux == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.azurelinux == 'true' uses: actions/cache/restore@v5 with: path: | @@ -225,6 +288,7 @@ runs: - name: Reuse the merged pull request's guest artifacts id: reuse if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.reuse == 'true' && inputs.record-artifact != '' @@ -253,13 +317,16 @@ runs: shell: bash run: >- docker build + --platform "${{ steps.architecture.outputs.platform }}" + --build-arg NVX_ARCHITECTURE="${{ inputs.architecture }}" --file docker/Dockerfile - --target kernel-artifacts - --output type=local,dest=build + --target "${{ steps.architecture.outputs.kernel-target }}" + --output type=local,dest="${{ steps.architecture.outputs.directory }}" . - name: Save Linux kernel (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.kernel == 'true' && @@ -275,7 +342,7 @@ runs: - name: Restore Linux debug kernel (zstd) id: cache-linux-debug-kernel-zstd - if: steps.components.outputs.debug-kernel == 'true' + if: inputs.architecture == 'x86_64' && steps.components.outputs.debug-kernel == 'true' uses: actions/cache/restore@v5 with: path: | @@ -300,6 +367,7 @@ runs: - name: Save Linux debug kernel (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.debug-kernel == 'true' && @@ -322,13 +390,16 @@ runs: shell: bash run: >- docker build + --platform "${{ steps.architecture.outputs.platform }}" + --build-arg NVX_ARCHITECTURE="${{ inputs.architecture }}" --file docker/Dockerfile - --target initramfs-artifacts - --output type=local,dest=build + --target "${{ steps.architecture.outputs.alpine-target }}" + --output type=local,dest="${{ steps.architecture.outputs.directory }}" . - name: Save Alpine disk image (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.alpine == 'true' && @@ -351,15 +422,18 @@ runs: shell: bash run: >- docker build + --platform "${{ steps.architecture.outputs.platform }}" + --build-arg NVX_ARCHITECTURE="${{ inputs.architecture }}" --file docker/Dockerfile - --target ubuntu-initramfs-artifacts - --output type=local,dest=build + --target "${{ steps.architecture.outputs.ubuntu-target }}" + --output type=local,dest="${{ steps.architecture.outputs.directory }}" . # A reused image passed this check in the run that built it, as a cached # one did. - name: Verify Ubuntu artifact determinism (Docker) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && ( steps.components.outputs.ubuntu == 'true' && @@ -378,6 +452,7 @@ runs: - name: Save Ubuntu initramfs (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.ubuntu == 'true' && @@ -411,6 +486,7 @@ runs: - name: Save Azure Linux initramfs (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.azurelinux == 'true' && @@ -434,13 +510,16 @@ runs: shell: bash run: >- docker build + --platform "${{ steps.architecture.outputs.platform }}" + --build-arg NVX_ARCHITECTURE="${{ inputs.architecture }}" --file docker/Dockerfile - --target ubuntu-distro-layer-artifacts - --output type=local,dest=build + --target "${{ steps.architecture.outputs.distro-target }}" + --output type=local,dest="${{ steps.architecture.outputs.directory }}" . - name: Save Ubuntu distro layer (zstd) if: >- + inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.save-cache == 'true' && steps.components.outputs.ubuntu == 'true' && @@ -458,7 +537,7 @@ runs: # and the dev push that merge this run's pull request can check them before # they reuse them. - name: Record guest artifact keys and digests - if: inputs.restore-only != 'true' && inputs.record-artifact != '' + if: inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.record-artifact != '' shell: bash env: COMPONENTS: ${{ inputs.components }} @@ -469,7 +548,7 @@ runs: --keys "${GUEST_CACHE_KEYS}" - name: Upload guest artifact record - if: inputs.restore-only != 'true' && inputs.record-artifact != '' + if: inputs.architecture == 'x86_64' && inputs.restore-only != 'true' && inputs.record-artifact != '' uses: actions/upload-artifact@v7 with: name: ${{ inputs.record-artifact }} diff --git a/.github/actions/build-openvmm/action.yml b/.github/actions/build-openvmm/action.yml index a271a26bc..a787d2ece 100644 --- a/.github/actions/build-openvmm/action.yml +++ b/.github/actions/build-openvmm/action.yml @@ -2,6 +2,10 @@ name: Build OpenVMM description: Checkout and cache or build one reusable OpenVMM binary inputs: + architecture: + description: Required native executable ISA + required: false + default: x86_64 ssh-key: description: SSH deploy key used to checkout OpenVMM required: true @@ -151,6 +155,8 @@ runs: if (-not (Test-Path -LiteralPath "${{ inputs.binary-path }}" -PathType Leaf)) { throw "OpenVMM binary was not produced: ${{ inputs.binary-path }}" } + python -c "import sys; from pathlib import Path; sys.path.insert(0, 'scripts'); from nvx_tools.common import require_pe_architecture; require_pe_architecture(Path('${{ inputs.binary-path }}'), '${{ inputs.architecture }}')" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - name: Verify OpenVMM provenance on Linux if: runner.os != 'Windows' diff --git a/.github/actions/validate-runner/action.yml b/.github/actions/validate-runner/action.yml index 849685be7..bc88760ad 100644 --- a/.github/actions/validate-runner/action.yml +++ b/.github/actions/validate-runner/action.yml @@ -2,6 +2,10 @@ name: Validate runner description: Verify the toolchain and virtualization backend required by an NVX job inputs: + architecture: + description: Native runner ISA, never an emulated process ISA + required: false + default: x86_64 backend: description: Virtualization backend expected on the runner required: true @@ -52,6 +56,12 @@ runs: exit 1 fi cargo --version + expected_host="${{ inputs.architecture }}-unknown-linux-gnu" + actual_host=$(rustc -vV | sed -n 's/^host: //p') + test "${actual_host}" = "${expected_host}" || { + echo "::error::Rust host ${actual_host} is not native ${expected_host}" >&2 + exit 1 + } cargo nextest --version sccache --version test "${RUSTC_WRAPPER:-}" = sccache @@ -110,6 +120,26 @@ runs: throw "$rustVersion does not match Rust $toolchain, which rust-toolchain.toml pins" } cargo --version + $architecture = "${{ inputs.architecture }}" + switch ($architecture) { + "x86_64" { $nativeArchitecture = "X64" } + "aarch64" { $nativeArchitecture = "Arm64" } + default { throw "Unsupported runner architecture: $architecture" } + } + $runtime = [System.Runtime.InteropServices.RuntimeInformation] + if ($runtime::OSArchitecture.ToString() -ne $nativeArchitecture -or + $runtime::ProcessArchitecture.ToString() -ne $nativeArchitecture) { + throw "Runner OS and PowerShell must both be native $nativeArchitecture" + } + $expectedHost = "$architecture-pc-windows-msvc" + $rustHost = (rustc -vV | Select-String '^host: ').Line.Substring(6) + if ($rustHost -ne $expectedHost) { + throw "Rust host $rustHost is not native $expectedHost" + } + if ($architecture -eq "aarch64" -and + -not [string]::IsNullOrWhiteSpace($env:CARGO_BUILD_TARGET)) { + throw "Native ARM builds require CARGO_BUILD_TARGET unset, not an inherited cross-build override" + } cargo nextest --version sccache --version if ($env:RUSTC_WRAPPER -ne "sccache") { @@ -152,19 +182,21 @@ runs: if ($jobSid -ne "S-1-5-20") { throw "Actions job uses SID $jobSid, expected Network Service" } - $system32 = Join-Path $env:SystemRoot "System32" - $pcatFirmware = @( - (Join-Path $system32 "vmfirmwarepcat.dll"), - (Join-Path $system32 "vmfirmware.dll") - ) - if (@($pcatFirmware | Where-Object { - Test-Path -LiteralPath $_ -PathType Leaf - }).Count -eq 0) { - throw "Hyper-V PCAT firmware was not found under $system32" - } - $svgaFirmware = Join-Path $system32 "VmEmulatedDevices.dll" - if (-not (Test-Path -LiteralPath $svgaFirmware -PathType Leaf)) { - throw "Hyper-V SVGA firmware was not found: $svgaFirmware" + if ($architecture -eq "x86_64") { + $system32 = Join-Path $env:SystemRoot "System32" + $pcatFirmware = @( + (Join-Path $system32 "vmfirmwarepcat.dll"), + (Join-Path $system32 "vmfirmware.dll") + ) + if (@($pcatFirmware | Where-Object { + Test-Path -LiteralPath $_ -PathType Leaf + }).Count -eq 0) { + throw "Hyper-V PCAT firmware was not found under $system32" + } + $svgaFirmware = Join-Path $system32 "VmEmulatedDevices.dll" + if (-not (Test-Path -LiteralPath $svgaFirmware -PathType Leaf)) { + throw "Hyper-V SVGA firmware was not found: $svgaFirmware" + } } # A cancelled job's harness can start OpenVMM after the runner's orphan @@ -271,6 +303,7 @@ runs: run: >- python3 scripts/nvx.py doctor --backend "${{ inputs.backend }}" + --architecture "${{ inputs.architecture }}" --checks H1 H2 H4 ${{ inputs.warp-probe == 'true' && 'H6' || '' }} ${{ inputs.verify-openvmm == 'true' && 'H3 --cpu-fingerprint "${RUNNER_TEMP}/nvx-cpu-fingerprint.json"' || '--no-openvmm' }} @@ -280,19 +313,37 @@ runs: - name: Qualify host time on Windows if: runner.os == 'Windows' shell: powershell - run: >- - python scripts\nvx.py doctor - --backend "${{ inputs.backend }}" - --checks H1 H2 H4 - ${{ inputs.warp-probe == 'true' && 'H6' || '' }} - ${{ inputs.verify-openvmm == 'true' && 'H3 --cpu-fingerprint "$env:RUNNER_TEMP\nvx-cpu-fingerprint.json"' || '--no-openvmm' }} - --ci-schedule - --summary "$env:GITHUB_STEP_SUMMARY" + run: | + $ErrorActionPreference = "Stop" + $architecture = "${{ inputs.architecture }}" + $checks = @("H1", "H2", "H4") + $arguments = @("--architecture", $architecture) + if ($architecture -eq "aarch64") { + if ("${{ inputs.verify-openvmm }}" -ne "true") { + # This is pre-build tooling/time admission, not CPU admission. + # Every ARM guest job must require the post-product H2/H3 gate. + $checks = @("H1", "H4") + Write-Output "ARM H2/H3 admission is pending the mandatory post-product verifier" + } + } + if ("${{ inputs.warp-probe }}" -eq "true") { $checks += "H6" } + if ("${{ inputs.verify-openvmm }}" -eq "true") { + $checks += "H3" + if ($architecture -eq "x86_64") { + $arguments += @("--cpu-fingerprint", "$env:RUNNER_TEMP\nvx-cpu-fingerprint.json") + } + } else { + $arguments += "--no-openvmm" + } + python scripts\nvx.py doctor --backend "${{ inputs.backend }}" ` + --checks @checks @arguments --ci-schedule ` + --summary "$env:GITHUB_STEP_SUMMARY" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # A failed CPU profile check keeps OpenVMM's fingerprint, which names the # host's whole CPU surface for a new generation or profile revision. - name: Upload the CPU fingerprint - if: failure() && inputs.verify-openvmm == 'true' + if: failure() && inputs.verify-openvmm == 'true' && inputs.architecture == 'x86_64' uses: actions/upload-artifact@v7 with: path: ${{ runner.temp }}/nvx-cpu-fingerprint.json diff --git a/.github/workflows/build-openvmm-binary.yml b/.github/workflows/build-openvmm-binary.yml index dc948a7f9..89fda792a 100644 --- a/.github/workflows/build-openvmm-binary.yml +++ b/.github/workflows/build-openvmm-binary.yml @@ -3,6 +3,11 @@ name: Build OpenVMM binary on: workflow_call: inputs: + architecture: + description: Native build runner ISA + required: false + type: string + default: x86_64 display-name: description: Platform name shown in the job list required: true @@ -46,6 +51,7 @@ jobs: uses: ./.github/actions/validate-runner with: backend: ${{ inputs.backend }} + architecture: ${{ inputs.architecture }} - name: Prepare sccache uses: ./.github/actions/sccache @@ -58,6 +64,7 @@ jobs: ssh-key: ${{ secrets.OPENVMM_DEPLOY_KEY }} backend: ${{ inputs.backend }} binary-path: ${{ inputs.binary }} + architecture: ${{ inputs.architecture }} - name: Report sccache if: always() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a26a46b97..a96873f27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,7 +200,7 @@ jobs: retention-days: 1 build-nvx-rs-windows-msvc: - name: nvx-rs binary / Windows MSVC + name: nvx-rs binary / Windows MSVC${{ matrix.architecture == 'aarch64' && ' / ARM64' || '' }} if: >- ${{ ( @@ -212,9 +212,17 @@ jobs: github.event.pull_request.head.repo.full_name == github.repository ) }} - runs-on: windows-latest + strategy: + fail-fast: false + matrix: + include: + - architecture: x86_64 + runner: windows-latest + target: x86_64-pc-windows-msvc + artifact: nvx-rs-windows-msvc + runs-on: ${{ matrix.runner }} timeout-minutes: 15 - steps: + steps: &windows-nvx-rs-build - name: Checkout uses: actions/checkout@v5 with: @@ -229,6 +237,7 @@ jobs: # The next step builds nvx-rs with the release that rust-toolchain.toml # pins, which rustup would otherwise install with its default profile. - name: Install the pinned Rust release + if: matrix.architecture == 'x86_64' shell: powershell run: | $ErrorActionPreference = "Stop" @@ -241,6 +250,21 @@ jobs: --profile minimal --no-self-update if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Verify native Windows build tools + shell: powershell + run: | + $ErrorActionPreference = "Stop" + $expected = if ("${{ matrix.architecture }}" -eq "aarch64") { "Arm64" } else { "X64" } + $runtime = [System.Runtime.InteropServices.RuntimeInformation] + if ($runtime::OSArchitecture.ToString() -ne $expected -or + $runtime::ProcessArchitecture.ToString() -ne $expected) { + throw "Windows build OS and process must be native $expected" + } + $hostTarget = (rustc -vV | Select-String '^host: ').Line.Substring(6) + if ($hostTarget -ne "${{ matrix.target }}") { + throw "Rust host $hostTarget is not native ${{ matrix.target }}" + } + # As on Linux. The static C runtime spares the self-hosted runners the # Visual C++ redistributable. - name: Build nvx-rs @@ -249,19 +273,30 @@ jobs: RUSTFLAGS: -C target-feature=+crt-static run: | $ErrorActionPreference = "Stop" - cargo build --release --locked --features cli --manifest-path nvx-rs/Cargo.toml + if ("${{ matrix.architecture }}" -eq "aarch64") { + cargo build --release --locked --features cli --manifest-path nvx-rs/Cargo.toml ` + --target "${{ matrix.target }}" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + New-Item -ItemType Directory -Path "nvx-rs\target\release" -Force | Out-Null + Copy-Item -LiteralPath "nvx-rs\target\${{ matrix.target }}\release\nvx-rs.exe" ` + -Destination "nvx-rs\target\release\nvx-rs.exe" + } else { + cargo build --release --locked --features cli --manifest-path nvx-rs/Cargo.toml + } if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - name: Record nvx-rs provenance shell: powershell run: | - python scripts\nvx.py record-nvx-rs-provenance --target x86_64-pc-windows-msvc + python -c "import sys; sys.path.insert(0, 'scripts'); from nvx_tools.common import require_pe_architecture; from nvx_tools.nvx_rs import binary_path; require_pe_architecture(binary_path(), '${{ matrix.architecture }}')" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + python scripts\nvx.py record-nvx-rs-provenance --target "${{ matrix.target }}" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - name: Upload nvx-rs executable uses: actions/upload-artifact@v7 with: - name: nvx-rs-windows-msvc-executable + name: ${{ matrix.artifact }}-executable path: nvx-rs/target/release/nvx-rs.exe if-no-files-found: error overwrite: true @@ -270,12 +305,35 @@ jobs: - name: Upload nvx-rs provenance uses: actions/upload-artifact@v7 with: - name: nvx-rs-windows-msvc-provenance + name: ${{ matrix.artifact }}-provenance path: build/nvx-rs.provenance.json if-no-files-found: error overwrite: true retention-days: 1 + # Same steps and profile as x86; this adds only native ISA/runner/identity. + build-nvx-rs-windows-aarch64-msvc: + name: nvx-rs binary / Windows ARM64 MSVC + needs: [openvmm-changes] + if: >- + ${{ + always() && !cancelled() && + (github.event_name != 'pull_request' || github.event.pull_request.draft == false) && + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && + (needs.openvmm-changes.result != 'success' || needs.openvmm-changes.outputs.run-microvm-tests == 'true') + }} + strategy: + fail-fast: false + matrix: + include: + - architecture: aarch64 + runner: ["self-hosted", "Windows", "ARM64", "Baremetal"] + target: aarch64-pc-windows-msvc + artifact: nvx-rs-windows-aarch64-msvc + runs-on: ${{ matrix.runner }} + timeout-minutes: 15 + steps: *windows-nvx-rs-build + # The NVX CLI tests do not depend on the backend, so they run once per OS on # GitHub-hosted runners rather than in every hypervisor job, with the nvx-rs # that the microVM jobs of the OS run. They read OpenVMM's pinned CPU @@ -719,6 +777,102 @@ jobs: if-no-files-found: error retention-days: 1 + # ARM uses the same native producers, without x86 cache/release identities. + # This is a build context, not native WHP or restricted-service proof. + artifacts-aarch64: + name: Build ARM64 cold guest artifacts + needs: [openvmm-changes] + if: >- + ${{ + always() && !cancelled() && + (github.event_name != 'pull_request' || github.event.pull_request.draft == false) && + ( + needs.openvmm-changes.result != 'success' || + ( + needs.openvmm-changes.outputs.run-guest-artifacts == 'true' && + needs.openvmm-changes.outputs.run-microvm-tests == 'true' + ) + ) + }} + runs-on: ubuntu-24.04-arm + timeout-minutes: 60 + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + persist-credentials: false + + - name: Build guest artifacts + uses: ./.github/actions/build-guest-artifacts + with: + architecture: aarch64 + components: kernel alpine ubuntu + save-cache: "false" + + - name: Upload ARM kernel + uses: actions/upload-artifact@v7 + with: + name: guest-aarch64-kernel + path: | + build/aarch64/Image + build/aarch64/Image.config + build/aarch64/Image.provenance.json + if-no-files-found: error + retention-days: 1 + + - name: Upload ARM Alpine initramfs + uses: actions/upload-artifact@v7 + with: + name: guest-aarch64-alpine + path: | + build/aarch64/initramfs.cpio.gz + build/aarch64/initramfs.cpio.gz.packages.json + build/aarch64/initramfs.provenance.json + if-no-files-found: error + retention-days: 1 + + - name: Upload ARM Ubuntu initramfs + uses: actions/upload-artifact@v7 + with: + name: guest-aarch64-ubuntu + path: | + build/aarch64/initramfs-ubuntu.cpio.gz + build/aarch64/initramfs-ubuntu.cpio.gz.packages.json + if-no-files-found: error + retention-days: 1 + + - name: Upload ARM Ubuntu distro layer + uses: actions/upload-artifact@v7 + with: + name: guest-aarch64-ubuntu-distro + path: | + build/aarch64/ubuntu-distro.erofs + build/aarch64/ubuntu-distro.erofs.manifest.json + build/aarch64/ubuntu-smoke-scratch.ext4 + if-no-files-found: error + retention-days: 1 + + - name: Build the runtime adapter's native ARM guest agent + shell: bash + working-directory: tests/runtime-adapter + run: | + set -euo pipefail + toolchain=$(sed -n 's/^channel = "\([^"]*\)".*/\1/p' ../../rust-toolchain.toml) + test -n "${toolchain}" + rustup toolchain install "${toolchain}" --profile minimal --no-self-update \ + --target aarch64-unknown-linux-musl + test "$(rustc "+${toolchain}" -vV | sed -n 's/^host: //p')" = aarch64-unknown-linux-gnu + cargo "+${toolchain}" build --locked --release --features guest \ + --target aarch64-unknown-linux-musl --bin runtime-adapter-guest + + - name: Upload the ARM runtime adapter guest agent + uses: actions/upload-artifact@v7 + with: + name: runtime-adapter-guest-aarch64 + path: tests/runtime-adapter/target/aarch64-unknown-linux-musl/release/runtime-adapter-guest + if-no-files-found: error + retention-days: 1 + # A dev push and a merge group reuse the guest artifact components that the # pull request that they merge built (see build-guest-artifacts). A # same-repository pull request rehearses that selection and check on the @@ -914,6 +1068,33 @@ jobs: secrets: OPENVMM_DEPLOY_KEY: ${{ secrets.OPENVMM_DEPLOY_KEY }} + build-openvmm-windows-aarch64-msvc: + name: OpenVMM binary / Windows ARM64 MSVC + needs: [openvmm-changes] + if: >- + ${{ + always() && !cancelled() && + (github.event_name != 'pull_request' || github.event.pull_request.draft == false) && + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && + ( + needs.openvmm-changes.result != 'success' || + ( + needs.openvmm-changes.outputs.run-openvmm-binaries == 'true' && + needs.openvmm-changes.outputs.run-microvm-tests == 'true' + ) + ) + }} + uses: ./.github/workflows/build-openvmm-binary.yml + with: + display-name: Windows ARM64 MSVC + runner: '["self-hosted", "Windows", "ARM64", "Baremetal"]' + architecture: aarch64 + backend: whp + artifact: openvmm-windows-aarch64-msvc + binary: openvmm/target/release/openvmm.exe + secrets: + OPENVMM_DEPLOY_KEY: ${{ secrets.OPENVMM_DEPLOY_KEY }} + # OpenVMM's own checkin gates test the revision that NVX pins, on each pull # request into feature/microvm/dev and on each push to it, so CI runs none of # OpenVMM's tests: this job checks that those gates passed the jobs that @@ -961,6 +1142,7 @@ jobs: }} run: >- python3 scripts/nvx.py check-openvmm-ci + --architecture aarch64 --wait-minutes "${WAIT_MINUTES}" --summary "${GITHUB_STEP_SUMMARY}" @@ -1097,6 +1279,199 @@ jobs: # adapter scenarios take about twice as long as on KVM and MSHV, runs them # in a third job beside the other two, so that its guest and sandbox job no # longer ends last in most runs (doc/ci.md#job-graph-and-runner-capacity). + # ARM uses the same caller and assertions, with explicit cold capability. + # Pool access and restricted-service admission remain prerequisites. + nvx-microvm-tests-whp-aarch64: + name: NVX ARM64/WHP cold cells / ${{ matrix.cell }} + needs: + - openvmm-changes + - artifacts-aarch64 + - build-openvmm-windows-aarch64-msvc + - build-nvx-rs-windows-aarch64-msvc + if: >- + ${{ + always() && !cancelled() && + needs.artifacts-aarch64.result == 'success' && + needs.build-openvmm-windows-aarch64-msvc.result == 'success' && + needs.build-nvx-rs-windows-aarch64-msvc.result == 'success' && + (github.event_name != 'pull_request' || github.event.pull_request.draft == false) && + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && + ( + needs.openvmm-changes.result != 'success' || + ( + needs.openvmm-changes.outputs.run-guest-artifacts == 'true' && + needs.openvmm-changes.outputs.run-openvmm-binaries == 'true' && + needs.openvmm-changes.outputs.run-microvm-tests == 'true' + ) + ) + }} + strategy: + fail-fast: false + max-parallel: 1 + matrix: + include: + - cell: cold + guest: alpine + root: initramfs + memory: 256 + scenarios: >- + ["command-line-limit","directional-network-policy","denied-filesystem-paths", + "filesystem-comma-paths","filesystem-owner","filesystem-policy", + "filesystem-shares","guest-boot","guest-identity","host-loopback-policy", + "interrupt-map","ipv6-egress-policy","lifecycle","l3-l4-egress-policy", + "l3-l4-egress-port-ranges","l3-l4-egress-protocols", + "managed-exec-config","private-network-ingress","sandbox-blocks", + "sandbox-lifecycle","sandbox-proxy-only","sandbox-ram-upper","smp", + "structured-outcome","virtio-features","virtio-net","workload-identity"] + - cell: blockless + guest: alpine + root: initramfs + memory: 1024 + scenarios: '["managed-lifecycle"]' + - cell: scratch + guest: ubuntu + root: scratch + memory: 1024 + scenarios: '["managed-lifecycle"]' + - cell: ram + guest: ubuntu + root: ram + memory: 1024 + scenarios: '["managed-lifecycle"]' + uses: ./.github/workflows/run-nvx-microvm-tests.yml + with: + display-name: ARM64/WHP cold / ${{ matrix.cell }} + runner: '["self-hosted", "Windows", "ARM64", "Baremetal"]' + architecture: aarch64 + backend: whp + openvmm-artifact: openvmm-windows-aarch64-msvc + nvx-rs-artifact: nvx-rs-windows-aarch64-msvc + scenarios: ${{ matrix.scenarios }} + cold-only: true + guest: ${{ matrix.guest }} + managed-root: ${{ matrix.root }} + memory-mib: ${{ matrix.memory }} + processors: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '[1,2,4,8]' || '[1,8]' }} + output-dir: build/test-results/microvm-aarch64-whp-${{ matrix.cell }} + result-id: ${{ matrix.cell }}-${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 'vp1-2-4-8' || 'vp1-8' }} + secrets: + OPENVMM_DEPLOY_KEY: ${{ secrets.OPENVMM_DEPLOY_KEY }} + + nvx-microvm-adapter-whp-aarch64: + name: NVX ARM64/WHP cold runtime adapter + needs: + - openvmm-changes + - artifacts-aarch64 + - build-openvmm-windows-aarch64-msvc + - build-nvx-rs-windows-aarch64-msvc + if: >- + ${{ + always() && !cancelled() && + needs.artifacts-aarch64.result == 'success' && + needs.build-openvmm-windows-aarch64-msvc.result == 'success' && + needs.build-nvx-rs-windows-aarch64-msvc.result == 'success' && + (github.event_name != 'pull_request' || github.event.pull_request.draft == false) && + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && + ( + needs.openvmm-changes.result != 'success' || + ( + needs.openvmm-changes.outputs.run-guest-artifacts == 'true' && + needs.openvmm-changes.outputs.run-openvmm-binaries == 'true' && + needs.openvmm-changes.outputs.run-microvm-tests == 'true' + ) + ) + }} + uses: ./.github/workflows/run-nvx-microvm-tests.yml + with: + display-name: ARM64/WHP cold runtime adapter + runner: '["self-hosted", "Windows", "ARM64", "Baremetal"]' + architecture: aarch64 + backend: whp + openvmm-artifact: openvmm-windows-aarch64-msvc + nvx-rs-artifact: nvx-rs-windows-aarch64-msvc + cold-only: true + runtime-adapter: true + result-id: cold-adapter + secrets: + OPENVMM_DEPLOY_KEY: ${{ secrets.OPENVMM_DEPLOY_KEY }} + + nvx-microvm-repeat-whp-aarch64: + name: NVX ARM64/WHP serial repetition / ${{ matrix.cell }} + needs: + - openvmm-changes + - artifacts-aarch64 + - build-openvmm-windows-aarch64-msvc + - build-nvx-rs-windows-aarch64-msvc + if: >- + ${{ + always() && !cancelled() && + (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && + needs.artifacts-aarch64.result == 'success' && + needs.build-openvmm-windows-aarch64-msvc.result == 'success' && + needs.build-nvx-rs-windows-aarch64-msvc.result == 'success' && + ( + needs.openvmm-changes.result != 'success' || + ( + needs.openvmm-changes.outputs.run-guest-artifacts == 'true' && + needs.openvmm-changes.outputs.run-openvmm-binaries == 'true' && + needs.openvmm-changes.outputs.run-microvm-tests == 'true' + ) + ) + }} + strategy: + fail-fast: false + max-parallel: 1 + matrix: + include: + - cell: cold-1vp-50 + scenarios: '["guest-boot"]' + processors: "[1]" + cycles: 50 + start-stop: 0 + - cell: cold-8vp-50 + scenarios: '["guest-boot"]' + processors: "[8]" + cycles: 50 + start-stop: 0 + - cell: public-lifecycle-25 + scenarios: '["sandbox-lifecycle"]' + processors: "[1]" + cycles: 25 + start-stop: 0 + - cell: scratch-start-stop-10 + scenarios: '["sandbox-lifecycle"]' + processors: "[1]" + cycles: 1 + start-stop: 10 + - cell: ram-start-stop-10 + scenarios: '["sandbox-ram-upper"]' + processors: "[1]" + cycles: 1 + start-stop: 10 + - cell: mixed-1-2-4-8vp + scenarios: '["smp","managed-lifecycle"]' + processors: "[1,2,4,8]" + cycles: 1 + start-stop: 0 + uses: ./.github/workflows/run-nvx-microvm-tests.yml + with: + display-name: ARM64/WHP serial / ${{ matrix.cell }} + runner: '["self-hosted", "Windows", "ARM64", "Baremetal"]' + architecture: aarch64 + backend: whp + openvmm-artifact: openvmm-windows-aarch64-msvc + nvx-rs-artifact: nvx-rs-windows-aarch64-msvc + scenarios: ${{ matrix.scenarios }} + processors: ${{ matrix.processors }} + cycles: ${{ matrix.cycles }} + start-stop-cycles: ${{ matrix.start-stop }} + cold-only: true + memory-mib: 1024 + output-dir: build/test-results/microvm-aarch64-whp-repeat-${{ matrix.cell }} + result-id: repeat-${{ matrix.cell }} + secrets: + OPENVMM_DEPLOY_KEY: ${{ secrets.OPENVMM_DEPLOY_KEY }} + nvx-microvm-guests-kvm: name: NVX microVM tests / Linux / KVM / Guests and sandboxes needs: [artifacts, distro-artifacts, build-openvmm-linux-gnu, build-nvx-rs-linux-musl, openvmm-changes] @@ -1719,16 +2094,19 @@ jobs: - nvx-rs - build-nvx-rs-linux-musl - build-nvx-rs-windows-msvc + - build-nvx-rs-windows-aarch64-msvc - nvx-cli-linux - nvx-cli-windows - openvmm-changes - artifacts - distro-artifacts + - artifacts-aarch64 - debug-kernel - guest-artifact-reuse - build-openvmm-linux-gnu - build-openvmm-linux-musl - build-openvmm-windows-msvc + - build-openvmm-windows-aarch64-msvc - openvmm-ci - nvx-microvm-tests-kvm - nvx-microvm-tests-mshv @@ -1737,6 +2115,9 @@ jobs: - nvx-microvm-guests-mshv - nvx-microvm-guests-whp - nvx-microvm-adapter-whp + - nvx-microvm-tests-whp-aarch64 + - nvx-microvm-adapter-whp-aarch64 + - nvx-microvm-repeat-whp-aarch64 - nvx-microvm-debug-kvm - nvx-microvm-debug-mshv - nvx-microvm-debug-whp @@ -1774,16 +2155,19 @@ jobs: NVX_RS_RESULT: ${{ needs.nvx-rs.result }} BUILD_NVX_RS_LINUX_MUSL_RESULT: ${{ needs.build-nvx-rs-linux-musl.result }} BUILD_NVX_RS_WINDOWS_MSVC_RESULT: ${{ needs.build-nvx-rs-windows-msvc.result }} + BUILD_NVX_RS_WINDOWS_AARCH64_MSVC_RESULT: ${{ needs.build-nvx-rs-windows-aarch64-msvc.result }} NVX_CLI_LINUX_RESULT: ${{ needs.nvx-cli-linux.result }} NVX_CLI_WINDOWS_RESULT: ${{ needs.nvx-cli-windows.result }} CHANGES_RESULT: ${{ needs.openvmm-changes.result }} ARTIFACTS_RESULT: ${{ needs.artifacts.result }} DISTRO_ARTIFACTS_RESULT: ${{ needs.distro-artifacts.result }} + ARTIFACTS_AARCH64_RESULT: ${{ needs.artifacts-aarch64.result }} DEBUG_KERNEL_RESULT: ${{ needs.debug-kernel.result }} GUEST_ARTIFACT_REUSE_RESULT: ${{ needs.guest-artifact-reuse.result }} BUILD_LINUX_GNU_RESULT: ${{ needs.build-openvmm-linux-gnu.result }} BUILD_LINUX_MUSL_RESULT: ${{ needs.build-openvmm-linux-musl.result }} BUILD_WINDOWS_MSVC_RESULT: ${{ needs.build-openvmm-windows-msvc.result }} + BUILD_WINDOWS_AARCH64_MSVC_RESULT: ${{ needs.build-openvmm-windows-aarch64-msvc.result }} OPENVMM_CI_RESULT: ${{ needs.openvmm-ci.result }} MICROVM_KVM_RESULT: ${{ needs.nvx-microvm-tests-kvm.result }} MICROVM_MSHV_RESULT: ${{ needs.nvx-microvm-tests-mshv.result }} @@ -1792,6 +2176,9 @@ jobs: MICROVM_GUESTS_MSHV_RESULT: ${{ needs.nvx-microvm-guests-mshv.result }} MICROVM_GUESTS_WHP_RESULT: ${{ needs.nvx-microvm-guests-whp.result }} MICROVM_ADAPTER_WHP_RESULT: ${{ needs.nvx-microvm-adapter-whp.result }} + MICROVM_WHP_AARCH64_RESULT: ${{ needs.nvx-microvm-tests-whp-aarch64.result }} + MICROVM_ADAPTER_WHP_AARCH64_RESULT: ${{ needs.nvx-microvm-adapter-whp-aarch64.result }} + MICROVM_REPEAT_WHP_AARCH64_RESULT: ${{ needs.nvx-microvm-repeat-whp-aarch64.result }} MICROVM_DEBUG_KVM_RESULT: ${{ needs.nvx-microvm-debug-kvm.result }} MICROVM_DEBUG_MSHV_RESULT: ${{ needs.nvx-microvm-debug-mshv.result }} MICROVM_DEBUG_WHP_RESULT: ${{ needs.nvx-microvm-debug-whp.result }} diff --git a/.github/workflows/run-nvx-microvm-tests.yml b/.github/workflows/run-nvx-microvm-tests.yml index 29d0da83c..0bd4b18f4 100644 --- a/.github/workflows/run-nvx-microvm-tests.yml +++ b/.github/workflows/run-nvx-microvm-tests.yml @@ -3,6 +3,61 @@ name: Run NVX microVM tests on: workflow_call: inputs: + architecture: + description: Native guest and runner ISA + required: false + type: string + default: x86_64 + scenarios: + description: JSON array of explicit existing scenario names + required: false + type: string + default: "[]" + cold-only: + description: Run maintained cold projections, not snapshot tails + required: false + type: boolean + default: false + guest: + description: Guest used by the selected correctness scenarios + required: false + type: string + default: alpine + processors: + description: JSON array of explicit processor counts; empty preserves defaults + required: false + type: string + default: "[]" + managed-root: + description: Existing managed lifecycle root, initramfs, scratch, or ram + required: false + type: string + default: initramfs + cycles: + description: Serial Windows repetitions with separate evidence directories + required: false + type: number + default: 1 + start-stop-cycles: + description: Start/Stop cycles of one provisioned public scratch/RAM sandbox; zero keeps the existing case + required: false + type: number + default: 0 + memory-mib: + description: Guest memory; zero keeps the selected guest's existing default + required: false + type: number + default: 0 + output-dir: + description: Optional ISA/root-qualified correctness evidence directory + required: false + type: string + default: "" + result-id: + description: Distinct ISA/VP/root/cycle evidence suffix for matrix cells + required: false + type: string + default: "" display-name: description: Platform name shown in the job list required: true @@ -100,6 +155,96 @@ jobs: - name: Set up retrying curl uses: ./.github/actions/setup-curl + - name: Bind shared correctness arguments + id: correctness + shell: bash + env: + ARCHITECTURE: ${{ inputs.architecture }} + BACKEND: ${{ inputs.backend }} + SCENARIOS: ${{ inputs.scenarios }} + PROCESSORS: ${{ inputs.processors }} + COLD_ONLY: ${{ inputs.cold-only }} + GUEST: ${{ inputs.guest }} + MANAGED_ROOT: ${{ inputs.managed-root }} + CYCLES: ${{ inputs.cycles }} + START_STOP_CYCLES: ${{ inputs.start-stop-cycles }} + MEMORY_MIB: ${{ inputs.memory-mib }} + OUTPUT_DIRECTORY: ${{ inputs.output-dir }} + DEBUG_KERNEL: ${{ inputs.debug-kernel }} + GUESTS_AND_SANDBOXES: ${{ inputs.guests-and-sandboxes }} + RUNTIME_ADAPTER: ${{ inputs.runtime-adapter }} + SHARD: ${{ inputs.shard }} + SHARD_COUNT: ${{ inputs.shard-count }} + RESULT_ID: ${{ inputs.result-id }} + run: | + ${{ runner.os == 'Windows' && 'python' || 'python3' }} - <<'PY' + import json + import os + import re + import sys + from pathlib import Path + + sys.path.insert(0, "scripts") + import nvx + from nvx_tools.microvm_tests import PUBLIC_SANDBOX_SCENARIOS + + architecture, backend = os.environ["ARCHITECTURE"], os.environ["BACKEND"] + if os.environ["RESULT_ID"] and re.fullmatch(r"[A-Za-z0-9_.-]+", os.environ["RESULT_ID"]) is None: + raise SystemExit("result-id must be an artifact-safe cell identifier") + scenarios = json.loads(os.environ["SCENARIOS"]) + processors = json.loads(os.environ["PROCESSORS"]) + if not isinstance(scenarios, list) or not all(isinstance(s, str) for s in scenarios): + raise SystemExit("scenarios must be a JSON string array") + if not isinstance(processors, list) or not all(type(p) is int for p in processors): + raise SystemExit("processors must be a JSON integer array") + cycles = int(os.environ["CYCLES"]) + if cycles < 1 or (os.environ["RUNNER_OS"] != "Windows" and cycles != 1): + raise SystemExit("serial cycles require Windows and a positive integer") + cold = os.environ["COLD_ONLY"] == "true" + debug = os.environ["DEBUG_KERNEL"] == "true" + if architecture == "aarch64": + if backend != "whp" or not cold or debug or os.environ["GUESTS_AND_SANDBOXES"] == "true": + raise SystemExit("ARM correctness requires the explicit Windows/WHP cold scope") + if not scenarios and os.environ["RUNTIME_ADAPTER"] != "true": + raise SystemExit("ARM correctness requires explicit existing scenarios") + arguments = ["test-microvm", "--backend", backend, "--architecture", architecture, + "--guest", os.environ["GUEST"]] + for scenario in scenarios: + arguments += ["--scenario", scenario] + if processors: + arguments += ["--processors", *map(str, processors)] + for name, option in (("START_STOP_CYCLES", "--start-stop-cycles"), ("MEMORY_MIB", "--memory-mib")): + value = int(os.environ[name]) + if value < 0: + raise SystemExit(f"{option} must be nonnegative; zero preserves the default") + if value: + arguments += [option, str(value)] + if cold: + arguments += ["--cold-only"] + if debug: + arguments += ["--debug-kernel"] + if int(os.environ["SHARD"]): + arguments += ["--shard", f'{os.environ["SHARD"]}/{os.environ["SHARD_COUNT"]}'] + if os.environ["MANAGED_ROOT"] != "initramfs": + arguments += ["--managed-root", os.environ["MANAGED_ROOT"]] + nvx.parse_args(arguments) + isa = "" if architecture == "x86_64" else f"-{architecture}" + directory = os.environ["OUTPUT_DIRECTORY"] or f"build/test-results/microvm{isa}-{backend}" + ("-debug" if debug else "") + workload_artifacts = not debug and ( + (not scenarios and not int(os.environ["SHARD"])) + or bool(set(scenarios) & PUBLIC_SANDBOX_SCENARIOS) + or os.environ["MANAGED_ROOT"] != "initramfs" + ) + with Path(os.environ["GITHUB_OUTPUT"]).open("a", encoding="utf-8") as output: + output.write(f"workload-artifacts={str(workload_artifacts).lower()}\n") + Path("build").mkdir(exist_ok=True) + Path("build/nvx-correctness-arguments.json").write_text( + json.dumps({"arguments": arguments, "cycles": cycles, "output_dir": directory, + "workload_artifacts": workload_artifacts}), + encoding="utf-8", + ) + PY + # The guest artifacts that the steps below boot or read. Every job # qualifies its runner with the kernel and the Alpine initramfs, the # shards of the default suite boot only those, and the debug-kernel jobs @@ -110,14 +255,14 @@ jobs: - name: Download guest kernel uses: actions/download-artifact@v8 with: - name: guest-kernel - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-kernel' || 'guest-kernel' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} - name: Download Alpine initramfs uses: actions/download-artifact@v8 with: - name: guest-alpine - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-alpine' || 'guest-alpine' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} - name: Download guest debug kernel if: inputs.debug-kernel @@ -127,27 +272,27 @@ jobs: path: build - name: Download Ubuntu initramfs - if: ${{ inputs.guests-and-sandboxes && !inputs.debug-kernel }} + if: ${{ (inputs.guests-and-sandboxes || inputs.guest == 'ubuntu') && !inputs.debug-kernel }} uses: actions/download-artifact@v8 with: - name: guest-ubuntu - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-ubuntu' || 'guest-ubuntu' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} - name: Download Ubuntu distro layer if: ${{ inputs.guests-and-sandboxes && !inputs.debug-kernel }} uses: actions/download-artifact@v8 with: - name: guest-ubuntu-distro - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-ubuntu-distro' || 'guest-ubuntu-distro' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} # The layer, its manifest, and the sandbox scratch template, which the # public sandbox scenarios of an unsharded default run read. - name: Download Ubuntu distro layer for the whole default run - if: ${{ !inputs.guests-and-sandboxes && !inputs.runtime-adapter && !inputs.debug-kernel && !inputs.shard }} + if: ${{ !inputs.guests-and-sandboxes && !inputs.runtime-adapter && !inputs.debug-kernel && !inputs.shard && steps.correctness.outputs.workload-artifacts == 'true' }} uses: actions/download-artifact@v8 with: - name: guest-ubuntu-distro - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-ubuntu-distro' || 'guest-ubuntu-distro' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} # The layer, its manifest, and the sandbox scratch template, from which # the layered runtime adapter scenarios boot their roots, in a job that @@ -156,8 +301,8 @@ jobs: if: ${{ inputs.runtime-adapter && !inputs.guests-and-sandboxes && !inputs.debug-kernel }} uses: actions/download-artifact@v8 with: - name: guest-ubuntu-distro - path: build + name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-ubuntu-distro' || 'guest-ubuntu-distro' }} + path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} - name: Download Azure Linux initramfs if: ${{ inputs.guests-and-sandboxes && !inputs.debug-kernel }} @@ -203,6 +348,7 @@ jobs: with: backend: ${{ inputs.backend }} verify-openvmm: "true" + architecture: ${{ inputs.architecture }} # The runner signals only a step's shell when the job is cancelled, so # the Linux steps exec the test harness, which can then stop OpenVMM and @@ -210,22 +356,33 @@ jobs: - name: Run NVX microVM tests on Linux if: runner.os != 'Windows' && !inputs.guests-and-sandboxes && !inputs.runtime-adapter shell: bash - run: >- - exec python3 scripts/nvx.py test-microvm - --backend "${{ inputs.backend }}" - ${{ inputs.debug-kernel && '--debug-kernel' || '' }} - ${{ inputs.shard && format('--shard {0}/{1}', inputs.shard, inputs.shard-count) || '' }} - --output-dir "build/test-results/microvm-${{ inputs.backend }}${{ inputs.debug-kernel && '-debug' || '' }}" + run: | + exec python3 - <<'PY' + import json + import os + import sys + from pathlib import Path + selected = json.loads(Path("build/nvx-correctness-arguments.json").read_bytes()) + os.execv(sys.executable, [sys.executable, "scripts/nvx.py", *selected["arguments"], + "--output-dir", selected["output_dir"]]) + PY - name: Run NVX microVM tests on Windows if: runner.os == 'Windows' && !inputs.guests-and-sandboxes && !inputs.runtime-adapter shell: powershell - run: >- - python scripts\nvx.py test-microvm - --backend "${{ inputs.backend }}" - ${{ inputs.debug-kernel && '--debug-kernel' || '' }} - ${{ inputs.shard && format('--shard {0}/{1}', inputs.shard, inputs.shard-count) || '' }} - --output-dir "build/test-results/microvm-${{ inputs.backend }}${{ inputs.debug-kernel && '-debug' || '' }}" + run: | + $ErrorActionPreference = "Stop" + $selected = Get-Content -LiteralPath "build/nvx-correctness-arguments.json" -Raw | + ConvertFrom-Json + $arguments = @($selected.arguments) + for ($cycle = 1; $cycle -le $selected.cycles; $cycle++) { + $directory = $selected.output_dir + if ($selected.cycles -gt 1) { + $directory = Join-Path $directory ("cycle-{0:D3}" -f $cycle) + } + python scripts\nvx.py @arguments --output-dir $directory + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } - name: Run public managed sandbox acceptance on Linux if: runner.os != 'Windows' && inputs.guests-and-sandboxes && !inputs.debug-kernel @@ -1318,13 +1475,15 @@ jobs: run: >- python3 scripts/nvx.py test-runtime-adapter --backend "${{ inputs.backend }}" + --architecture "${{ inputs.architecture }}" + ${{ inputs.cold-only && '--cold-only' || '' }} --guest-agent tests/runtime-adapter/target/x86_64-unknown-linux-musl/release/runtime-adapter-guest - name: Download the runtime adapter's guest agent on Windows if: runner.os == 'Windows' && inputs.runtime-adapter && !inputs.debug-kernel uses: actions/download-artifact@v8 with: - name: runtime-adapter-guest + name: ${{ inputs.architecture == 'aarch64' && 'runtime-adapter-guest-aarch64' || 'runtime-adapter-guest' }} path: build/runtime-adapter - name: Run runtime adapter scenarios on Windows @@ -1333,6 +1492,8 @@ jobs: run: >- python scripts\nvx.py test-runtime-adapter --backend "${{ inputs.backend }}" + --architecture "${{ inputs.architecture }}" + ${{ inputs.cold-only && '--cold-only' || '' }} --guest-agent build\runtime-adapter\runtime-adapter-guest # A job that runs the runtime adapter scenarios alone runs no @@ -1342,7 +1503,7 @@ jobs: if: failure() && (inputs.guests-and-sandboxes || !inputs.runtime-adapter) uses: actions/upload-artifact@v7 with: - name: nvx-microvm-tests-${{ inputs.backend }}${{ inputs.debug-kernel && '-debug' || '' }}${{ inputs.guests-and-sandboxes && '-guests' || '' }}${{ inputs.shard && format('-shard-{0}', inputs.shard) || '' }} + name: nvx-microvm-tests-${{ inputs.backend }}${{ inputs.architecture == 'aarch64' && format('-aarch64-{0}', inputs.managed-root) || '' }}${{ inputs.result-id && format('-{0}', inputs.result-id) || '' }}${{ inputs.debug-kernel && '-debug' || '' }}${{ inputs.guests-and-sandboxes && '-guests' || '' }}${{ inputs.shard && format('-shard-{0}', inputs.shard) || '' }} path: | build/test-results/public-exec-${{ inputs.backend }} build/test-results/microvm-${{ inputs.backend }} @@ -1350,6 +1511,8 @@ jobs: build/test-results/ubuntu-${{ inputs.backend }} build/test-results/ubuntu-kvm-extended build/test-results/azurelinux-${{ inputs.backend }} + build/test-results/microvm-aarch64-${{ inputs.backend }} + ${{ inputs.output-dir }} if-no-files-found: warn # Each job and attempt keeps the scenario duration report of every @@ -1360,7 +1523,7 @@ jobs: if: always() && (inputs.guests-and-sandboxes || !inputs.runtime-adapter) uses: actions/upload-artifact@v7 with: - name: nvx-microvm-durations-${{ runner.os }}-${{ inputs.backend }}-${{ inputs.debug-kernel && 'debug' || 'default' }}${{ inputs.guests-and-sandboxes && '-guests' || '' }}${{ inputs.shard && format('-shard-{0}', inputs.shard) || '' }}-${{ github.run_id }}-${{ github.run_attempt }} - path: build/test-results/*/scenario-durations.jsonl + name: nvx-microvm-durations-${{ runner.os }}-${{ inputs.backend }}-${{ inputs.debug-kernel && 'debug' || 'default' }}${{ inputs.architecture == 'aarch64' && format('-aarch64-{0}', inputs.managed-root) || '' }}${{ inputs.result-id && format('-{0}', inputs.result-id) || '' }}${{ inputs.guests-and-sandboxes && '-guests' || '' }}${{ inputs.shard && format('-shard-{0}', inputs.shard) || '' }}-${{ github.run_id }}-${{ github.run_attempt }} + path: build/test-results/**/scenario-durations.jsonl if-no-files-found: warn retention-days: 30 diff --git a/doc/build.md b/doc/build.md index c6c91d0c3..d294b3da4 100644 --- a/doc/build.md +++ b/doc/build.md @@ -61,8 +61,8 @@ does not establish ARM guest-platform support or native microVM qualification. The existing Docker `guest-binaries` stage accepts `--build-arg NVX_ARCHITECTURE=aarch64`. Its `guest-binary-artifacts` target uses BuildKit's existing local output. Select `--platform linux/arm64` -and a separate output directory for ARM builds. The seven-helper cold-boot -inventory includes the real ARM `nvx-time` entry point; missing required +and a separate output directory for ARM builds. The eight-helper cold-boot +inventory includes the real ARM `nvx-time` and `nvx-time-probe` entry points; missing required helpers and stale diagnostic exports fail source/manifest inspection. Compilation and ELF identity do not establish native product qualification. The architecture argument is not a CPU-profile @@ -70,11 +70,14 @@ selector. An ARM platform flag on an x86 engine may use emulation and is not native build evidence. The ARM cold-boot inventory uses that same producer without the -snapshot-only MMIO kick helper, device-I/O benchmark helper, or x86 time -probe. It still requires real `nvx-time` before normal `/init` can announce -readiness. Omitting unrelated diagnostics neither omits boot-time enforcement -nor qualifies ARM counter/timer probes. The default x86 inventory remains all -ten executables. +snapshot-only MMIO kick helper or device-I/O benchmark helper. It still +requires real `nvx-time` before normal `/init` can announce readiness. +Its `nvx-time-probe warp` shares x86's pairwise algorithm, bounds, and +verdicts, reading the fenced virtual counter and each selected CPU's actual +`CNTFRQ_EL0`. Its reports name `counter_hz` rather than TSC, and it rejects +x86-only latency/clock diagnostics and frequency overrides. Including the +probe does not qualify its measurements on a host. The default x86 inventory +and diagnostic output remain unchanged: all ten executables. Existing x86-only production helpers remain available to shared unit tests on ARM through their architecture-or-test compilation guards. The exact @@ -377,7 +380,7 @@ Both commands need the standard guest build outputs above. The second writes complete per-scenario logs under `build/test-results/microvm` by default. -All three initramfses install the same ten Rust executables under `/sbin`: +The x86 initramfses install the same ten Rust executables under `/sbin`: `nvx-console-pending`, `nvx-device-io`, `nvx-exit`, `nvx-ingress`, `nvx-init`, `nvx-managed-agent`, `nvx-mmio-write`, `nvx-reseed`, `nvx-time`, and `nvx-time-probe`. Docker builds them once in a Rust diff --git a/doc/ci.md b/doc/ci.md index abb5d9bb7..843cf6519 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -1014,8 +1014,77 @@ queueing, and the run without benchmarks 14.7, while 98 of the pool's 600 jobs would have waited 2 minutes or more, at a p90 of 4.8 minutes. The WHP platform job then ends last in most runs that run the benchmarks. +## ARM64 cold correctness + +The shared pipeline also declares native ARM64/WHP cold correctness. This is +source wiring, **not evidence that NVX can use the runner pool or that its jobs +have passed**. The existing OpenVMM `self-hosted`, `Windows`, `ARM64`, +`Baremetal` pool is a possible reuse target; NVX access and the existing +Network Service job/account, tool, ACL, time and cleanup checks must be verified +there. The workflow does not register a runner or reconfigure a user's PC. + +The same Windows CLI build steps are shared by YAML anchor, with separate +native x86 and ARM jobs and artifact identities; the x86 job still waits for +no other job. The existing VMM build workflow accepts the ISA, and the existing +guest action builds fresh ARM Docker exports on a native Linux ARM builder: +`guest-aarch64-{kernel,alpine,ubuntu,ubuntu-distro}` under `build/aarch64`. +The runtime adapter's real ARM musl guest agent is a separate artifact. +ARM neither restores nor publishes x86 guest reuse/cache records, release +catalogs or determinism evidence. + +`nvx-microvm-tests-whp-aarch64` calls the same correctness workflow with explicit +cold scenarios, not the x86 snapshot shards. Its inventory covers every +maintained cold scenario once, with separate blockless, EROFS/scratch and +EROFS/RAM managed variants. PRs and merge groups use 1/8 VPs for boot, SMP and +those managed variants; full scheduled/dispatched runs use 1/2/4/8. Other +scenarios retain their existing VP contract, including public one-VP sandboxes. +The cold cell uses 256 MiB and the managed fixtures 1 GiB; these selections are +not claims of a maximum qualified memory. The separate adapter caller uses +the existing complete registry and its declared cold capability projection. + +Layered managed fixtures use the same Alpine control initramfs as public +sandboxes and the selected Ubuntu EROFS workload layer, not Ubuntu's interactive +initramfs as the control guest. ARM device assertions retain each fixed MMIO +window and interrupt requirement through Linux resources and DT bindings; +x86 retains command-line discovery. SMP reads the CPU node's declared DT cell +width rather than assuming a 64-bit `reg`. The cold projections, including +private-network ingress, retain their traffic and policy assertions but defer +the snapshot tail; the default x86 full cases still run those tails. + +The scheduled/dispatched serial job selects these existing cases: + +| Selection | Count and state lifetime | +| --- | --- | +| `guest-boot`, 1 VP | 50 cold boots, separate cycle evidence | +| `guest-boot`, 8 VPs | 50 cold boots, separate cycle evidence | +| `sandbox-lifecycle`, 1 VP | 25 complete cases, each with Deprovision and its existing negative/recovery assertions | +| `sandbox-lifecycle --start-stop-cycles 10` | 10 clean Start/Stop cycles of one provisioned scratch sandbox | +| `sandbox-ram-upper --start-stop-cycles 10` | 10 Start/Stop cycles of one provisioned RAM sandbox, checking reset after every stop | +| `smp`, `managed-lifecycle` | Ordered 1/2/4/8-VP sequences in one job without rebooting the runner | + +These are case counts, not a fabricated total VM count: the public lifecycle +case also exercises refused starts, overlap and crash recovery. The existing +1,000-iteration shared-status race is unchanged. The shared workflow forwards +ISA, scenarios, processors, memory, root and cycles, downloads only the guest +components those selections read, and retains recursive per-cycle durations +and distinct ISA/root/cell failure artifacts. No ARM duration partition has +been measured; ARM cold reports cannot rebalance the existing full x86 shards. + +ARM producer, CLI, VMM, cold and adapter results feed `Required status check`; +the repetition result is required for full runs and explicitly skipped for +PRs/merge groups. Existing H4 and selected-check policy remains: unselected H5/H7 +checks are unverified, not new ARM-only per-job prerequisites. Native CPU/time +preflight and partial functional evidence are not full UTC or service-account +qualification. ARM snapshots, the x86 exhaustive CPUID/MSR/fault-hook cases, +and an ARM debug-kernel campaign are not included. The bounded adversarial +campaign additionally needs its trusted controller/executor, explicit ISA +routing and approved resource/credit limits; no campaign is launched or +credited by these source changes. The fork-headed OpenVMM CI acceptance rule +is unchanged and remains a separate prerequisite. + ## MicroVM test shards +The existing x86-64 partition is unchanged. `nvx.py test-microvm --shard INDEX/COUNT` runs one of COUNT shards of the default Alpine suite on the default kernel, which holds the scenarios that `test-microvm` runs without `--scenario` but the public sandbox scenarios, @@ -1753,7 +1822,15 @@ requires the jobs of the gates that cover NVX's use of OpenVMM, `run vmm-tests` jobs of `x64-linux-amd-kvm`, `x64-linux-intel-mshv`, `x64-windows-intel`, and `x64-windows-amd`, to have passed for the pinned revision, in a run of either workflow whose head is the revision in -`microsoft/openvmm`. A pull request's run tests GitHub's merge of the pull +`microsoft/openvmm`. The Phase 3 CI call explicitly selects +`--architecture aarch64`, additionally requiring the existing upstream +`unit tests [aarch64-windows]` and `run vmm-tests [aarch64-windows]` jobs. +All six x86 requirements remain, and the standalone command still defaults +to x86-only coverage. Both ISAs use the same latest-attempt assessment and +missing/pending/failure rules; a skipped ARM job is not a pass. This extends +coverage, not trust: the existing fork-headed run rejection remains intact, +including for the selected PR until an exception is explicitly approved. +A pull request's run tests GitHub's merge of the pull request into the branch, which holds the tree of the head while the head descends from the branch, as landing it requires. The job reads the pin from the checkout's index and the public repository's runs with the run's token, diff --git a/doc/openvmm-upstream-roadmap.md b/doc/openvmm-upstream-roadmap.md index d46426931..a300d56ac 100644 --- a/doc/openvmm-upstream-roadmap.md +++ b/doc/openvmm-upstream-roadmap.md @@ -11,18 +11,29 @@ summary, and commit mapping below cover positions 001-124, the PR09 fixups at positions 234-236, the PR13 fixup at position 240, the PR18 fixup at position 241, the PR20 fixup at position 242, and the PR19 fixup at position 243. -- NVX's pinned OpenVMM revision: `73cf403574a8907ee94dab0ab9d648152b832b05`, position 269, the - head of `feature/microvm/release/v6.1`. The v6.1 rebase replayed the 268 commits of +- NVX's pinned OpenVMM revision: `b09c58843ae310dfff9ae68e9e822f9c5846b914`, position 272, + the provisional local ARM integration + candidate for microsoft/openvmm#5045. Its three linear ARM/import-reconciliation + commits follow the inherited pin `73cf403574a8907ee94dab0ab9d648152b832b05` at + position 269, the head of `feature/microvm/release/v6.1`. + The v6.1 rebase replayed the 268 commits of `feature/microvm/dev` at NVX's previous pin, `5ca20ee08`, whose first 220 commits are those of `feature/microvm/release/v6.0`, onto the new fork base without the seven whose changes upstream had landed, and added eight fixups at its tip, positions 262-269. A commit's position is its v6.0 position less the number of dropped commits before it: v6.0 positions 003-007 are positions 002-006, 010-013 are 007-010, 015-050 are 011-046, and 054-268 are 047-261; see - [Conflicts of the v6.1 rebase](#conflicts-of-the-v61-rebase). The pin is 145 commits past the - mapped tip on the same first-parent chain. Positions 125-233, 237-239, and 244-269 are not yet + [Conflicts of the v6.1 rebase](#conflicts-of-the-v61-rebase). The pin is 148 commits past the + mapped tip on the same first-parent chain. Positions 125-233, 237-239, and 244-272 are not yet assigned to PRs, positions 234-236 are PR09 fixups, position 240 is a PR13 fixup, position 241 is a PR18 fixup, position 242 is a PR20 fixup, and position 243 is a PR19 fixup; see [Commits after the mapped tip](#commits-after-the-mapped-tip). + This exact local candidate is provisional: independent review and the final-source-pair + Phase 3 matrix are pending, and it is not the currently published pull-request head. + The former pins `6036d7ee6f56357b18f01b126b9f7463473deddf` and + `38016f6637f0c61fb55c9ee31033ceec428e346c`, their products, and their native/trial + receipts remain historical evidence, not qualification of this rewritten baseline. + ARM remains cold-boot-only. Its shared admission verifier does not establish UTC, + snapshots, or a wider PA contract; no CI trust-policy exception is implied by this pin. - Upstream main: `7d90c41044077e31ca060df9206532f579f24716` (2026-11-13), the fork base itself; see [Upstream main past the fork base](#upstream-main-past-the-fork-base). @@ -1150,7 +1161,10 @@ The physical branch is one first-parent chain: -> RTC port reads wider than a byte zero-extended [260] -> periodic timer's missed periods skipped at once [261] -> v6.1 rebase fixups [262-269] - -> 73cf40357 (NVX pin) + -> governed ARM64 cold boot on WHP [270] + -> ARM admission through the existing shared time ABI verifier [271] + -> shared time ABI report imports reconciled with the inherited baseline [272] + -> b09c58843 (NVX pin) ``` For upstream review, PR01-PR03, PR05, PR06, and PR14 can be rebased independently onto current @@ -1191,7 +1205,7 @@ PR26's position 119, PR25's position 118, PR11's position 028, and PR13's positi ## Commits after the mapped tip -The NVX pin extends the chain past position 124 without merges. Of the 145 later commits, +The NVX pin extends the chain past position 124 without merges. Of the 148 later commits, positions 234-236 are PR09 fixups, position 240 is a PR13 fixup, position 241 is a PR18 fixup, position 242 is a PR20 fixup, position 243 is a PR19 fixup, positions 262-269 are the fixups of the v6.1 rebase, and the others are not yet classified or assigned to PRs. @@ -1200,7 +1214,8 @@ and 162-200 did, which developed one concept; "(part)" marks a v2.4 fixup that s commits. Positions 180-184 followed the v3.0 reorganization, positions 185-198 are the ABI restart of the v4.0 reorganization, positions 199-204 followed it, positions 205-211 followed the v5.0 reorganization, positions 212 and 213 followed the v5.1 rebase, positions 214-261 followed the -v6.0 reorganization, and positions 262-269 are the v6.1 rebase's fixups, so they combine none, +v6.0 reorganization, positions 262-269 are the v6.1 rebase's fixups, and positions 270-272 +are the provisional ARM replay, so they combine none, apart from position 213, which combines v5.1 positions 222 and 223. Each commit's position is its v6.0 position less seven, the number of commits that the v6.1 rebase dropped before it, and its v6.0 position is its v5.1 position through 147 and one less from v5.1 position 149 on; see @@ -1357,12 +1372,24 @@ v6.0 position is its v5.1 position through 147 and one less from v5.1 position 1 | 267 | `4a1d9b07a` | - | - | - | - | - | Guide, openvmm_entry: describe upstream's snapshots with the chain's publication (v6.1 rebase fixup for microsoft/openvmm#4553); fold into 028, 032, and 069 | | 268 | `63688dd58` | - | - | - | - | - | vmm_tests: save the ttrpc interface test's VM with a VMBus NIC (v6.1 rebase fixup for microsoft/openvmm#4553); fold into 044 | | 269 | `73cf40357` | - | - | - | - | - | openvmm_helpers: drop an independent snapshot copy's page cache (v6.1 rebase fixup for microsoft/openvmm#4553); fold into 028 | +| 270 | `30f64b509` | - | - | - | - | - | microvm: enable governed ARM64 cold boot on WHP (provisional local replay for microsoft/openvmm#5045) | +| 271 | `b2304344b` | - | - | - | - | - | microvm: verify ARM64 CPU and time admission through the shared report and verifier (provisional local replay for microsoft/openvmm#5045) | +| 272 | `b09c58843` | - | - | - | - | - | microvm: preserve time ABI imports across report sharing (provisional local replay for microsoft/openvmm#5045) | The remarks that say whether commits apply to upstream main record what was found on upstream main when each commit was mapped: the v3.0 reorganization's base, `b2676222b`, for the commits that it regrouped, and later fork bases, up to `ba105dd7f`, for later commits. They name the positions that the commits have now, but the v6.1 rebase did not check them again on `7d90c4104`. +Positions 270-272 replay only the three ARM cold-boot/admission/import commits onto the +complete rewritten upstream baseline. Position 270 shares the existing direct loader, +device-tree, hypervisor, CPU-profile and time ABI foundations. Position 271 reuses its +ARM backend and effective-ID readbacks through the shared `TimeAbiReport`, preflight and +verifier; it preserves x86 output and rejects ARM fault hooks. Position 272 retains the +baseline's microVM time-report imports. These depend on the fork's microVM foundations, +not an independently qualified upstream change; no upstream package build, final NVX +matrix, full host/UTC/H7 qualification or ARM snapshot support is claimed here. + Some of these commits change mapped work rather than add to it. Position 140 removes the legacy microVM clock paths, changing files that PR10 and PR17 also change, and makes manifest version 6 the only snapshot format, changing files that PR11 and PR17 also change. Position diff --git a/doc/usage.md b/doc/usage.md index 3a340937e..6334fbe11 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -767,6 +767,7 @@ run's results or stopped, after persisting the others. ```text python3 scripts/nvx.py check-openvmm-ci + [--architecture {x86_64,aarch64}] [--revision SHA] [--wait-minutes MINUTES] [--summary PATH] @@ -779,7 +780,13 @@ and OpenVMM CI workflows of `microsoft/openvmm` whose head is the revision, with the latest attempt of each of their jobs, and requires each job that covers NVX's use of OpenVMM, the x86-64 Linux and Windows unit tests and the VMM tests on KVM, MSHV, and Windows, to have passed in at least one of those -runs. It ignores the runs of a pull request from a fork, which run the fork's +runs. The default `x86_64` selection retains those six jobs. +`--architecture aarch64` also requires the existing native Windows ARM +unit and VMM jobs, `unit tests [aarch64-windows]` and +`run vmm-tests [aarch64-windows]`, without removing any x86 requirement. +The shared CI pipeline selects this eight-job coverage. Missing, skipped, +pending or failed ARM evidence cannot pass. This selection does not change +workflow or repository trust: it ignores the runs of a pull request from a fork, which run the fork's copy of the workflows, and the workflows' other jobs. A job is pending while a run that has not finished may still pass it, failed when every run that ran it finished it without passing, and missing when no run will run it. With @@ -1144,9 +1151,12 @@ python3 scripts/nvx.py test-microvm [--architecture {x86_64,aarch64}] [--guest {alpine,ubuntu,azurelinux}] [--scenario SCENARIO]... + [--cold-only] [--debug-kernel] [--shard INDEX/COUNT] [--processors {1,2,4,8} ...] + [--managed-root {initramfs,scratch,ram}] + [--start-stop-cycles COUNT] [--memory-mib MIB] [--timeout SECONDS] [--output-dir PATH] @@ -1181,6 +1191,21 @@ selection and uses `build/aarch64/Image`, matching initramfs and managed-layer inputs; it does not qualify every scenario listed here for ARM. Public sandbox scenarios retain the existing one-VP CLI contract; `--processors` does not add a sandbox processor option or change saved configurations. +`--cold-only` requires explicit scenario selection and rejects cases without a +maintained cold projection. It retains all cold assertions and preboot refusals +of `filesystem-policy`, `filesystem-shares`, and `ipv6-egress-policy`, omitting +only their snapshot portions. `interrupt-map` retains every device's driver, +traffic, trigger, and exclusive-handler checks; ARM additionally checks the +DT's SPI index and rising-edge cells against the GIC hardware INTID, not Linux's +dynamically allocated IRQ number. ARM requires `--cold-only` for these mixed +scenarios. Snapshot-only cases are not silently replaced or reported as passing. +The maintained cold inventory includes `command-line-limit`, whose effective +command line uses the shared 2,048-byte binding on both ISAs. The complete +inventory and explicit deferral reasons are +`COLD_ONLY_SCENARIOS` and `COLD_DEFERRED_SCENARIOS` in the existing runner. +`console-exit` is a restore/backpressure case, not a cold case. The guest's +`time-abi-conformance` exhaustive X1-X6 command and the host-correction fault +hooks remain x86-only; they are not renamed or reported as ARM passes. `--shard INDEX/COUNT`, such as `1/2`, runs shard INDEX of the COUNT shards of the default Alpine suite on the default kernel, the scenarios of a run without `--scenario` but the public sandbox scenarios, which CI runs in its guest and @@ -1223,6 +1248,35 @@ the boot to the managed agent, and runs the ignored `nvx-rs` test `tests/managed_lifecycle.rs` with Cargo, which starts OpenVMM with the scenario's command line and drives the guest's control session; the scenario then checks OpenVMM's outcome report and the guest console. The +default managed fixture remains a single-vCPU initramfs boot. Explicit +`--processors` counts also select its and `guest-boot`'s VP counts, without changing the existing +SMP/restore defaults of 1, 2, 4 and 8. `--managed-root scratch` and +`--managed-root ram` require `--guest ubuntu` and reuse its maintained EROFS +layer and the same authenticated Rust test. Both make two cold boots per VP +count: scratch requires absent/present previous state and a clean journal +after each boot; RAM requires absent/absent state and attaches no scratch. +Non-default fixture logs have separate VP/root/boot directories and refuse +to overwrite existing evidence; select a fresh `--output-dir` for a rerun. + +`--start-stop-cycles COUNT` applies only to explicit `sandbox-lifecycle` or +`sandbox-ram-upper` selections. It repeats clean Start/Stop of **one +provisioned public one-VP sandbox**, without changing its public configuration. +Scratch must retain the written state and a clean journal on each stop; the +RAM upper must lose the preceding boot's write on each restart. RAM therefore +requires at least two cycles. Omitting the option preserves the existing cases: +one clean scratch cycle before its overlap/crash/recovery assertions, and two +RAM starts. Explicit repetitions keep numbered cycle operations, runtime +records, logs and outcomes; the existing identity/refusal/recovery cases still +run and are not counted as clean repetition cycles. A failure is not retried. + +The shared `smp` probe retains the x86 APIC/LAPIC assertions. On ARM64 it +checks the CPU's 64-bit DT affinity instead of an APIC ID, the architected +timer's per-CPU interrupt progress instead of `LOC`, and reschedule/call IPIs +instead of the x86 interrupt labels. Both retain online-count, flat +package/core/thread topology, pinned worker rendezvous, bounded timer +progress and warp assertions. `smp-lapic` remains explicitly x86-only. + +The `virtio-features` scenario boots a guest with every fixed virtio device: the NIC, the dormant host filesystem slot, both consoles, and both sandbox blocks. The guest reports, for each device, the base of its MMIO window, its virtio @@ -1259,6 +1313,8 @@ names its kind. The first line, `run`, describes the run: | `schema`, `schema_version` | `nvx-microvm-durations` and `1`. The version changes only when a reader of the previous version would misread a report, not when a field is added. | | `started_at` | When the run and its `setup` started, in UTC, such as `2026-10-21T13:50:00.123Z` | | `guest`, `backend` | The `--guest` and the `--backend` | +| `architecture` | The selected guest/counter ISA; reports without this field predate ARM64 and are x86-only inputs | +| `scope` | `cold` with `--cold-only`, otherwise `full`; an omitted field denotes an older full-scope report | | `kernel` | `debug` with `--debug-kernel`, otherwise `default` | | `processors` | The `--processors` counts, without repeats | | `scenarios` | The selected scenarios | @@ -1272,6 +1328,7 @@ follow one another without gaps, so they add up to the run's time: where the OS doesn't report that start, until the first scenario starts; - a `scenario` for each scenario execution, until the next one starts. `console-exit`, `smp`, and `smp-lapic` execute once per processor count; + managed lifecycle also records each selected VP and each layered cold boot; - `teardown`, which sums up the time ABI evidence and records the run's outcome. @@ -1280,7 +1337,7 @@ Every span has its `started_at`, its `seconds`, rounded to the millisecond, its `SIGTERM`, and an `error`: for a failure, the exception's type and message, cut to 1,000 characters, and otherwise `null`. A `scenario` record also has the -`scenario`, the `guest`, `backend`, and `kernel`, and its `processors`: the +`scenario`, the `guest`, `backend`, `architecture`, `scope`, and `kernel`, and its `processors`: the `--processors` counts that the execution covers, such as `[4]` for `smp` on 4 vCPUs, the largest count for `time-abi-conformance`, all of them for `smp-snapshot` and `restore-processors`, those up to 4 for @@ -1289,6 +1346,11 @@ take them. A failed run ends with the failed scenario's record and the `teardown`; a run that is killed keeps every record that it completed and has no `teardown`. +Layered managed executions also record a `variant` naming their root mode, +boot index and expected previous state. These are additive diagnostic fields, +not changes to a sandbox or VM state format. Neither ARM64 nor cold-projection +reports silently feed the existing full-scope x86 shard estimates. + ### `plan-microvm-shards` ```text @@ -1334,6 +1396,7 @@ changed shard. ```text python3 scripts/nvx.py doctor --backend {kvm,mshv,whp} + [--architecture {x86_64,aarch64}] [--checks ID ...] [--openvmm PATH] [--kernel PATH] @@ -1356,22 +1419,55 @@ check and the subset that CI runs. | Option | Default | Description | | --- | --- | --- | | `--backend {kvm,mshv,whp}` | required | Select the backend to qualify. | +| `--architecture {x86_64,aarch64}` | native host ISA | Select the native counter and guest artifact ISA. Emulated-ISA qualification is refused; ARM64 requires WHP. | | `--checks ID ...` | `H1` to `H7` | Run only these checks, from `H1` to `H7`, in order. | | `--openvmm PATH` | `openvmm/target/release/openvmm[.exe]` | Select the OpenVMM binary for `H2`, `H3`, and `H6`. | -| `--kernel PATH` | `build/vmlinux` | Select the guest kernel for `H3` and `H6`. | -| `--initrd PATH` | `build/initramfs.cpio.gz` | Select the guest initramfs for `H3` and `H6`. | -| `--cpu-fingerprint PATH` | `nvx-cpu-fingerprint-.json` in the probe directory | Select where `H2` writes OpenVMM's CPU fingerprint. | -| `--no-openvmm` | off | Qualify without an OpenVMM binary. `H2` then checks the CPU identity and generation but not the CPU profile, and `--checks` must exclude `H3` and `H6`, which boot OpenVMM. | +| `--kernel PATH` | `build/vmlinux`, or `build/aarch64/Image` on ARM64 | Select the guest kernel for `H3` and `H6`. | +| `--initrd PATH` | `build/initramfs.cpio.gz`, or `build/aarch64/initramfs.cpio.gz` on ARM64 | Select the guest initramfs for `H3` and `H6`. | +| `--cpu-fingerprint PATH` | `nvx-cpu-fingerprint-.json` in the probe directory | Select where x86 `H2` writes OpenVMM's CPU fingerprint. Explicit use on ARM is rejected, not redirected to another format. | +| `--no-openvmm` | off | Qualify without an OpenVMM binary. x86 `H2` checks CPU identity/generation but not the profile; ARM `H2` remains nonpassing without admission evidence. Exclude `H3` and `H6`, which launch OpenVMM. | | `--ci-schedule` | off | Run `H4` and `H6` on CI's short schedules: 3 rate samples 1 s apart instead of 13 samples 10 s apart, and two warp-probe runs instead of five. | | `--probe-dir PATH` | `$RUNNER_TOOL_CACHE/nvx-host-time-probe`, or `build/host-time-probe` | Select the cache directory for the host probe, which the doctor builds with `rustc`. | | `--summary PATH` | none | Append a Markdown summary, for example to `$GITHUB_STEP_SUMMARY`. | | `--timeout SECONDS` | `120` | Set the seconds allowed for each probe or guest. `H4` gets its sampling window on top. | +The host probe cache is ISA-specific. On ARM64, `H4` measures `CNTVCT_EL0` +against the same host clock references and applies the same stability, +uncertainty, correction and synchronization assertions as x86. Its native +`CNTFRQ_EL0` observation is not VMM programming/readback or CPU-profile proof. +The existing `tsc_hz` fact slots remain compatibility fields for counter rates. +QPC and the architected counter may share an oscillator, so their agreement +does not independently establish a UTC frequency or authority. Windows' +programmed-adjustment mode alone does not establish whether UTC is +synchronized; the retained published-status gate and `H7`'s source check +remain distinct. Read-only NTP offset observations do not discipline Windows +or substitute for those admission requirements. + +ARM `H2` and `H3` share one invocation of OpenVMM's existing experimental +time ABI verifier when the selected OpenVMM supports its ARM +report. They require a registered profile/digest, observed counter and address +metadata, verified feature-bank and effective-ID admission, and +`guest_started=false`; selected-contract INFO logs do not substitute. Legacy +ARM `--cpu-fingerprint` remains unsupported. A VMM without the ARM verifier +fails explicitly, rather than skipping or reinterpreting x86 fields. + +The verifier may create partition and VP objects, but returns before guest +execution; its success is neither a claim of no VP allocation nor UTC +authority. Both ISAs run only the selected checks; unselected checks remain +unverified. Partial warp/counter evidence is not full host or UTC qualification, +and any failed selected check fails the run. Local and CI checks use the same +scenarios and assertions on any admitted native ARM64/WHP host. Profile +identities and address requirements come from registered catalog data, counter +frequency from native/admitted observations, and capacity from the host; +the currently recorded Oryon results do not qualify other hardware. + ### `test-runtime-adapter` ```text python3 scripts/nvx.py test-runtime-adapter --backend {kvm,mshv,whp} + [--architecture {x86_64,aarch64}] + [--cold-only] [--guest-agent PATH] [--check-only] [--cargo CARGO] diff --git a/kernel/patches/arm64/0001-nvx-platform-mmio.patch b/kernel/patches/arm64/0001-nvx-platform-mmio.patch index eb4f7f2ad..09a7d4202 100644 --- a/kernel/patches/arm64/0001-nvx-platform-mmio.patch +++ b/kernel/patches/arm64/0001-nvx-platform-mmio.patch @@ -35,7 +35,7 @@ Subject: [PATCH] hvc: add the restricted NVX ARM64 development platform binding obj-$(CONFIG_HVC_RISCV_SBI) += hvc_riscv_sbi.o --- a/drivers/tty/hvc/hvc_nvx_mmio.c +++ b/drivers/tty/hvc/hvc_nvx_mmio.c -@@ -0,0 +1,253 @@ +@@ -0,0 +1,277 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include @@ -43,12 +43,16 @@ Subject: [PATCH] hvc: add the restricted NVX ARM64 development platform binding +#include +#include +#include ++#include +#include +#include ++#include +#include +#include +#include ++#include +#include ++#include + +#include "hvc_console.h" + @@ -103,11 +107,31 @@ Subject: [PATCH] hvc: add the restricted NVX ARM64 development platform binding + writeb(text[i], device->port.membase + NVX_DATA); +} + ++static char nvx_early_cmdline[COMMAND_LINE_SIZE] __initdata; ++ ++static int __init nvx_early_loglevel(char *param, char *val, ++ const char *unused, void *arg) ++{ ++ int level; ++ ++ if (!strcmp(param, "quiet")) ++ console_loglevel = CONSOLE_LOGLEVEL_QUIET; ++ else if (!strcmp(param, "debug")) ++ console_loglevel = CONSOLE_LOGLEVEL_DEBUG; ++ else if (!strcmp(param, "loglevel") && val && get_option(&val, &level)) ++ console_loglevel = level; ++ return 0; ++} ++ +static int __init nvx_early_setup(struct earlycon_device *device, + const char *options) +{ + if (device->port.mapbase != NVX_BASE || !device->port.membase) + return -EINVAL; ++ /* Apply later loglevel options before earlycon flushes its print buffer. */ ++ strscpy(nvx_early_cmdline, boot_command_line, sizeof(nvx_early_cmdline)); ++ parse_args("early NVX console", nvx_early_cmdline, NULL, 0, 0, 0, NULL, ++ nvx_early_loglevel); + device->con->write = nvx_early_write; + return 0; +} diff --git a/nvx-rs/README.md b/nvx-rs/README.md index 5218bb770..46888ff0b 100644 --- a/nvx-rs/README.md +++ b/nvx-rs/README.md @@ -2797,9 +2797,14 @@ disk's block device. | `nvx-managed-agent CONTROL_TTY ROOTFS HOSTNAME UID GID USER HOME` | Serves the managed control session and supervises sequential workloads; `--exec-config-fd FD -- WORKLOAD ...` is the direct agent's internal launch helper | | `nvx-ingress [inherit\|start] GATEWAY_IPV4` | Announces reachable TCP listeners and settled UDP sockets to the portable-network gateway, from a privileged source port that it binds, or, with `inherit`, from its standard input, a socket that a clone's application bound to one; `start` starts `inherit` as `Announcer::start` does and exits once it runs, or with status 1 if it does not start, for a guest agent that cannot hold the announcer; `test DIRECTORY` runs synthetic procfs snapshots | | `nvx-time [--report-only] COMMAND` | Enforces NVX time ABI v1 through shared cold-boot checks, time-state publication, and the discipline and violation-watcher daemon on x86_64 and aarch64; capture/restore and the `test NAME ...` decoder and process hooks remain x86_64-only | -| `nvx-time-probe latency\|warp\|clock ...` | Diagnoses clock-read latency, cross-CPU TSC warp and offset, the clocks, CPUID, clock events, kernel messages, and optionally MSRs (x86_64) | +| `nvx-time-probe latency\|warp\|clock ...` | Diagnoses x86 clocks, CPUID and optional MSRs; the pairwise counter-warp diagnostic also supports aarch64 | | `nvx-init TIME_DAEMON [ANNOUNCER]` | Takes PID 1 over from a layered root's early boot, with its time daemon and optional announcer: gives itself and them an out-of-memory score adjustment of -1000 and a nice value of -10, collects every child's status, and, after `sync`, ends the VM with status 125 when a helper ends or 0 on `SIGTERM`; elsewhere it exits with 2 (x86_64, aarch64) | +On aarch64, the probe's measurement command is `warp`, using fenced +`CNTVCT_EL0` reads and the actual `CNTFRQ_EL0` on every selected CPU. It reports +`counter_hz` and rejects x86-only latency/clock commands and frequency overrides. +The x86 command lines and output remain unchanged. + The init agent also uses the private, read-only `nvx-init --root-device distro|scratch|no-scratch` query on ARM. It resolves only the fixed distro and scratch protocol roles through root-child OF diff --git a/nvx-rs/src/bin/nvx-time-probe.rs b/nvx-rs/src/bin/nvx-time-probe.rs index b567e8e03..c5345df99 100644 --- a/nvx-rs/src/bin/nvx-time-probe.rs +++ b/nvx-rs/src/bin/nvx-time-probe.rs @@ -1,13 +1,17 @@ //! `nvx-time-probe COMMAND [OPTIONS]`; see `nvx::guest::time_probe`. -#[cfg(all(target_os = "linux", target_arch = "x86_64"))] +#[cfg(all( + target_os = "linux", + any(target_arch = "x86_64", target_arch = "aarch64") +))] fn main() -> std::process::ExitCode { nvx::guest::time_probe::main() } -// The program measures the x86 time-stamp counter of NVX's x86_64 guests. Elsewhere this stub -// fails, so that every target that CI checks with `--all-features` still builds. -#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))] +#[cfg(not(all( + target_os = "linux", + any(target_arch = "x86_64", target_arch = "aarch64") +)))] fn main() -> std::process::ExitCode { std::process::ExitCode::FAILURE } diff --git a/nvx-rs/src/guest/mod.rs b/nvx-rs/src/guest/mod.rs index cba9eba5c..4c10e0563 100644 --- a/nvx-rs/src/guest/mod.rs +++ b/nvx-rs/src/guest/mod.rs @@ -134,6 +134,6 @@ pub mod spawn; pub mod terminal; #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] pub mod time; -#[cfg(target_arch = "x86_64")] +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] #[doc(hidden)] pub mod time_probe; diff --git a/nvx-rs/src/guest/parse.rs b/nvx-rs/src/guest/parse.rs index 0bc07d3ea..75552049a 100644 --- a/nvx-rs/src/guest/parse.rs +++ b/nvx-rs/src/guest/parse.rs @@ -19,7 +19,6 @@ use std::str::FromStr; /// /// Returns `None` for an empty argument, any other character, a decimal number with a leading /// zero, which C read as octal, or a value above `u64::MAX`. -#[cfg(any(target_arch = "x86_64", test))] pub(crate) fn parse_u64(text: &[u8]) -> Option { let text = std::str::from_utf8(text).ok()?; let (digits, radix) = match text.strip_prefix("0x").or_else(|| text.strip_prefix("0X")) { diff --git a/nvx-rs/src/guest/status.rs b/nvx-rs/src/guest/status.rs index 00db0e9a7..40d22a423 100644 --- a/nvx-rs/src/guest/status.rs +++ b/nvx-rs/src/guest/status.rs @@ -21,7 +21,6 @@ pub(crate) enum ExitStatus { Usage = 2, /// A benchmark could not open, connect, size, or time its device, or a diagnostic could not /// prepare or run its measurement. - #[cfg(any(target_arch = "x86_64", test))] SetupFailure = 3, /// A benchmark transfer or send was incomplete. #[cfg(any(target_arch = "x86_64", test))] @@ -42,7 +41,6 @@ pub(crate) enum CommandError { Operation, /// A benchmark could not open, connect, size, or time its device, or a diagnostic could not /// prepare or run its measurement. - #[cfg(any(target_arch = "x86_64", test))] Setup, /// A benchmark transfer or send was incomplete. #[cfg(any(target_arch = "x86_64", test))] @@ -61,7 +59,6 @@ impl From> for ExitStatus { Ok(()) => Self::Success, Err(CommandError::Usage) => Self::Usage, Err(CommandError::Operation) => Self::Failure, - #[cfg(any(target_arch = "x86_64", test))] Err(CommandError::Setup) => Self::SetupFailure, #[cfg(any(target_arch = "x86_64", test))] Err(CommandError::Transfer) => Self::TransferFailure, diff --git a/nvx-rs/src/guest/sys/clock.rs b/nvx-rs/src/guest/sys/clock.rs index 81ed997bf..48e76e74a 100644 --- a/nvx-rs/src/guest/sys/clock.rs +++ b/nvx-rs/src/guest/sys/clock.rs @@ -28,7 +28,6 @@ pub(crate) enum Clock { MonotonicRaw, /// The monotonic clock as the kernel saved it at the last scheduler tick, which a read /// returns without reading the clocksource, so that it advances once per tick. - #[cfg(any(target_arch = "x86_64", test))] MonotonicCoarse, /// The time since boot, with suspend. Boottime, @@ -44,7 +43,6 @@ impl Clock { Self::Monotonic => ClockId::CLOCK_MONOTONIC, #[cfg(any(target_arch = "x86_64", test))] Self::MonotonicRaw => ClockId::CLOCK_MONOTONIC_RAW, - #[cfg(any(target_arch = "x86_64", test))] Self::MonotonicCoarse => ClockId::CLOCK_MONOTONIC_COARSE, Self::Boottime => ClockId::CLOCK_BOOTTIME, Self::ProcessCpuTime => ClockId::CLOCK_PROCESS_CPUTIME_ID, diff --git a/nvx-rs/src/guest/sys/mod.rs b/nvx-rs/src/guest/sys/mod.rs index fef6e22a1..5c382ffc4 100644 --- a/nvx-rs/src/guest/sys/mod.rs +++ b/nvx-rs/src/guest/sys/mod.rs @@ -151,12 +151,12 @@ pub(crate) use rooted::{ set_mount_attributes, unmount_beneath, }; pub(crate) use scheduler::{ - AffinityGuard, IdlePriority, pin_current_thread, promote_all_threads, thread_count, + AffinityGuard, IdlePriority, current_affinity, pin_current_thread, promote_all_threads, + thread_count, }; #[cfg(target_arch = "x86_64")] pub(crate) use scheduler::{ - SchedulingPolicy, current_affinity, current_cpu, current_thread, scheduling_policy, - set_scheduling_policy, + SchedulingPolicy, current_cpu, current_thread, scheduling_policy, set_scheduling_policy, }; pub(crate) use secret::zeroize; #[cfg(any(target_arch = "x86_64", test))] diff --git a/nvx-rs/src/guest/sys/scheduler.rs b/nvx-rs/src/guest/sys/scheduler.rs index ba48f9e4c..135fdabd2 100644 --- a/nvx-rs/src/guest/sys/scheduler.rs +++ b/nvx-rs/src/guest/sys/scheduler.rs @@ -21,10 +21,8 @@ const PROMOTION_PASSES: usize = 2; /// A CPU affinity mask. #[derive(Clone, Debug)] -#[cfg(any(target_arch = "x86_64", test))] pub(crate) struct CpuAffinity(CpuSet); -#[cfg(any(target_arch = "x86_64", test))] impl CpuAffinity { /// Returns whether the mask contains `cpu`. pub(crate) fn contains(&self, cpu: usize) -> bool { @@ -40,7 +38,6 @@ impl CpuAffinity { } /// Returns the calling thread's CPU affinity mask. -#[cfg(any(target_arch = "x86_64", test))] pub(crate) fn current_affinity() -> Result { sched_getaffinity(CALLING_THREAD).map(CpuAffinity) } diff --git a/nvx-rs/src/guest/time_probe/format.rs b/nvx-rs/src/guest/time_probe/format.rs index 022ea049d..419d3f074 100644 --- a/nvx-rs/src/guest/time_probe/format.rs +++ b/nvx-rs/src/guest/time_probe/format.rs @@ -5,13 +5,17 @@ //! spellings of the values that are not finite differ, which [`fixed`] maps to C's. /// Seconds in a day, which split a time into its day and the seconds within it. +#[cfg(target_arch = "x86_64")] const SECONDS_PER_DAY: i64 = 24 * 60 * 60; /// Days from 0000-03-01 to 1970-01-01 in the proleptic Gregorian calendar, which /// [`civil_date`] counts from. +#[cfg(target_arch = "x86_64")] const DAYS_TO_UNIX_EPOCH: i64 = 719_468; /// Days in a 400-year cycle of the Gregorian calendar. +#[cfg(target_arch = "x86_64")] const DAYS_PER_ERA: i64 = 146_097; /// Years in a 400-year cycle of the Gregorian calendar. +#[cfg(target_arch = "x86_64")] const YEARS_PER_ERA: i64 = 400; /// Formats `value` with C's `%.{precision}f`. @@ -39,12 +43,14 @@ pub(super) fn f1(value: f64) -> String { } /// Formats a nine-decimal seconds field with C `%.9f`. +#[cfg(target_arch = "x86_64")] pub(super) fn f9(value: f64) -> String { fixed(value, 9) } /// Returns the proleptic Gregorian year, month, and day of `days` since 1970-01-01, by Howard /// Hinnant's `civil_from_days`, which counts from 0000-03-01 so that a leap day ends its year. +#[cfg(target_arch = "x86_64")] fn civil_date(days: i64) -> (i64, i64, i64) { let days = days + DAYS_TO_UNIX_EPOCH; let era = days.div_euclid(DAYS_PER_ERA); @@ -65,6 +71,7 @@ fn civil_date(days: i64) -> (i64, i64, i64) { /// Formats Unix `seconds` as C's `strftime` with `%Y-%m-%dT%H:%M:%S` formats `gmtime_r`'s /// UTC broken-down time. +#[cfg(target_arch = "x86_64")] pub(super) fn utc_seconds(seconds: i64) -> String { let (year, month, day) = civil_date(seconds.div_euclid(SECONDS_PER_DAY)); let time = seconds.rem_euclid(SECONDS_PER_DAY); diff --git a/nvx-rs/src/guest/time_probe/format/tests.rs b/nvx-rs/src/guest/time_probe/format/tests.rs index 363e8738f..9d0ec8292 100644 --- a/nvx-rs/src/guest/time_probe/format/tests.rs +++ b/nvx-rs/src/guest/time_probe/format/tests.rs @@ -5,10 +5,12 @@ fn formats_with_c_rounding_and_spelling() { assert_eq!(f0(12.5), "12"); assert_eq!(f0(13.5), "14"); assert_eq!(f1(12.25), "12.2"); + #[cfg(target_arch = "x86_64")] assert_eq!(f9(1.5), "1.500000000"); assert_eq!(f1(-0.0), "-0.0"); assert_eq!(f0(f64::INFINITY), "inf"); assert_eq!(f1(f64::NEG_INFINITY), "-inf"); + #[cfg(target_arch = "x86_64")] assert_eq!(f9(f64::NAN), "nan"); assert_eq!(f0(-f64::NAN), "-nan"); } @@ -24,12 +26,16 @@ fn formats_the_complete_finite_double_range_without_truncation() { assert_eq!(one_decimal.len(), 311); assert!(one_decimal.ends_with(".0")); - let nine_decimals = f9(f64::MAX); - assert_eq!(nine_decimals.len(), 319); - assert!(nine_decimals.ends_with(".000000000")); + #[cfg(target_arch = "x86_64")] + { + let nine_decimals = f9(f64::MAX); + assert_eq!(nine_decimals.len(), 319); + assert!(nine_decimals.ends_with(".000000000")); + } } #[test] +#[cfg(target_arch = "x86_64")] fn utc_times_follow_the_gregorian_calendar() { assert_eq!(utc_seconds(0), "1970-01-01T00:00:00"); assert_eq!(utc_seconds(-1), "1969-12-31T23:59:59"); diff --git a/nvx-rs/src/guest/time_probe/mod.rs b/nvx-rs/src/guest/time_probe/mod.rs index 8ba01524c..6a2669867 100644 --- a/nvx-rs/src/guest/time_probe/mod.rs +++ b/nvx-rs/src/guest/time_probe/mod.rs @@ -1,14 +1,18 @@ //! `nvx-time-probe`, the guest-side diagnostics for the NVX time ABI. //! -//! It keeps the commands, output, and exit statuses of the C program that it replaced: 0 on +//! On x86 it keeps the commands and output of the C program that it replaced. ARM shares +//! the warp algorithm using the architectural virtual counter, without x86-only commands. +//! Both keep the exit statuses: 0 on //! success, 1 for a warp check that fails, 2 for an invalid command line, and 3 for a //! measurement that could not run. Its numeric options are plain decimal, or `0x`-prefixed //! hexadecimal for the integers, and its rate options decimal floating point, as the other guest //! programs read their arguments. It reads the kernel's numbers, such as `/proc/cpuinfo`'s //! rates, only in the form in which the kernel writes them. +#[cfg(target_arch = "x86_64")] mod clock; mod format; +#[cfg(target_arch = "x86_64")] mod latency; mod support; mod warp; @@ -26,6 +30,7 @@ pub(super) const VERSION: &str = "1.1"; pub(super) const MAX_CPUS: usize = 1024; /// Byte-exact command help and exit-status contract. +#[cfg(target_arch = "x86_64")] const USAGE: &[u8] = br#"usage: nvx-time-probe COMMAND [OPTIONS] Commands: @@ -51,6 +56,21 @@ The TSC rate comes from --tsc-hz, sysfs tsc_freq_khz, the kernel log, or Exit status: 0 success, 1 warp FAIL, 2 usage error, 3 runtime error. "#; +/// ARM keeps the pairwise algorithm without advertising x86-only diagnostics. +#[cfg(target_arch = "aarch64")] +const USAGE: &[u8] = br#"usage: nvx-time-probe COMMAND [OPTIONS] + +Commands: + warp [--duration-ms N] [--cpus LIST] [--bound-ns N] + Pairwise cross-CPU CNTVCT_EL0 checks: spinlock monotonicity and + ping-pong offset bounds, each running N ms per pair (default 100). + LIST looks like 0-3,6 (default: every CPU in the affinity mask). + The bound defaults to 1000 ns; the rate is read from CNTFRQ_EL0. + version + +Exit status: 0 success, 1 warp FAIL, 2 usage error, 3 runtime error. +"#; + /// Writes one diagnostic assembled from byte slices. pub(super) fn report(stream: &mut dyn Write, parts: &[&[u8]]) { sys::report(stream, parts); @@ -77,8 +97,10 @@ fn run( return Err(CommandError::Usage); }; match command { + #[cfg(target_arch = "x86_64")] b"latency" => latency::run(rest, out, err), b"warp" => warp::run(rest, out, err), + #[cfg(target_arch = "x86_64")] b"clock" => clock::run(rest, out, err), b"version" | b"--version" => { let _ = writeln!(out, "nvx-time-probe {VERSION}"); diff --git a/nvx-rs/src/guest/time_probe/support.rs b/nvx-rs/src/guest/time_probe/support.rs index 1a72b5fd1..6a32338c6 100644 --- a/nvx-rs/src/guest/time_probe/support.rs +++ b/nvx-rs/src/guest/time_probe/support.rs @@ -2,62 +2,90 @@ use std::fmt; use std::io::Write; -use std::sync::OnceLock; -use std::time::Duration; +#[cfg(target_arch = "x86_64")] +use std::{sync::OnceLock, time::Duration}; -use crate::guest::kernel_text::{self, KmsgRecord, SyslogLine}; +use crate::guest::kernel_text; +#[cfg(target_arch = "x86_64")] +use crate::guest::kernel_text::{KmsgRecord, SyslogLine}; +#[cfg(target_arch = "x86_64")] use crate::guest::parse::{parse_decimal, parse_f64}; use crate::guest::status::CommandError; -use crate::guest::sys::{self, Errno, Mode, OpenFlags, TimeValLike, kernel}; +use crate::guest::sys::{self, Errno}; +#[cfg(target_arch = "x86_64")] +use crate::guest::sys::{Mode, OpenFlags, TimeValLike, kernel}; use super::MAX_CPUS; /// The largest structured `/dev/kmsg` record, the kernel's `CONSOLE_EXT_LOG_MAX`. +#[cfg(target_arch = "x86_64")] const KMSG_RECORD_MAX: usize = 8192; /// Size of the buffer for the kernel's log when the kernel does not report the log's size. +#[cfg(target_arch = "x86_64")] const FALLBACK_LOG_SIZE: usize = 1 << 20; -/// Nanoseconds in a second, which scale a TSC rate's cycles. +/// Nanoseconds in a second, which scale the selected counter's cycles. pub(super) const NANOSECONDS_PER_SECOND: f64 = 1e9; /// kHz in a MHz, and Hz in a kHz. +#[cfg(target_arch = "x86_64")] const THOUSAND: f64 = 1000.0; /// The interval over which the probe measures the TSC rate when nothing reports it. +#[cfg(target_arch = "x86_64")] const MEASURE_INTERVAL: Duration = Duration::from_millis(200); -/// Where the probe found the TSC rate. +/// Where the probe found the selected ISA's counter rate. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(super) enum TscRateSource { /// The `--tsc-hz` option. + #[cfg(target_arch = "x86_64")] Option, /// The kernel's `tsc_freq_khz` sysfs attribute. + #[cfg(target_arch = "x86_64")] SysfsTscFreqKhz, /// The kernel log's refined TSC calibration. + #[cfg(target_arch = "x86_64")] KmsgRefined, /// The kernel log's detected TSC rate. + #[cfg(target_arch = "x86_64")] KmsgDetectedTsc, /// The kernel log's detected processor rate. + #[cfg(target_arch = "x86_64")] KmsgDetectedProcessor, /// The first `cpu MHz` of `/proc/cpuinfo`. + #[cfg(target_arch = "x86_64")] CpuinfoCpuMhz, /// A measurement against `CLOCK_MONOTONIC_RAW`. + #[cfg(target_arch = "x86_64")] MeasuredMonotonicRaw, + /// The actual architectural nominal frequency, without a guessed or measured fallback. + #[cfg(target_arch = "aarch64")] + CntfrqEl0, } impl fmt::Display for TscRateSource { /// Writes the source's stable output token. fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str(match self { + #[cfg(target_arch = "x86_64")] Self::Option => "option", + #[cfg(target_arch = "x86_64")] Self::SysfsTscFreqKhz => "sysfs-tsc_freq_khz", + #[cfg(target_arch = "x86_64")] Self::KmsgRefined => "kmsg-refined", + #[cfg(target_arch = "x86_64")] Self::KmsgDetectedTsc => "kmsg-detected-tsc", + #[cfg(target_arch = "x86_64")] Self::KmsgDetectedProcessor => "kmsg-detected-processor", + #[cfg(target_arch = "x86_64")] Self::CpuinfoCpuMhz => "cpuinfo-cpu-mhz", + #[cfg(target_arch = "x86_64")] Self::MeasuredMonotonicRaw => "measured-monotonic-raw", + #[cfg(target_arch = "aarch64")] + Self::CntfrqEl0 => "cntfrq_el0", }) } } -/// Detected TSC frequency and the source that supplied it. +/// Counter frequency and the source that supplied it. #[derive(Clone, Copy)] pub(super) struct TscRate { /// Cycles per second, zero for a measurement that could not read its clock. @@ -67,6 +95,7 @@ pub(super) struct TscRate { } /// Parses a positive, finite rate option, such as `--tsc-hz`, in decimal floating point. +#[cfg(target_arch = "x86_64")] pub(super) fn parse_rate(text: &[u8]) -> Option { parse_f64(text).filter(|value| *value > 0.0) } @@ -197,6 +226,7 @@ pub(super) fn format_cpu_list(cpus: &[usize]) -> String { /// Parses a decimal number in the form in which the kernel prints rates, such as `2194.843`: /// digits with an optional fraction, after optional spaces and tabs. +#[cfg(target_arch = "x86_64")] fn parse_kernel_decimal(text: &[u8]) -> Option { let number = std::str::from_utf8(text) .ok()? @@ -212,6 +242,7 @@ fn parse_kernel_decimal(text: &[u8]) -> Option { /// Iterates the records of the nonblocking `/dev/kmsg`, skipping those that the kernel overwrote /// before the probe read them. Fails with the error that ended the reading when it read no /// record, such as `EAGAIN` for a log without records. +#[cfg(target_arch = "x86_64")] fn kmsg_from_dev(mut consume: impl FnMut(KmsgRecord<'_>)) -> Result<(), Errno> { let log = sys::open( kernel::KERNEL_LOG_DEVICE, @@ -238,6 +269,7 @@ fn kmsg_from_dev(mut consume: impl FnMut(KmsgRecord<'_>)) -> Result<(), Errno> { /// Iterates the lines of the whole `syslog(2)` buffer, which the probe reads when `/dev/kmsg` /// yields no records. +#[cfg(target_arch = "x86_64")] fn kmsg_from_syslog(mut consume: impl FnMut(KmsgRecord<'_>)) -> Result<(), Errno> { let size = kernel::kernel_log_size() .ok() @@ -261,17 +293,20 @@ fn kmsg_from_syslog(mut consume: impl FnMut(KmsgRecord<'_>)) -> Result<(), Errno } /// Iterates kernel messages, preferring structured `/dev/kmsg`. +#[cfg(target_arch = "x86_64")] pub(super) fn kmsg_foreach(mut consume: impl FnMut(KmsgRecord<'_>)) -> Result<(), Errno> { kmsg_from_dev(&mut consume).or_else(|_| kmsg_from_syslog(consume)) } /// Reads `/proc/cpuinfo` once, as raw bytes, which are empty when it cannot be read. +#[cfg(target_arch = "x86_64")] fn cpuinfo() -> &'static [u8] { static TEXT: OnceLock> = OnceLock::new(); TEXT.get_or_init(|| sys::read_file(kernel::CPU_INFORMATION).unwrap_or_default()) } /// Returns the value of the first `/proc/cpuinfo` line whose key starts with `key`. +#[cfg(target_arch = "x86_64")] fn cpuinfo_value(key: &[u8]) -> Option<&'static [u8]> { cpuinfo() .split(|&byte| byte == b'\n') @@ -283,6 +318,7 @@ fn cpuinfo_value(key: &[u8]) -> Option<&'static [u8]> { } /// Lazily extracts CPU-zero feature-flag words. +#[cfg(target_arch = "x86_64")] fn cpu_flags() -> &'static [Vec] { static FLAGS: OnceLock>> = OnceLock::new(); FLAGS.get_or_init(|| { @@ -297,11 +333,13 @@ fn cpu_flags() -> &'static [Vec] { } /// Returns whether cpuinfo contains one exact feature flag. +#[cfg(target_arch = "x86_64")] pub(super) fn cpuinfo_has_flag(flag: &[u8]) -> bool { cpu_flags().iter().any(|word| word == flag) } /// Returns the first positive cpuinfo MHz value. +#[cfg(target_arch = "x86_64")] fn cpuinfo_mhz() -> Option { cpuinfo_value(b"cpu MHz") .and_then(parse_kernel_decimal) @@ -309,6 +347,7 @@ fn cpuinfo_mhz() -> Option { } /// Returns the positive MHz value between a kernel message's `prefix` and `suffix`. +#[cfg(target_arch = "x86_64")] fn mhz_after(text: &[u8], prefix: &[u8], suffix: &[u8]) -> Option { let start = kernel_text::find(text, prefix)? + prefix.len(); let value = &text[start..]; @@ -317,12 +356,14 @@ fn mhz_after(text: &[u8], prefix: &[u8], suffix: &[u8]) -> Option { } /// Converts MHz to whole kHz, rounded, and then to hertz, as the C probe did. +#[cfg(target_arch = "x86_64")] fn mhz_to_hz(mhz: f64) -> f64 { (mhz * THOUSAND).round() * THOUSAND } /// Measures the TSC rate against the raw monotonic clock over `interval`, or returns zero when /// the clock cannot be read. +#[cfg(target_arch = "x86_64")] pub(super) fn measure_tsc_hz(interval: Duration) -> f64 { let first = sys::clock_time(sys::Clock::MonotonicRaw); let t0 = sys::x86::rdtsc_fenced(); @@ -341,6 +382,7 @@ pub(super) fn measure_tsc_hz(interval: Duration) -> f64 { } /// Returns the TSC rate that the kernel exposes in sysfs, when it does. +#[cfg(target_arch = "x86_64")] fn sysfs_tsc_rate() -> Option { let khz = parse_decimal(&sys::read_line(kernel::TSC_FREQUENCY_KHZ).ok()?)?; (khz > 0).then_some(TscRate { @@ -351,6 +393,7 @@ fn sysfs_tsc_rate() -> Option { /// Returns the TSC rate that the kernel logged: its last refined calibration, or else its last /// detected TSC rate, or else its last detected processor rate. +#[cfg(target_arch = "x86_64")] fn kmsg_tsc_rate() -> Option { let (mut refined, mut tsc, mut processor) = (None, None, None); let _ = kmsg_foreach(|record| { @@ -379,6 +422,7 @@ fn kmsg_tsc_rate() -> Option { /// Returns the rate of `/proc/cpuinfo`'s first `cpu MHz`, unless the `aperfmperf` flag shows that /// the processor's frequency varies. +#[cfg(target_arch = "x86_64")] fn cpuinfo_tsc_rate() -> Option { let mhz = cpuinfo_mhz()?; (!cpuinfo_has_flag(b"aperfmperf")).then(|| TscRate { @@ -389,6 +433,7 @@ fn cpuinfo_tsc_rate() -> Option { /// Detects the TSC rate from the `--tsc-hz` option, then sysfs, then the kernel log, then /// cpuinfo, and measures it as a last resort. +#[cfg(target_arch = "x86_64")] pub(super) fn detect_tsc_rate(override_hz: Option) -> TscRate { override_hz .map(|hz| TscRate { @@ -405,6 +450,7 @@ pub(super) fn detect_tsc_rate(override_hz: Option) -> TscRate { } /// Reads the active clocksource, or `unknown`. +#[cfg(target_arch = "x86_64")] pub(super) fn current_clocksource() -> Vec { sys::read_line(kernel::CURRENT_CLOCKSOURCE).unwrap_or_else(|_| b"unknown".to_vec()) } diff --git a/nvx-rs/src/guest/time_probe/support/tests.rs b/nvx-rs/src/guest/time_probe/support/tests.rs index cbcddffa4..f7b199f77 100644 --- a/nvx-rs/src/guest/time_probe/support/tests.rs +++ b/nvx-rs/src/guest/time_probe/support/tests.rs @@ -30,10 +30,13 @@ fn numeric_options_are_strict() { assert_eq!(parse_u64(b"10"), Some(10)); assert!(parse_u64(b"010").is_none()); assert!(parse_u64(b"1x").is_none()); - assert_eq!(parse_rate(b"2.5"), Some(2.5)); - assert_eq!(parse_rate(b"1e200"), Some(1e200)); - assert!(parse_rate(b"0").is_none()); - assert!(parse_rate(b"2.5x").is_none()); + #[cfg(target_arch = "x86_64")] + { + assert_eq!(parse_rate(b"2.5"), Some(2.5)); + assert_eq!(parse_rate(b"1e200"), Some(1e200)); + assert!(parse_rate(b"0").is_none()); + assert!(parse_rate(b"2.5x").is_none()); + } } /// Returns the diagnostic that `arguments` prints for an invalid option or value. @@ -66,6 +69,7 @@ fn options_take_inline_or_following_values() { } #[test] +#[cfg(target_arch = "x86_64")] fn kernel_numbers_are_read_in_the_kernels_form() { assert_eq!(parse_kernel_decimal(b" 2194.843"), Some(2194.843)); assert_eq!(parse_kernel_decimal(b" 3.000000"), Some(3.0)); @@ -97,6 +101,7 @@ fn kernel_numbers_are_read_in_the_kernels_form() { } #[test] +#[cfg(target_arch = "x86_64")] fn rate_sources_print_their_tokens() { assert_eq!( TscRateSource::SysfsTscFreqKhz.to_string(), diff --git a/nvx-rs/src/guest/time_probe/tests.rs b/nvx-rs/src/guest/time_probe/tests.rs index b0b03a56f..34aa5bf53 100644 --- a/nvx-rs/src/guest/time_probe/tests.rs +++ b/nvx-rs/src/guest/time_probe/tests.rs @@ -39,3 +39,48 @@ fn the_shared_statuses_keep_the_probes_contract() { assert_eq!(ExitStatus::from(result) as u8, status, "{result:?}"); } } + +#[test] +#[cfg(target_arch = "aarch64")] +fn arm_refuses_x86_diagnostics_and_counter_frequency_overrides() { + for arguments in [ + vec![&b"latency"[..]], + vec![&b"clock"[..]], + vec![&b"warp"[..], b"--tsc-hz", b"1000000000"], + vec![&b"warp"[..], b"--tsc-hz=1000000000"], + ] { + let mut out = Vec::new(); + let mut err = Vec::new(); + assert_eq!( + run(&args(&arguments), &mut out, &mut err), + Err(CommandError::Usage) + ); + assert!(out.is_empty()); + assert!(!err.is_empty()); + } +} + +#[test] +#[cfg(target_arch = "aarch64")] +fn arm_warp_reports_the_architectural_rate_without_tsc_fields() { + let cpu = support::affinity_cpus().unwrap()[0].to_string(); + let mut out = Vec::new(); + let mut err = Vec::new(); + assert_eq!( + run( + &args(&[b"warp", b"--cpus", cpu.as_bytes()]), + &mut out, + &mut err + ), + Ok(()) + ); + assert!(err.is_empty()); + let text = String::from_utf8(out).unwrap(); + let frequency = crate::guest::sys::aarch64::counter_frequency_hz().unwrap(); + assert!(text.contains(&format!( + "counter_hz={frequency} counter_hz_source=cntfrq_el0" + ))); + assert!(!text.contains("tsc_hz")); + assert!(text.contains("pairs=0 verdict=PASS bound_ns=1000")); + assert!(text.contains("conclusive=1")); +} diff --git a/nvx-rs/src/guest/time_probe/warp.rs b/nvx-rs/src/guest/time_probe/warp.rs index ac469f63c..7ce20190b 100644 --- a/nvx-rs/src/guest/time_probe/warp.rs +++ b/nvx-rs/src/guest/time_probe/warp.rs @@ -7,11 +7,78 @@ use std::thread; use super::format::{f0, f1}; use super::support::{ Arguments, NANOSECONDS_PER_SECOND, TscRate, affinity_cpus, check_cpus_allowed, cycles_to_ns, - detect_tsc_rate, format_cpu_list, parse_cpu_list, parse_rate, round_ll, + format_cpu_list, parse_cpu_list, round_ll, }; +#[cfg(target_arch = "x86_64")] +use super::support::{detect_tsc_rate, parse_rate}; use crate::guest::parse::parse_u64; use crate::guest::status::CommandError; +#[cfg(target_arch = "x86_64")] +use crate::guest::sys::x86::pause; use crate::guest::sys::{self, Errno, TimeValLike}; +#[cfg(target_arch = "aarch64")] +use std::hint::spin_loop as pause; + +/// Counter units in the ISA-specific diagnostic, without changing x86 output. +#[cfg(target_arch = "x86_64")] +const COUNTER_HZ_FIELD: &str = "tsc_hz"; +#[cfg(target_arch = "aarch64")] +const COUNTER_HZ_FIELD: &str = "counter_hz"; + +/// Reads the counter used by the unchanged pairwise algorithms. +fn read_counter() -> u64 { + #[cfg(target_arch = "x86_64")] + { + sys::x86::rdtsc() + } + #[cfg(target_arch = "aarch64")] + { + sys::aarch64::virtual_counter() + } +} + +/// Orders the counter read after preceding accesses. +fn read_counter_ordered() -> u64 { + #[cfg(target_arch = "x86_64")] + { + sys::x86::rdtsc_lfence() + } + #[cfg(target_arch = "aarch64")] + { + sys::aarch64::virtual_counter() + } +} + +/// Brackets the counter read with the ISA's existing barriers. +fn read_counter_fenced() -> u64 { + #[cfg(target_arch = "x86_64")] + { + sys::x86::rdtsc_fenced() + } + #[cfg(target_arch = "aarch64")] + { + sys::aarch64::virtual_counter() + } +} + +/// Requires the actual nominal counter frequency to agree on every selected CPU. +#[cfg(target_arch = "aarch64")] +fn architectural_rate(cpus: &[usize]) -> Result { + let _affinity = sys::AffinityGuard::save()?; + let mut frequency = None; + for &cpu in cpus { + sys::pin_current_thread(cpu)?; + let current = sys::aarch64::counter_frequency_hz()?; + if frequency.is_some_and(|previous| previous != current) { + return Err(Errno::EPROTO); + } + frequency = Some(current); + } + Ok(TscRate { + hz: frequency.ok_or(Errno::EINVAL)? as f64, + source: super::support::TscRateSource::CntfrqEl0, + }) +} /// Milliseconds that each test runs per CPU pair without `--duration-ms`. const DEFAULT_DURATION_MS: u64 = 100; @@ -221,7 +288,7 @@ fn barrier(ready: &AtomicU32, abort: &AtomicBool, failed: bool) -> bool { } ready.fetch_add(1, Ordering::SeqCst); while ready.load(Ordering::SeqCst) < 2 { - sys::x86::pause(); + pause(); } !abort.load(Ordering::SeqCst) } @@ -250,7 +317,7 @@ fn warp_worker( if !barrier(&state.ready.0, &state.abort, pinned.is_err()) { return pinned.map(|()| 0); } - let end = sys::x86::rdtsc_lfence().wrapping_add(budget_cycles); + let end = read_counter_ordered().wrapping_add(budget_cycles); let deadline = coarse_ns().wrapping_add( (cycles_to_ns(budget_cycles as f64, rate) + STALL_SECONDS * NANOSECONDS_PER_SECOND) as u64, ); @@ -258,11 +325,11 @@ fn warp_worker( loop { while state.lock.0.swap(true, Ordering::Acquire) { while state.lock.0.load(Ordering::Relaxed) { - sys::x86::pause(); + pause(); } } let previous = state.last_tsc.load(Ordering::Relaxed); - let now = sys::x86::rdtsc_lfence(); + let now = read_counter_ordered(); state.last_tsc.store(now, Ordering::Relaxed); if previous > now { state.max_warp.fetch_max(previous - now, Ordering::Relaxed); @@ -271,7 +338,7 @@ fn warp_worker( state.lock.0.store(false, Ordering::Release); if iteration & WARP_CHECK_MASK == 0 { if leader - && (sys::x86::rdtsc() > end + && (read_counter() > end || (iteration & WARP_STALL_CHECK_MASK == 0 && coarse_ns() > deadline)) { state.stop.store(true, Ordering::Relaxed); @@ -314,7 +381,7 @@ fn ping_leader( if !barrier(&state.ready.0, &state.abort, pinned.is_err()) { return Err(pinned.err().unwrap_or(Errno::EINVAL)); } - let end = sys::x86::rdtsc_lfence().wrapping_add(budget_cycles); + let end = read_counter_ordered().wrapping_add(budget_cycles); let mut result = LeaderResult { rounds: 0, min_rtt: u64::MAX, @@ -326,18 +393,18 @@ fn ping_leader( let mut round = 1_u64; loop { let mut spins = 0_u64; - let t1 = sys::x86::rdtsc_fenced(); + let t1 = read_counter_fenced(); state.sequence.0.store(2 * round - 1, Ordering::Release); while state.sequence.0.load(Ordering::Acquire) != 2 * round { spins += 1; - if spins & SPIN_CHECK_MASK == 0 && sys::x86::rdtsc().wrapping_sub(t1) > stall_cycles { + if spins & SPIN_CHECK_MASK == 0 && read_counter().wrapping_sub(t1) > stall_cycles { result.stalled = true; state.sequence.0.store(PP_STOP, Ordering::Release); return Ok(result); } - sys::x86::pause(); + pause(); } - let t3 = sys::x86::rdtsc_lfence(); + let t3 = read_counter_ordered(); let t2 = state.t2.load(Ordering::Relaxed); let rtt = t3.wrapping_sub(t1); let lo = t2.wrapping_sub(t3) as i64; @@ -352,7 +419,7 @@ fn ping_leader( offsets.push(lo.wrapping_add(hi)); } result.rounds = round; - if round & PING_CHECK_MASK == 0 && sys::x86::rdtsc() > end { + if round & PING_CHECK_MASK == 0 && read_counter() > end { state.sequence.0.store(PP_STOP, Ordering::Release); return Ok(result); } @@ -381,16 +448,16 @@ fn ping_follower(state: &PingState, cpu: usize, stall_cycles: u64) -> Result<(), } spins += 1; if spins & SPIN_CHECK_MASK == 0 { - let now = sys::x86::rdtsc(); + let now = read_counter(); if wait_start == 0 { wait_start = now; } else if now.wrapping_sub(wait_start) > stall_cycles { return Ok(()); } } - sys::x86::pause(); + pause(); } - state.t2.store(sys::x86::rdtsc_fenced(), Ordering::Relaxed); + state.t2.store(read_counter_fenced(), Ordering::Relaxed); state.sequence.0.store(2 * round, Ordering::Release); round += 1; } @@ -473,6 +540,7 @@ pub(super) fn run( ) -> Result<(), CommandError> { let mut duration_ms = DEFAULT_DURATION_MS; let mut bound_ns = DEFAULT_BOUND_NS; + #[cfg(target_arch = "x86_64")] let mut override_hz = None; let mut cpus = None; let mut arguments = Arguments::new(b"warp", arguments); @@ -487,7 +555,15 @@ pub(super) fn run( } else if let Some(value) = arguments.value(argument, b"--bound-ns") { bound_ns = parse_u64(value).ok_or_else(|| arguments.invalid(err))?; } else if let Some(value) = arguments.value(argument, b"--tsc-hz") { - override_hz = Some(parse_rate(value).ok_or_else(|| arguments.invalid(err))?); + #[cfg(target_arch = "x86_64")] + { + override_hz = Some(parse_rate(value).ok_or_else(|| arguments.invalid(err))?); + } + #[cfg(target_arch = "aarch64")] + { + let _ = value; + return Err(arguments.invalid(err)); + } } else { return Err(arguments.invalid(err)); } @@ -514,7 +590,21 @@ pub(super) fn run( CommandError::Setup })?; check_cpus_allowed(b"warp", &cpus, err)?; + #[cfg(target_arch = "x86_64")] let rate = detect_tsc_rate(override_hz); + #[cfg(target_arch = "aarch64")] + let rate = architectural_rate(&cpus).map_err(|error| { + super::report( + err, + &[ + b"nvx-time-probe warp: invalid per-CPU CNTFRQ_EL0: ", + error.desc().as_bytes(), + b"\n", + ], + ); + CommandError::Setup + })?; + #[cfg(target_arch = "x86_64")] if rate.hz <= 0.0 { super::report( err, @@ -534,7 +624,7 @@ pub(super) fn run( let _ = writeln!( out, "nvx-time-probe {} warp: cpus={cpu_text} pairs={expected_pairs} duration_ms={duration_ms} \ - (per test per pair) tsc_hz={} tsc_hz_source={} bound_ns={bound_ns}", + (per test per pair) {COUNTER_HZ_FIELD}={} {COUNTER_HZ_FIELD}_source={} bound_ns={bound_ns}", super::VERSION, f0(rate.hz), rate.source @@ -618,10 +708,15 @@ pub(super) fn run( let _ = writeln!(out, "single CPU: no pairs to compare"); } if !conclusive { + let read_name = if cfg!(target_arch = "x86_64") { + "RDTSC" + } else { + "CNTVCT_EL0" + }; let _ = writeln!( out, "warning: offset uncertainty (+/-{} ns) is not below the bound ({bound_ns} ns); \ - the verdict is not conclusive (trapped RDTSC or a descheduled vCPU?)", + the verdict is not conclusive (trapped {read_name} or a descheduled vCPU?)", round_ll(cycles_to_ns(max_uncertainty, rate)) ); } @@ -637,8 +732,8 @@ pub(super) fn run( out, "NVX-TIME-PROBE warp-detail max_abs_offset_cycles={} max_uncertainty_ns={} \ max_skew_bound_ns={} total_warps={total_warps} inconsistent_pairs={inconsistent} \ - stalled_pairs={stalled} cpus={cpu_text} duration_ms={duration_ms} tsc_hz={} \ - tsc_hz_source={} conclusive={}", + stalled_pairs={stalled} cpus={cpu_text} duration_ms={duration_ms} {COUNTER_HZ_FIELD}={} \ + {COUNTER_HZ_FIELD}_source={} conclusive={}", f1(max_abs_offset), round_ll(cycles_to_ns(max_uncertainty, rate)), round_ll(cycles_to_ns(max_skew_bound, rate)), diff --git a/nvx-rs/src/guest/time_probe/warp/tests.rs b/nvx-rs/src/guest/time_probe/warp/tests.rs index 819cbe2ee..0ac5778cc 100644 --- a/nvx-rs/src/guest/time_probe/warp/tests.rs +++ b/nvx-rs/src/guest/time_probe/warp/tests.rs @@ -4,9 +4,27 @@ use super::*; /// A TSC rate of 1 GHz, at which a cycle is a nanosecond. const GIGAHERTZ: TscRate = TscRate { hz: 1e9, + #[cfg(target_arch = "x86_64")] source: TscRateSource::Option, + #[cfg(target_arch = "aarch64")] + source: TscRateSource::CntfrqEl0, }; +#[test] +#[cfg(target_arch = "aarch64")] +fn arm_warp_uses_the_actual_counter_rate_and_restores_affinity() { + let before = affinity_cpus().unwrap(); + let rate = architectural_rate(&before[..1]).unwrap(); + assert_eq!( + rate.hz, + sys::aarch64::counter_frequency_hz().unwrap() as f64 + ); + assert_eq!(rate.source, TscRateSource::CntfrqEl0); + assert_eq!(affinity_cpus().unwrap(), before); + assert!(matches!(architectural_rate(&[]), Err(Errno::EINVAL))); + assert_eq!(affinity_cpus().unwrap(), before); +} + /// Returns a ping-pong leader's result whose round trips bound the offset to `lo..=hi` /// cycles, and whose quickest round trip took `min_rtt` cycles at twice the offset /// `min_offset_x2`. diff --git a/nvx-rs/src/host/cli/cpu_generations.json b/nvx-rs/src/host/cli/cpu_generations.json index 501f33fc5..7bbf35e92 100644 --- a/nvx-rs/src/host/cli/cpu_generations.json +++ b/nvx-rs/src/host/cli/cpu_generations.json @@ -81,5 +81,31 @@ "name": "turin", "cpus": [{ "family": 26, "model": 2, "steppings": [0, 15] }] } + }, + { + "vendor": "qualcomm", + "sha256": "sha256:20960eafb1f3fb34304b876506e4345bd3fcfb626635d9927ac362898854394d", + "profile": { + "schema": "nvx.arm64.cpu.v1", + "id": "qualcomm.oryon-x1.v1", + "physical_address_bits": 36, + "fields": [ + { "register": "ID_AA64PFR0_EL1" }, + { "register": "ID_AA64PFR1_EL1" }, + { "register": "ID_AA64PFR2_EL1" }, + { "register": "ID_AA64ISAR0_EL1" }, + { "register": "ID_AA64ISAR1_EL1" }, + { "register": "ID_AA64ISAR2_EL1" }, + { "register": "ID_AA64MMFR0_EL1" }, + { "register": "ID_AA64MMFR1_EL1" }, + { "register": "ID_AA64MMFR2_EL1" }, + { "register": "ID_AA64MMFR3_EL1" }, + { "register": "ID_AA64MMFR4_EL1" }, + { "register": "ID_AA64DFR0_EL1" }, + { "register": "ID_AA64DFR1_EL1" }, + { "register": "ID_AA64ZFR0_EL1" }, + { "register": "ID_AA64SMFR0_EL1" } + ] + } } ] diff --git a/nvx-rs/src/host/cli/cpu_profile.rs b/nvx-rs/src/host/cli/cpu_profile.rs index b0eaf16cc..38bb314c1 100644 --- a/nvx-rs/src/host/cli/cpu_profile.rs +++ b/nvx-rs/src/host/cli/cpu_profile.rs @@ -7,7 +7,9 @@ //! OpenVMM submodule: its ID, the vendor of its CPUs, and its generation's name and CPU models, //! each a display family, a display model, and the first and last of its steppings. The revisions //! of a generation's profile share its generation, which the guidance lists once. -//! `tests/openvmm_cpu_profiles.rs` compares the copy with the submodule's documents. +//! ARM identities retain their own schema and digest in the same copy; they are not CPUID +//! generations and do not enter this x86 guidance. `tests/openvmm_cpu_profiles.rs` compares both +//! kinds of identity with the submodule's documents. //! [`HostCpu::current`] identifies the host CPU with CPUID, as OpenVMM does. //! //! On an Intel or AMD CPU that no built-in profile serves, `--cpu-profile auto`, the default, falls @@ -117,7 +119,16 @@ impl Profile { /// Returns the built-in CPU profiles of [`CATALOG`]. fn catalog() -> Vec { - serde_json::from_str(CATALOG).expect("cpu_generations.json lists the built-in CPU profiles") + let documents: Vec = serde_json::from_str(CATALOG) + .expect("cpu_generations.json lists the built-in CPU profiles"); + documents + .into_iter() + .filter(|document| document["profile"]["schema"] != "nvx.arm64.cpu.v1") + .map(|document| { + serde_json::from_value(document) + .expect("cpu_generations.json lists valid CPUID profile identities") + }) + .collect() } /// Returns the generations of the built-in profiles in `catalog` as the guidance lists them, such diff --git a/nvx-rs/tests/guest_tools.rs b/nvx-rs/tests/guest_tools.rs index 0e3d277b4..3ac20291f 100644 --- a/nvx-rs/tests/guest_tools.rs +++ b/nvx-rs/tests/guest_tools.rs @@ -1245,7 +1245,7 @@ fn ingress_start_fails_when_the_announcer_does_not_start() { ); } -#[cfg(target_arch = "x86_64")] +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] /// Returns the first CPU that this process may run on. fn first_allowed_cpu() -> usize { let affinity = nix::sched::sched_getaffinity(nix::unistd::Pid::from_raw(0)).unwrap(); @@ -2152,6 +2152,27 @@ fn time_test_mode_covers_checks_events_records_and_workers() { } } +#[test] +#[cfg(target_arch = "aarch64")] +fn arm_coldboot_warp_has_a_real_cli_entrypoint() { + assert_eq!( + run("nvx-time-probe", ["version"]), + (Some(0), b"nvx-time-probe 1.1\n".to_vec(), Vec::new()) + ); + let cpu = first_allowed_cpu().to_string(); + let (status, stdout, stderr) = run( + "nvx-time-probe", + ["warp", "--duration-ms", "1", "--cpus", &cpu], + ); + assert_eq!(status, Some(0), "{}", String::from_utf8_lossy(&stderr)); + assert!(stderr.is_empty()); + let text = String::from_utf8(stdout).unwrap(); + assert!(text.contains("counter_hz_source=cntfrq_el0")); + assert!(!text.contains("tsc_hz")); + assert!(text.contains("pairs=0 verdict=PASS bound_ns=1000")); + assert!(text.contains("conclusive=1")); +} + #[test] #[cfg(target_arch = "x86_64")] fn time_probe_cli_and_small_diagnostics_run() { diff --git a/nvx-rs/tests/openvmm_cpu_profiles.rs b/nvx-rs/tests/openvmm_cpu_profiles.rs index 0e18a8886..12f930f89 100644 --- a/nvx-rs/tests/openvmm_cpu_profiles.rs +++ b/nvx-rs/tests/openvmm_cpu_profiles.rs @@ -15,6 +15,24 @@ use serde_json::{Value, json}; /// Returns the identity of the profile `document`, with the fields that the copy holds: its ID, /// its vendor, and its generation's name and CPU models. fn identity(document: &Value) -> Value { + if document["profile"]["schema"] == "nvx.arm64.cpu.v1" { + let fields: Vec = document["profile"]["fields"] + .as_array() + .expect("an ARM profile names its ID registers") + .iter() + .map(|field| json!({"register": field["register"]})) + .collect(); + return json!({ + "vendor": document["vendor"], + "sha256": document["sha256"], + "profile": { + "schema": document["profile"]["schema"], + "id": document["profile"]["id"], + "physical_address_bits": document["profile"]["physical_address_bits"], + "fields": fields, + }, + }); + } let generation = &document["generation"]; let cpus: Vec = generation["cpus"] .as_array() @@ -39,7 +57,14 @@ fn identity(document: &Value) -> Value { fn by_id(profiles: impl IntoIterator) -> BTreeMap { let mut identities = BTreeMap::new(); for profile in profiles { - let id = profile["id"].as_str().unwrap().to_owned(); + let id = if profile["profile"]["schema"] == "nvx.arm64.cpu.v1" { + &profile["profile"]["id"] + } else { + &profile["id"] + } + .as_str() + .unwrap() + .to_owned(); assert!( identities.insert(id.clone(), profile).is_none(), "{id} is listed twice" @@ -87,7 +112,7 @@ fn the_copy_matches_the_submodules_profiles() { assert!( by_id(copy) == by_id(pinned), "src/host/cli/cpu_generations.json differs from the CPU profiles that the OpenVMM \ - submodule pins: copy the ID, the vendor, and the generation of each profile, and keep \ - the order in which nvx-rs run lists the generations" + submodule pins: copy each ISA's identity, retaining ARM schema/digest/address width \ + instead of CPUID fields, and keep the order in which nvx-rs run lists the generations" ); } diff --git a/openvmm b/openvmm index 73cf40357..b09c58843 160000 --- a/openvmm +++ b/openvmm @@ -1 +1 @@ -Subproject commit 73cf403574a8907ee94dab0ab9d648152b832b05 +Subproject commit b09c58843ae310dfff9ae68e9e822f9c5846b914 diff --git a/scripts/nvx_tools/benchmark.py b/scripts/nvx_tools/benchmark.py index 79242a230..e4eff7dcb 100644 --- a/scripts/nvx_tools/benchmark.py +++ b/scripts/nvx_tools/benchmark.py @@ -4075,15 +4075,23 @@ def benchmark_device_io_workload( def smp_probe_script( processors: int, *, + architecture: str = "x86_64", exit_guest: bool = True, network_gateway: str | None = None, ioapic_irq: int | None = None, ) -> str: if processors not in (1, 2, 4, 8): raise ValueError("microVM SMP probe supports 1, 2, 4, or 8 vCPUs") + if architecture not in ("x86_64", "aarch64"): + raise ValueError(f"unsupported SMP probe architecture: {architecture}") if (network_gateway is None) != (ioapic_irq is None): raise ValueError("network gateway and IOAPIC IRQ must be specified together") - apic_ids = ",".join(str(cpu) for cpu in range(processors)) + if architecture == "aarch64" and network_gateway is not None: + raise ValueError("the IOAPIC SMP network probe is x86-only") + apic_ids = ",".join( + f"0x{cpu:016x}" if architecture == "aarch64" else str(cpu) + for cpu in range(processors) + ) network_probe = "" if network_gateway is not None and ioapic_irq is not None: network_probe = _render_benchmark_script( @@ -4093,6 +4101,8 @@ def smp_probe_script( ) rendered = _render_benchmark_script( "smp-probe.sh.in", + ARCHITECTURE=architecture, + IDENTITY_LIST_NAME="dt_mpidrs" if architecture == "aarch64" else "apic_ids", PROCESSORS=str(processors), APIC_IDS=apic_ids, NETWORK_PROBE=network_probe, diff --git a/scripts/nvx_tools/benchmark_scripts/smp-probe.sh.in b/scripts/nvx_tools/benchmark_scripts/smp-probe.sh.in index 5a34f900a..b3f9a0f8c 100644 --- a/scripts/nvx_tools/benchmark_scripts/smp-probe.sh.in +++ b/scripts/nvx_tools/benchmark_scripts/smp-probe.sh.in @@ -1,10 +1,28 @@ set -eu trap 'status=$?; if [ "$status" -ne 0 ]; then nvx-exit "$status"; fi' EXIT expected=@PROCESSORS +architecture=@ARCHITECTURE +timer_name=loc +timer_failure=SMP-LAPIC-FAIL +identity_name=apic +read_dt_mpidr() { + mpidr_cells="$(od -An -tx1 -v "$1/../#address-cells" | tr -d '[:space:]')" || return 1 + mpidr_raw="$(od -An -tx1 -v "$1/reg" | tr -d '[:space:]')" || return 1 + case "$mpidr_cells:${#mpidr_raw}" in + 00000001:8 | 00000002:16) ;; + *) return 1 ;; + esac + printf '%016x\n' "0x$mpidr_raw" +} +if [ "$architecture" = aarch64 ]; then + timer_name=arch_timer + timer_failure=SMP-TIMER-FAIL + identity_name=dt_mpidr +fi online="$(getconf _NPROCESSORS_ONLN)" [ "$online" -eq "$expected" ] || { echo "SMP-ONLINE-FAIL expected=$expected actual=$online"; exit 81; } -loc_before="$(awk -v expected="$expected" '/^LOC:/ { for (cpu = 0; cpu < expected; cpu++) printf "%s%s", $(cpu + 2), (cpu + 1 == expected ? "" : " "); exit }' /proc/interrupts)" -[ "$(printf "%s\n" "$loc_before" | awk '{ print NF }')" -eq "$expected" ] || { echo "SMP-LAPIC-FAIL missing-local-timer-counters"; exit 87; } +loc_before="$(awk -v expected="$expected" -v architecture="$architecture" '(architecture == "x86_64" && $1 == "LOC:") || (architecture == "aarch64" && $NF == "arch_timer") { for (cpu = 0; cpu < expected; cpu++) printf "%s%s", $(cpu + 2), (cpu + 1 == expected ? "" : " "); exit }' /proc/interrupts)" +[ "$(printf "%s\n" "$loc_before" | awk '{ print NF }')" -eq "$expected" ] || { echo "$timer_failure missing-local-timer-counters"; exit 87; } worker_dir="/tmp/nvx-smp-probe-$$" worker_script="$worker_dir/worker" rm -rf "$worker_dir" @@ -15,26 +33,35 @@ set -eu cpu="$1" result="$2" apic_id="$3" +architecture="${4:-x86_64}" +timer_failure=SMP-LAPIC-FAIL +[ "$architecture" != aarch64 ] || timer_failure=SMP-TIMER-FAIL actual="$(awk '{ print $39 }' /proc/self/stat)" [ "$actual" -eq "$cpu" ] || { echo "SMP-WORKER-FAIL requested=$cpu actual=$actual"; exit 87; } read_loc_counter() { while read -r label cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 rest; do - if [ "$label" = "LOC:" ]; then - case "$cpu" in - 0) current=$cpu0 ;; - 1) current=$cpu1 ;; - 2) current=$cpu2 ;; - 3) current=$cpu3 ;; - 4) current=$cpu4 ;; - 5) current=$cpu5 ;; - 6) current=$cpu6 ;; - 7) current=$cpu7 ;; - *) echo "SMP-WORKER-FAIL unsupported-cpu=$cpu"; exit 87 ;; + if [ "$architecture" = aarch64 ]; then + case " $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5 $cpu6 $cpu7 $rest " in + *" arch_timer "*) ;; + *) continue ;; esac - return 0 + elif [ "$label" != "LOC:" ]; then + continue fi + case "$cpu" in + 0) current=$cpu0 ;; + 1) current=$cpu1 ;; + 2) current=$cpu2 ;; + 3) current=$cpu3 ;; + 4) current=$cpu4 ;; + 5) current=$cpu5 ;; + 6) current=$cpu6 ;; + 7) current=$cpu7 ;; + *) echo "SMP-WORKER-FAIL unsupported-cpu=$cpu"; exit 87 ;; + esac + return 0 done "$result" NVX_SMP_WORKER chmod +x "$worker_script" @@ -55,35 +82,44 @@ worker_pids="" for cpu in $(seq 0 $((expected - 1))); do topology="/sys/devices/system/cpu/cpu${cpu}/topology" [ "$(cat "$topology/physical_package_id")" -eq 0 ] || exit 82 - [ "$(cat "$topology/die_id")" -eq 0 ] || exit 83 + if [ "$architecture" = x86_64 ]; then + [ "$(cat "$topology/die_id")" -eq 0 ] || exit 83 + fi [ "$(cat "$topology/core_id")" -eq "$cpu" ] || exit 84 [ "$(cat "$topology/thread_siblings_list")" = "$cpu" ] || exit 85 - apic_id="$(awk -v target="$cpu" '$1 == "processor" { processor = $3 } $1 == "apicid" && processor == target { print $3; exit }' /proc/cpuinfo)" - [ "$apic_id" -eq "$cpu" ] || { echo "SMP-APIC-FAIL cpu=$cpu apic=$apic_id"; exit 86; } + if [ "$architecture" = aarch64 ]; then + apic_id="$(read_dt_mpidr "/sys/devices/system/cpu/cpu${cpu}/of_node")" || { echo "SMP-MPIDR-FAIL cpu=$cpu invalid-DT-reg"; exit 86; } + expected_id="$(printf '%016x' "$cpu")" + [ "$apic_id" = "$expected_id" ] || { echo "SMP-MPIDR-FAIL cpu=$cpu dt_mpidr=$apic_id expected=$expected_id"; exit 86; } + apic_id="0x$apic_id" + else + apic_id="$(awk -v target="$cpu" '$1 == "processor" { processor = $3 } $1 == "apicid" && processor == target { print $3; exit }' /proc/cpuinfo)" + [ "$apic_id" -eq "$cpu" ] || { echo "SMP-APIC-FAIL cpu=$cpu apic=$apic_id"; exit 86; } + fi result="$worker_dir/$cpu" - taskset -c "$cpu" "$worker_script" "$cpu" "$result" "$apic_id" & + taskset -c "$cpu" "$worker_script" "$cpu" "$result" "$apic_id" "$architecture" & worker_pids="$worker_pids $!" workers=$((workers + 1)) done for pid in $worker_pids; do wait "$pid" done -loc_after="$(awk -v expected="$expected" '/^LOC:/ { for (cpu = 0; cpu < expected; cpu++) printf "%s%s", $(cpu + 2), (cpu + 1 == expected ? "" : " "); exit }' /proc/interrupts)" -[ "$(printf "%s\n" "$loc_after" | awk '{ print NF }')" -eq "$expected" ] || { echo "SMP-LAPIC-FAIL missing-local-timer-counters"; exit 87; } +loc_after="$(awk -v expected="$expected" -v architecture="$architecture" '(architecture == "x86_64" && $1 == "LOC:") || (architecture == "aarch64" && $NF == "arch_timer") { for (cpu = 0; cpu < expected; cpu++) printf "%s%s", $(cpu + 2), (cpu + 1 == expected ? "" : " "); exit }' /proc/interrupts)" +[ "$(printf "%s\n" "$loc_after" | awk '{ print NF }')" -eq "$expected" ] || { echo "$timer_failure missing-local-timer-counters"; exit 87; } for cpu in $(seq 0 $((expected - 1))); do read -r actual current apic_id <"$worker_dir/$cpu" field=$((cpu + 1)) before="$(printf "%s\n" "$loc_before" | awk -v field="$field" '{ print $field }')" after="$(printf "%s\n" "$loc_after" | awk -v field="$field" '{ print $field }')" - [ "$after" -gt "$before" ] || { echo "SMP-LAPIC-FAIL cpu=$cpu before=$before after=$after"; exit 88; } - [ "$after" -ge "$current" ] || { echo "SMP-LAPIC-FAIL cpu=$cpu worker=$current after=$after"; exit 88; } - echo "SMP-WORKER-OK cpu=$cpu apic=$apic_id actual=$actual loc_after=$after" + [ "$after" -gt "$before" ] || { echo "$timer_failure cpu=$cpu before=$before after=$after"; exit 88; } + [ "$after" -ge "$current" ] || { echo "$timer_failure cpu=$cpu worker=$current after=$after"; exit 88; } + echo "SMP-WORKER-OK cpu=$cpu $identity_name=$apic_id actual=$actual ${timer_name}_after=$after" if [ "$cpu" -gt 0 ]; then - ipi="$(awk -v field=$((cpu + 2)) '/^(RES|CAL):/ { total += $field } END { print total + 0 }' /proc/interrupts)" + ipi="$(awk -v field=$((cpu + 2)) -v architecture="$architecture" '(architecture == "x86_64" && $1 ~ /^(RES|CAL):$/) || (architecture == "aarch64" && $1 ~ /^IPI[01]:$/) { total += $field } END { print total + 0 }' /proc/interrupts)" [ "$ipi" -gt 0 ] || { echo "SMP-IPI-FAIL cpu=$cpu count=$ipi"; exit 89; } fi done -echo "SMP-INTERRUPTS-OK loc_before=$loc_before loc_after=$loc_after" -echo "SMP-TOPOLOGY-OK requested=$expected online=$online sockets=1 cores=$expected threads=1 apic_ids=@APIC_IDS bsp=0 workers=$workers" +echo "SMP-INTERRUPTS-OK ${timer_name}_before=$loc_before ${timer_name}_after=$loc_after" +echo "SMP-TOPOLOGY-OK requested=$expected online=$online sockets=1 cores=$expected threads=1 @IDENTITY_LIST_NAME=@APIC_IDS bsp=0 workers=$workers" rm -rf "$worker_dir" @{NETWORK_PROBE}echo @COMPLETION_MARKER diff --git a/scripts/nvx_tools/ci.py b/scripts/nvx_tools/ci.py index c3a4135f6..1e30870ee 100644 --- a/scripts/nvx_tools/ci.py +++ b/scripts/nvx_tools/ci.py @@ -34,16 +34,19 @@ "nvx-rs": "NVX_RS_RESULT", "build-nvx-rs-linux-musl": "BUILD_NVX_RS_LINUX_MUSL_RESULT", "build-nvx-rs-windows-msvc": "BUILD_NVX_RS_WINDOWS_MSVC_RESULT", + "build-nvx-rs-windows-aarch64-msvc": "BUILD_NVX_RS_WINDOWS_AARCH64_MSVC_RESULT", "nvx-cli-linux": "NVX_CLI_LINUX_RESULT", "nvx-cli-windows": "NVX_CLI_WINDOWS_RESULT", "openvmm-changes": "CHANGES_RESULT", "artifacts": "ARTIFACTS_RESULT", "distro-artifacts": "DISTRO_ARTIFACTS_RESULT", + "artifacts-aarch64": "ARTIFACTS_AARCH64_RESULT", "debug-kernel": "DEBUG_KERNEL_RESULT", "guest-artifact-reuse": "GUEST_ARTIFACT_REUSE_RESULT", "build-openvmm-linux-gnu": "BUILD_LINUX_GNU_RESULT", "build-openvmm-linux-musl": "BUILD_LINUX_MUSL_RESULT", "build-openvmm-windows-msvc": "BUILD_WINDOWS_MSVC_RESULT", + "build-openvmm-windows-aarch64-msvc": "BUILD_WINDOWS_AARCH64_MSVC_RESULT", "openvmm-ci": "OPENVMM_CI_RESULT", "nvx-microvm-tests-kvm": "MICROVM_KVM_RESULT", "nvx-microvm-tests-mshv": "MICROVM_MSHV_RESULT", @@ -52,6 +55,9 @@ "nvx-microvm-guests-mshv": "MICROVM_GUESTS_MSHV_RESULT", "nvx-microvm-guests-whp": "MICROVM_GUESTS_WHP_RESULT", "nvx-microvm-adapter-whp": "MICROVM_ADAPTER_WHP_RESULT", + "nvx-microvm-tests-whp-aarch64": "MICROVM_WHP_AARCH64_RESULT", + "nvx-microvm-adapter-whp-aarch64": "MICROVM_ADAPTER_WHP_AARCH64_RESULT", + "nvx-microvm-repeat-whp-aarch64": "MICROVM_REPEAT_WHP_AARCH64_RESULT", "nvx-microvm-debug-kvm": "MICROVM_DEBUG_KVM_RESULT", "nvx-microvm-debug-mshv": "MICROVM_DEBUG_MSHV_RESULT", "nvx-microvm-debug-whp": "MICROVM_DEBUG_WHP_RESULT", @@ -94,6 +100,11 @@ "nvx-microvm-guests-whp", "nvx-microvm-adapter-whp", ) +REQUIRED_CI_ARM_MICROVM_JOBS = ( + "nvx-microvm-tests-whp-aarch64", + "nvx-microvm-adapter-whp-aarch64", +) +REQUIRED_CI_ARM_REPETITION_JOB = "nvx-microvm-repeat-whp-aarch64" # Pull requests run the CI debug kernel on MSHV, merge groups run it on KVM, # and dev pushes and full runs run it on every backend. REQUIRED_CI_MICROVM_DEBUG_JOBS = ("nvx-microvm-debug-mshv",) @@ -437,6 +448,30 @@ def required_ci_expected_results( REQUIRED_CI_DISTRO_ARTIFACT_JOB: ( "success" if run_guest_artifacts else "skipped" ), + "artifacts-aarch64": ( + "success" + if changes.run_microvm_tests and run_guest_artifacts + else "skipped" + ), + "build-openvmm-windows-aarch64-msvc": ( + "success" + if repository_jobs_enabled + and changes.run_microvm_tests + and run_openvmm_binaries + else "skipped" + ), + "build-nvx-rs-windows-aarch64-msvc": ( + "success" + if repository_jobs_enabled and changes.run_microvm_tests + else "skipped" + ), + REQUIRED_CI_ARM_REPETITION_JOB: ( + "success" + if event_name in CI_FULL_RUN_EVENTS + and repository_jobs_enabled + and run_microvm_tests + else "skipped" + ), REQUIRED_CI_DEBUG_KERNEL_JOB: "success" if run_guest_artifacts else "skipped", # A merge group skips the rehearsal, which its pull request's run made. REQUIRED_CI_GUEST_ARTIFACT_REUSE_JOB: ( @@ -482,6 +517,14 @@ def required_ci_expected_results( for job in REQUIRED_CI_MICROVM_TEST_JOBS } ) + expected.update( + { + job: "success" + if repository_jobs_enabled and run_microvm_tests + else "skipped" + for job in REQUIRED_CI_ARM_MICROVM_JOBS + } + ) if event_name == "pull_request": enabled_debug_jobs = set(REQUIRED_CI_MICROVM_DEBUG_JOBS) elif event_name == "merge_group": diff --git a/scripts/nvx_tools/common.py b/scripts/nvx_tools/common.py index 513a22af2..5f0bcb778 100644 --- a/scripts/nvx_tools/common.py +++ b/scripts/nvx_tools/common.py @@ -31,6 +31,39 @@ class ScriptError(RuntimeError): """Raised for an actionable command-line workflow failure.""" +def host_architecture() -> str: + architecture = platform.machine().lower() + if architecture in ("arm64", "aarch64"): + return "aarch64" + if architecture in ("amd64", "x86_64"): + return "x86_64" + raise ScriptError(f"unsupported native host architecture {architecture!r}") + + +def require_pe_architecture(path: Path, architecture: str) -> Path: + """Require the PE/COFF machine before executing a Windows product.""" + machines = {"x86_64": 0x8664, "aarch64": 0xAA64} + if architecture not in machines: + raise ScriptError(f"unsupported PE architecture {architecture!r}") + with path.open("rb") as stream: + dos = stream.read(64) + if len(dos) != 64 or dos[:2] != b"MZ": + raise ScriptError(f"{path} has no valid DOS/PE header") + offset = int.from_bytes(dos[60:64], "little") + if offset < 64: + raise ScriptError(f"{path} has an invalid PE header offset") + stream.seek(offset) + header = stream.read(6) + if len(header) != 6 or header[:4] != b"PE\0\0": + raise ScriptError(f"{path} has no valid PE/COFF header") + machine = int.from_bytes(header[4:6], "little") + if machine != machines[architecture]: + raise ScriptError( + f"{path} has PE machine {machine:#06x}, expected native {architecture}" + ) + return path + + def is_link_or_junction(path: Path) -> bool: """Return whether ``path`` is a symbolic link or, on Windows, a junction. diff --git a/scripts/nvx_tools/doctor.py b/scripts/nvx_tools/doctor.py index f071df4c1..b17b9fc91 100644 --- a/scripts/nvx_tools/doctor.py +++ b/scripts/nvx_tools/doctor.py @@ -13,6 +13,7 @@ import ctypes import hashlib import itertools +import json import math import os import platform @@ -26,12 +27,15 @@ from pathlib import Path from .benchmark import run_guest_script, workload_boot_command -from .build_constants import AlpineBuildConstants, BuildConstants, KernelBuildConstants +from .build_config import KernelBuildConfig +from .build_constants import AlpineBuildConstants, BuildConstants from .ci import OPENVMM_TEST_BACKENDS from .common import ( ScriptError, artifact_path, + host_architecture, openvmm_binary_path, + require_pe_architecture, require_tool, ) from .time_abi import ( @@ -45,7 +49,9 @@ HostCpu, TimeAbiFailure, TimeAbiMonitor, + arm_cpu_profile, check_warp_probe, + counter_hz_is_valid, cpu_generation, describe_cpu_generations, is_catalog_profile_id, @@ -181,6 +187,9 @@ class DoctorContext: # when qualification runs without OpenVMM. fingerprint: Path | None = None schedule: Schedule = QUALIFICATION_SCHEDULE + architecture: str = "x86_64" + no_openvmm: bool = False + arm_preflight: CheckResult | None = None def host_is_windows() -> bool: @@ -204,7 +213,7 @@ def probe_path(directory: Path) -> Path: """Return the cached host probe binary for the current probe source.""" digest = hashlib.sha256(PROBE_SOURCE.read_bytes()).hexdigest()[:16] suffix = ".exe" if os.name == "nt" else "" - return directory / f"nvx-host-time-probe-{digest}{suffix}" + return directory / f"nvx-host-time-probe-{host_architecture()}-{digest}{suffix}" def build_probe(directory: Path) -> Path: @@ -218,6 +227,11 @@ def build_probe(directory: Path) -> Path: completed = subprocess.run( [ rustc, + *( + ["--target", f"{host_architecture()}-pc-windows-msvc"] + if host_is_windows() + else [] + ), "--edition=2021", "-C", "opt-level=2", @@ -284,6 +298,26 @@ def _probe_record( raise ScriptError(f"host time probe printed no {kind} record") +def _arm64_host_counter( + context: DoctorContext, records: Sequence[tuple[str, dict[str, str]]] +) -> int: + cpu = _probe_record(records, "cpu") + if cpu.get("architecture") != "aarch64" or cpu.get("counter") != "cntvct_el0": + raise ScriptError("ARM64 qualification requires a native CNTVCT_EL0 probe") + try: + frequency = int(cpu["counter_hz"]) + except (KeyError, ValueError) as error: + raise ScriptError( + "host probe reported no valid CNTFRQ_EL0 frequency" + ) from error + if not counter_hz_is_valid(frequency, architecture="aarch64"): + raise ScriptError(f"host probe reported an invalid CNTFRQ_EL0: {frequency}") + context.facts.update( + architecture="aarch64", counter="cntvct_el0", host_counter_hz=str(frequency) + ) + return frequency + + def _linux_cpuinfo(path: Path = CPUINFO_PATH) -> dict[str, str]: """Return the first processor's /proc/cpuinfo fields.""" fields: dict[str, str] = {} @@ -432,6 +466,20 @@ def check_backend(context: DoctorContext) -> CheckResult: def check_cpu(context: DoctorContext) -> CheckResult: + if context.architecture == "aarch64": + frequency = _arm64_host_counter(context, run_probe(context, "cpu")) + context.facts.update(cpu="aarch64", os=sys.platform) + context.facts.setdefault("profile", "unverified") + if not context.no_openvmm: + result = check_openvmm_preflight(context) + return CheckResult("H2", result.passed, result.detail) + return CheckResult( + "H2", + False, + "ARM64 CPU/profile admission is unsupported without OpenVMM: " + "the existing --x-time-abi-verify report is required; " + f"host CNTFRQ_EL0={frequency} Hz is evidence only", + ) info = host_cpu(context) signature = f"{info['vendor']} {info['family']}/{info['model']}/{info['stepping']}" context.facts.update( @@ -614,6 +662,15 @@ def _guest_vcpus() -> int: def check_openvmm_preflight(context: DoctorContext) -> CheckResult: + if context.architecture == "aarch64" and context.arm_preflight is not None: + return context.arm_preflight + result = _check_openvmm_preflight(context) + if context.architecture == "aarch64": + context.arm_preflight = result + return result + + +def _check_openvmm_preflight(context: DoctorContext) -> CheckResult: for path, description in ( (context.openvmm, "OpenVMM"), (context.kernel, "guest kernel"), @@ -621,6 +678,8 @@ def check_openvmm_preflight(context: DoctorContext) -> CheckResult: ): if not path.is_file(): return CheckResult("H3", False, f"{description} was not found at {path}") + if context.architecture == "aarch64": + require_pe_architecture(context.openvmm, context.architecture) command = [ os.fspath(context.openvmm), "--machine", @@ -647,14 +706,14 @@ def check_openvmm_preflight(context: DoctorContext) -> CheckResult: check=False, ) output = f"{completed.stdout}\n{completed.stderr}" - verify = next( - ( - line.strip() - for line in output.splitlines() - if line.strip().startswith(VERIFY_PREFIX) - ), - None, - ) + lines = [ + line.strip() + for line in output.splitlines() + if line.strip().startswith(VERIFY_PREFIX) + ] + if context.architecture == "aarch64" and len(lines) > 1: + return CheckResult("H3", False, "OpenVMM emitted multiple verification records") + verify = next(iter(lines), None) if verify is None: last = next( (line.strip() for line in reversed(output.splitlines()) if line.strip()), @@ -678,6 +737,8 @@ def check_openvmm_preflight(context: DoctorContext) -> CheckResult: f"{prefix}OpenVMM verification failed (exit {completed.returncode}): " f"{fields.get('detail', verify)}", ) + if context.architecture == "aarch64": + return _check_arm_preflight(context, fields) problems: list[str] = [] if fields.get("backend") != context.backend: problems.append(f"OpenVMM verified backend {fields.get('backend')}") @@ -733,6 +794,102 @@ def check_openvmm_preflight(context: DoctorContext) -> CheckResult: return CheckResult("H3", True, detail) +def _check_arm_preflight( + context: DoctorContext, fields: Mapping[str, str] +) -> CheckResult: + """Validate the existing verifier's observed ARM admission, not UTC authority.""" + problems: list[str] = [] + expected = { + "v": "1", + "architecture": "aarch64", + "backend": context.backend, + "feature_bank_count": "2", + "backend_readback": "verified", + "effective_cpu": "verified", + "guest_started": "false", + } + for name, value in expected.items(): + if fields.get(name) != value: + problems.append(f"{name}={fields.get(name)!r}, expected {value}") + legacy = { + "tsc_hz", + "native_tsc_hz", + "lapic_hz", + "msr_route", + "sync", + } & fields.keys() + if legacy: + problems.append( + "ARM verification contains x86/UTC aliases: " + ", ".join(sorted(legacy)) + ) + identities = json.loads( + ( + BuildConstants.REPO_ROOT + / "nvx-rs" + / "src" + / "host" + / "cli" + / "cpu_generations.json" + ).read_bytes() + ) + catalog = { + profile.profile_id: profile + for document in identities + if (profile := arm_cpu_profile(document)) is not None + } + profile = catalog.get(fields.get("cpu_profile", "")) + if profile is None: + problems.append("OpenVMM verified no pinned ARM CPU profile") + elif fields.get("cpu_profile_sha256") != profile.sha256: + problems.append("ARM CPU profile digest differs from the pinned identity") + numbers: dict[str, int] = {} + for name, maximum in ( + ("counter_hz", (1 << 32) - 1), + ("backend_usable_gpa_bits", 64), + ("configured_gpa_bits", 64), + ("architectural_pa_bits", 64), + ("effective_parange", 15), + ("feature_bank0", (1 << 64) - 1), + ("feature_bank1", (1 << 64) - 1), + ("cpu_id_registers_verified", (1 << 32) - 1), + ): + value = fields.get(name, "") + if re.fullmatch(r"[0-9]+", value) is None or int(value) > maximum: + problems.append(f"{name}={value!r} is not a bounded unsigned integer") + else: + numbers[name] = int(value) + if not problems and profile is not None: + if "host_counter_hz" not in context.facts: + _arm64_host_counter(context, run_probe(context, "cpu")) + if numbers["counter_hz"] != int(context.facts["host_counter_hz"]): + problems.append("WHP counter frequency differs from host CNTFRQ_EL0") + bits = profile.physical_address_bits + parange = (32, 36, 40, 42, 44, 48, 52).index(bits) + if ( + numbers["configured_gpa_bits"] != bits + or numbers["architectural_pa_bits"] != bits + or numbers["backend_usable_gpa_bits"] < bits + or numbers["effective_parange"] != parange + ): + problems.append( + "ARM address-width readbacks differ from the pinned contract" + ) + if numbers["cpu_id_registers_verified"] != len(profile.registers): + problems.append("ARM verification did not check every pinned ID register") + detail = " ".join(f"{name}={value}" for name, value in fields.items()) + if problems: + return CheckResult("H3", False, "; ".join(problems) + f"; {detail}") + context.facts.update(fields) + context.facts["profile"] = fields["cpu_profile"] + context.facts["profile_digest"] = fields["cpu_profile_sha256"] + return CheckResult( + "H3", + True, + detail + + "; partition/VP objects may be created; no guest execution or UTC authority is claimed", + ) + + def _rate_points( samples: Sequence[Mapping[str, str]], clock: Mapping[str, str], role: str ) -> list[tuple[int, int, float]]: @@ -1088,6 +1245,9 @@ def check_rate(context: DoctorContext) -> CheckResult: str(schedule.rate_interval_ms), duration=(schedule.rate_samples - 1) * schedule.rate_interval_ms / 1000, ) + counter_hz: int | None = None + if context.architecture == "aarch64": + counter_hz = _arm64_host_counter(context, records) clocks = {fields.get("role"): fields for kind, fields in records if kind == "clock"} for role in ("rate", "stability"): if role not in clocks: @@ -1120,6 +1280,10 @@ def check_rate(context: DoctorContext) -> CheckResult: agreement_ppm = (max(rates) - min(rates)) / stable_rate * 1e6 uncertainty_ppm = max(uncertainties_ppm) declared = context.facts.get("native_tsc_hz") or context.facts.get("tsc_hz") + declared_source = "backend" + if declared is None and counter_hz is not None: + declared = str(counter_hz) + declared_source = "host CNTFRQ_EL0" declared_hz = None if declared is None else int(declared) # Over the window, CLOCK_MONOTONIC also carries the slew with which # chronyd removes its current offset, which reaches hundreds of ppm for @@ -1180,8 +1344,9 @@ def conclusive(estimate: ChronyFrequency) -> bool: context.facts["measured_tsc_hz"] = f"{measured:.0f}" context.facts["rate_agreement_ppm"] = f"{agreement_ppm:.3f}" context.facts["rate_uncertainty_ppm"] = f"{uncertainty_ppm:.3f}" + counter_name = "cntvct_el0" if context.architecture == "aarch64" else "tsc" detail = ( - f"tsc_hz={measured:.0f} {reference} from {len(samples)} " + f"{counter_name}_hz={measured:.0f} {reference} from {len(samples)} " f"samples {schedule.rate_interval_ms / 1000:g} s apart; against " f"{stability_clock['name']} (resolution " f"{float(stability_clock['resolution_ns']):g} ns) the interval rates agree " @@ -1190,7 +1355,7 @@ def conclusive(estimate: ChronyFrequency) -> bool: ) problems: list[str] = [] warning = "" - if not MIN_TSC_HZ <= measured <= MAX_TSC_HZ: + if not counter_hz_is_valid(measured, architecture=context.architecture): problems.append(f"[E_TSC_RATE_IMPLAUSIBLE] measured {measured:.0f} Hz") if uncertainty_ppm > RATE_UNCERTAINTY_PPM: problems.append( @@ -1209,7 +1374,9 @@ def conclusive(estimate: ChronyFrequency) -> bool: else: deviation_ppm = abs(_deviation_ppm(measured, declared_hz)) context.facts["rate_deviation_ppm"] = f"{deviation_ppm:.3f}" - detail += f"; {deviation_ppm:.3f} ppm from the backend's {declared} Hz" + detail += ( + f"; {deviation_ppm:.3f} ppm from the {declared_source}'s {declared} Hz" + ) if isinstance(chrony, ChronyFrequency): # The rate passes only when the whole range within chronyd's skew # lies within the limit. @@ -1223,18 +1390,18 @@ def conclusive(estimate: ChronyFrequency) -> bool: within = "" if nearest > RATE_TOLERANCE_PPM: problems.append( - f"the backend rate is {deviation_ppm:.3f} ppm from the measured " + f"the {declared_source} rate is {deviation_ppm:.3f} ppm from the measured " f"rate{within} (limit {RATE_TOLERANCE_PPM:g} ppm)" ) elif farthest > RATE_TOLERANCE_PPM: problems.append( - f"the measurement is inconclusive: the backend rate is " + f"the measurement is inconclusive: the {declared_source} rate is " f"{deviation_ppm:.3f} ppm from the measured rate{within}, which " f"straddles the limit of {RATE_TOLERANCE_PPM:g} ppm{reread_problem}" ) elif deviation_ppm > RATE_WARNING_PPM: warning = ( - f"the backend rate is {deviation_ppm:.3f} ppm from the measured " + f"the {declared_source} rate is {deviation_ppm:.3f} ppm from the measured " f"rate, more than {RATE_WARNING_PPM:g} ppm: the host's clock " f"correction uses {deviation_ppm / RATE_TOLERANCE_PPM:.0%} of the " f"guest's {RATE_TOLERANCE_PPM:g} ppm budget, and one run can't " @@ -1347,8 +1514,9 @@ def _warp_guest( WARP_PROBE_COMPLETION_MARKER, timeout=context.timeout, time_abi_status=True, + architecture=context.architecture, ) - monitor = TimeAbiMonitor(command) + monitor = TimeAbiMonitor(command, architecture=context.architecture) monitor.feed(result["text"].encode()) monitor.finish() monitor.require_status("the warp probe") @@ -1398,8 +1566,12 @@ def worst(name: str) -> int: return max(int(warp[name]) for warp in rounds) context.facts["guest_warp_ns"] = str(worst("max_abs_offset_ns")) - context.facts.setdefault("tsc_hz", boots[0]["tsc_hz"]) - context.facts.setdefault("lapic_hz", boots[0]["lapic_hz"]) + if context.architecture == "aarch64": + # The guest marker's shared counter slot keeps its legacy name. + context.facts.setdefault("counter_hz", boots[0]["tsc_hz"]) + else: + context.facts.setdefault("tsc_hz", boots[0]["tsc_hz"]) + context.facts.setdefault("lapic_hz", boots[0]["lapic_hz"]) return CheckResult( "H6", True, @@ -1541,6 +1713,9 @@ def summary_markdown( ("", f"**{result.check} warning:** {_escape_markdown(result.warning)}") ) reported = ( + ("architecture", "Counter architecture"), + ("counter", "Counter"), + ("host_counter_hz", "Host counter frequency (Hz, not VMM readback)"), ("generation", "Generation"), ("cpu", "CPU"), ("microcode", "Microcode"), @@ -1574,6 +1749,18 @@ def summary_markdown( def run(args: argparse.Namespace) -> int: if args.backend not in OPENVMM_TEST_BACKENDS: raise ScriptError(f"unsupported backend {args.backend!r}") + if args.architecture != host_architecture(): + raise ScriptError( + f"doctor requires the native host architecture {host_architecture()}, " + f"not {args.architecture}" + ) + if args.architecture == "aarch64" and args.backend != "whp": + raise ScriptError("ARM64 host qualification currently requires Windows/WHP") + if args.architecture == "aarch64" and args.cpu_fingerprint is not None: + raise ScriptError( + "--cpu-fingerprint is an unsupported legacy x86 interface on ARM64; " + "H2 uses the existing --x-time-abi-verify admission report instead" + ) checks = tuple(dict.fromkeys(args.checks or CHECK_IDS)) if args.no_openvmm: booting = [check for check in checks if check in OPENVMM_CHECKS] @@ -1583,20 +1770,27 @@ def run(args: argparse.Namespace) -> int: ) probe_directory = args.probe_dir or default_probe_directory() fingerprint: Path | None = None - if not args.no_openvmm: + if not args.no_openvmm and args.architecture == "x86_64": fingerprint = args.cpu_fingerprint or ( probe_directory / f"nvx-cpu-fingerprint-{args.backend}.json" ) context = DoctorContext( backend=args.backend, openvmm=args.openvmm or openvmm_binary_path(), - kernel=args.kernel or artifact_path(KernelBuildConstants.BINARY_NAME), - initrd=args.initrd or artifact_path(AlpineBuildConstants.INITRAMFS_NAME), + kernel=args.kernel + or KernelBuildConfig.for_architecture(args.architecture).output, + initrd=args.initrd + or artifact_path( + AlpineBuildConstants.INITRAMFS_NAME, architecture=args.architecture + ), openvmm_args=tuple(args.openvmm_arg), probe_directory=probe_directory, timeout=args.timeout, fingerprint=fingerprint, schedule=CI_SCHEDULE if args.ci_schedule else QUALIFICATION_SCHEDULE, + architecture=args.architecture, + no_openvmm=args.no_openvmm, + facts={"architecture": args.architecture}, ) results = run_checks(context, checks) failed = [result.check for result in results if not result.passed] @@ -1627,6 +1821,12 @@ def configure_parser(parser: argparse.ArgumentParser) -> None: "Qualify this host for the NVX time ABI (doc/ci.md, 'Host qualification')." ) parser.add_argument("--backend", choices=OPENVMM_TEST_BACKENDS, required=True) + parser.add_argument( + "--architecture", + choices=("x86_64", "aarch64"), + default=host_architecture(), + help="native counter/artifact ISA to qualify (default: native host ISA)", + ) parser.add_argument( "--checks", nargs="+", diff --git a/scripts/nvx_tools/guest_binaries.py b/scripts/nvx_tools/guest_binaries.py index 70aeceb2d..ce18ddde4 100644 --- a/scripts/nvx_tools/guest_binaries.py +++ b/scripts/nvx_tools/guest_binaries.py @@ -45,14 +45,14 @@ def guest_rust_target(architecture: str) -> str: def guest_binary_inventory(architecture: str = "x86_64") -> tuple[str, ...]: - """Keep x86's inventory and omit non-cold-boot ARM diagnostic executables.""" + """Keep shared boot/warp helpers and omit ARM's unsupported x86 I/O probes.""" guest_rust_target(architecture) if architecture == "x86_64": return GuestRustBuildConstants.BINARIES return tuple( binary for binary in GuestRustBuildConstants.BINARIES - if binary not in ("nvx-mmio-write", "nvx-device-io", "nvx-time-probe") + if binary not in ("nvx-mmio-write", "nvx-device-io") ) diff --git a/scripts/nvx_tools/host_time_probe.rs b/scripts/nvx_tools/host_time_probe.rs index 4285b1f3c..420570d7d 100644 --- a/scripts/nvx_tools/host_time_probe.rs +++ b/scripts/nvx_tools/host_time_probe.rs @@ -1,16 +1,16 @@ -//! Host TSC probe for NVX time ABI host qualification. +//! Host counter probe for NVX time ABI host qualification. //! //! `nvx.py doctor` builds this file with `rustc` and runs it for the host //! checks that doc/ci.md ("Host qualification") describes: H2 (the CPU //! identity and the host's invariant-TSC bit), H4 (sleep-separated samples of -//! the TSC against the host's monotonic clocks), and H5 (cross-CPU TSC skew +//! the counter against the host's monotonic clocks), and H5 (cross-CPU counter skew //! between pinned threads). It has no dependencies and prints //! `NVX-HOST-TIME-PROBE` lines of `key=value` fields; the doctor applies the //! bounds. use std::process::ExitCode; -use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::Arc; use std::thread; use std::time::{Duration, Instant}; @@ -20,6 +20,7 @@ const EXIT_USAGE: u8 = 2; const EXIT_ERROR: u8 = 3; #[inline(always)] +#[cfg(target_arch = "x86_64")] fn tsc() -> u64 { // SAFETY: LFENCE and RDTSC are baseline x86-64 instructions. unsafe { @@ -30,6 +31,23 @@ fn tsc() -> u64 { } } +#[inline(always)] +#[cfg(target_arch = "aarch64")] +fn tsc() -> u64 { + let counter: u64; + // SAFETY: qualification reads the unprivileged architected counter, ordered by ISB. + unsafe { + core::arch::asm!( + "isb", + "mrs {counter}, cntvct_el0", + counter = out(reg) counter, + options(nomem, nostack, preserves_flags), + ); + } + counter +} + +#[cfg(target_arch = "x86_64")] fn cpuid(leaf: u32) -> [u32; 4] { // SAFETY: CPUID is a baseline x86-64 instruction. Newer Rust releases // declare the intrinsic safe, older ones unsafe. @@ -89,7 +107,11 @@ mod affinity { fn GetCurrentThread() -> Handle; fn GetCurrentProcess() -> Handle; fn SetThreadAffinityMask(thread: Handle, mask: usize) -> usize; - fn GetProcessAffinityMask(process: Handle, process_mask: *mut usize, system_mask: *mut usize) -> i32; + fn GetProcessAffinityMask( + process: Handle, + process_mask: *mut usize, + system_mask: *mut usize, + ) -> i32; } pub fn allowed() -> Result, String> { @@ -164,7 +186,10 @@ mod clock { /// Returns the clock's reported resolution in nanoseconds. pub fn resolution_ns(self) -> Result { - let mut time = Timespec { tv_sec: 0, tv_nsec: 0 }; + let mut time = Timespec { + tv_sec: 0, + tv_nsec: 0, + }; // SAFETY: time points to a valid timespec. if unsafe { clock_getres(self.id, &mut time) } != 0 { return Err(format!( @@ -179,7 +204,10 @@ mod clock { /// Returns the clock in ticks. #[inline(always)] pub fn now(self) -> u64 { - let mut time = Timespec { tv_sec: 0, tv_nsec: 0 }; + let mut time = Timespec { + tv_sec: 0, + tv_nsec: 0, + }; // SAFETY: time points to a valid timespec, and both clocks always // exist. unsafe { clock_gettime(self.id, &mut time) }; @@ -283,8 +311,12 @@ fn parse_cpus(text: &str) -> Result, String> { Some((start, end)) => (start, end), None => (part, part), }; - let start: usize = start.parse().map_err(|_| format!("invalid CPU list {text:?}"))?; - let end: usize = end.parse().map_err(|_| format!("invalid CPU list {text:?}"))?; + let start: usize = start + .parse() + .map_err(|_| format!("invalid CPU list {text:?}"))?; + let end: usize = end + .parse() + .map_err(|_| format!("invalid CPU list {text:?}"))?; if end < start { return Err(format!("invalid CPU range {part:?}")); } @@ -315,6 +347,7 @@ fn format_cpus(cpus: &[usize]) -> String { parts.join(",") } +#[cfg(target_arch = "x86_64")] fn cpu() -> Result<(), String> { let [max_basic, ebx, ecx, edx] = cpuid(0); let mut vendor = Vec::new(); @@ -358,8 +391,26 @@ fn cpu() -> Result<(), String> { Ok(()) } -/// Reads the TSC between two reads of `clock` and returns the tightest of 64 -/// such brackets as (TSC, clock ticks before the read, clock ticks between +#[cfg(target_arch = "aarch64")] +fn cpu() -> Result<(), String> { + let frequency: u64; + // SAFETY: CNTFRQ_EL0 is the architected counter's unprivileged frequency register. + unsafe { + core::arch::asm!( + "mrs {frequency}, cntfrq_el0", + frequency = out(reg) frequency, + options(nomem, nostack, preserves_flags), + ); + } + if frequency == 0 { + return Err("CNTFRQ_EL0 reports a zero counter frequency".into()); + } + println!("{PREFIX} cpu architecture=aarch64 counter=cntvct_el0 counter_hz={frequency}"); + Ok(()) +} + +/// Reads the counter between two reads of `clock` and returns the tightest of 64 +/// such brackets as (counter, clock ticks before the read, clock ticks between /// the two clock reads). fn clock_sample(clock: clock::Clock) -> (u64, u64, u64) { let mut best: Option<(u64, u64, u64)> = None; @@ -404,6 +455,8 @@ fn clock_step(clock: clock::Clock) -> Result<(u64, bool), String> { fn rate(arguments: &[String]) -> Result<(), String> { check_options(arguments, &["--samples", "--interval-ms"])?; + #[cfg(target_arch = "aarch64")] + cpu()?; let samples: u32 = number(arguments, "--samples", 3)?; let interval_ms: u64 = number(arguments, "--interval-ms", 1000)?; if samples < 2 || interval_ms == 0 { @@ -418,7 +471,11 @@ fn rate(arguments: &[String]) -> Result<(), String> { let reported_ns = clock.resolution_ns()?; let (step, repeated) = clock_step(clock)?; let step_ns = step as f64 * 1e9 / hz as f64; - let resolution_ns = if repeated { reported_ns.max(step_ns) } else { reported_ns }; + let resolution_ns = if repeated { + reported_ns.max(step_ns) + } else { + reported_ns + }; println!( "{PREFIX} clock role={role} name={} hz={hz} resolution_ns={resolution_ns:.3} \ reported_resolution_ns={reported_ns:.3} step_ns={step_ns:.3} repeated={}", @@ -573,7 +630,10 @@ fn measure_pair(initiator: usize, responder: usize, duration: Duration) -> Resul } fn skew(arguments: &[String]) -> Result<(), String> { - check_options(arguments, &["--duration-ms", "--cpus", "--tsc-hz", "--bound-ns"])?; + check_options( + arguments, + &["--duration-ms", "--cpus", "--tsc-hz", "--bound-ns"], + )?; let duration_ms: u64 = number(arguments, "--duration-ms", 5)?; let bound_ns: f64 = number(arguments, "--bound-ns", 1000.0)?; let allowed = affinity::allowed()?; @@ -610,7 +670,10 @@ fn skew(arguments: &[String]) -> Result<(), String> { pairs += 1; if pair.stalled { stalled += 1; - println!("{PREFIX} pair cpus={first}-{second} rounds={} stalled=1", pair.rounds); + println!( + "{PREFIX} pair cpus={first}-{second} rounds={} stalled=1", + pair.rounds + ); continue; } inconsistent += usize::from(!pair.consistent); diff --git a/scripts/nvx_tools/microvm_durations.py b/scripts/nvx_tools/microvm_durations.py index 28bfa8cfb..8bc4de90e 100644 --- a/scripts/nvx_tools/microvm_durations.py +++ b/scripts/nvx_tools/microvm_durations.py @@ -113,6 +113,8 @@ def __init__( kernel: str, processors: Sequence[int], scenarios: Sequence[str], + architecture: str = "x86_64", + scope: str = "full", clock: Callable[[], float] = time.monotonic, wall_clock: Callable[[], float] = time.time, started: float | None = None, @@ -127,7 +129,13 @@ def __init__( self._offset = wall_clock() - now if started is None: started = now - max(0.0, process_age_seconds() or 0.0) - self._dimensions = {"guest": guest, "backend": backend, "kernel": kernel} + self._dimensions = { + "guest": guest, + "backend": backend, + "kernel": kernel, + "architecture": architecture, + "scope": scope, + } self._span: dict[str, object] = {"record": "setup"} self._span_started = started self._write( @@ -150,6 +158,7 @@ def start( message: str, *, processors: Sequence[int] | None = None, + variant: str | None = None, ) -> None: """End the open span, print `message` at once, and time `scenario`, which runs on `processors` if it takes processor counts.""" @@ -160,6 +169,8 @@ def start( **self._dimensions, "processors": None if processors is None else [*dict.fromkeys(processors)], } + if variant is not None: + self._span["variant"] = variant self._write(ended) print(message, flush=True) diff --git a/scripts/nvx_tools/microvm_shards.py b/scripts/nvx_tools/microvm_shards.py index dfd12c145..8710ae693 100644 --- a/scripts/nvx_tools/microvm_shards.py +++ b/scripts/nvx_tools/microvm_shards.py @@ -238,6 +238,8 @@ def read_reports( backend = header.get("backend") if ( header.get("guest") != "alpine" + or header.get("architecture", "x86_64") != "x86_64" + or header.get("scope", "full") != "full" or header.get("kernel") != "default" or header.get("processors") != list(processors) or not isinstance(backend, str) diff --git a/scripts/nvx_tools/microvm_test_scripts/filesystem-shares.sh b/scripts/nvx_tools/microvm_test_scripts/filesystem-shares.sh index e9a11af6b..5deb228a5 100644 --- a/scripts/nvx_tools/microvm_test_scripts/filesystem-shares.sh +++ b/scripts/nvx_tools/microvm_test_scripts/filesystem-shares.sh @@ -18,8 +18,8 @@ expect_read_only() { # One virtio-fs slot carries every share as a child of one aggregate, which # the guest mounts where only root can enter and binds at each target. -grep -q 'virtio_mmio.device=0x1000@0xd0001000:17' /proc/cmdline || fail 40 -if grep -q '0xd0008000' /proc/cmdline; then +fixed_virtio_present d0001000 17 || fail 40 +if ! fixed_virtio_absent d0008000; then fail 41 fi grep -q 'virtfs_dir=/run/nvx/shares virtfs_tag=microvm virtfs_mode=rw virtfs_aggregate=1' /proc/cmdline || fail 42 diff --git a/scripts/nvx_tools/microvm_test_scripts/interrupt-map.sh.in b/scripts/nvx_tools/microvm_test_scripts/interrupt-map.sh.in index 49561a0a3..34181fc59 100644 --- a/scripts/nvx_tools/microvm_test_scripts/interrupt-map.sh.in +++ b/scripts/nvx_tools/microvm_test_scripts/interrupt-map.sh.in @@ -1,4 +1,5 @@ set -eu +architecture=@ARCHITECTURE@ fail() { code="$1" echo "NVX-INTERRUPT-MAP-FAIL code=$code" @@ -15,22 +16,6 @@ bound_devices() { echo "$bound" } -# Prints the base of the MMIO window that /proc/iomem lists under the name of -# the virtio-mmio platform device $1. -window_base() { - while IFS=' ' read -r range separator name _; do - [ "$separator" = : ] && [ "$name" = "$1" ] || continue - echo "${range%%-*}" - return 0 - done /dev/null -rtc="$(dd if=/dev/port bs=1 skip=113 count=1 2>/dev/null | od -An -tu1 | tr -d '[:space:]')" -[ "$rtc" = 2 ] || fail 40 +architecture="$(uname -m)" +if [ "$architecture" = aarch64 ]; then + /sbin/nvx-time sample || fail 40 + early_console=nvx-mmio0 + local_timer="$(awk '$NF == "arch_timer" { print $2; exit }' /proc/interrupts)" +elif [ "$architecture" = x86_64 ]; then + printf '\013' | dd of=/dev/port bs=1 seek=112 count=1 conv=notrunc 2>/dev/null + rtc="$(dd if=/dev/port bs=1 skip=113 count=1 2>/dev/null | od -An -tu1 | tr -d '[:space:]')" + [ "$rtc" = 2 ] || fail 40 + early_console=earlyxe90 + local_timer="$(awk '/^LOC:/ { print $2; exit }' /proc/interrupts)" +else + fail 40 +fi [ "$(date +%s)" -ge 1500000000 ] || fail 41 -local_timer="$(awk '/^LOC:/ { print $2; exit }' /proc/interrupts)" [ "${local_timer:-0}" -gt 0 ] || fail 42 uptime_before="$(awk '{ print int($1); exit }' /proc/uptime)" sleep 1 @@ -23,20 +33,25 @@ uptime_after="$(awk '{ print int($1); exit }' /proc/uptime)" # kernel knows earlycon=, so it does not pass it to user space with the # parameters that it does not know. check_early_console() { + early_console="${1:-earlyxe90}" log="$(dmesg)" - case "$log" in *'bootconsole [earlyxe90] enabled'*) ;; *) fail 44 ;; esac - case "$log" in *'bootconsole [earlyxe90] disabled'*) ;; *) fail 45 ;; esac + case "$log" in *"bootconsole [$early_console] enabled"*) ;; *) fail 44 ;; esac + case "$log" in *"bootconsole [$early_console] disabled"*) ;; *) fail 45 ;; esac if printf '%s\n' "$log" | grep -F 'Unknown kernel command line parameters' | grep -qF 'earlycon='; then fail 46 fi } -check_early_console +check_early_console "$early_console" # OpenVMM relays the byte channel to its stderr beside the boot console, where # the scenario requires these bytes unchanged and in order. The last one ends # their line in the scenario's log, which interleaves stderr and the console. for octal in 000 015 012 177 377 012; do - printf "\\$octal" | dd of=/dev/port bs=1 seek=233 count=1 conv=notrunc 2>/dev/null + if [ "$architecture" = aarch64 ]; then + printf "\\$octal" | dd of=/dev/nvx-platform bs=1 seek=0 count=1 conv=notrunc 2>/dev/null + else + printf "\\$octal" | dd of=/dev/port bs=1 seek=233 count=1 conv=notrunc 2>/dev/null + fi done echo NVX-LIFECYCLE-OK nvx-exit 0 diff --git a/scripts/nvx_tools/microvm_test_scripts/sandbox-blocks.sh b/scripts/nvx_tools/microvm_test_scripts/sandbox-blocks.sh index 9b4b0b668..2751c9745 100644 --- a/scripts/nvx_tools/microvm_test_scripts/sandbox-blocks.sh +++ b/scripts/nvx_tools/microvm_test_scripts/sandbox-blocks.sh @@ -15,11 +15,11 @@ for name in vda vdb; do [ -b "/dev/$name" ] || fail 20 done [ ! -b /dev/vdc ] || fail 30 -grep -q 'virtio_mmio.device=0x1000@0xd0003000:19' /proc/cmdline || fail 21 -grep -q 'virtio_mmio.device=0x1000@0xd0006000:22' /proc/cmdline || fail 24 +fixed_virtio_present d0003000 19 || fail 21 +fixed_virtio_present d0006000 22 || fail 24 # The windows and interrupts of the removed runtime and custom layers stay unassigned. -! grep -q '0xd0004000' /proc/cmdline || fail 31 -! grep -q '0xd0005000' /proc/cmdline || fail 32 +fixed_virtio_absent d0004000 || fail 31 +fixed_virtio_absent d0005000 || fail 32 [ "$(cat /sys/block/vda/ro)" = 1 ] || fail 25 [ "$(cat /sys/block/vdb/ro)" = 0 ] || fail 28 printf MICROVM-SCRATCH-OK | dd of=/dev/vdb bs=512 count=1 conv=sync,notrunc 2>/dev/null diff --git a/scripts/nvx_tools/microvm_test_scripts/virtio-mmio.sh b/scripts/nvx_tools/microvm_test_scripts/virtio-mmio.sh new file mode 100644 index 000000000..7f10b561d --- /dev/null +++ b/scripts/nvx_tools/microvm_test_scripts/virtio-mmio.sh @@ -0,0 +1,63 @@ +# Resolve the Linux resource of a bound virtio device, on either discovery bus. +window_range() { + while IFS=' ' read -r range separator name _; do + [ "$separator" = : ] && [ "$name" = "$1" ] || continue + echo "$range" + return 0 + done None: "scenarios unless --scenario is given" ), ) + parser.add_argument( + "--cold-only", + action="store_true", + help="run only the explicitly selected cold scope; requires --scenario, " + "keeps all cold assertions of mixed scenarios and defers their snapshot tail", + ) parser.add_argument( "--shard", type=parse_shard, @@ -826,9 +903,22 @@ def configure_parser(parser: argparse.ArgumentParser) -> None: type=int, choices=MICROVM_PROCESSOR_COUNTS, nargs="+", - default=list(MICROVM_PROCESSOR_COUNTS), metavar="COUNT", - help="processor counts for SMP and restore tests (default: 1 2 4 8)", + help="processor counts for SMP, restore and managed lifecycle tests " + "(default: 1 2 4 8 for SMP/restore, 1 for managed lifecycle)", + ) + parser.add_argument( + "--managed-root", + choices=("initramfs", "scratch", "ram"), + default="initramfs", + help="managed-lifecycle root fixture; scratch/ram require --guest ubuntu " + "and reuse its maintained distro layer (default: initramfs)", + ) + parser.add_argument( + "--start-stop-cycles", + type=positive_int, + help="repeat Start/Stop of one provisioned public scratch/RAM sandbox; " + "requires sandbox-lifecycle or sandbox-ram-upper (RAM requires at least 2)", ) parser.add_argument( "--memory-mib", @@ -991,6 +1081,13 @@ def _read_script(name: str) -> str: script = (MICROVM_TEST_SCRIPTS_DIR / name).read_text(encoding="utf-8") if not script.endswith("\n"): raise ValueError(f"microVM test script must end with a newline: {name}") + if name in ( + "filesystem-shares.sh", + "interrupt-map.sh.in", + "sandbox-blocks.sh", + "virtio-net.sh", + ): + script = _read_script("virtio-mmio.sh") + script return script @@ -1269,6 +1366,7 @@ def run_guest_boot( timeout: float, log_path: Path, architecture: str | None = None, + processors: int = 1, ) -> None: command = workload_boot_command( executable, @@ -1277,6 +1375,7 @@ def run_guest_boot( initrd, memory_mib, "quiet loglevel=0", + processors=processors, ) run_guest_script( command, @@ -1911,7 +2010,10 @@ def run_smp( timeout: float, log_path: Path, counting_lapic: bool = False, + architecture: str = "x86_64", ) -> None: + if counting_lapic and architecture != "x86_64": + raise ScriptError("smp-lapic is an x86 counting-LAPIC check") command = workload_boot_command( executable, backend, @@ -1922,7 +2024,7 @@ def run_smp( processors=processors, ) script = ( - smp_probe_script(processors, exit_guest=False) + smp_probe_script(processors, exit_guest=False, architecture=architecture) + warp_probe_script() + "nvx-exit 0\n" ) @@ -3609,6 +3711,7 @@ def run_ipv6_egress_policy( timeout: float, output_dir: Path, guest: str = "alpine", + cold_only: bool = False, ) -> None: endpoints = _bind_ipv6_egress_ports() try: @@ -3691,17 +3794,18 @@ def run_ipv6_egress_policy( } ) - _run_ipv6_egress_snapshot( - executable, - kernel, - initrd, - backend, - memory_mib=memory_mib, - timeout=timeout, - output_dir=output_dir, - endpoint=endpoints["tcp6-named"], - named_port=named_port, - ) + if not cold_only: + _run_ipv6_egress_snapshot( + executable, + kernel, + initrd, + backend, + memory_mib=memory_mib, + timeout=timeout, + output_dir=output_dir, + endpoint=endpoints["tcp6-named"], + named_port=named_port, + ) invalid = workload_boot_command( executable, @@ -4576,6 +4680,7 @@ def run_private_network_ingress( memory_mib: int, timeout: float, output_dir: Path, + cold_only: bool = False, ) -> None: """Verify that ``--network-ingress allow`` publishes the guest's listeners. @@ -4764,6 +4869,8 @@ def unpublished() -> None: probe=unpublished, ) + if cold_only: + return with tempfile.TemporaryDirectory(prefix="nvx-ingress-snapshot-") as temporary: invalid = _private_ingress_command( executable, @@ -5403,10 +5510,13 @@ class InterruptMapEntry(NamedTuple): actions: str fired: int unhandled: int + dt_interrupts: str | None = None def parse_interrupt_map( output: str, + *, + architecture: str = "x86_64", ) -> tuple[dict[str, dict[int, InterruptMapEntry]], dict[str, int]]: """Return the interrupt-map scenario's reports in ``output``, by step and by the base of each device's window, and the guest's ERR, MIS, and SPU @@ -5427,7 +5537,12 @@ def parse_interrupt_map( fields = dict(field.split("=", 1) for field in line[len(prefix) :].split()) if prefix == INTERRUPT_MAP_ERRORS_PREFIX: errors = { - name: int(fields[name]) for name in INTERRUPT_MAP_ERROR_COUNTS + name: int(fields[name]) + for name in ( + ("err",) + if architecture == "aarch64" + else INTERRUPT_MAP_ERROR_COUNTS + ) } continue step = fields["step"] @@ -5441,6 +5556,7 @@ def parse_interrupt_map( fields["actions"], int(fields["count"]), int(fields["unhandled"]), + fields.get("dt_interrupts"), ) except (KeyError, ValueError) as error: raise RuntimeError( @@ -5462,6 +5578,7 @@ def check_interrupt_map( *, before: str, after: str = "traffic", + architecture: str = "x86_64", ) -> None: """Check the interrupt-map scenario's reports against the map of the architecture guide (2.4.2 and Table 2.7): after the steps ``before`` and @@ -5473,6 +5590,7 @@ def check_interrupt_map( interrupt (MIS), and no spurious APIC interrupt (SPU). Raises RuntimeError naming each departure.""" + arm = architecture == "aarch64" problems: list[str] = [] for step in (before, after): entries = steps.get(step) @@ -5492,12 +5610,34 @@ def check_interrupt_map( f"no {expected.name} is reported at {base:#x} after step {step}" ) continue - if entry.irq != expected.irq: + if not arm and entry.irq != expected.irq: problems.append( f"{expected.name} at {base:#x} interrupts on IRQ {entry.irq}, " f"not {expected.irq}" ) - if entry.chip != "IO-APIC" or entry.hwirq != entry.irq: + if arm: + # DT names SPI index N; the GIC hardware INTID is 32 + N. + # Linux's allocated IRQ number is neither of those. + slot = (base - 0xD000_0000) // 0x1000 + if entry.chip != "GICv3" or entry.hwirq != 32 + slot: + problems.append( + f"{expected.name}'s Linux IRQ {entry.irq} is INTID " + f"{entry.hwirq} of {entry.chip}, not GICv3 INTID {32 + slot}" + ) + if entry.dt_interrupts != f"00000000{slot:08x}00000001": + problems.append( + f"{expected.name}'s DT interrupt cells are " + f"{entry.dt_interrupts!r}, not [GIC_SPI=0, {slot}, " + "EDGE_RISING=1]" + ) + if ( + entry.irq < 0 + or sum(other.irq == entry.irq for other in entries.values()) != 1 + ): + problems.append( + f"{expected.name}'s Linux IRQ {entry.irq} is invalid or shared" + ) + elif entry.chip != "IO-APIC" or entry.hwirq != entry.irq: problems.append( f"{expected.name}'s IRQ {entry.irq} is input {entry.hwirq} of " f"{entry.chip}, not the IOAPIC input of its number" @@ -5515,14 +5655,23 @@ def check_interrupt_map( for base in sorted(bases): expected = MICROVM_VIRTIO_DEVICES[base] first, last = steps[before][base], steps[after][base] + if arm and first.irq != last.irq: + problems.append( + f"{expected.name}'s Linux IRQ changed from {first.irq} " + f"to {last.irq} with traffic" + ) if last.fired <= first.fired: problems.append( f"{expected.name}'s IRQ {first.irq} fired {first.fired} times " f"after step {before} and {last.fired} after step {after}" ) - if not errors: + if arm and not errors: + problems.append("the guest reported no GIC Err count") + elif arm and errors["err"]: + problems.append(f"/proc/interrupts counts {errors['err']} GIC errors (Err)") + elif not arm and not errors: problems.append("the guest reported no ERR, MIS, and SPU counts") - elif any(errors.values()): + elif not arm and any(errors.values()): problems.append( f"/proc/interrupts counts {errors['err']} APIC errors or spurious PIC " f"interrupts (ERR), {errors['mis']} misrouted IOAPIC interrupts " @@ -5535,7 +5684,9 @@ def check_interrupt_map( ) -def _interrupt_map_script(devices: int, *, capture: str) -> str: +def _interrupt_map_script( + devices: int, *, capture: str, architecture: str = "x86_64" +) -> str: """Return the interrupt-map scenario's guest script for a guest with ``devices`` virtio devices, which runs ``capture`` between its boot report and its traffic. @@ -5546,6 +5697,7 @@ def _interrupt_map_script(devices: int, *, capture: str) -> str: "interrupt-map.sh.in", DEVICES=str(devices), CAPTURE=capture, + ARCHITECTURE=architecture, GUEST_ATTACH="".join(f"\\{byte:03o}" for byte in INTERRUPT_MAP_GUEST_ATTACH), ) @@ -5559,6 +5711,8 @@ def run_interrupt_map( memory_mib: int, timeout: float, output_dir: Path, + cold_only: bool = False, + architecture: str = "x86_64", ) -> None: """Check the interrupt map of the architecture guide (2.4.2 and Table 2.7) end to end. @@ -5572,6 +5726,10 @@ def run_interrupt_map( IOAPIC interrupt, or spurious interrupt. A snapshot of a microVM with the NIC, the share, and the boot console then restores with the same interrupts, which fire again after the restore.""" + if architecture == "aarch64" and not cold_only: + raise ScriptError( + "ARM64 interrupt-map requires --cold-only; restore is unsupported" + ) with tempfile.TemporaryDirectory(prefix="nvx-interrupt-map-") as temporary: root = Path(temporary) share = root / "share" @@ -5599,13 +5757,23 @@ def run_interrupt_map( ) result = run_guest_script( command, - _interrupt_map_script(len(MICROVM_VIRTIO_DEVICES), capture=""), + _interrupt_map_script( + len(MICROVM_VIRTIO_DEVICES), capture="", architecture=architecture + ), INTERRUPT_MAP_COMPLETION_MARKER, timeout=timeout, log_path=output_dir / "interrupt-map.log", ) - steps, errors = parse_interrupt_map(result["output"]) - check_interrupt_map(steps, errors, MICROVM_VIRTIO_DEVICES, before="boot") + steps, errors = parse_interrupt_map(result["output"], architecture=architecture) + check_interrupt_map( + steps, + errors, + MICROVM_VIRTIO_DEVICES, + before="boot", + architecture=architecture, + ) + if cold_only: + return snapshot_path = root / "snapshot" capture_command = [ @@ -10015,6 +10183,7 @@ def run_filesystem_shares( memory_mib: int, timeout: float, output_dir: Path, + cold_only: bool = False, ) -> None: """Attach a read-write workspace, a read-only tool cache, a data directory with a hidden root, and a read-only and a read-write file, each without @@ -10179,6 +10348,8 @@ def run_filesystem_shares( invalid, output_dir / f"filesystem-shares-{name}.log", timeout, expected ) + if cold_only: + return # Every child belongs to the snapshot contract, in order. snapshot = root / "snapshot" with OpenvmmProcess( @@ -10339,6 +10510,7 @@ def run_filesystem_policy( memory_mib: int, timeout: float, output_dir: Path, + cold_only: bool = False, ) -> None: """Narrow a read-write share's writes and expose a path in a hidden subtree. @@ -10441,6 +10613,8 @@ def boot_command(mode: str = "rw") -> list[str]: expected, ) + if cold_only: + return # The policy belongs to the snapshot contract, and the restored guest # keeps both its writable handle and the policy. snapshot = root / "snapshot" @@ -11370,6 +11544,43 @@ def run(args: argparse.Namespace) -> int: validate_openvmm_test_backend(args.backend) descriptor = guest_descriptor(args.guest) architecture = getattr(args, "architecture", "x86_64") + cold_only = getattr(args, "cold_only", False) + if cold_only and args.scenario is None: + raise ScriptError("--cold-only requires explicit --scenario selection") + if cold_only: + outside = set(args.scenario) - COLD_ONLY_SCENARIOS + if outside: + raise ScriptError( + "scenario(s) have no maintained cold projection: " + + ", ".join(sorted(outside)) + ) + if architecture == "aarch64" and args.scenario is not None: + outside = set(args.scenario) - COLD_ONLY_SCENARIOS + mixed = set(args.scenario) & COLD_PROJECTION_SCENARIOS + if outside or (mixed and not cold_only): + raise ScriptError( + "ARM64 correctness cannot run a snapshot/x86-only scope; " + "select maintained cold scenarios explicitly and use --cold-only " + "for mixed scenarios" + ) + managed_processors = tuple(dict.fromkeys(args.processors or (1,))) + args.processors = args.processors or list(MICROVM_PROCESSOR_COUNTS) + managed_root = getattr(args, "managed_root", "initramfs") + start_stop_cycles = getattr(args, "start_stop_cycles", None) + if start_stop_cycles is not None: + if not args.scenario or not set(args.scenario) <= { + "sandbox-lifecycle", + "sandbox-ram-upper", + }: + raise ScriptError( + "--start-stop-cycles requires explicit public scratch/RAM scenarios" + ) + if "sandbox-ram-upper" in args.scenario and start_stop_cycles < 2: + raise ScriptError( + "RAM-upper acceptance requires at least two Start/Stop cycles" + ) + if managed_root != "initramfs" and descriptor.name != "ubuntu": + raise ScriptError("--managed-root scratch/ram requires --guest ubuntu") debug_kernel = getattr(args, "debug_kernel", False) if architecture == "aarch64" and args.scenario is None: raise ScriptError( @@ -11448,6 +11659,13 @@ def run(args: argparse.Namespace) -> int: f"{guest_label} guest does not support correctness scenario(s): " + ", ".join(sorted(unsupported)) ) + if managed_root != "initramfs" and "managed-lifecycle" not in scenarios: + raise ScriptError("--managed-root requires the managed-lifecycle scenario") + layered = ( + load_workload_artifacts(architecture=architecture) + if managed_root != "initramfs" + else None + ) # A default run runs the public sandbox scenarios too, so their Ubuntu # artifacts must be there before any scenario runs. public = [ @@ -11481,6 +11699,8 @@ def run(args: argparse.Namespace) -> int: kernel="debug" if debug_kernel else "default", processors=args.processors, scenarios=scenarios, + architecture=architecture, + scope="cold" if cold_only else "full", ) as report: _run_scenarios( report, @@ -11491,6 +11711,8 @@ def run(args: argparse.Namespace) -> int: kernel=kernel, initrd=initrd, output_dir=output_dir, + managed_processors=managed_processors, + layered=layered, ) report.finish() report_time_abi_evidence( @@ -11513,27 +11735,38 @@ def _run_scenarios( kernel: Path, initrd: Path, output_dir: Path, + managed_processors: Sequence[int] = (1,), + layered: WorkloadArtifacts | None = None, ) -> None: """Run the selected scenarios in their fixed order, and time each execution in `report`.""" architecture = getattr(args, "architecture", "x86_64") + cold_only = getattr(args, "cold_only", False) if "guest-boot" in scenarios: - report.start( - "guest-boot", - f"Running {descriptor.distribution} initramfs boot correctness " - f"on OpenVMM/{args.backend}", - ) - run_guest_boot( - executable, - kernel, - initrd, - args.backend, - descriptor, - memory_mib=args.memory_mib, - timeout=args.timeout, - log_path=output_dir / f"{descriptor.name}-guest-boot.log", - architecture=architecture, - ) + for processors in managed_processors: + report.start( + "guest-boot", + f"Running {descriptor.distribution} initramfs boot correctness " + f"({processors} vCPU) on OpenVMM/{args.backend}", + processors=[processors], + ) + run_guest_boot( + executable, + kernel, + initrd, + args.backend, + descriptor, + memory_mib=args.memory_mib, + timeout=args.timeout, + log_path=output_dir + / ( + f"{descriptor.name}-guest-boot.log" + if managed_processors == (1,) + else f"{descriptor.name}-guest-boot-{processors}vcpu.log" + ), + architecture=architecture, + **({"processors": processors} if managed_processors != (1,) else {}), + ) if "guest-identity" in scenarios: report.start( "guest-identity", @@ -11641,6 +11874,7 @@ def _run_scenarios( memory_mib=args.memory_mib, timeout=args.timeout, output_dir=output_dir, + cold_only=cold_only, ) if "filesystem-policy" in scenarios: report.start( @@ -11656,6 +11890,7 @@ def _run_scenarios( memory_mib=args.memory_mib, timeout=args.timeout, output_dir=output_dir, + cold_only=cold_only, ) if "filesystem-comma-paths" in scenarios: report.start( @@ -11733,6 +11968,11 @@ def _run_scenarios( timeout=args.timeout, output_dir=output_dir, architecture=architecture, + **( + {"start_stop_cycles": args.start_stop_cycles} + if getattr(args, "start_stop_cycles", None) is not None + else {} + ), ) if "sandbox-proxy-only" in scenarios: report.start( @@ -11755,21 +11995,76 @@ def _run_scenarios( timeout=args.timeout, output_dir=output_dir, architecture=architecture, + **( + {"start_stop_cycles": args.start_stop_cycles} + if getattr(args, "start_stop_cycles", None) is not None + else {} + ), ) if "managed-lifecycle" in scenarios: - report.start( - "managed-lifecycle", - f"Running managed microVM lifecycle on OpenVMM/{args.backend}", - ) - run_managed_lifecycle( - executable, - kernel, - initrd, - args.backend, - memory_mib=args.memory_mib, - timeout=args.timeout, - output_dir=output_dir, - ) + managed_root = getattr(args, "managed_root", "initramfs") + managed_initrd = initrd + if layered is not None: + control_initrd = BuildConfig.initramfs_config("alpine", architecture).output + assert control_initrd is not None + managed_initrd = require_file( + control_initrd, "Alpine sandbox control initramfs" + ) + for processors in managed_processors: + case_root = output_dir + if managed_root != "initramfs" or managed_processors != (1,): + case_root /= f"managed-lifecycle-{managed_root}-{processors}vcpu" + if case_root.exists(): + raise ScriptError( + f"managed fixture evidence already exists: {case_root}; " + "select a fresh --output-dir" + ) + case_root.mkdir() + scratch = None + if managed_root == "scratch": + assert layered is not None + scratch = case_root / "scratch.ext4" + shutil.copyfile(layered.scratch_template, scratch) + if not scratch_journal_clean(scratch): + raise ScriptError( + f"managed scratch template is not clean: {scratch}" + ) + states = ( + ("absent", "present" if scratch is not None else "absent") + if layered is not None + else (None,) + ) + for index, previous in enumerate(states, 1): + log_root = case_root + variant = None + if previous is not None: + log_root /= f"boot-{index}-{previous}" + log_root.mkdir() + variant = f"{managed_root}-boot-{index}-{previous}" + report.start( + "managed-lifecycle", + f"Running managed microVM lifecycle ({processors} vCPU, " + f"root={managed_root}, previous={previous}) on OpenVMM/{args.backend}", + processors=[processors], + variant=variant, + ) + run_managed_lifecycle( + executable, + kernel, + managed_initrd, + args.backend, + memory_mib=args.memory_mib, + timeout=args.timeout, + output_dir=log_root, + processors=processors, + layered=layered, + scratch=scratch, + expected_previous_state=previous, + ) + if scratch is not None and not scratch_journal_clean(scratch): + raise RuntimeError( + f"managed scratch journal is not clean: {scratch}" + ) if "structured-outcome" in scenarios: report.start( "structured-outcome", @@ -11847,6 +12142,7 @@ def _run_scenarios( timeout=args.timeout, output_dir=output_dir, guest=descriptor.name, + cold_only=cold_only, ) if "host-loopback-policy" in scenarios: report.start( @@ -11875,6 +12171,7 @@ def _run_scenarios( memory_mib=args.memory_mib, timeout=args.timeout, output_dir=output_dir, + **({"cold_only": True} if cold_only else {}), ) if "denied-filesystem-paths" in scenarios: report.start( @@ -11938,6 +12235,7 @@ def _run_scenarios( timeout=args.timeout, log_path=output_dir / f"{scenario}-{processors}.log", counting_lapic=counting_lapic, + architecture=architecture, ) if "sandbox-blocks" in scenarios: report.start( @@ -12253,6 +12551,8 @@ def _run_scenarios( memory_mib=args.memory_mib, timeout=args.timeout, output_dir=output_dir, + cold_only=cold_only, + architecture=architecture, ) if "command-line-limit" in scenarios: report.start( diff --git a/scripts/nvx_tools/openvmm_ci.py b/scripts/nvx_tools/openvmm_ci.py index 2b0dae2a1..ec94c583a 100644 --- a/scripts/nvx_tools/openvmm_ci.py +++ b/scripts/nvx_tools/openvmm_ci.py @@ -9,7 +9,9 @@ on KVM, MSHV, and Windows, to have passed for the pinned revision in either workflow, and waits while they run. The gates' other jobs, such as the VMM tests on TDX and SEV-SNP hosts, test OpenHCL and confidential VMs, which NVX does not -use. See doc/ci.md, "OpenVMM CI". +use. ARM selection adds the existing native Windows ARM unit and VMM jobs, +without removing x86 coverage or changing workflow/repository trust. +See doc/ci.md, "OpenVMM CI". """ from __future__ import annotations @@ -44,6 +46,10 @@ "run vmm-tests [x64-windows-intel]", "run vmm-tests [x64-windows-amd]", ) +OPENVMM_CI_ARM64_REQUIRED_JOBS = ( + "unit tests [aarch64-windows]", + "run vmm-tests [aarch64-windows]", +) # How long the check waits between two looks at runs that have not finished. # OpenVMM's gates take one and a half to two hours, so a look every five # minutes adds little to a wait, and keeps a wait's requests, three a look, @@ -225,6 +231,7 @@ def check_openvmm_ci( revision: str, *, wait_seconds: float, + required: Sequence[str] = OPENVMM_CI_REQUIRED_JOBS, sleep: Callable[[float], None] = time.sleep, clock: Callable[[], float] = time.monotonic, ) -> list[Verdict]: @@ -235,7 +242,7 @@ def check_openvmm_ci( failures = 0 while True: try: - verdicts = assess_openvmm_ci(openvmm_ci_runs(api, revision)) + verdicts = assess_openvmm_ci(openvmm_ci_runs(api, revision), required) except (ScriptError, OSError) as error: failures += 1 if failures > FAILED_LOOK_RETRIES or clock() + POLL_SECONDS > deadline: @@ -293,7 +300,12 @@ def command_check_openvmm_ci(args: argparse.Namespace) -> None: # too, under a lower rate limit. token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN") or None api = GitHubClient(token, os.environ.get("GITHUB_API_URL") or GITHUB_API_URL) - verdicts = check_openvmm_ci(api, revision, wait_seconds=args.wait_minutes * 60) + required: tuple[str, ...] = OPENVMM_CI_REQUIRED_JOBS + if args.architecture == "aarch64": + required += OPENVMM_CI_ARM64_REQUIRED_JOBS + verdicts = check_openvmm_ci( + api, revision, wait_seconds=args.wait_minutes * 60, required=required + ) for verdict in verdicts: print(f"{verdict.state}: {verdict.job}: {verdict.detail}") if args.summary is not None: @@ -326,6 +338,13 @@ def configure_parser(parser: argparse.ArgumentParser) -> None: "Check that OpenVMM's checkin gates passed the jobs that cover NVX's use " "of OpenVMM for the pinned OpenVMM revision (doc/ci.md, 'OpenVMM CI')." ) + parser.add_argument( + "--architecture", + choices=("x86_64", "aarch64"), + default="x86_64", + help="coverage ISA: aarch64 adds native Windows ARM unit/VMM jobs " + "without dropping any x86 jobs (default: x86_64)", + ) parser.add_argument( "--revision", metavar="SHA", diff --git a/scripts/nvx_tools/runtime_adapter_tests.py b/scripts/nvx_tools/runtime_adapter_tests.py index f8295a674..33a5faa1f 100644 --- a/scripts/nvx_tools/runtime_adapter_tests.py +++ b/scripts/nvx_tools/runtime_adapter_tests.py @@ -22,20 +22,36 @@ from pathlib import Path from typing import Any, cast -from .build_constants import BuildConstants, OpenVMMBuildConstants +from .build_constants import BuildConstants, GuestRustBuildConstants from .ci import OPENVMM_TEST_BACKENDS, validate_openvmm_test_backend -from .common import ScriptError, require_file +from .common import ScriptError, host_architecture, require_file +from .elf import check_static_executables ADAPTER_DIRECTORY = BuildConstants.REPO_ROOT / "tests" / "runtime-adapter" PACKAGE = "runtime-adapter" SCENARIOS = ADAPTER_DIRECTORY / "scenarios.txt" -GUEST_AGENT = ( - ADAPTER_DIRECTORY +GUEST_AGENTS = { + architecture: ADAPTER_DIRECTORY / "target" - / OpenVMMBuildConstants.MUSL_RUST_TARGET + / target / "release" / "runtime-adapter-guest" -) + for architecture, target in GuestRustBuildConstants.TARGETS.items() +} +GUEST_AGENT = GUEST_AGENTS["x86_64"] +SCENARIO_SCOPES = { + "template_capture": "portable", + "template_operations": "portable", + "clone_start": "portable", + "host_session": "portable", + "staged_images": "portable", + "layered_launch": "portable", + "vm_restart": "cold", + "vm_steps": "cold", + "vm_layered": "cold", + "vm_template": "snapshot", + "vm_clone": "snapshot", +} # libtest's line for a test that ended, and the summary of a test target's run. _TEST_LINE = re.compile(r"^test (\S+) \.\.\. (\S+)") _RESULT_LINE = re.compile(r"^test result: \S+\. (\d+) passed; ") @@ -55,12 +71,22 @@ def configure_parser(parser: argparse.ArgumentParser) -> None: "scenario that tests/runtime-adapter/scenarios.txt names, by its name." ) parser.add_argument("--backend", choices=OPENVMM_TEST_BACKENDS, required=True) + parser.add_argument( + "--architecture", + choices=GuestRustBuildConstants.ARCHITECTURES, + default="x86_64", + ) + parser.add_argument( + "--cold-only", + action="store_true", + help="run the explicitly classified portable/cold targets, retaining the " + "exhaustive full-suite naming check; report snapshot targets as deferred", + ) parser.add_argument( "--guest-agent", type=Path, - default=GUEST_AGENT, - help="the adapter's guest agent, a static musl executable (default: its " - "release build in tests/runtime-adapter)", + help="the adapter's guest agent, a static musl executable of --architecture " + "(default: its ISA-specific release build in tests/runtime-adapter)", ) parser.add_argument( "--check-only", @@ -119,7 +145,9 @@ def cargo_test_targets(cargo: str, environment: dict[str, str]) -> list[str]: raise ScriptError(f"Cargo's metadata of the adapter has no package {PACKAGE}") -def cargo_test(cargo: str, target: str | None, *arguments: str) -> list[str]: +def cargo_test( + cargo: str, target: str | None, *arguments: str, host_target: str | None = None +) -> list[str]: """Returns the command that runs the test target `target` of the adapter's host-only configuration, or the unit tests of its library for `None`, with libtest's `arguments`.""" @@ -130,6 +158,7 @@ def cargo_test(cargo: str, target: str | None, *arguments: str) -> list[str]: "--locked", "--features", "host", + *(["--target", host_target] if host_target is not None else []), *selection, "--", *arguments, @@ -230,7 +259,11 @@ def streamed(command: list[str], environment: dict[str, str]) -> tuple[str, int] def suite_problems( - targets: Sequence[Target], cargo: str, environment: dict[str, str] + targets: Sequence[Target], + cargo: str, + environment: dict[str, str], + *, + host_target: str | None = None, ) -> list[str]: """Returns why `targets` are not the adapter's suite: each target that is not one of the adapter's test targets, each scenario that names a test that its target does @@ -243,7 +276,15 @@ def suite_problems( problems.append(f"{target.name} is not a test target of the adapter") continue listed = listing( - cargo_test(cargo, target.name, "--list", "--format", "terse"), environment + cargo_test( + cargo, + target.name, + "--list", + "--format", + "terse", + host_target=host_target, + ), + environment, ) if listed.returncode != 0: problems.append(f"cannot list the tests of {target.name}:\n{listed.stderr}") @@ -252,7 +293,15 @@ def suite_problems( named = {target.name for target in targets} others = [name for name in available if name not in named] for name in [None, *others]: - command = cargo_test(cargo, name, "--ignored", "--list", "--format", "terse") + command = cargo_test( + cargo, + name, + "--ignored", + "--list", + "--format", + "terse", + host_target=host_target, + ) listed = listing(command, environment) what = "the library" if name is None else name if listed.returncode != 0: @@ -269,13 +318,66 @@ def command_test_runtime_adapter(args: argparse.Namespace) -> int: backend = cast(str, args.backend) cargo = cast(str, args.cargo) check_only = cast(bool, args.check_only) - targets = read_scenarios() + architecture = getattr(args, "architecture", "x86_64") + cold_only = getattr(args, "cold_only", False) + if architecture != host_architecture(): + raise ScriptError("runtime adapter validation requires its native host ISA") + if architecture == "aarch64" and (backend != "whp" or sys.platform != "win32"): + raise ScriptError( + "ARM64 runtime adapter validation requires native Windows/WHP" + ) + if architecture == "aarch64" and not check_only and not cold_only: + raise ScriptError("ARM64 adapter runs require explicit --cold-only selection") + all_targets = read_scenarios() + targets = all_targets + if cold_only: + named = {target.name for target in all_targets} + if named != SCENARIO_SCOPES.keys(): + raise ScriptError( + "runtime adapter scope inventory differs from its canonical targets: " + f"unclassified={sorted(named - SCENARIO_SCOPES.keys())}; " + f"stale={sorted(SCENARIO_SCOPES.keys() - named)}" + ) + if any( + scope not in ("portable", "cold", "snapshot") + for scope in SCENARIO_SCOPES.values() + ): + raise ScriptError("runtime adapter inventory has an unknown scenario scope") + targets = [ + target + for target in all_targets + if SCENARIO_SCOPES[target.name] in ("portable", "cold") + ] + if not any( + SCENARIO_SCOPES[target.name] == "cold" and target.tests + for target in targets + ): + raise ScriptError("runtime adapter cold scope selects no cold cases") + deferred = [ + target + for target in all_targets + if SCENARIO_SCOPES[target.name] == "snapshot" + ] + print( + f"runtime adapter cold scope on {architecture}: " + f"{sum(len(target.tests) for target in targets)} selected tests; " + f"{sum(len(target.tests) for target in deferred)} deferred snapshot tests " + f"({', '.join(target.name for target in deferred)})" + ) + host_target = "aarch64-pc-windows-msvc" if architecture == "aarch64" else None environment = os.environ.copy() if not check_only: validate_openvmm_test_backend(backend) guest = require_file( - cast(Path, args.guest_agent), "runtime adapter guest agent" + cast(Path | None, args.guest_agent) or GUEST_AGENTS[architecture], + "runtime adapter guest agent", ) + try: + check_static_executables([guest], architecture=architecture) + except ValueError as error: + raise ScriptError( + f"invalid runtime adapter guest agent: {error}" + ) from error environment["NVX_HYPERVISOR"] = backend # Cargo runs the tests in the adapter's directory, so a relative directory of # artifacts is the caller's, and NVX takes an empty one for none. @@ -284,11 +386,16 @@ def command_test_runtime_adapter(args: argparse.Namespace) -> int: Path(artifacts).resolve() if artifacts else BuildConstants.REPO_ROOT ) environment["RUNTIME_ADAPTER_GUEST"] = os.fspath(guest.resolve()) - problems = suite_problems(targets, cargo, environment) + problems = suite_problems(all_targets, cargo, environment, host_target=host_target) if not problems and not check_only: for target in targets: command = cargo_test( - cargo, target.name, "--include-ignored", "--exact", *target.tests + cargo, + target.name, + "--include-ignored", + "--exact", + *target.tests, + host_target=host_target, ) output, status = streamed(command, environment) problems.extend(run_problems(target, output, status)) @@ -302,7 +409,8 @@ def command_test_runtime_adapter(args: argparse.Namespace) -> int: return 1 if check_only: print( - f"{count} scenarios name exactly the tests of {len(targets)} targets, and " + f"{sum(len(target.tests) for target in all_targets)} scenarios name exactly " + f"the tests of {len(all_targets)} targets, and " "neither the library nor another target has an ignored test" ) else: diff --git a/scripts/nvx_tools/sandbox_lifecycle_tests.py b/scripts/nvx_tools/sandbox_lifecycle_tests.py index 5f85d5a19..6da4cfab2 100644 --- a/scripts/nvx_tools/sandbox_lifecycle_tests.py +++ b/scripts/nvx_tools/sandbox_lifecycle_tests.py @@ -411,6 +411,7 @@ def __init__( artifacts: WorkloadArtifacts, root: Path, architecture: str = "x86_64", + start_stop_cycles: int = 1, ) -> None: self.backend = backend self.timeout = timeout @@ -418,6 +419,10 @@ def __init__( self.artifacts = artifacts self.root = root self.architecture = architecture + if start_stop_cycles < 1: + raise ScriptError("sandbox Start/Stop cycles must be positive") + self.start_stop_cycles = start_stop_cycles + self.cycle: int | None = None self.state = root / "state" self.identity_state = root / "identity-state" self.scratch = root / "scratch.ext4" @@ -476,6 +481,7 @@ def record( "stdout_bytes": len(result.stdout), "stderr_bytes": len(result.stderr), "state_entries": None if state is None else state_entries(state), + **({"cycle": self.cycle} if self.cycle is not None else {}), } ) @@ -576,13 +582,32 @@ def run(self) -> None: self.check_identity_admission() self.check_unprovisioned() self.provision() + if self.start_stop_cycles > 1: + self.cycle = 1 runtime = self.start(description="first start") + if self.cycle is not None: + self.copy_evidence(self.state / RUNTIME, "cycle-001-runtime.json") self.check_running_transitions(runtime) self.check_warm_state() self.check_security_profile() self.check_bounded_results() self.check_deprovision_while_running(runtime) self.stop(runtime, layer_digest) + if self.start_stop_cycles > 1: + self.copy_evidence(self.state / OUTCOME, "cycle-001-outcome.json") + self.copy_evidence(self.state / LOG, "cycle-001-openvmm.log") + for cycle in range(2, self.start_stop_cycles + 1): + self.cycle = cycle + runtime = self.start(description=f"Start/Stop cycle {cycle}") + self.copy_evidence(self.state / RUNTIME, f"cycle-{cycle:03}-runtime.json") + result = self.exec("/bin/cat", f"--arg={STATE_PATH}", expected=None) + self.require_output( + result, STATE_CONTENT, f"scratch state in cycle {cycle}" + ) + self.stop(runtime, layer_digest) + self.copy_evidence(self.state / OUTCOME, f"cycle-{cycle:03}-outcome.json") + self.copy_evidence(self.state / LOG, f"cycle-{cycle:03}-openvmm.log") + self.cycle = None restarted = self.start_overlapping() result = self.exec("/bin/cat", f"--arg={STATE_PATH}", expected=None) self.require_output(result, STATE_CONTENT, "the restarted sandbox's state") @@ -1111,8 +1136,15 @@ def run_acceptance(acceptance: LifecycleAcceptance) -> None: def run_sandbox_lifecycle( - backend: str, *, timeout: float, output_dir: Path, architecture: str = "x86_64" + backend: str, + *, + timeout: float, + output_dir: Path, + architecture: str = "x86_64", + start_stop_cycles: int = 1, ) -> None: + if start_stop_cycles < 1: + raise ScriptError("sandbox Start/Stop cycles must be positive") artifacts = load_workload_artifacts(architecture=architecture) output_dir.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix="nvx-public-lifecycle-")) @@ -1124,5 +1156,6 @@ def run_sandbox_lifecycle( artifacts=artifacts, root=root, architecture=architecture, + start_stop_cycles=start_stop_cycles, ) ) diff --git a/scripts/nvx_tools/sandbox_ram_upper_tests.py b/scripts/nvx_tools/sandbox_ram_upper_tests.py index 4680a14f3..b1222d370 100644 --- a/scripts/nvx_tools/sandbox_ram_upper_tests.py +++ b/scripts/nvx_tools/sandbox_ram_upper_tests.py @@ -20,12 +20,15 @@ from pathlib import Path from typing import cast +from .common import ScriptError from .managed_exec_tests import load_workload_artifacts from .sandbox_lifecycle_tests import ( CONFIG, + LOG, OUTCOME, PROBE, PROVISIONED_ENTRIES, + RUNTIME, STOPPED_ENTRIES, LifecycleAcceptance, Refusal, @@ -188,6 +191,10 @@ def check_one_shot(self) -> None: def check_managed(self) -> None: """A managed sandbox records the RAM upper without a scratch image, and its upper holds the workload's writes until the sandbox stops.""" + if self.start_stop_cycles < 2: + raise ScriptError( + "RAM-upper acceptance requires at least two Start/Stop cycles" + ) self.invoke("provision", *self.ram_options(), state=self.state) self.require_entries(self.state, PROVISIONED_ENTRIES, "after provision") config = json.loads((self.state / CONFIG).read_text(encoding="utf-8")) @@ -202,7 +209,11 @@ def check_managed(self) -> None: "scratch_binding": None, }: raise RuntimeError(f"provision recorded the RAM upper as {recorded!r}") + if self.start_stop_cycles > 2: + self.cycle = 1 self.start(description="first start") + if self.cycle is not None: + self.copy_evidence(self.state / RUNTIME, "cycle-001-runtime.json") result = self.exec(PROBE, "--arg=entry") self.save_evidence("probe.log", result.stdout + result.stderr) for marker in probe_markers(entry=True): @@ -221,13 +232,32 @@ def check_managed(self) -> None: result = self.exec("/bin/cat", f"--arg={STATE_PATH}", expected=None) self.require_output(result, STATE_CONTENT, "the RAM upper's state") self.stop_sandbox("first stop") - # A new start begins with an empty upper. - self.start(description="start after the stop") - result = self.exec( - "/bin/sh", "--arg=-c", f"--arg=test ! -e {STATE_PATH}", expected=None - ) - self.require_output(result, b"", "the restarted sandbox's empty upper") - self.stop_sandbox("second stop") + for cycle in range(2, self.start_stop_cycles + 1): + if self.start_stop_cycles > 2: + self.cycle = cycle + self.start(description="start after the stop") + if self.cycle is not None: + self.copy_evidence( + self.state / RUNTIME, f"cycle-{cycle:03}-runtime.json" + ) + result = self.exec( + "/bin/sh", "--arg=-c", f"--arg=test ! -e {STATE_PATH}", expected=None + ) + self.require_output(result, b"", "the restarted sandbox's empty upper") + if cycle < self.start_stop_cycles: + result = self.exec( + "/bin/sh", + "--arg=-c", + f"--arg=printf 'kept in RAM\\n' >{STATE_PATH}", + expected=None, + ) + self.require_output(result, b"", f"RAM state in cycle {cycle}") + self.stop_sandbox( + "second stop" + if self.start_stop_cycles == 2 + else f"cycle-{cycle:03}-stop" + ) + self.cycle = None self.invoke("deprovision", state=self.state) if self.state.exists(): raise RuntimeError("deprovision kept the RAM-upper sandbox's state") @@ -257,11 +287,25 @@ def stop_sandbox(self, description: str) -> None: ) check_managed_report(managed_report(self.state), self.backend) self.require_processes((), f"after the {description}") + if self.cycle is not None: + self.copy_evidence( + self.state / OUTCOME, f"cycle-{self.cycle:03}-outcome.json" + ) + self.copy_evidence(self.state / LOG, f"cycle-{self.cycle:03}-openvmm.log") def run_sandbox_ram_upper( - backend: str, *, timeout: float, output_dir: Path, architecture: str = "x86_64" + backend: str, + *, + timeout: float, + output_dir: Path, + architecture: str = "x86_64", + start_stop_cycles: int = 2, ) -> None: + if start_stop_cycles < 2: + raise ScriptError( + "RAM-upper acceptance requires at least two Start/Stop cycles" + ) artifacts = load_workload_artifacts(architecture=architecture) output_dir.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix="nvx-public-ram-upper-")) @@ -273,5 +317,6 @@ def run_sandbox_ram_upper( artifacts=artifacts, root=root, architecture=architecture, + start_stop_cycles=start_stop_cycles, ) ) diff --git a/scripts/nvx_tools/time_abi.py b/scripts/nvx_tools/time_abi.py index b49e797a0..d2252527a 100644 --- a/scripts/nvx_tools/time_abi.py +++ b/scripts/nvx_tools/time_abi.py @@ -179,6 +179,60 @@ def describe_cpu_generations( OPENVMM_CPU_PROFILES = Path("vmm_core", "cpu_profile", "profiles") +@dataclass(frozen=True) +class ArmCpuProfile: + """The ISA-specific identity of a pinned ARM profile, not a CPUID generation.""" + + profile_id: str + vendor: str + sha256: str + physical_address_bits: int + registers: tuple[str, ...] + + +def arm_cpu_profile(document: object) -> ArmCpuProfile | None: + """Read an ARM identity; leave CPUID documents to their existing reader.""" + if not isinstance(document, dict) or "profile" not in document: + return None + document = cast(dict[str, object], document) + profile_value = document["profile"] + if not isinstance(profile_value, dict): + raise ValueError("its ARM profile is not a JSON object") + profile = cast(dict[str, object], profile_value) + if profile.get("schema") != "nvx.arm64.cpu.v1": + raise ValueError("its ARM profile schema is unsupported") + profile_id = profile.get("id") + vendor = document.get("vendor") + sha256 = document.get("sha256") + bits = _profile_int(profile.get("physical_address_bits"), "physical address bits") + fields = profile.get("fields") + if not isinstance(fields, list) or not fields: + raise ValueError("its ARM profile names no ID registers") + registers: list[str] = [] + for entry in cast(list[object], fields): + if not isinstance(entry, dict): + raise ValueError("its ARM ID register is not a JSON object") + register = cast(dict[str, object], entry).get("register") + if ( + not isinstance(register, str) + or re.fullmatch(r"ID_AA64[A-Z0-9]+_EL1", register) is None + or register in registers + ): + raise ValueError("its ARM ID register is malformed or repeated") + registers.append(register) + if ( + not isinstance(profile_id, str) + or _PROFILE_ID.fullmatch(profile_id) is None + or not isinstance(vendor, str) + or not vendor + or not isinstance(sha256, str) + or re.fullmatch(r"sha256:[0-9a-f]{64}", sha256) is None + or bits not in (32, 36, 40, 42, 44, 48, 52) + ): + raise ValueError("its ARM profile identity is malformed") + return ArmCpuProfile(profile_id, vendor, sha256[7:], bits, tuple(registers)) + + def _profile_int(value: object, name: str) -> int: if isinstance(value, bool) or not isinstance(value, int): raise ValueError(f"its {name} is not an integer") @@ -229,7 +283,7 @@ def _profile_generation(document: object) -> CpuGeneration: def openvmm_cpu_generations(openvmm_dir: Path) -> tuple[CpuGeneration, ...]: - """Return the generations of the pinned CPU profiles in the OpenVMM + """Return the x86 CPUID generations of the pinned CPU profiles in the OpenVMM checkout ``openvmm_dir``, from which the OpenVMM that it builds selects with ``--cpu-profile auto``, each once. @@ -239,7 +293,10 @@ def openvmm_cpu_generations(openvmm_dir: Path) -> tuple[CpuGeneration, ...]: generations: list[CpuGeneration] = [] for path in sorted(directory.glob("*.json")): try: - generation = _profile_generation(json.loads(path.read_bytes())) + document = json.loads(path.read_bytes()) + if arm_cpu_profile(document) is not None: + continue + generation = _profile_generation(document) except (OSError, ValueError) as error: raise ValueError(f"cannot read the CPU profile {path}: {error}") from error if generation not in generations: @@ -604,6 +661,13 @@ def _counter_architecture(command: Sequence[str]) -> str: ) +def counter_hz_is_valid(hz: int | float, *, architecture: str = "x86_64") -> bool: + """Apply the existing TSC or architected CNTFRQ contract.""" + if architecture == "aarch64": + return 0 < hz <= 0xFFFFFFFF + return architecture == "x86_64" and MIN_TSC_HZ <= hz <= MAX_TSC_HZ + + def _validate_marker( fields: Mapping[str, str], *, @@ -622,13 +686,13 @@ def _validate_marker( try: tsc_hz = int(fields.get("tsc_hz", "")) if architecture == "aarch64": - if not 0 < tsc_hz <= 0xFFFFFFFF: + if not counter_hz_is_valid(tsc_hz, architecture=architecture): problems.append( f"counter frequency={tsc_hz} is not a nonzero CNTFRQ value" ) elif architecture != "x86_64": problems.append(f"unknown counter architecture {architecture!r}") - elif not MIN_TSC_HZ <= tsc_hz <= MAX_TSC_HZ: + elif not counter_hz_is_valid(tsc_hz, architecture=architecture): problems.append(f"tsc_hz={tsc_hz} is outside 500 MHz to 10 GHz") except ValueError: problems.append(f"tsc_hz={fields.get('tsc_hz')!r} is not an integer") diff --git a/scripts/setup/README.md b/scripts/setup/README.md index df1397f08..06e340614 100644 --- a/scripts/setup/README.md +++ b/scripts/setup/README.md @@ -94,8 +94,22 @@ $token = $null Both scripts verify the Actions runner package against the manifest's checksum. Linux runner labels start with `linux`, the selected backend, and -`virtual-machine`; Windows labels start with `windows`, `whp`, and -`virtual-machine`. The scripts also assign exactly one runner role. By default +`virtual-machine`; Windows labels start with `windows`, `whp`, and the selected +`-HostType` (`virtual-machine` by default on x86). Windows ARM64 runner setup +requires an explicit `-HostType baremetal` or `-HostType virtual-machine`; it +never infers the host type from the ISA. Windows setup selects native pinned +ARM64 or x64 tools and Visual Studio targets from the OS architecture, and +rejects an emulated PowerShell process. GitHub also supplies its native `ARM64` +or `X64` runner label. Use that label in job selectors rather than relying on +the OS/backend labels to distinguish architectures. ARM64 cold microVM jobs +do not require the x86 PCAT/SVGA firmware check. + +These are provisioning capabilities, not evidence that an ARM64 runner is +registered, service-qualified, or admitted by repository policy. Runner +registration and required-check deployment need the corresponding maintainer +permissions and a separately qualified service environment. + +The scripts also assign exactly one runner role. By default they add `general`, which every non-benchmark backend job requires. `--benchmark-runner` on Linux and `-BenchmarkRunner` on Windows add `benchmark` instead, never `general`. Exactly one runner of each backend's pool diff --git a/scripts/setup/setup-linux.sh b/scripts/setup/setup-linux.sh index 24fc17d01..05b8fcaa6 100644 --- a/scripts/setup/setup-linux.sh +++ b/scripts/setup/setup-linux.sh @@ -128,7 +128,7 @@ load_tool_manifest() { platform=${platform%.*} case "$platform" in '' | *[!a-z0-9_-]*) tool_manifest_error "unsupported key: ${key}" ;; - linux-x86_64 | windows-x86_64) ;; + linux-x86_64 | windows-x86_64 | windows-aarch64) ;; *) tool_manifest_error "unsupported platform: ${platform}" ;; esac ;; diff --git a/scripts/setup/setup-windows-whp.ps1 b/scripts/setup/setup-windows-whp.ps1 index 8154402cc..7a796358c 100644 --- a/scripts/setup/setup-windows-whp.ps1 +++ b/scripts/setup/setup-windows-whp.ps1 @@ -37,7 +37,11 @@ param( [Parameter()] [ValidatePattern('^[A-Za-z0-9_.-]+(,[A-Za-z0-9_.-]+)*$')] - [string]$ExtraRunnerLabels + [string]$ExtraRunnerLabels, + + [Parameter()] + [ValidateSet("virtual-machine", "baremetal")] + [string]$HostType ) Set-StrictMode -Version 2.0 @@ -79,7 +83,7 @@ function Read-ToolManifest { if ($field.StartsWith("artifacts.")) { $platform = $Matches[2] $field = $Matches[3] - if ($platform -cnotin @("linux-x86_64", "windows-x86_64")) { + if ($platform -cnotin @("linux-x86_64", "windows-x86_64", "windows-aarch64")) { throw "${location}: unsupported platform: $platform" } } @@ -135,10 +139,12 @@ function Get-ToolArtifact { function Get-ExpectedRunnerLabels { param( [string]$AdditionalLabels, - [switch]$BenchmarkRunner + [switch]$BenchmarkRunner, + [ValidateSet("virtual-machine", "baremetal")] + [string]$HostType = "virtual-machine" ) - $labels = @("windows", "whp", "virtual-machine") + $labels = @("windows", "whp", $HostType.ToLowerInvariant()) if ($BenchmarkRunner) { $labels += "benchmark" } @@ -160,10 +166,20 @@ function Get-ExpectedRunnerLabels { return $labels -join ',' } +function Get-ToolPlatform { + param([Parameter(Mandatory = $true)][string]$Architecture) + switch -CaseSensitive ($Architecture) { + "X64" { return "windows-x86_64" } + "Arm64" { return "windows-aarch64" } + default { throw "unsupported native Windows architecture: $Architecture" } + } +} + # The versions, artifacts, and checksums of the tools that this script # installs; stage the manifest next to the script. -$ToolPlatform = "windows-x86_64" $ToolManifest = Read-ToolManifest (Join-Path $PSScriptRoot "tool-versions.conf") +$NativeArchitecture = [Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() +$ToolPlatform = Get-ToolPlatform $NativeArchitecture $RustToolchain = Get-ToolManifestValue $ToolManifest "rust.toolchain" $CargoNextestVersion = Get-ToolManifestValue $ToolManifest "cargo_nextest.version" $CargoLlvmCovVersion = Get-ToolManifestValue $ToolManifest "cargo_llvm_cov.version" @@ -180,8 +196,42 @@ $RunnerVersion = $runnerRelease.Version $RunnerArtifact = $runnerRelease.Name $RunnerSha256 = $runnerRelease.Sha256 +if ([Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString() -cne + $NativeArchitecture) { + throw "setup requires native $NativeArchitecture PowerShell, not an emulated process" +} +if ([string]::IsNullOrWhiteSpace($HostType)) { + if ($RunnerOnly -and $NativeArchitecture -ceq "Arm64") { + throw "ARM64 runner setup requires an explicit -HostType baremetal or virtual-machine" + } + $HostType = "virtual-machine" +} +$VisualStudioToolsComponent = if ($NativeArchitecture -ceq "Arm64") { + "Microsoft.VisualStudio.Component.VC.Tools.ARM64" +} else { + "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" +} +$VisualStudioArchitecture = if ($NativeArchitecture -ceq "Arm64") { "arm64" } else { "amd64" } +$RustTargets = if ($NativeArchitecture -ceq "Arm64") { + @("aarch64-unknown-none", "aarch64-unknown-uefi") +} else { + @("x86_64-unknown-none", "x86_64-unknown-uefi") +} +$RustHost = if ($NativeArchitecture -ceq "Arm64") { + "aarch64-pc-windows-msvc" +} else { + "x86_64-pc-windows-msvc" +} +$GuestKernelName = if ($NativeArchitecture -ceq "Arm64") { "Image" } else { "vmlinux" } +$GuestBuildRelativeDirectory = if ($NativeArchitecture -ceq "Arm64") { + "build\aarch64" +} else { + "build" +} + $ExpectedRunnerLabels = Get-ExpectedRunnerLabels ` - -AdditionalLabels $ExtraRunnerLabels -BenchmarkRunner:$BenchmarkRunner + -AdditionalLabels $ExtraRunnerLabels -BenchmarkRunner:$BenchmarkRunner ` + -HostType $HostType if (-not $RunnerOnly) { if ([string]::IsNullOrWhiteSpace($Workspace)) { @@ -197,9 +247,9 @@ $BenchmarkScratchVariable = "NVX_BENCHMARK_SCRATCH" $BenchmarkScratchName = "nvx-benchmark-scratch" $RustupHome = Join-Path $ToolRoot "rustup" $RequiredGuestArtifacts = @( - "vmlinux", - "vmlinux.config", - "vmlinux.provenance.json", + $GuestKernelName, + "$GuestKernelName.config", + "$GuestKernelName.provenance.json", "initramfs.cpio.gz", "initramfs.cpio.gz.packages.json", "initramfs.provenance.json", @@ -207,10 +257,14 @@ $RequiredGuestArtifacts = @( "initramfs-ubuntu.cpio.gz.packages.json", "ubuntu-distro.erofs", "ubuntu-distro.erofs.manifest.json", - "ubuntu-smoke-scratch.ext4", - "initramfs-azurelinux.cpio.gz", - "initramfs-azurelinux.cpio.gz.packages.json" + "ubuntu-smoke-scratch.ext4" ) +if ($NativeArchitecture -ceq "X64") { + $RequiredGuestArtifacts += @( + "initramfs-azurelinux.cpio.gz", + "initramfs-azurelinux.cpio.gz.packages.json" + ) +} function Assert-LastExitCode { param([Parameter(Mandatory = $true)][string]$Description) @@ -804,7 +858,7 @@ function Test-VisualStudioBuildTools { $instances = @(& $vswhere ` -products * ` -requires ` - Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + $VisualStudioToolsComponent ` Microsoft.VisualStudio.Component.Windows11SDK.26100 ` -property installationPath) return $LASTEXITCODE -eq 0 -and $instances.Count -gt 0 @@ -826,7 +880,7 @@ function Install-Toolchain { if (-not (Test-VisualStudioBuildTools)) { $vsArguments = @( "--override", - "--wait --quiet --norestart --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows11SDK.26100 --includeRecommended" + "--wait --quiet --norestart --add Microsoft.VisualStudio.Workload.VCTools --add $VisualStudioToolsComponent --add Microsoft.VisualStudio.Component.Windows11SDK.26100 --includeRecommended" ) Install-WinGetPackage "Microsoft.VisualStudio.2022.BuildTools" $vsArguments } @@ -882,12 +936,8 @@ function Install-Toolchain { "toolchain", "install", $RustToolchain, "--profile", "minimal", "--no-self-update" ) - Invoke-Native $rustupPath @( - "target", "add", - "x86_64-unknown-none", - "x86_64-unknown-uefi", - "--toolchain", $RustToolchain - ) + Invoke-Native $rustupPath (@("target", "add") + $RustTargets + + @("--toolchain", $RustToolchain)) # cargo-llvm-cov merges and reports coverage profiles with the release's # own llvm-profdata and llvm-cov. Invoke-Native $rustupPath @( @@ -1494,7 +1544,7 @@ function Copy-GuestArtifacts { $revision = Get-CurrentRevision Assert-GuestArtifactSet $GuestArtifactsDirectory $revision - $buildDirectory = Join-Path $Workspace "build" + $buildDirectory = Join-Path $Workspace $GuestBuildRelativeDirectory New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null foreach ($name in @($RequiredGuestArtifacts) + @("REVISION", "SHA256SUMS")) { Copy-Item ` @@ -1514,7 +1564,7 @@ function Get-VisualStudioEnvironment { $installationOutput = @(& $vswhere ` -latest ` -products * ` - -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + -requires $VisualStudioToolsComponent ` -property installationPath) Assert-LastExitCode "Visual Studio discovery" $installationPath = ($installationOutput -join "").Trim() @@ -1536,7 +1586,7 @@ function Build-Nvx { Push-Location $Workspace try { Invoke-Native $python @("scripts\nvx.py", "verify") - $command = 'call "{0}" -no_logo -arch=amd64 -host_arch=amd64 && "{1}" scripts\nvx.py build-openvmm' -f $vsDevCmd, $python + $command = 'call "{0}" -no_logo -arch={2} -host_arch={2} && "{1}" scripts\nvx.py build-openvmm' -f $vsDevCmd, $python, $VisualStudioArchitecture Invoke-Native $env:ComSpec @("/d", "/s", "/c", $command) } finally { @@ -1619,13 +1669,16 @@ function Assert-Environment { } $rustVersion = & (Get-RequiredCommand "rustup.exe") ` - run $RustToolchain rustc --version + run $RustToolchain rustc --version --verbose Assert-LastExitCode "Rust $RustToolchain" $rustVersionText = $rustVersion -join "`n" if ($rustVersionText -notmatch "rustc ([0-9]+\.[0-9]+\.[0-9]+)" -or $Matches[1] -ne $RustToolchain) { throw "Rust $RustToolchain is required, found $rustVersionText" } + if ($rustVersionText -notmatch "(?m)^host: $([regex]::Escape($RustHost))`r?$") { + throw "native Rust host $RustHost is required, found $rustVersionText" + } $nextestVersion = & (Get-RequiredCommand "cargo-nextest.exe") --version Assert-LastExitCode "cargo-nextest --version" if (($nextestVersion -join "`n") -notmatch ` @@ -1671,7 +1724,7 @@ function Assert-Environment { $installedTargets = & (Get-RequiredCommand "rustup.exe") ` target list --installed --toolchain $RustToolchain Assert-LastExitCode "rustup target list" - foreach ($target in @("x86_64-unknown-none", "x86_64-unknown-uefi")) { + foreach ($target in $RustTargets) { if ($target -notin @($installedTargets)) { throw "Rust target $target is not installed" } @@ -1693,7 +1746,9 @@ function Assert-Environment { if ($feature.State -ne "Enabled") { throw "Hyper-V is not enabled" } - Assert-PcatFirmware + if ($NativeArchitecture -ceq "X64") { + Assert-PcatFirmware + } } if ($SkipWorkspace) { @@ -1703,7 +1758,8 @@ function Assert-Environment { try { Invoke-Native $python @("scripts\nvx.py", "verify") if ($RequireBuild) { - Assert-GuestArtifactSet "$Workspace\build" (Get-CurrentRevision) + Assert-GuestArtifactSet (Join-Path $Workspace $GuestBuildRelativeDirectory) ` + (Get-CurrentRevision) if (-not (Test-Path ` -LiteralPath "$Workspace\openvmm\target\release\openvmm.exe" ` -PathType Leaf)) { @@ -1809,7 +1865,9 @@ if (-not $SkipBuild) { if (-not $SkipBuild -and [string]::IsNullOrWhiteSpace($GuestArtifactsDirectory) -and - -not (Test-Path -LiteralPath "$Workspace\build\vmlinux" -PathType Leaf)) { + -not (Test-Path -LiteralPath (Join-Path ` + (Join-Path $Workspace $GuestBuildRelativeDirectory) $GuestKernelName) ` + -PathType Leaf)) { Write-Output "NVX_GUEST_ARTIFACTS_REQUIRED=1" Write-Output "Stage a same-revision guest bundle and rerun with -GuestArtifactsDirectory." exit 21 diff --git a/scripts/setup/tool-versions.conf b/scripts/setup/tool-versions.conf index 3e2739107..82fe55cc7 100644 --- a/scripts/setup/tool-versions.conf +++ b/scripts/setup/tool-versions.conf @@ -9,8 +9,8 @@ # releases. TOOL.artifacts.PLATFORM.name names a download relative to the # tool's release, with {version} standing for TOOL.version, and # TOOL.artifacts.PLATFORM.sha256 is its lowercase SHA-256 digest. PLATFORM is -# linux-x86_64 or windows-x86_64. Setup rejects a missing, malformed, or -# incomplete manifest before it changes the host. +# linux-x86_64, windows-x86_64 or windows-aarch64. Setup rejects a missing, +# malformed or incomplete manifest before it changes the host. # Equal to the channel in rust-toolchain.toml, which rustup reads. rust.toolchain=1.97.1 @@ -20,6 +20,8 @@ rustup.artifacts.linux-x86_64.name=x86_64-unknown-linux-gnu/rustup-init rustup.artifacts.linux-x86_64.sha256=dda7234360b7f578ca8b0ddcb80145646fa61a67c1720a5abc7051b35c9fcb71 rustup.artifacts.windows-x86_64.name=x86_64-pc-windows-msvc/rustup-init.exe rustup.artifacts.windows-x86_64.sha256=6f4bef66261261fcb43131be8720bab817d403a09edec7455c371974b90bdb7e +rustup.artifacts.windows-aarch64.name=aarch64-pc-windows-msvc/rustup-init.exe +rustup.artifacts.windows-aarch64.sha256=01aa49cf9574a8bd0ae52005d7de2590e8f27181ded6748236e702c92aef826d # Setup builds cargo-nextest and cargo-llvm-cov with cargo install, so they # have no artifacts. cargo-llvm-cov measures coverage with the llvm-tools @@ -32,9 +34,13 @@ sccache.artifacts.linux-x86_64.name=sccache-v{version}-x86_64-unknown-linux-musl sccache.artifacts.linux-x86_64.sha256=45f1447fbe231e3037bde351ef70677dd212216c8d62ae7ca409fecc4d6acc89 sccache.artifacts.windows-x86_64.name=sccache-v{version}-x86_64-pc-windows-msvc.tar.gz sccache.artifacts.windows-x86_64.sha256=1a63c1be2beab3f04d27e4cc145443e092e02d3dd83a51030989829d7023091b +sccache.artifacts.windows-aarch64.name=sccache-v{version}-aarch64-pc-windows-msvc.tar.gz +sccache.artifacts.windows-aarch64.sha256=9c1f3ecaeeae2e69171ff704867aa99813d2d68ae4d172dd34b11a07037ddd27 actions_runner.version=2.338.2 actions_runner.artifacts.linux-x86_64.name=actions-runner-linux-x64-{version}.tar.gz actions_runner.artifacts.linux-x86_64.sha256=baebf204307bac6193480852732f0aba2ae97b6c5597c244f4d5558390147c40 actions_runner.artifacts.windows-x86_64.name=actions-runner-win-x64-{version}.zip actions_runner.artifacts.windows-x86_64.sha256=a1f17aa987fc8158bc7521d284912267a0d01b7c2c4684b33c86783b5e8221cc +actions_runner.artifacts.windows-aarch64.name=actions-runner-win-arm64-{version}.zip +actions_runner.artifacts.windows-aarch64.sha256=0790e3f586c2c5388ed8e293e7cef01bd0e8a2c5c68dd0a628f848b61da4b3a7 diff --git a/scripts/test-layout-allowlist.json b/scripts/test-layout-allowlist.json index f1cd37dc8..8e2d63b78 100644 --- a/scripts/test-layout-allowlist.json +++ b/scripts/test-layout-allowlist.json @@ -7,12 +7,12 @@ "nvx-rs/src/guest/entry.rs": 1, "nvx-rs/src/guest/exec.rs": 4, "nvx-rs/src/guest/kernel_text.rs": 4, - "nvx-rs/src/guest/parse.rs": 4, + "nvx-rs/src/guest/parse.rs": 3, "nvx-rs/src/guest/reseed.rs": 1, "nvx-rs/src/guest/root/block.rs": 1, "nvx-rs/src/guest/root/kernel.rs": 2, - "nvx-rs/src/guest/status.rs": 9, - "nvx-rs/src/guest/sys/clock.rs": 6, + "nvx-rs/src/guest/status.rs": 6, + "nvx-rs/src/guest/sys/clock.rs": 4, "nvx-rs/src/guest/sys/discipline.rs": 4, "nvx-rs/src/guest/sys/entry.rs": 3, "nvx-rs/src/guest/sys/fd.rs": 3, @@ -22,7 +22,7 @@ "nvx-rs/src/guest/sys/mod.rs": 5, "nvx-rs/src/guest/sys/poll.rs": 3, "nvx-rs/src/guest/sys/process.rs": 3, - "nvx-rs/src/guest/sys/scheduler.rs": 4, + "nvx-rs/src/guest/sys/scheduler.rs": 1, "nvx-rs/src/guest/sys/signal.rs": 5, "nvx-rs/src/guest/sys/socket.rs": 1, "nvx-rs/src/guest/sys/spawn.rs": 6, diff --git a/scripts/test_guest_binaries.py b/scripts/test_guest_binaries.py index 945a79242..c816ed6f5 100644 --- a/scripts/test_guest_binaries.py +++ b/scripts/test_guest_binaries.py @@ -6,12 +6,13 @@ import json import os import re +import shlex import struct import sys import tempfile import unittest from collections.abc import Generator, Sequence -from pathlib import Path +from pathlib import Path, PurePosixPath from typing import cast from unittest.mock import MagicMock, patch @@ -27,6 +28,7 @@ managed_exec_tests, microvm_tests, sandbox_lifecycle_tests, + time_abi, ubuntu, ) from nvx_tools.build_constants import ( # noqa: E402 @@ -1257,19 +1259,28 @@ def test_arm_initramfs_cli_preserves_legacy_default_routing(self): ), ) - def test_arm_cold_boot_inventory_keeps_required_time_and_omits_diagnostics(self): + def test_arm_cold_boot_inventory_keeps_time_and_warp_but_omits_x86_io(self): self.assertIs( guest_binaries.guest_binary_inventory(), GuestRustBuildConstants.BINARIES, ) inventory = guest_binaries.guest_binary_inventory("aarch64") - self.assertEqual(len(inventory), 7) + self.assertEqual(len(inventory), 8) self.assertIn("nvx-time", inventory) + self.assertIn("nvx-time-probe", inventory) self.assertIn("nvx-init", inventory) self.assertIn("nvx-exit", inventory) - for binary in ("nvx-mmio-write", "nvx-device-io", "nvx-time-probe"): + for binary in ("nvx-mmio-write", "nvx-device-io"): self.assertNotIn(binary, inventory) + def test_guest_producers_include_the_shared_doctor_and_smp_warp_dependency(self): + executable = PurePosixPath(shlex.split(time_abi.warp_probe_command())[0]).name + for architecture in ("x86_64", "aarch64"): + with self.subTest(architecture=architecture): + self.assertIn( + executable, guest_binaries.guest_binary_inventory(architecture) + ) + def test_docker_architecture_input_reuses_the_shared_producer_and_export(self): dockerfile = (BuildConstants.REPO_ROOT / "docker" / "Dockerfile").read_text( encoding="utf-8" diff --git a/scripts/test_microvm_tests.py b/scripts/test_microvm_tests.py index 389084176..cb8036b50 100644 --- a/scripts/test_microvm_tests.py +++ b/scripts/test_microvm_tests.py @@ -405,7 +405,19 @@ def test_parser_defaults_to_all_correctness_scenarios(self): args = nvx.parse_args(["test-microvm", "--backend", "mshv"]) self.assertIsNone(args.scenario) - self.assertEqual(args.processors, [1, 2, 4, 8]) + self.assertIsNone(args.processors) + self.assertEqual(args.managed_root, "initramfs") + self.assertFalse(args.cold_only) + self.assertIsNone(args.start_stop_cycles) + self.assertEqual( + set(microvm_tests.MICROVM_TEST_SCENARIOS), + microvm_tests.COLD_ONLY_SCENARIOS + | set(microvm_tests.COLD_DEFERRED_SCENARIOS), + ) + self.assertFalse( + microvm_tests.COLD_ONLY_SCENARIOS + & set(microvm_tests.COLD_DEFERRED_SCENARIOS) + ) self.assertEqual(args.guest, "alpine") self.assertIsNone(args.memory_mib) self.assertEqual(args.timeout, 60.0) @@ -430,6 +442,54 @@ def test_parser_accepts_selected_scenarios_and_processors(self): self.assertEqual(args.scenario, ["smp"]) self.assertEqual(args.processors, [2, 8]) self.assertEqual(args.output_dir, Path("results")) + cold = nvx.parse_args( + [ + "test-microvm", + "--backend", + "whp", + "--architecture", + "aarch64", + "--scenario", + "interrupt-map", + "--cold-only", + ] + ) + self.assertTrue(cold.cold_only) + self.assertEqual(cold.architecture, "aarch64") + for scenario, cycles in (("smp", 10), ("sandbox-ram-upper", 1)): + rejected = nvx.parse_args( + [ + "test-microvm", + "--backend", + "whp", + "--scenario", + scenario, + "--start-stop-cycles", + str(cycles), + ] + ) + with ( + patch.object(microvm_tests, "validate_openvmm_test_backend"), + patch.object(microvm_tests, "require_file") as require_file, + self.assertRaisesRegex( + microvm_tests.ScriptError, "requires explicit|at least two" + ), + ): + microvm_tests.run(rejected) + require_file.assert_not_called() + for selection in ([], ["--scenario", "snapshot-tiers"]): + rejected = nvx.parse_args( + ["test-microvm", "--backend", "whp", "--cold-only", *selection] + ) + with ( + patch.object(microvm_tests, "validate_openvmm_test_backend"), + patch.object(microvm_tests, "require_file") as require_file, + self.assertRaisesRegex( + microvm_tests.ScriptError, "requires explicit|no maintained cold" + ), + ): + microvm_tests.run(rejected) + require_file.assert_not_called() def test_parser_accepts_ubuntu_guest_profile(self): args = nvx.parse_args( @@ -1538,7 +1598,9 @@ class PublicSandboxLifecycleTests(unittest.TestCase): for (_, _, name, field), digit in zip(_RUNTIME_PROVENANCE, "123", strict=True) } - def _run(self, root: Path, fake: _FakeSandboxCli) -> Path: + def _run( + self, root: Path, fake: _FakeSandboxCli, *, start_stop_cycles: int | None = None + ) -> Path: distro = root / "ubuntu-distro.erofs" distro.write_bytes(b"distro") template = root / "ubuntu-smoke-scratch.ext4" @@ -1593,7 +1655,10 @@ def fixture(prefix: str) -> str: ), ): sandbox_lifecycle_tests.run_sandbox_lifecycle( - "whp", timeout=2, output_dir=output_dir + "whp", + timeout=2, + output_dir=output_dir, + start_stop_cycles=1 if start_stop_cycles is None else start_stop_cycles, ) return output_dir @@ -1666,6 +1731,37 @@ def test_acceptance_drives_the_complete_public_lifecycle(self): self.assertIn( b"NVX-UBUNTU-SANDBOX-ENTRY-OK", evidence["sandbox-lifecycle-probe.log"] ) + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + fake = _FakeSandboxCli() + output_dir = self._run(root, fake, start_stop_cycles=10) + repeated = json.loads( + (output_dir / "sandbox-lifecycle-checks.json").read_text( + encoding="utf-8" + ) + ) + cycle_checks = [record for record in repeated if "cycle" in record] + for cycle in range(1, 11): + operations = [ + record["operation"] + for record in cycle_checks + if record["cycle"] == cycle + and record["expected_returncode"] == 0 + and record["operation"] in ("start", "stop") + ] + self.assertEqual(operations, ["start", "stop"]) + self.assertTrue( + ( + output_dir / f"sandbox-lifecycle-cycle-{cycle:03}-outcome.json" + ).is_file() + ) + states = { + record["argv"][record["argv"].index("--state-dir") + 1] + for record in cycle_checks + } + self.assertEqual(len(states), 1) + self.assertFalse(any(fake.running.values())) + self.assertEqual(list(root.glob("nvx-public-lifecycle-*")), []) def test_acceptance_detects_lifecycle_regressions(self): regressions = { @@ -2809,7 +2905,13 @@ class PublicSandboxRamUpperTests(unittest.TestCase): "deprovision", ] - def _run(self, root: Path, fake: _FakeRamUpperSandboxCli) -> Path: + def _run( + self, + root: Path, + fake: _FakeRamUpperSandboxCli, + *, + start_stop_cycles: int | None = None, + ) -> Path: distro = root / "ubuntu-distro.erofs" distro.write_bytes(b"distro") template = root / "ubuntu-smoke-scratch.ext4" @@ -2858,7 +2960,10 @@ def fixture(prefix: str) -> str: ), ): sandbox_ram_upper_tests.run_sandbox_ram_upper( - "mshv", timeout=2, output_dir=output_dir + "mshv", + timeout=2, + output_dir=output_dir, + start_stop_cycles=2 if start_stop_cycles is None else start_stop_cycles, ) return output_dir @@ -2906,6 +3011,36 @@ def test_acceptance_runs_sandboxes_whose_upper_is_in_ram(self): self.assertEqual( ["--scratch" in argv for argv in launches], [True, False, False] ) + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + fake = _FakeRamUpperSandboxCli() + output_dir = self._run(root, fake, start_stop_cycles=10) + repeated = json.loads( + (output_dir / "sandbox-ram-upper-checks.json").read_text( + encoding="utf-8" + ) + ) + cycle_checks = [record for record in repeated if "cycle" in record] + for cycle in range(1, 11): + operations = [ + record["operation"] + for record in cycle_checks + if record["cycle"] == cycle + and record["operation"] in ("start", "stop") + ] + self.assertEqual(operations, ["start", "stop"]) + self.assertTrue( + ( + output_dir / f"sandbox-ram-upper-cycle-{cycle:03}-outcome.json" + ).is_file() + ) + states = { + record["argv"][record["argv"].index("--state-dir") + 1] + for record in cycle_checks + } + self.assertEqual(len(states), 1) + self.assertFalse(any(fake.running.values())) + self.assertEqual(list(root.glob("nvx-public-ram-upper-*")), []) def test_acceptance_detects_ram_upper_regressions(self): regressions = { @@ -3490,6 +3625,7 @@ def _run( guest_writes_toolcache: bool = False, guest_links_children: bool = False, guest_writes_settings: bool = False, + cold_only: bool = False, ) -> list[list[str]]: launched: list[list[str]] = [] children = self._children @@ -3626,6 +3762,7 @@ def wait(self, _timeout: float) -> openvmm_process.OpenvmmProcessResult: memory_mib=128, timeout=40, output_dir=Path(temporary), + cold_only=cold_only, ) link, target = symlink.call_args.args self.assertEqual( @@ -3714,6 +3851,11 @@ def policy(command: list[str], option: str) -> list[str]: self.assertIn("--mount", launched[14]) self.assertEqual(self._children(launched[15]), every) self.assertEqual(self._children(launched[16]), every) + cold = self._run(cold_only=True) + self.assertEqual(len(cold), 10) + for command in cold: + self.assertNotIn("--snapshot-destination", command) + self.assertNotIn("--restore-snapshot", command) def test_scenario_rejects_a_write_to_the_read_only_share(self): with self.assertRaisesRegex(RuntimeError, "modified the read-only share"): @@ -3743,7 +3885,9 @@ def _values(command: list[str], option: str) -> list[str]: command[index + 1] for index, value in enumerate(command) if value == option ] - def _run(self, *, guest_writes_outside: bool = False) -> list[list[str]]: + def _run( + self, *, guest_writes_outside: bool = False, cold_only: bool = False + ) -> list[list[str]]: launched: list[list[str]] = [] values = self._values @@ -3835,6 +3979,7 @@ def wait(self, _timeout: float) -> openvmm_process.OpenvmmProcessResult: memory_mib=128, timeout=40, output_dir=Path(temporary), + cold_only=cold_only, ) link, target = symlink.call_args.args self.assertEqual((link.name, target), ("seed-link", "../seed")) @@ -3882,6 +4027,11 @@ def test_scenario_narrows_writes_and_restores_the_policy(self): self._values(launched[9], "--mount-allow"), self._values(boot, "--mount-allow"), ) + cold = self._run(cold_only=True) + self.assertEqual(len(cold), 6) + for command in cold: + self.assertNotIn("--snapshot-destination", command) + self.assertNotIn("--restore-snapshot", command) def test_scenario_rejects_a_write_outside_the_writable_paths(self): with self.assertRaisesRegex(RuntimeError, "outside its writable paths"): @@ -4418,6 +4568,9 @@ def test_managed_lifecycle_runs_the_nvx_rs_test_and_checks_what_it_leaves(self): self.assertEqual(preserved, self._managed_report()) def test_managed_layered_inputs_reuse_the_same_authenticated_test(self): + def require(path: Path, _description: str) -> Path: + return path + with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) artifacts = microvm_tests.WorkloadArtifacts( @@ -4466,6 +4619,113 @@ def test_managed_layered_inputs_reuse_the_same_authenticated_test(self): environment["NVX_MANAGED_LIFECYCLE_PREVIOUS_STATE"], "present" if scratch else "absent", ) + artifacts.scratch_template.write_bytes(bytes(2048)) + for mode, counts in itertools.product( + ("initramfs", "scratch", "ram"), (None, [1, 8]) + ): + output = ( + root / f"dispatch-{mode}-{'default' if counts is None else '1-8'}" + ) + options = [] if counts is None else ["--processors", "1", "8"] + args = nvx.parse_args( + [ + "test-microvm", + "--backend", + "whp", + "--architecture", + "aarch64", + "--guest", + "ubuntu", + "--scenario", + "managed-lifecycle", + "--managed-root", + mode, + "--output-dir", + str(output), + *options, + ] + ) + with ( + patch.object(microvm_tests, "validate_openvmm_test_backend"), + patch.object(microvm_tests, "require_file", side_effect=require), + patch.object( + microvm_tests, "load_workload_artifacts", return_value=artifacts + ) as load, + patch.object(microvm_tests, "run_managed_lifecycle") as run, + ): + self.assertEqual(microvm_tests.run(args), 0) + expected_counts = counts or [1] + states = ( + [None] + if mode == "initramfs" + else ["absent", "present" if mode == "scratch" else "absent"] + ) + self.assertEqual( + [call.kwargs["processors"] for call in run.call_args_list], + [cpu for cpu in expected_counts for _ in states], + ) + self.assertEqual( + [ + call.kwargs["expected_previous_state"] + for call in run.call_args_list + ], + states * len(expected_counts), + ) + if mode == "initramfs": + load.assert_not_called() + self.assertTrue( + all( + call.kwargs["layered"] is None + for call in run.call_args_list + ) + ) + if counts is None: + self.assertEqual(run.call_args.kwargs["output_dir"], output) + else: + load.assert_called_once_with(architecture="aarch64") + self.assertTrue( + all( + call.kwargs["layered"] == artifacts + for call in run.call_args_list + ) + ) + for call in run.call_args_list: + bootstrap = microvm_tests.BuildConfig.initramfs_config( + "alpine" if mode != "initramfs" else "ubuntu", "aarch64" + ).output + self.assertEqual(call.args[2], bootstrap) + scratch = call.kwargs["scratch"] + if mode == "scratch": + self.assertNotEqual(scratch, artifacts.scratch_template) + self.assertEqual(scratch.read_bytes(), bytes(2048)) + else: + self.assertIsNone(scratch) + executions = [ + record + for record in _read_report(output / microvm_durations.REPORT_NAME) + if record["record"] == "scenario" + ] + self.assertEqual(len(executions), len(expected_counts) * len(states)) + self.assertTrue( + all( + record["architecture"] == "aarch64" + and record["outcome"] == "passed" + for record in executions + ) + ) + self.assertEqual( + [record["processors"] for record in executions], + [[cpu] for cpu in expected_counts for _ in states], + ) + if mode != "initramfs": + self.assertEqual( + [record["variant"] for record in executions], + [ + f"{mode}-boot-{index}-{state}" + for _ in expected_counts + for index, state in enumerate(states, 1) + ], + ) def test_managed_lifecycle_hands_the_test_an_absolute_pid_journal(self): # The nvx-rs test records OpenVMM in an adversarial campaign's journal @@ -5087,6 +5347,50 @@ def test_private_network_ingress_scenario_covers_three_policies(self): self.assertIn("--snapshot-destination", snapshot) self.assertEqual(snapshot[snapshot.index("--network-ingress") + 1], "allow") + def test_private_network_ingress_cold_projection_keeps_all_three_policies(self): + with ( + tempfile.TemporaryDirectory() as temporary, + patch.object(microvm_tests, "_private_ingress_port", return_value=12345), + patch.object(microvm_tests.socket, "socket") as listener, + patch.object(microvm_tests, "_run_private_ingress_guest") as guest, + patch.object(microvm_tests, "OpenvmmProcess") as process, + patch.object( + microvm_tests, + "workload_boot_command", + side_effect=_fresh_openvmm_command, + ), + ): + listener.return_value.getsockname.return_value = ("127.0.0.1", 12346) + listener.return_value.accept.side_effect = TimeoutError + microvm_tests.run_private_network_ingress( + Path("openvmm"), + Path("kernel"), + Path("initrd"), + "whp", + memory_mib=128, + timeout=5, + output_dir=Path(temporary), + cold_only=True, + ) + self.assertEqual(guest.call_count, 3) + self.assertEqual( + [ + (call.kwargs["ingress"], call.kwargs["expect"]) + for call in guest.call_args_list + ], + [("allow", "reached"), ("allow", "unreached"), ("deny", "unreached")], + ) + process.assert_not_called() + self.assertTrue( + all( + "--snapshot-destination" not in call.args[0] + for call in guest.call_args_list + ) + ) + self.assertIn( + "private-network-ingress", microvm_tests.COLD_PROJECTION_SCENARIOS + ) + def test_private_network_ingress_snapshot_must_be_rejected_before_boot(self): diagnostic = b"microVM snapshots do not support --network-ingress allow" for result in ( @@ -7675,15 +7979,7 @@ def test_smp_worker_requires_bounded_local_timer_progress(self): shell = _posix_shell() if shell is None: self.skipTest("POSIX shell is unavailable") - worker = ( - benchmark.smp_probe_script(2) - .split("<<'NVX_SMP_WORKER'\n", 1)[1] - .split("\nNVX_SMP_WORKER", 1)[0] - ) - worker = worker.replace("/proc/interrupts", "interrupts").replace( - "timer_attempts=10000", "timer_attempts=8" - ) - for name, initial, advanced, advance_read, actual, status, reads in ( + cases = ( ("frozen", "LOC: 100 100", "LOC: 100 100", 3, 1, 88, 9), ("other-cpu", "LOC: 100 100", "LOC: 101 100", 3, 1, 88, 9), ("delayed", "LOC: 100 100", "LOC: 100 101", 4, 1, 0, 4), @@ -7692,12 +7988,37 @@ def test_smp_worker_requires_bounded_local_timer_progress(self): ("backwards", "LOC: 100 100", "LOC: 100 99", 3, 1, 88, 9), ("missing", "RES: 1 1", "RES: 1 1", 0, 1, 87, 2), ("wrong-cpu", "LOC: 100 100", "LOC: 100 101", 3, 0, 87, 0), - ): - with self.subTest(name=name), tempfile.TemporaryDirectory() as temporary: + ) + for architecture, case in itertools.product(("x86_64", "aarch64"), cases): + name, initial, advanced, advance_read, actual, status, reads = case + worker = ( + benchmark.smp_probe_script(2, architecture=architecture) + .split("<<'NVX_SMP_WORKER'\n", 1)[1] + .split("\nNVX_SMP_WORKER", 1)[0] + .replace("/proc/interrupts", "interrupts") + .replace("timer_attempts=10000", "timer_attempts=8") + ) + identity = "1" + timer_failure = "SMP-LAPIC-FAIL" + if architecture == "aarch64": + initial = initial.replace("LOC:", "11:") + ( + " GICv3 27 Level arch_timer" if initial.startswith("LOC:") else "" + ) + advanced = advanced.replace("LOC:", "11:") + ( + " GICv3 27 Level arch_timer" if advanced.startswith("LOC:") else "" + ) + identity = "0x0000000000000001" + timer_failure = "SMP-TIMER-FAIL" + with ( + self.subTest(architecture=architecture, name=name), + tempfile.TemporaryDirectory() as temporary, + ): root = Path(temporary) - (root / "interrupts").write_text(initial + "\n", encoding="ascii") + (root / "interrupts").write_text( + initial + "\n", encoding="ascii", newline="\n" + ) result = subprocess.run( - [shell, "-s", "--", "1", "result", "1"], + [shell, "-s", "--", "1", "result", identity, architecture], cwd=root, input=( "loc_reads=0\n" @@ -7724,13 +8045,13 @@ def test_smp_worker_requires_bounded_local_timer_progress(self): if status: self.assertFalse((root / "result").exists()) self.assertIn( - "SMP-WORKER-FAIL" if name == "wrong-cpu" else "SMP-LAPIC-FAIL", + "SMP-WORKER-FAIL" if name == "wrong-cpu" else timer_failure, result.stdout, ) else: self.assertEqual( (root / "result").read_text(encoding="ascii").split(), - ["1", "101", "1"], + ["1", "101", identity], ) def test_snapshot_core_waits_for_no_destination_marker_line_before_exit(self): @@ -8559,7 +8880,7 @@ def test_lifecycle_script_exits_on_unexpected_command_failure(self): self.skipTest("POSIX shell is unavailable") script = microvm_tests._read_script("lifecycle.sh") - prologue, separator, _ = script.partition("\nprintf '\\013' | dd") + prologue, separator, _ = script.partition("\narchitecture=") self.assertTrue(separator) prologue = prologue.replace("nvx-exit", "record_exit") result = subprocess.run( @@ -8610,7 +8931,7 @@ def test_lifecycle_script_checks_the_early_console(self): self.skipTest("POSIX shell is unavailable") script = microvm_tests._read_script("lifecycle.sh") # The scenario runs the function that this test runs. - self.assertIn("\ncheck_early_console\n", script) + self.assertIn('\ncheck_early_console "$early_console"\n', script) start = script.index("check_early_console() {\n") end = script.index("\n}\n", start) + len("\n}\n") function = script[start:end] @@ -8700,7 +9021,9 @@ def test_smp_uses_requested_processor_count(self): "quiet loglevel=0", processors=4, ) - smp_probe_script.assert_called_once_with(4, exit_guest=False) + smp_probe_script.assert_called_once_with( + 4, exit_guest=False, architecture="x86_64" + ) run_guest_script.assert_called_once_with( ["openvmm", "boot"], "probe\n" + time_abi.warp_probe_script() + "nvx-exit 0\n", @@ -11181,9 +11504,70 @@ def require(path: Path, _description: str) -> Path: timeout=60.0, output_dir=Path(temporary), guest="alpine", + cold_only=False, ) self.assertIn("ipv6-egress-policy", microvm_tests.MICROVM_TEST_SCENARIOS) + def test_fixed_virtio_discovery_uses_named_kernel_resources_and_dt_binding(self): + shell = _posix_shell() + if shell is None: + self.skipTest("POSIX shell is unavailable") + script = microvm_tests._read_script("virtio-mmio.sh") + script = ( + script.replace("/proc/iomem", "iomem") + .replace("/proc/cmdline", "cmdline") + .replace("/sys/bus/virtio/devices", "virtio") + ) + for architecture, size, spi, command, status in ( + ("aarch64", 4096, 1, "fixed_virtio_present d0001000 17", 0), + ("aarch64", 8192, 1, "fixed_virtio_present d0001000 17", 1), + ("aarch64", 4096, 2, "fixed_virtio_present d0001000 17", 1), + ("aarch64", 4096, 1, "fixed_virtio_absent d0001000", 1), + ("aarch64", 4096, 1, "fixed_virtio_absent d0004000", 0), + ("x86_64", 4096, 1, "fixed_virtio_present d0001000 17", 0), + ("x86_64", 4096, 1, "fixed_virtio_present d0001000 18", 1), + ): + with ( + self.subTest( + architecture=architecture, size=size, spi=spi, command=command + ), + tempfile.TemporaryDirectory() as temporary, + ): + root = Path(temporary) + node = root / "platform" / "d0001000.virtio" / "of_node" + node.mkdir(parents=True) + (root / "virtio" / "virtio0").mkdir(parents=True) + (root / "iomem").write_text( + f"d0001000-{0xD0001000 + size - 1:08x} : d0001000.virtio\n", + encoding="utf-8", + newline="\n", + ) + (root / "cmdline").write_text( + "virtio_mmio.device=0x1000@0xd0001000:17\n", + encoding="utf-8", + newline="\n", + ) + (node / "compatible").write_bytes(b"virtio,mmio\0") + (node / "interrupts").write_bytes( + b"".join(value.to_bytes(4, "big") for value in (0, spi, 1)) + ) + result = subprocess.run( + [shell], + input=( + f"uname() {{ echo {architecture}; }}\n" + "readlink() { echo platform/d0001000.virtio/virtio0; }\n" + + script + + "\n" + + command + + "\n" + ), + text=True, + capture_output=True, + check=False, + cwd=root, + ) + self.assertEqual(result.returncode, status, result.stderr) + def test_sandbox_blocks_use_fixed_roles_and_access(self): with ( patch.object( @@ -11454,6 +11838,7 @@ def _interrupt_report( shared: str = "", unhandled: Mapping[int, int] | None = None, errors: tuple[int, int, int] | None = (0, 0, 0), + architecture: str = "x86_64", ) -> str: """Returns the interrupt-map scenario's report of `steps`: after each step, each device by the base of its window, with its name, interrupt, @@ -11464,16 +11849,28 @@ def _interrupt_report( for step, devices in steps.items(): for base, (name, irq, count) in devices.items(): actions = name + (f",{shared}" if shared else "") + slot = (base - 0xD000_0000) // 0x1000 + hwirq = 32 + slot if architecture == "aarch64" else irq + binding = ( + f" dt_interrupts=00000000{slot:08x}00000001" + if architecture == "aarch64" + else "" + ) lines.append( f"NVX-INTERRUPT-MAP step={step} base={base:#x} device={name} " - f"irq={irq} chip={chip} hwirq={irq} type={trigger} " + f"irq={irq} chip={chip} hwirq={hwirq} type={trigger} " f"actions={actions} count={count} " - f"unhandled={(unhandled or {}).get(base, 0)}\r" + f"unhandled={(unhandled or {}).get(base, 0)}{binding}\r" ) if errors is not None: lines.append( - f"NVX-INTERRUPT-MAP-ERRORS err={errors[0]} mis={errors[1]} " - f"spu={errors[2]}\r" + f"NVX-INTERRUPT-MAP-ERRORS err={errors[0]}" + + ( + "" + if architecture == "aarch64" + else f" mis={errors[1]} spu={errors[2]}" + ) + + "\r" ) lines.append("NVX-INTERRUPT-MAP-OK\r") return "\n".join(lines) + "\n" @@ -11631,6 +12028,55 @@ def test_interrupt_map_names_each_departure_from_the_guide(self): with self.assertRaisesRegex(RuntimeError, "is reported twice after step boot"): microvm_tests.parse_interrupt_map(report + report) + arm_steps = { + step: { + base: (name, 100 + (base - 0xD000_0000) // 0x1000, count) + for base, (name, _irq, count) in devices.items() + } + for step, devices in accepted.items() + } + arm_report = self._interrupt_report( + arm_steps, chip="GICv3", architecture="aarch64" + ) + steps, errors = microvm_tests.parse_interrupt_map( + arm_report, architecture="aarch64" + ) + microvm_tests.check_interrupt_map( + steps, errors, bases, before="boot", architecture="aarch64" + ) + for bad, problem in ( + (arm_report.replace("hwirq=32 ", "hwirq=16 "), "not GICv3 INTID 32"), + (arm_report.replace("hwirq=32 ", "hwirq=64 "), "not GICv3 INTID 32"), + (arm_report.replace("chip=GICv3", "chip=IO-APIC"), "not GICv3"), + ( + arm_report.replace( + "000000000000000000000001", "000000000000002000000001" + ), + "DT interrupt cells", + ), + ( + arm_report.replace( + "000000000000000600000001", "000000000000000600000004" + ), + "EDGE_RISING", + ), + (arm_report.replace("type=edge", "type=level"), "level-triggered"), + ( + arm_report.replace("actions=virtio0 ", "actions=virtio0,rtc0 "), + "shares IRQ", + ), + (arm_report.replace("err=0", "err=2"), "2 GIC errors"), + (arm_report.replace("irq=106 ", "irq=100 "), "invalid or shared"), + ): + with self.subTest(arm=problem): + steps, errors = microvm_tests.parse_interrupt_map( + bad, architecture="aarch64" + ) + with self.assertRaisesRegex(RuntimeError, problem): + microvm_tests.check_interrupt_map( + steps, errors, bases, before="boot", architecture="aarch64" + ) + def test_interrupt_map_boots_every_device_and_restores_the_nic_share_and_console( self, ): @@ -11722,6 +12168,45 @@ def wait(self, _timeout: float) -> openvmm_process.OpenvmmProcessResult: "echo NVX-INTERRUPT-MAP-CAPTURE\nnvx-snapshot\nreport restore\n", staged[0] ) + launched.clear() + arm_steps = { + step: { + base: (name, 100 + (base - 0xD000_0000) // 0x1000, count) + for base, (name, _irq, count) in devices.items() + } + for step, devices in { + **self._documented_interrupts(bases, "boot", 1), + **self._documented_interrupts(bases, "traffic", 5), + }.items() + } + arm_cold = self._interrupt_report( + arm_steps, chip="GICv3", architecture="aarch64" + ) + with ( + tempfile.TemporaryDirectory() as temporary, + patch.object( + microvm_tests, + "run_guest_script", + return_value={"text": arm_cold, "output": arm_cold}, + ) as cold_guest, + patch.object(microvm_tests, "OpenvmmProcess", FakeProcess), + ): + microvm_tests.run_interrupt_map( + Path("openvmm"), + Path("Image"), + Path("initrd"), + "whp", + memory_mib=128, + timeout=60, + output_dir=Path(temporary), + architecture="aarch64", + cold_only=True, + ) + self.assertEqual(launched, []) + self.assertEqual(cold_guest.call_count, 1) + self.assertIn("architecture=aarch64", cold_guest.call_args.args[1]) + self.assertIn('"$platform/of_node/interrupts"', cold_guest.call_args.args[1]) + # A restore whose interrupts differ from those before the capture fails. restored = restored.replace("irq=17 ", "irq=21 ").replace( "hwirq=17", "hwirq=21" @@ -11774,7 +12259,7 @@ def test_interrupt_map_attaches_the_control_console_to_its_broker(self): len(microvm_tests.INTERRUPT_MAP_SNAPSHOT_DEVICES), ): script = microvm_tests._interrupt_map_script(devices, capture="") - self.assertNotIn("@", script) + self.assertNotRegex(script, r"@[A-Z][A-Z_]*@") # The control console's step writes the record, once, to the # console held open, raw, and silent until its interrupt. steps = re.findall( @@ -16151,7 +16636,14 @@ def test_runner_dispatches_selected_scenarios_once(self): args = argparse.Namespace( backend="whp", guest="alpine", - scenario=["smp", "smp", "smp-lapic", "smp-lapic"], + scenario=[ + "guest-boot", + "guest-boot", + "smp", + "smp", + "smp-lapic", + "smp-lapic", + ], processors=[2, 2, 8], memory_mib=128, timeout=60.0, @@ -16169,11 +16661,16 @@ def require(path: Path, _description: str) -> Path: side_effect=require, ), patch.object(microvm_tests, "run_lifecycle") as run_lifecycle, + patch.object(microvm_tests, "run_guest_boot") as run_guest_boot, patch.object(microvm_tests, "run_smp") as run_smp, ): self.assertEqual(microvm_tests.run(args), 0) run_lifecycle.assert_not_called() + self.assertEqual( + [entry.kwargs["processors"] for entry in run_guest_boot.call_args_list], + [2, 8], + ) self.assertEqual( [entry.args[4] for entry in run_smp.call_args_list], [2, 8, 2, 8], @@ -17025,8 +17522,8 @@ def scenario(*_args: object, **_kwargs: object) -> None: stack.enter_context(redirect_stdout(stdout)) self.assertEqual(microvm_tests.run(args), 0) - # console-exit, smp, and smp-lapic run once per processor count. - self.assertEqual(len(progress), len(scenarios) + 3) + # Boot, managed lifecycle, console exit and both SMP variants honor the explicit VPs. + self.assertEqual(len(progress), len(scenarios) + 5) for line in progress: self.assertRegex(line, r"^Running .+ on OpenVMM/kvm$") @@ -17080,7 +17577,13 @@ def require(path: Path, _description: str) -> Path: # Each execution names the processor counts that it covers, if any. expected: list[tuple[str, list[int] | None]] = [] for scenario in scenarios: - if scenario in ("console-exit", "smp", "smp-lapic"): + if scenario in ( + "guest-boot", + "managed-lifecycle", + "console-exit", + "smp", + "smp-lapic", + ): expected.extend((scenario, [processors]) for processors in (2, 1)) elif scenario in ( "smp-snapshot", @@ -18234,7 +18737,13 @@ def test_spans_cover_the_run_from_the_process_start_without_gaps(self): self.assertEqual(written, [1, 2, 3, 4]) self.assertNotIn(b"\r", raw) self.assertEqual(stdout.getvalue(), "Running smp\nRunning lifecycle\n") - dimensions = {"guest": "alpine", "backend": "kvm", "kernel": "debug"} + dimensions = { + "guest": "alpine", + "backend": "kvm", + "kernel": "debug", + "architecture": "x86_64", + "scope": "full", + } passed = {"outcome": "passed", "error": None} self.assertEqual( records, @@ -18914,6 +19423,17 @@ def test_reports_give_samples_of_the_default_suite_only(self): smp, teardown=False, ) + arm = _write_durations( + root / "arm" / microvm_durations.REPORT_NAME, + "whp", + smp, + ) + arm.write_text( + arm.read_text(encoding="utf-8").replace( + '"guest": "alpine"', '"guest": "alpine", "architecture": "aarch64"' + ), + encoding="utf-8", + ) _write_durations( root / "whp" / microvm_durations.REPORT_NAME, "whp", diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index ab2e9bf74..0caa671a1 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -57,6 +57,7 @@ merge_queue, microvm_durations, microvm_shards, + microvm_tests, nvx_rs, openvmm_ci, openvmm_process, @@ -80,7 +81,6 @@ ZstdBuildConstants, ) from nvx_tools.microvm_tests import ( # noqa: E402 - MICROVM_PROCESSOR_COUNTS, PUBLIC_SANDBOX_SCENARIOS, default_suite, ) @@ -552,33 +552,33 @@ def needs(name: str) -> list[str]: return results -def _matrix_legs(job: Mapping[str, Any]) -> list[dict[str, Any]]: +def _matrix_legs( + job: Mapping[str, Any], *, event_name: str = "pull_request" +) -> list[dict[str, Any]]: """Return the inputs that each leg of a job that calls a reusable workflow passes, with the expressions of its matrix and strategy resolved; a job without a matrix has one leg.""" strategy: Mapping[str, Any] = job.get("strategy", {}) matrix: dict[str, list[Any]] = dict(strategy.get("matrix", {})) - if {"include", "exclude"} & set(matrix): + included = matrix.pop("include", []) + if "exclude" in matrix or (included and matrix): raise AssertionError(f"unsupported matrix: {matrix}") - combinations = [ + combinations = included or [ dict(zip(matrix, values, strict=True)) for values in itertools.product(*matrix.values()) ] legs: list[dict[str, Any]] = [] for combination in combinations: - expressions: dict[str, Any] = { - f"${{{{ matrix.{name} }}}}": value for name, value in combination.items() + context = { + "matrix": combination, + "strategy": {"job-total": len(combinations)}, + "github": {"event_name": event_name}, } - expressions["${{ strategy.job-total }}"] = len(combinations) - def resolve(value: Any, expressions: dict[str, Any] = expressions) -> Any: + def resolve(value: Any, context: dict[str, Any] = context) -> Any: if not isinstance(value, str): return value - if value in expressions: - return expressions[value] - for expression, replacement in expressions.items(): - value = value.replace(expression, str(replacement)) - return value + return _interpolate_expressions(value, context, {}) legs.append( {name: resolve(value) for name, value in job.get("with", {}).items()} @@ -587,32 +587,81 @@ def resolve(value: Any, expressions: dict[str, Any] = expressions) -> Any: def _resolve_inputs(text: str, inputs: Mapping[str, Any]) -> str: - """Resolve the input expressions of a reusable workflow's step: an input, - `inputs.NAME && 'VALUE' || 'OTHER'`, and `inputs.NAME && format(...) - || 'OTHER'` with inputs as the arguments.""" - - def value(name: str) -> Any: - return inputs[name.removeprefix("inputs.")] - - def formatted(match: re.Match[str]) -> str: - if not value(match.group(1)): - return match.group(4) - arguments = [str(value(name.strip())) for name in match.group(3).split(",")] - return match.group(2).format(*arguments) - - text = re.sub( - r"\$\{\{ (inputs\.[a-z-]+) && format\('([^']*)', ([^)]*)\) " - r"\|\| '([^']*)' \}\}", - formatted, + """Resolve the same expression grammar used by workflow conditions.""" + + def format_values(template: str, *args: Any) -> str: + return template.format(*args) + + return re.sub( + r"\$\{\{(.*?)\}\}", + lambda match: ( + match.group(0) + if re.search(r"\b(?:runner|github)\.", match.group(1)) + else _expression_string( + _evaluate_expression( + match.group(1), + {"inputs": inputs}, + {"format": format_values}, + ) + ) + ), text, + flags=re.DOTALL, ) - text = re.sub( - r"\$\{\{ (inputs\.[a-z-]+) && '([^']*)' \|\| '([^']*)' \}\}", - lambda match: match.group(2 if value(match.group(1)) else 3), - text, + + +def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, Any]: + path = ( + BuildConstants.REPO_ROOT / ".github" / "workflows" / "run-nvx-microvm-tests.yml" ) - return re.sub( - r"\$\{\{ (inputs\.[a-z-]+) \}\}", lambda match: str(value(match.group(1))), text + workflow = yaml.safe_load(path.read_text(encoding="utf-8")) + step = next( + step + for step in workflow["jobs"]["test"]["steps"] + if step["name"] == "Bind shared correctness arguments" + ) + defaults = { + name: definition.get("default") + for name, definition in workflow[True]["workflow_call"]["inputs"].items() + } + inputs = defaults | dict(inputs) + environment = { + **os.environ, + **{name: _resolve_inputs(value, inputs) for name, value in step["env"].items()}, + "RUNNER_OS": system, + "PYTHONPATH": str(BuildConstants.REPO_ROOT / "scripts"), + } + script = step["run"].split("<<'PY'\n", 1)[1].rsplit("\nPY", 1)[0] + with tempfile.TemporaryDirectory() as directory: + environment["GITHUB_OUTPUT"] = str(Path(directory) / "outputs") + result = subprocess.run( + [sys.executable, "-c", script], + cwd=directory, + env=environment, + capture_output=True, + text=True, + timeout=30, + check=False, + ) + if result.returncode: + raise AssertionError(result.stderr) + return json.loads( + (Path(directory) / "build" / "nvx-correctness-arguments.json").read_text( + encoding="utf-8" + ) + ) + + +def _runner_system(runner: str | list[str]) -> str: + labels: list[str] = ( + (json.loads(runner) if runner.startswith("[") else [runner]) + if isinstance(runner, str) + else runner + ) + return ( + "Windows" + if any("windows" in str(label).lower() for label in labels) + else "Linux" ) @@ -5944,8 +5993,105 @@ def test_command_reports_each_verdict_and_fails_unless_every_job_passed(self): text, ) + def test_arm_coverage_requires_both_existing_jobs_without_trusting_forks(self): + arm_jobs = openvmm_ci.OPENVMM_CI_ARM64_REQUIRED_JOBS + self.assertEqual( + arm_jobs, + ("unit tests [aarch64-windows]", "run vmm-tests [aarch64-windows]"), + ) + cases: list[tuple[str | None, str]] = [(None, "success"), (None, "fork")] + cases.extend( + (name, state) + for name in arm_jobs + for state in ( + "missing", + "failure", + "skipped", + "pending", + "unlisted-pending", + ) + ) + for target, state in cases: + with self.subTest(target=target, state=state): + jobs = _openvmm_gate_jobs(7) + for name in arm_jobs: + if name == target and state in ("missing", "unlisted-pending"): + continue + jobs.append( + _openvmm_job( + 7, + name, + status="in_progress" + if name == target and state == "pending" + else "completed", + conclusion=None + if name == target and state == "pending" + else state + if name == target + else "success", + ) + ) + run = _openvmm_run( + 7, + status="in_progress" + if state == "unlisted-pending" + else "completed", + head_repository="ahuja-gautam/openvmm" + if state == "fork" + else "microsoft/openvmm", + ) + api = _FakeOpenVMMCiApi(([run], {7: jobs})) + args = nvx.parse_args( + [ + "check-openvmm-ci", + "--architecture", + "aarch64", + "--revision", + _OPENVMM_REVISION, + ] + ) + with ( + patch.object(openvmm_ci, "GitHubClient", return_value=api), + contextlib.redirect_stdout(io.StringIO()) as output, + ): + if state == "success": + args.handler(args) + else: + with self.assertRaises(common.ScriptError): + args.handler(args) + lines = output.getvalue().splitlines() + verdicts = [line for line in lines if not line.startswith("::")] + self.assertEqual(len(verdicts), 8) + if state == "fork": + self.assertTrue( + all(line.startswith("missing:") for line in verdicts) + ) + self.assertEqual(api.requests, ["runs"]) + elif state == "success": + self.assertTrue( + all(line.startswith("passed:") for line in verdicts) + ) + else: + expected = ( + "pending" + if state in ("pending", "unlisted-pending") + else "missing" + if state == "missing" + else "failed" + ) + self.assertTrue( + any( + line.startswith(f"{expected}: {target}:") + for line in verdicts + ) + ) + self.assertEqual( + sum(line.startswith("passed:") for line in verdicts), 7 + ) + def test_command_checks_the_pin_with_any_token(self): args = nvx.parse_args(["check-openvmm-ci"]) + self.assertEqual(args.architecture, "x86_64") api = _FakeOpenVMMCiApi(([_openvmm_run(7)], {7: _openvmm_gate_jobs(7)})) with ( patch.object( @@ -6061,6 +6207,17 @@ def load(name: str) -> Any: *DockerBuildConstants.DEBUG_KERNEL_ARTIFACT_NAMES, }, ) + components.update( + { + f"guest-aarch64-{name}": components[f"guest-{name}"] + for name in ("alpine", "ubuntu", "ubuntu-distro") + } + ) + components["guest-aarch64-kernel"] = { + "Image", + "Image.config", + "Image.provenance.json", + } producers: dict[str, str] = {} for job_name, job in jobs.items(): @@ -6075,7 +6232,12 @@ def load(name: str) -> Any: self.assertNotIn(name, producers) producers[name] = job_name paths = str(arguments["path"]).split() - self.assertTrue(all(path.startswith("build/") for path in paths)) + prefix = ( + "build/aarch64/" + if name.startswith("guest-aarch64-") + else "build/" + ) + self.assertTrue(all(path.startswith(prefix) for path in paths)) self.assertEqual( {PurePosixPath(path).name for path in paths}, components[name] ) @@ -6090,27 +6252,43 @@ def load(name: str) -> Any: "azurelinux": {"guest-azurelinux"}, "debug-kernel": {"guest-debug-kernel"}, } - built: dict[str, str] = {} + architectural_uploads = { + ("x86_64", name): names for name, names in uploads.items() + } | { + ("aarch64", name): { + artifact.replace("guest-", "guest-aarch64-", 1) + for artifact in uploads[name] + } + for name in ("kernel", "alpine", "ubuntu") + } + built: dict[tuple[str, str], str] = {} for job_name, job in jobs.items(): for step in job.get("steps", []): if step.get("uses") != "./.github/actions/build-guest-artifacts": continue selected = str(step.get("with", {}).get("components", "")).split() + architecture = step.get("with", {}).get("architecture", "x86_64") with self.subTest(producer=job_name): self.assertTrue(selected) for component in selected: - self.assertIn(component, uploads) - self.assertNotIn(component, built) - built[component] = job_name + key = (architecture, component) + self.assertIn(key, architectural_uploads) + self.assertNotIn(key, built) + built[key] = job_name self.assertEqual( { name for name, producer in producers.items() if producer == job_name }, - set[str]().union(*(uploads[name] for name in selected)), + set[str]().union( + *( + architectural_uploads[architecture, name] + for name in selected + ) + ), ) - self.assertEqual(set(built), set(uploads)) + self.assertEqual(set(built), set(architectural_uploads)) kernel_alpine = { KernelBuildConstants.BINARY_NAME, @@ -6153,6 +6331,12 @@ def load(name: str) -> Any: } def reads(step: dict[str, Any], context: Mapping[str, object]) -> set[str]: + architecture = context.get("inputs.architecture", "x86_64") + kernel = ( + "Image" + if architecture == "aarch64" + else KernelBuildConstants.BINARY_NAME + ) uses = str(step.get("uses", "")) if uses.startswith("./"): self.assertIn(uses, actions) @@ -6161,11 +6345,22 @@ def reads(step: dict[str, Any], context: Mapping[str, object]) -> set[str]: and step.get("with", {}).get("verify-openvmm") != "true" ): return set() - return actions[uses] + return { + kernel if name == KernelBuildConstants.BINARY_NAME else name + for name in actions[uses] + } if uses: self.assertTrue(uses.startswith("actions/"), uses) return set() script = str(step["run"]) + if step.get("name", "").startswith("Run NVX microVM tests on "): + inputs = { + name.removeprefix("inputs."): value + for name, value in context.items() + if name.startswith("inputs.") + } + selected = _correctness_arguments(inputs, str(context["runner.os"])) + script = "nvx.py " + shlex.join(selected["arguments"]) files = { name for name in re.findall(r"\bbuild[/\\]([\w.-]+)", script) @@ -6202,36 +6397,37 @@ def reads(step: dict[str, Any], context: Mapping[str, object]) -> set[str]: # A default run of a guest that controls sandboxes runs # the public sandbox scenarios too, but no shard does. default_run = not (scenarios or debug or sharded) - if scenarios & PUBLIC_SANDBOX_SCENARIOS or ( - default_run and descriptor.sandbox_control + if ( + scenarios & PUBLIC_SANDBOX_SCENARIOS + or (default_run and descriptor.sandbox_control) + or ( + "managed-lifecycle" in scenarios + and context.get("inputs.managed-root", "initramfs") + != "initramfs" + ) ): files |= workload else: self.assertIn(command, commands) files |= commands[command] - return files + return { + kernel if name == KernelBuildConstants.BINARY_NAME else name + for name in files + } def holds(condition: object, context: Mapping[str, object]) -> bool: - # The conjunctions of atoms that the steps that read or download - # guest artifacts use; anything else fails the test. - for term in _expression_conjuncts(str(condition or "true")): - if term == "true": - continue - match = re.fullmatch( - r"(!?)\s*([\w.-]+)(?:\s*(==|!=)\s*'([^']*)')?", term - ) - self.assertIsNotNone(match, term) - assert match is not None - negated, name, operator, literal = match.groups() - value = context[name] - result = ( - bool(value) - if operator is None - else (str(value) == literal) == (operator == "==") - ) - if result == bool(negated): - return False - return True + nested: dict[str, Any] = {} + for name, value in context.items(): + fields = name.split(".") + target = nested + for field in fields[:-1]: + target = target.setdefault(field, {}) + target[fields[-1]] = value + return _expression_truthy( + _evaluate_expression( + str(condition or "true"), nested, _job_status_functions(True) + ) + ) def consume( steps: list[dict[str, Any]], context: Mapping[str, object] @@ -6240,26 +6436,44 @@ def consume( # its steps read, or None if it downloads none; such a job reads # none from its build directory either. downloads: set[str] = set() + inputs = { + name.removeprefix("inputs."): value + for name, value in context.items() + if name.startswith("inputs.") + } + if any(step.get("id") == "correctness" for step in steps): + selected = _correctness_arguments(inputs, str(context["runner.os"])) + context = dict(context) | { + "steps.correctness.outputs.workload-artifacts": str( + selected["workload_artifacts"] + ).lower() + } for step in steps: arguments = step.get("with", {}) - if str(step.get("uses", "")).startswith( - "actions/download-artifact@" - ) and str(arguments.get("name", arguments.get("pattern"))).startswith( - "guest-" + name = _resolve_inputs( + str(arguments.get("name", arguments.get("pattern"))), inputs + ) + if ( + str(step.get("uses", "")).startswith("actions/download-artifact@") + and name.startswith("guest-") + and holds(step.get("if"), context) ): self.assertNotIn("pattern", arguments) - self.assertEqual(arguments["path"], "build") - if holds(step.get("if"), context): - downloads.add(arguments["name"]) + self.assertEqual( + _resolve_inputs(arguments["path"], inputs), + "build/aarch64" + if inputs.get("architecture") == "aarch64" + else "build", + ) + downloads.add(name) if not downloads: return None read: set[str] = set() for step in steps: if str(step.get("uses", "")).startswith("actions/download-artifact@"): continue - files = reads(step, context) - if files and holds(step.get("if"), context): - read |= files + if holds(step.get("if"), context): + read |= reads(step, context) return downloads, read consumers: set[str] = set() @@ -6279,11 +6493,7 @@ def consume( inputs = {**defaults, **leg} contexts.append( { - "runner.os": ( - "Windows" - if "windows" in json.loads(inputs["runner"]) - else "Linux" - ), + "runner.os": _runner_system(inputs["runner"]), **{ f"inputs.{name}": value for name, value in inputs.items() @@ -6299,11 +6509,7 @@ def consume( legs = job.get("strategy", {}).get("matrix", {}).get("include", [{}]) contexts = [ { - "runner.os": ( - "Windows" - if "windows" in json.loads(leg.get("runner", "[]")) - else "Linux" - ), + "runner.os": _runner_system(leg.get("runner", [])), **{f"matrix.{name}": value for name, value in leg.items()}, } for leg in legs @@ -6315,7 +6521,12 @@ def consume( continue consumers.add(job_name) downloaded, read = downloads - expected = {name for name, files in components.items() if files & read} + arm = context.get("inputs.architecture") == "aarch64" + expected = { + name + for name, files in components.items() + if name.startswith("guest-aarch64-") == arm and files & read + } with self.subTest(job=job_name, context=context): self.assertEqual(downloaded, expected) needs = job.get("needs", []) @@ -6333,6 +6544,8 @@ def consume( consumers, { *ci.REQUIRED_CI_MICROVM_TEST_JOBS, + *ci.REQUIRED_CI_ARM_MICROVM_JOBS, + ci.REQUIRED_CI_ARM_REPETITION_JOB, *ci.REQUIRED_CI_MICROVM_DEBUG_JOBS, *ci.REQUIRED_CI_MICROVM_DEBUG_PUSH_JOBS, *ci.REQUIRED_CI_PLATFORM_JOBS, @@ -6365,7 +6578,11 @@ def consume( downloaded, read = result self.assertEqual( downloaded, - {name for name, files in components.items() if files & read}, + { + name + for name, files in components.items() + if not name.startswith("guest-aarch64-") and files & read + }, ) self.assertIn("guest-ubuntu-distro", downloaded) @@ -6898,6 +7115,18 @@ def test_required_ci_result_policy(self): ) for event_name, same_repository, flags, successful_jobs in cases: changes = ci.CiChanges(*flags) + successful_jobs = set(successful_jobs) + if changes.run_microvm_tests: + if changes.run_guest_artifacts: + successful_jobs.add("artifacts-aarch64") + if event_name != "pull_request" or same_repository: + successful_jobs.add("build-nvx-rs-windows-aarch64-msvc") + if changes.run_openvmm_binaries: + successful_jobs.add("build-openvmm-windows-aarch64-msvc") + if changes.run_guest_artifacts: + successful_jobs.update(ci.REQUIRED_CI_ARM_MICROVM_JOBS) + if event_name in ci.CI_FULL_RUN_EVENTS: + successful_jobs.add(ci.REQUIRED_CI_ARM_REPETITION_JOB) with self.subTest( event_name=event_name, same_repository=same_repository, @@ -7048,6 +7277,26 @@ def test_ci_jobs_follow_their_change_detector_output(self): # The release and the recording of the performance results accept a # skipped OpenVMM CI check only when the change selected none (#690). gates = ("release", "performance-record") + arm_selections = { + "artifacts-aarch64": ["run-guest-artifacts", "run-microvm-tests"], + "build-nvx-rs-windows-aarch64-msvc": ["run-microvm-tests"], + "build-openvmm-windows-aarch64-msvc": [ + "run-openvmm-binaries", + "run-microvm-tests", + ], + **dict.fromkeys( + (*ci.REQUIRED_CI_ARM_MICROVM_JOBS, ci.REQUIRED_CI_ARM_REPETITION_JOB), + ["run-guest-artifacts", "run-openvmm-binaries", "run-microvm-tests"], + ), + } + for job_name, outputs in arm_selections.items(): + with self.subTest(job=job_name): + job = _workflow_job(workflow, job_name) + self.assertIn("needs.openvmm-changes.result != 'success'", job) + self.assertEqual( + re.findall(r"needs\.openvmm-changes\.outputs\.([a-z-]+)", job), + outputs, + ) for job_name in gates: with self.subTest(job=job_name): self.assertEqual( @@ -7066,7 +7315,7 @@ def test_ci_jobs_follow_their_change_detector_output(self): for job_name in jobs if "needs.openvmm-changes.outputs." in _workflow_job(workflow, job_name) }, - set(selections) | {"required-status-check", *gates}, + set(selections) | set(arm_selections) | {"required-status-check", *gates}, ) # The detector checks and forwards exactly the classifier's outputs. script = _workflow_step(workflow, "openvmm-changes", "Detect relevant changes") @@ -7536,7 +7785,16 @@ def test_ci_full_runs_do_not_publish_record_or_save_caches(self): else: # Only cache writes follow save-cache, so builds still # run when an artifact misses the cache. - self.assertNotIn("save-cache", str(entry)) + self.assertNotIn( + "save-cache", + str( + { + key: value + for key, value in entry.items() + if key != "env" + } + ), + ) continue writes[source] = writes.get(source, 0) + 1 @@ -7560,10 +7818,15 @@ def test_ci_full_runs_do_not_publish_record_or_save_caches(self): for name, callee, arguments in calls if callee in save_cache_actions ] - self.assertEqual(len(save_cache_calls), 4) + self.assertEqual(len(save_cache_calls), 5) for name, arguments in save_cache_calls: with self.subTest(call=name): - self.assertEqual(arguments.get("save-cache"), save_cache) + self.assertEqual( + arguments.get("save-cache"), + "false" + if arguments.get("architecture") == "aarch64" + else save_cache, + ) # No other push-only job condition is allowed in this workflow: only # the release, performance persistence, the four save-cache arguments, # and the two reuse arguments name the push event; ci.yml itself writes @@ -7989,7 +8252,14 @@ def step(job: str, name: str) -> str: download, ) self.assertIn("uses: actions/download-artifact@v8\n", download) - self.assertIn("name: runtime-adapter-guest\n", download) + for architecture, expected in ( + ("x86_64", "runtime-adapter-guest"), + ("aarch64", "runtime-adapter-guest-aarch64"), + ): + self.assertIn( + f"name: {expected}\n", + _resolve_inputs(download, {"architecture": architecture}), + ) self.assertIn("path: build/runtime-adapter\n", download) for system, setup, guest_agent in ( ("Linux", linux_build, agent), @@ -9145,6 +9415,10 @@ def test_ci_shares_openvmm_inputs_and_binary_artifacts(self): "whp", "openvmm-windows-msvc", ), + "build-openvmm-windows-aarch64-msvc": ( + "whp", + "openvmm-windows-aarch64-msvc", + ), } self.assertEqual( workflow.count("uses: ./.github/workflows/build-openvmm-binary.yml"), @@ -9487,15 +9761,12 @@ def test_guest_artifact_restore_only_guards_builds_and_cache_saves(self): name = "" with self.subTest(step=name): condition = _yaml_scalar(step, "if") - guard = "inputs.restore-only != 'true' && " - self.assertTrue(condition.startswith(guard), condition) - cache_condition = condition.removeprefix(guard) - self.assertIn("cache-hit != 'true'", cache_condition) - if "||" in cache_condition: - self.assertTrue( - _outer_parentheses_enclose(cache_condition), - cache_condition, - ) + conjuncts = _expression_conjuncts(condition) + self.assertIn("inputs.restore-only != 'true'", conjuncts) + self.assertIn("cache-hit != 'true'", condition) + for conjunct in conjuncts: + if "||" in conjunct: + self.assertTrue(_outer_parentheses_enclose(conjunct), conjunct) def test_guest_artifact_restore_only_leaves_restore_steps_active(self): action = ( @@ -9528,6 +9799,99 @@ def test_guest_artifact_restore_only_leaves_restore_steps_active(self): continue self.assertNotIn("restore-only", condition) + def test_arm_guest_producer_requires_fresh_native_inputs(self): + path = ( + BuildConstants.REPO_ROOT + / ".github" + / "actions" + / "build-guest-artifacts" + / "action.yml" + ) + action = yaml.safe_load(path.read_text(encoding="utf-8")) + step = next( + step for step in action["runs"]["steps"] if step.get("id") == "architecture" + ) + shell = shutil.which("bash") + self.assertIsNotNone(shell, "the maintained guest producer requires Bash") + assert shell is not None + defaults = { + "ARCHITECTURE": "aarch64", + "COMPONENTS": "kernel alpine ubuntu", + "RESTORE_ONLY": "false", + "SAVE_CACHE": "false", + "REUSE": "false", + "RECORD": "", + "ENGINE": "arm64", + "GITHUB_OUTPUT": "outputs", + } + cases: list[tuple[dict[str, str], bool]] = [ + ({}, True), + ({"ENGINE": "aarch64"}, True), + ( + {"ARCHITECTURE": "x86_64", "SAVE_CACHE": "true", "ENGINE": "unused"}, + True, + ), + ({"ENGINE": "x86_64"}, False), + ({"ARCHITECTURE": "unknown"}, False), + ({"COMPONENTS": "kernel debug-kernel"}, False), + ({"COMPONENTS": "azurelinux"}, False), + ] + cases.extend( + ({name: "true"}, False) for name in ("RESTORE_ONLY", "SAVE_CACHE", "REUSE") + ) + cases.append(({"RECORD": "record"}, False)) + stub = 'docker() { test "$*" = "info --format {{.Architecture}}" || return 79; printf "%s\\n" "$ENGINE"; }\n' + for overrides, passes in cases: + with ( + self.subTest(overrides=overrides), + tempfile.TemporaryDirectory() as directory, + ): + environment = os.environ | defaults | overrides + result = subprocess.run( + [shell, "-c", stub + step["run"]], + cwd=directory, + env=environment, + capture_output=True, + text=True, + timeout=15, + check=False, + ) + self.assertEqual(result.returncode == 0, passes, result.stderr) + output = Path(directory) / "outputs" + if passes: + fields = dict( + line.split("=", 1) + for line in output.read_text(encoding="utf-8").splitlines() + ) + arm = environment["ARCHITECTURE"] == "aarch64" + self.assertEqual( + fields["directory"], "build/aarch64" if arm else "build" + ) + self.assertEqual( + fields["platform"], "linux/arm64" if arm else "linux/amd64" + ) + if arm: + self.assertEqual( + { + name: fields[name] + for name in ( + "kernel-target", + "alpine-target", + "ubuntu-target", + "distro-target", + ) + }, + { + "kernel-target": "arm64-kernel-artifacts", + "alpine-target": "arm64-artifacts", + "ubuntu-target": "arm64-ubuntu-artifacts", + "distro-target": "arm64-ubuntu-distro-layer-artifacts", + }, + ) + else: + self.assertIn("::error::", result.stderr) + self.assertFalse(output.exists()) + def test_guest_artifact_jobs_record_their_components(self): github = BuildConstants.REPO_ROOT / ".github" action = yaml.safe_load( @@ -9576,7 +9940,11 @@ def test_guest_artifact_jobs_record_their_components(self): self.assertEqual(record["name"], "Record guest artifact keys and digests") self.assertEqual( _expression_conjuncts(record["if"]), - ["inputs.restore-only != 'true'", "inputs.record-artifact != ''"], + [ + "inputs.architecture == 'x86_64'", + "inputs.restore-only != 'true'", + "inputs.record-artifact != ''", + ], ) self.assertEqual( record["env"], @@ -9624,8 +9992,13 @@ def test_guest_artifact_jobs_record_their_components(self): continue arguments = step["with"] with self.subTest(job=job_name): - if arguments["components"].split() == ["debug-kernel"]: + if ( + arguments["components"].split() == ["debug-kernel"] + or arguments.get("architecture") == "aarch64" + ): self.assertNotIn("record-artifact", arguments) + if arguments.get("architecture") == "aarch64": + self.assertEqual(arguments["save-cache"], "false") continue name = arguments["record-artifact"] self.assertFalse(name.startswith("guest-"), name) @@ -9712,6 +10085,7 @@ def test_dev_pushes_reuse_the_guest_artifacts_of_their_pull_requests(self): self.assertEqual( _expression_conjuncts(reuse["if"]), [ + "inputs.architecture == 'x86_64'", "inputs.restore-only != 'true'", "inputs.reuse == 'true'", "inputs.record-artifact != ''", @@ -9928,6 +10302,10 @@ def test_reuse_downloads_the_artifacts_of_each_recorded_component(self): for job_name, job in workflow["jobs"].items(): for step in job.get("steps", []): if step.get("uses") == "./.github/actions/build-guest-artifacts": + if step.get("with", {}).get("architecture", "x86_64") != "x86_64": + self.assertEqual(step["with"].get("save-cache"), "false") + self.assertNotIn("record-artifact", step["with"]) + continue for component in step["with"]["components"].split(): builders[component] = job_name uploads = _guest_uploads() @@ -9948,7 +10326,16 @@ def test_reuse_downloads_the_artifacts_of_each_recorded_component(self): sorted(files), sorted(release.GUEST_ARTIFACT_COMPONENTS[component]), ) - self.assertEqual(set(uploads) - handed_over, {"guest-debug-kernel"}) + self.assertEqual( + set(uploads) - handed_over, + { + "guest-debug-kernel", + "guest-aarch64-kernel", + "guest-aarch64-alpine", + "guest-aarch64-ubuntu", + "guest-aarch64-ubuntu-distro", + }, + ) def test_ci_runs_debug_kernel_on_mshv_for_prs_and_all_for_non_prs(self): workflow = ( @@ -10048,8 +10435,14 @@ def condition(job: str) -> str: "if: inputs.debug-kernel", microvm_workflow[download - 120 : download], ) - debug_flag = "${{ inputs.debug-kernel && '--debug-kernel' || '' }}" - self.assertEqual(microvm_workflow.count(debug_flag), 2) + binding = _workflow_step( + workflow=microvm_workflow, + job_name="test", + step_name="Bind shared correctness arguments", + ) + self.assertIn( + 'if debug:\n arguments += ["--debug-kernel"]', binding + ) # The debug run replaces every production-kernel workload rather than # adding to it: each step that drives nvx.py without the debug kernel # flag boots build/vmlinux, so it must skip the debug jobs (#371). @@ -10069,7 +10462,7 @@ def condition(job: str) -> str: except AssertionError: step_condition = "" with self.subTest(step=name): - if debug_flag in script: + if "nvx-correctness-arguments.json" in script: debug_steps.append(name) self.assertNotIn("debug-kernel", step_condition) continue @@ -10129,7 +10522,9 @@ def test_ci_runs_the_steps_after_the_default_microvm_suite_beside_it(self): for kind in ("tests", "guests", "debug") for backend in backends } - | {f"nvx-microvm-adapter-{backend}" for backend in separate}, + | {f"nvx-microvm-adapter-{backend}" for backend in separate} + | set(ci.REQUIRED_CI_ARM_MICROVM_JOBS) + | {ci.REQUIRED_CI_ARM_REPETITION_JOB}, ) for backend, label in backends.items(): suite = jobs[f"nvx-microvm-tests-{backend}"] @@ -10195,10 +10590,14 @@ def test_ci_runs_the_steps_after_the_default_microvm_suite_beside_it(self): names = [step["name"] for step in steps] setup = names[: names.index("Validate runner") + 1] downloads = { - step["name"]: step["with"]["name"] + step["name"]: _resolve_inputs( + step["with"]["name"], {"architecture": "x86_64"} + ) for step in steps if str(step.get("uses", "")).startswith("actions/download-artifact@") - and str(step["with"]["name"]).startswith("guest-") + and _resolve_inputs( + str(step["with"]["name"]), {"architecture": "x86_64"} + ).startswith("guest-") } uploads = [ step @@ -10230,6 +10629,8 @@ def selected( "inputs.runtime-adapter": adapter, "!inputs.runtime-adapter": single or not adapter, "!inputs.shard": not sharded, + "steps.correctness.outputs.workload-artifacts == 'true'": True, + "(inputs.guests-and-sandboxes || inputs.guest == 'ubuntu')": guests, } chosen: list[str] = [] for step in steps: @@ -10364,7 +10765,11 @@ def uploads_in(upload: Mapping[str, Any], leg: Mapping[str, Any]) -> bool: for leg in legs if not uploads_in(upload, leg) ], - [f"{backends[backend]} / Runtime adapter" for backend in separate], + [ + leg["display-name"] + for leg in legs + if leg["runtime-adapter"] and not leg["guests-and-sandboxes"] + ], ) failure_logs = next( step @@ -10418,12 +10823,16 @@ def test_ci_runs_each_default_microvm_suite_in_its_shards(self): sharded = { step["name"]: str(step["run"]) for step in steps - if "inputs.shard" in str(step.get("run", "")) + if step["name"].startswith("Run NVX microVM tests on ") } self.assertEqual( set(sharded), {"Run NVX microVM tests on Linux", "Run NVX microVM tests on Windows"}, ) + for command in sharded.values(): + self.assertIn("nvx-correctness-arguments.json", command) + self.assertIn("selected", command) + self.assertIn("os.execv(", sharded["Run NVX microVM tests on Linux"]) partition = microvm_shards.load_partition() suite = default_suite() shard = "Shard ${{ matrix.shard }} of ${{ strategy.job-total }}" @@ -10467,19 +10876,14 @@ def test_ci_runs_each_default_microvm_suite_in_its_shards(self): ) ran: list[str] = [] for leg in legs: - command = _resolve_inputs( - sharded[f"Run NVX microVM tests on {system}"], leg - ) - self.assertNotIn("${{", command) - args = nvx.parse_args( - shlex.split(command.split("nvx.py ", 1)[1].replace("\\", "/")) - ) + selected = _correctness_arguments(leg, system) + args = nvx.parse_args(selected["arguments"]) self.assertEqual( (args.backend, args.shard, args.scenario, args.debug_kernel), (backend, (leg["shard"], count), None, False), ) self.assertEqual(args.guest, "alpine") - self.assertEqual(args.processors, list(MICROVM_PROCESSOR_COUNTS)) + self.assertIsNone(args.processors) ran.extend( microvm_shards.shard_scenarios( partition, backend, args.shard, suite @@ -10491,9 +10895,79 @@ def test_ci_runs_each_default_microvm_suite_in_its_shards(self): for kind in ("guests", "debug"): for backend in backends: leg = {**defaults, **jobs[f"nvx-microvm-{kind}-{backend}"]["with"]} - for step_name, run in sharded.items(): + for step_name in sharded: with self.subTest(job=f"{kind}-{backend}", step=step_name): - self.assertNotIn("--shard", _resolve_inputs(run, leg)) + selected = _correctness_arguments( + leg, "Windows" if backend == "whp" else "Linux" + ) + self.assertNotIn("--shard", selected["arguments"]) + self.assertEqual( + "--debug-kernel" in selected["arguments"], kind == "debug" + ) + + arm = jobs["nvx-microvm-tests-whp-aarch64"] + self.assertFalse(arm["strategy"]["fail-fast"]) + self.assertEqual(arm["strategy"]["max-parallel"], 1) + for event in ("pull_request", "merge_group", "schedule", "workflow_dispatch"): + cells = _matrix_legs(arm, event_name=event) + observed: list[tuple[str, str]] = [] + for cell in cells: + selected = _correctness_arguments(cell, "Windows") + args = nvx.parse_args(selected["arguments"]) + with self.subTest(event=event, cell=cell["result-id"]): + self.assertEqual(args.architecture, "aarch64") + self.assertTrue(args.cold_only) + self.assertIsNone(args.shard) + self.assertFalse(args.debug_kernel) + self.assertEqual(args.backend, "whp") + self.assertEqual( + args.processors, + [1, 2, 4, 8] if event in ci.CI_FULL_RUN_EVENTS else [1, 8], + ) + self.assertEqual( + args.memory_mib, + 1024 if args.scenario == ["managed-lifecycle"] else 256, + ) + observed.extend( + ( + scenario, + args.managed_root + if scenario == "managed-lifecycle" + else "cold", + ) + for scenario in args.scenario + ) + expected = { + (scenario, "cold") + for scenario in microvm_tests.COLD_ONLY_SCENARIOS + if scenario != "managed-lifecycle" + } + expected.update( + ("managed-lifecycle", root) for root in ("initramfs", "scratch", "ram") + ) + self.assertEqual(set(observed), expected) + self.assertEqual(len(observed), len(expected)) + repeat = jobs[ci.REQUIRED_CI_ARM_REPETITION_JOB] + self.assertEqual(repeat["strategy"]["max-parallel"], 1) + expected_repetitions = { + "cold-1vp-50": (["guest-boot"], [1], 50, None), + "cold-8vp-50": (["guest-boot"], [8], 50, None), + "public-lifecycle-25": (["sandbox-lifecycle"], [1], 25, None), + "scratch-start-stop-10": (["sandbox-lifecycle"], [1], 1, 10), + "ram-start-stop-10": (["sandbox-ram-upper"], [1], 1, 10), + "mixed-1-2-4-8vp": (["smp", "managed-lifecycle"], [1, 2, 4, 8], 1, None), + } + observed_repetitions: dict[str, tuple[Any, ...]] = {} + for cell in _matrix_legs(repeat, event_name="schedule"): + selected = _correctness_arguments(cell, "Windows") + args = nvx.parse_args(selected["arguments"]) + observed_repetitions[cell["result-id"].removeprefix("repeat-")] = ( + args.scenario, + args.processors, + selected["cycles"], + args.start_stop_cycles, + ) + self.assertEqual(observed_repetitions, expected_repetitions) def test_benchmarks_rely_on_the_microvm_correctness_jobs(self): # #286: the benchmark action ran a second smp-lapic gate before @@ -10561,7 +11035,7 @@ def test_ci_checks_openvmm_ci_instead_of_running_openvmm_tests(self): self.assertEqual(check["env"]["GH_TOKEN"], "${{ github.token }}") self.assertEqual( check["run"], - 'python3 scripts/nvx.py check-openvmm-ci --wait-minutes "${WAIT_MINUTES}" ' + 'python3 scripts/nvx.py check-openvmm-ci --architecture aarch64 --wait-minutes "${WAIT_MINUTES}" ' '--summary "${GITHUB_STEP_SUMMARY}"', ) # A pull request, whose pin promotion passes once OpenVMM's CI does, @@ -10882,6 +11356,10 @@ def test_ci_hands_nvx_rs_to_the_microvm_and_package_jobs(self): provenance = _workflow_step( workflow, job_name, "Upload nvx-rs provenance" ) + if job_name == "build-nvx-rs-windows-msvc": + record = record.replace('"${{ matrix.target }}"', target) + upload = upload.replace("${{ matrix.artifact }}", artifact) + provenance = provenance.replace("${{ matrix.artifact }}", artifact) for option in ("--release", "--locked", "--features cli"): self.assertIn(option, build) self.assertIn("--manifest-path nvx-rs/Cargo.toml", build) @@ -11745,22 +12223,87 @@ def test_runners_qualify_their_host_time_before_every_job(self): self.assertIn(f" shell: {shell}\n", step) self.assertIn(command, step) self.assertIn('--backend "${{ inputs.backend }}"', step) - self.assertIn("--checks H1 H2 H4\n", step) - self.assertIn( - "${{ inputs.warp-probe == 'true' && 'H6' || '' }}\n", step - ) - fingerprint = ( - '"${RUNNER_TEMP}/nvx-cpu-fingerprint.json"' - if shell == "bash" - else '"$env:RUNNER_TEMP\\nvx-cpu-fingerprint.json"' - ) - self.assertIn( - "${{ inputs.verify-openvmm == 'true' && " - f"'H3 --cpu-fingerprint {fingerprint}' || '--no-openvmm' }}}}\n", - step, - ) - self.assertIn("--ci-schedule\n", step) + if shell == "bash": + self.assertIn("--checks H1 H2 H4\n", step) + self.assertIn( + "${{ inputs.warp-probe == 'true' && 'H6' || '' }}\n", step + ) + self.assertIn( + "${{ inputs.verify-openvmm == 'true' && " + "'H3 --cpu-fingerprint \"${RUNNER_TEMP}/nvx-cpu-fingerprint.json\"' || '--no-openvmm' }}\n", + step, + ) + else: + self.assertIn('$checks = @("H1", "H2", "H4")', step) + self.assertIn('$checks = @("H1", "H4")', step) + self.assertIn('$checks += "H6"', step) + self.assertIn('$checks += "H3"', step) + self.assertIn('if ($architecture -eq "x86_64")', step) + self.assertNotIn('"H5"', step) + self.assertNotIn('"H7"', step) + self.assertIn("--ci-schedule", step) self.assertIn(summary, step) + if os.name == "nt": + script = _composite_action_script( + validate_runner, "Qualify host time on Windows" + ) + for architecture in ("x86_64", "aarch64"): + for verify, warp in ( + ("false", "false"), + ("true", "false"), + ("true", "true"), + ): + rendered = script + for name, value in { + "architecture": architecture, + "backend": "whp", + "verify-openvmm": verify, + "warp-probe": warp, + }.items(): + rendered = rendered.replace("${{ inputs." + name + " }}", value) + stub = ( + "function python { " + "$json = @($args) | ConvertTo-Json -Compress; " + "Write-Output ('NVX_TEST_ARGS=' + $json); " + "$global:LASTEXITCODE=0 }\n" + ) + result = run_powershell( + [ + "powershell.exe", + "-NoProfile", + "-NonInteractive", + "-Command", + stub + rendered, + ], + env={ + **os.environ, + "RUNNER_TEMP": str(self._testMethodName), + "GITHUB_STEP_SUMMARY": "summary", + }, + ) + self.assertEqual(result.returncode, 0, result.stderr) + line = next( + line + for line in result.stdout.splitlines() + if line.startswith("NVX_TEST_ARGS=") + ) + arguments = nvx.parse_args( + json.loads(line.removeprefix("NVX_TEST_ARGS="))[1:] + ) + self.assertEqual(arguments.architecture, architecture) + expected = {"H1", "H4"} + if architecture == "x86_64" or verify == "true": + expected.add("H2") + if verify == "true": + expected.add("H3") + if warp == "true": + expected.add("H6") + self.assertEqual(set(arguments.checks), expected) + self.assertEqual(arguments.no_openvmm, verify == "false") + self.assertEqual( + arguments.cpu_fingerprint is not None, + architecture == "x86_64" and verify == "true", + ) args = nvx.parse_args( ["doctor", "--backend", "kvm", "--checks", "H1", "H2", "H4", "H3"] + ["--cpu-fingerprint", "fingerprint.json", "--ci-schedule"] @@ -11787,7 +12330,10 @@ def test_runners_qualify_their_host_time_before_every_job(self): # A failed CPU profile check keeps OpenVMM's fingerprint. upload = validate_runner.split(" - name: Upload the CPU fingerprint\n")[1] upload = upload.split("\n\n", 1)[0] - self.assertIn("if: failure() && inputs.verify-openvmm == 'true'\n", upload) + self.assertIn( + "if: failure() && inputs.verify-openvmm == 'true' && inputs.architecture == 'x86_64'\n", + upload, + ) self.assertIn("path: ${{ runner.temp }}/nvx-cpu-fingerprint.json\n", upload) self.assertIn("if-no-files-found: ignore\n", upload) # Jobs that run OpenVMM qualify the runner after downloading it. @@ -11951,7 +12497,7 @@ def test_windows_runner_setup_selects_exactly_one_runner_role(self): ) # Registration and check mode share one label set. self.assertEqual( - windows_setup.count('@("windows", "whp", "virtual-machine")'), 1 + windows_setup.count('@("windows", "whp", $HostType.ToLowerInvariant())'), 1 ) for function_name, assignment in ( ("Install-ActionsRunner", "\n $labels = $ExpectedRunnerLabels\n"), @@ -12923,7 +13469,7 @@ def test_every_microvm_job_uploads_its_scenario_durations(self): self.assertEqual(upload["uses"], "actions/upload-artifact@v7") self.assertEqual( upload["with"]["path"], - f"build/test-results/*/{microvm_durations.REPORT_NAME}", + f"build/test-results/**/{microvm_durations.REPORT_NAME}", ) # The path's pattern finds the report of every test-microvm step. microvm_runs = [ @@ -12947,11 +13493,15 @@ def test_every_microvm_job_uploads_its_scenario_durations(self): kernel = "${{ inputs.debug-kernel && 'debug' || 'default' }}" part = "${{ inputs.guests-and-sandboxes && '-guests' || '' }}" shard = "${{ inputs.shard && format('-shard-{0}', inputs.shard) || '' }}" + isa = "${{ inputs.architecture == 'aarch64' && format('-aarch64-{0}', inputs.managed-root) || '' }}" + cell = "${{ inputs.result-id && format('-{0}', inputs.result-id) || '' }}" name = upload["with"]["name"] self.assertEqual( name, "nvx-microvm-durations-${{ runner.os }}-${{ inputs.backend }}-" + kernel + + isa + + cell + part + shard + "-${{ github.run_id }}-${{ github.run_attempt }}", @@ -12967,6 +13517,8 @@ def test_every_microvm_job_uploads_its_scenario_durations(self): set(jobs), { *ci.REQUIRED_CI_MICROVM_TEST_JOBS, + *ci.REQUIRED_CI_ARM_MICROVM_JOBS, + ci.REQUIRED_CI_ARM_REPETITION_JOB, *ci.REQUIRED_CI_MICROVM_DEBUG_JOBS, *ci.REQUIRED_CI_MICROVM_DEBUG_PUSH_JOBS, }, @@ -12980,9 +13532,7 @@ def test_every_microvm_job_uploads_its_scenario_durations(self): if inputs.get("runtime-adapter", False) is True and not guests: continue legs += 1 - system = ( - "Windows" if "windows" in json.loads(inputs["runner"]) else "Linux" - ) + system = _runner_system(inputs["runner"]) debug = inputs.get("debug-kernel", False) is True index = inputs.get("shard", 0) for attempt in (1, 2): @@ -12992,6 +13542,18 @@ def test_every_microvm_job_uploads_its_scenario_durations(self): .replace(kernel, "debug" if debug else "default") .replace(part, "-guests" if guests else "") .replace(shard, f"-shard-{index}" if index else "") + .replace( + isa, + f"-aarch64-{inputs.get('managed-root', 'initramfs')}" + if inputs.get("architecture", "x86_64") != "x86_64" + else "", + ) + .replace( + cell, + f"-{inputs['result-id']}" + if inputs.get("result-id") + else "", + ) .replace("${{ github.run_id }}", "39585909588") .replace("${{ github.run_attempt }}", str(attempt)) ) @@ -17753,8 +18315,12 @@ def test_ci_guest_artifact_components_select_their_steps(self): for line in action.splitlines() if line.startswith(" - name: ") ] - self.assertEqual(steps[0], "Select guest artifact components") + self.assertEqual( + steps[:2], + ["Select native guest architecture", "Select guest artifact components"], + ) always = { + "Select native guest architecture", "Select guest artifact components", "Resolve guest artifact versions", "Resolve guest cache keys", @@ -21253,6 +21819,9 @@ def _run( targets: Mapping[str, str] | None = None, check_only: bool = False, artifacts: str | None = None, + architecture: str = "x86_64", + cold_only: bool = False, + scopes: Mapping[str, str] | None = None, ) -> tuple[int, list[tuple[list[str], dict[str, str]]], str, str]: """Runs the handler on the scenarios at `path`, for an adapter whose Cargo metadata holds the test targets `targets`, by name with their sources, and @@ -21298,9 +21867,20 @@ def fake_streamed( return f"{output}\ntest result: ok. {len(names)} passed; 0 failed;\n", 0 guest = path.parent / "runtime-adapter-guest" - guest.write_bytes(b"") + header = bytearray(64) + header[:6] = b"\x7fELF\x02\x01" + header[16:18] = (2).to_bytes(2, "little") + header[18:20] = (183 if architecture == "aarch64" else 62).to_bytes(2, "little") + header[20:24] = (1).to_bytes(4, "little") + header[52:54] = (64).to_bytes(2, "little") + guest.write_bytes(header) args = argparse.Namespace( - backend="kvm", cargo="cargo", check_only=check_only, guest_agent=guest + backend="whp" if architecture == "aarch64" else "kvm", + cargo="cargo", + check_only=check_only, + guest_agent=guest, + architecture=architecture, + cold_only=cold_only, ) scenarios = runtime_adapter_tests.read_scenarios(path) with ( @@ -21308,6 +21888,19 @@ def fake_streamed( runtime_adapter_tests, "read_scenarios", return_value=scenarios ), patch.object(runtime_adapter_tests, "ADAPTER_DIRECTORY", path.parent), + patch.object( + runtime_adapter_tests, "host_architecture", return_value=architecture + ), + patch.object( + runtime_adapter_tests.sys, + "platform", + "win32" if architecture == "aarch64" else sys.platform, + ), + ( + patch.object(runtime_adapter_tests, "SCENARIO_SCOPES", dict(scopes)) + if scopes is not None + else contextlib.nullcontext() + ), patch.object(runtime_adapter_tests, "validate_openvmm_test_backend"), patch.object(runtime_adapter_tests, "listing", fake_listing), patch.object(runtime_adapter_tests, "streamed", fake_streamed), @@ -21327,7 +21920,25 @@ def test_cli_registers_the_suite(self): self.assertEqual(args.backend, "kvm") self.assertEqual(args.cargo, "cargo") self.assertFalse(args.check_only) - self.assertEqual(args.guest_agent, runtime_adapter_tests.GUEST_AGENT) + self.assertIsNone(args.guest_agent) + self.assertEqual(args.architecture, "x86_64") + self.assertFalse(args.cold_only) + arm = nvx.parse_args( + [ + "test-runtime-adapter", + "--backend", + "whp", + "--architecture", + "aarch64", + "--cold-only", + "--guest-agent", + "agent", + ] + ) + self.assertTrue(arm.cold_only) + self.assertEqual( + (arm.architecture, arm.guest_agent), ("aarch64", Path("agent")) + ) self.assertIs(args.handler, runtime_adapter_tests.command_test_runtime_adapter) def test_ci_runs_the_suite_by_name_on_each_backend(self): @@ -21381,6 +21992,14 @@ def test_the_adapter_s_readme_lists_its_scenarios(self): rows = re.findall(r"^\| `(\w+)` \| `(\w+)` \|", section, re.MULTILINE) self.assertEqual(rows, named) + self.assertEqual( + set(runtime_adapter_tests.SCENARIO_SCOPES), + {target.name for target in targets}, + ) + self.assertEqual( + set(runtime_adapter_tests.SCENARIO_SCOPES.values()), + {"portable", "cold", "snapshot"}, + ) def test_libtest_s_terse_list_names_the_tests(self): self.assertEqual( @@ -21487,6 +22106,69 @@ def test_the_handler_checks_the_names_then_runs_each_target_by_name(self): status, runs, stdout, _ = self._run(path, listings, check_only=True) self.assertEqual((status, runs), (0, [])) self.assertIn("3 scenarios name exactly the tests of 2 targets", stdout) + cold_path = self._scenarios("vm_a a\nvm_a b\nunit x\nother restored\n") + cold_listings = { + **listings, + ("other", "--list"): "restored: test\n", + } + scopes = {"vm_a": "cold", "unit": "portable", "other": "snapshot"} + for architecture in ("x86_64", "aarch64"): + status, runs, stdout, stderr = self._run( + cold_path, + cold_listings, + architecture=architecture, + cold_only=True, + scopes=scopes, + ) + self.assertEqual(status, 0, stderr) + self.assertEqual( + [command[command.index("--test") + 1] for command, _ in runs], + ["vm_a", "unit"], + ) + self.assertIn("3 selected tests; 1 deferred snapshot tests (other)", stdout) + for command, _ in runs: + if architecture == "aarch64": + self.assertEqual( + command[command.index("--target") + 1], + "aarch64-pc-windows-msvc", + ) + else: + self.assertNotIn("--target", command) + status, runs, stdout, _ = self._run( + cold_path, + cold_listings, + architecture=architecture, + cold_only=True, + check_only=True, + scopes=scopes, + ) + self.assertEqual((status, runs), (0, [])) + self.assertIn("4 scenarios name exactly the tests of 3 targets", stdout) + with self.assertRaisesRegex(common.ScriptError, "unclassified"): + self._run(cold_path, cold_listings, cold_only=True, scopes={"vm_a": "cold"}) + with self.assertRaisesRegex(common.ScriptError, "no cold cases"): + self._run( + cold_path, + cold_listings, + cold_only=True, + scopes={name: "portable" for name in scopes}, + ) + with self.assertRaisesRegex(common.ScriptError, "unknown scenario scope"): + self._run( + cold_path, + cold_listings, + cold_only=True, + scopes={**scopes, "unit": "unknown"}, + ) + broken = { + **cold_listings, + ("other", "--list"): "restored: test\nunlisted: test\n", + } + status, runs, _, stderr = self._run( + cold_path, broken, cold_only=True, scopes=scopes + ) + self.assertEqual((status, runs), (1, [])) + self.assertIn("other has the test unlisted", stderr) def test_the_handler_takes_a_relative_directory_of_artifacts_from_the_caller(self): path = self._scenarios("unit x\n") @@ -24221,6 +24903,56 @@ def test_smp_probe_uses_explicit_topology_and_worker_rendezvous(self): benchmark.smp_probe_script(3) with self.assertRaises(ValueError): benchmark.smp_probe_script(4, network_gateway="10.0.0.1") + arm = benchmark.smp_probe_script(4, architecture="aarch64") + self.assertIn("architecture=aarch64", arm) + self.assertIn('read_dt_mpidr "/sys/devices/system/cpu/cpu${cpu}/of_node"', arm) + self.assertIn('"$1/reg"', arm) + self.assertIn("SMP-MPIDR-FAIL", arm) + self.assertIn("SMP-TIMER-FAIL", arm) + self.assertIn("arch_timer", arm) + self.assertIn("/^IPI[01]:$/", arm) + self.assertIn("dt_mpidrs=" + ",".join(f"0x{cpu:016x}" for cpu in range(4)), arm) + self.assertNotIn("@", arm) + with self.assertRaisesRegex(ValueError, "x86-only"): + benchmark.smp_probe_script( + 4, architecture="aarch64", network_gateway="10.0.0.1", ioapic_irq=16 + ) + + def test_smp_arm_identity_reads_the_declared_device_tree_cell_width(self): + shell = shutil.which("sh") + if shell is None: + self.skipTest("POSIX shell is unavailable") + script = benchmark.smp_probe_script(1, architecture="aarch64") + start = script.index("read_dt_mpidr() {\n") + end = script.index("\n}\n", start) + len("\n}\n") + function = script[start:end] + for cells, width, status in ( + (1, 4, 0), + (2, 8, 0), + (1, 8, 1), + (2, 4, 1), + (3, 12, 1), + ): + with ( + self.subTest(cells=cells, width=width), + tempfile.TemporaryDirectory() as temporary, + ): + root = Path(temporary) + node = root / "cpus" / "cpu0" + node.mkdir(parents=True) + (node.parent / "#address-cells").write_bytes(cells.to_bytes(4, "big")) + (node / "reg").write_bytes((7).to_bytes(width, "big")) + result = subprocess.run( + [shell], + input=function + "\nread_dt_mpidr cpus/cpu0\n", + text=True, + capture_output=True, + check=False, + cwd=root, + ) + self.assertEqual(result.returncode, status, result.stderr) + if status == 0: + self.assertEqual(result.stdout, "0000000000000007\n") def test_snapshot_request_triggers_waiting_capture_controller(self): script = benchmark.snapshot_request_script( diff --git a/scripts/test_time_abi.py b/scripts/test_time_abi.py index 25529ffcb..0da61f084 100644 --- a/scripts/test_time_abi.py +++ b/scripts/test_time_abi.py @@ -340,6 +340,7 @@ def git(directory: Path, *arguments: str) -> str | None: ) assert listing is not None pinned: dict[str, tuple[str, str, tuple[tuple[int, int, range], ...]]] = {} + pinned_arm: dict[str, time_abi.ArmCpuProfile] = {} temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) checkout = Path(temporary.name) @@ -352,6 +353,11 @@ def git(directory: Path, *arguments: str) -> str | None: assert content is not None (profiles / Path(path).name).write_text(content, encoding="utf-8") document = json.loads(content) + arm = time_abi.arm_cpu_profile(document) + if arm is not None: + self.assertNotIn(arm.profile_id, pinned_arm) + pinned_arm[arm.profile_id] = arm + continue generation = document["generation"] # Keyed by profile ID, so that a revision that the copy lacks fails # the comparison instead of replacing another. @@ -383,6 +389,18 @@ def git(directory: Path, *arguments: str) -> str | None: for revision in range(1, generation.revision + 1) } self.assertEqual(copy, pinned) + copied_documents = json.loads( + ( + root / "nvx-rs" / "src" / "host" / "cli" / "cpu_generations.json" + ).read_text(encoding="utf-8") + ) + copied_arm: dict[str, time_abi.ArmCpuProfile] = {} + for document in copied_documents: + arm = time_abi.arm_cpu_profile(document) + if arm is not None: + self.assertNotIn(arm.profile_id, copied_arm) + copied_arm[arm.profile_id] = arm + self.assertEqual(copied_arm, pinned_arm) # benchmark reads the same generations from these documents, as it # reads them from the OpenVMM checkout that it builds. self.assertEqual( @@ -406,6 +424,34 @@ def test_reads_the_cpu_profiles_of_an_openvmm_checkout(self): generations = time_abi.openvmm_cpu_generations(checkout) self.assertEqual(set(generations), {icelake, alderlake, sapphire_rapids}) self.assertEqual(len(generations), 3) + arm_profile: dict[str, object] = { + "schema": "nvx.arm64.cpu.v1", + "id": "qualcomm.oryon-x1.v1", + "physical_address_bits": 36, + "fields": [{"register": "ID_AA64PFR0_EL1"}], + } + arm: dict[str, object] = { + "vendor": "qualcomm", + "sha256": "sha256:" + "a" * 64, + "profile": arm_profile, + } + ( + checkout / time_abi.OPENVMM_CPU_PROFILES / "qualcomm.oryon-x1.v1.json" + ).write_text(json.dumps(arm), encoding="utf-8") + self.assertEqual( + time_abi.arm_cpu_profile(arm), + time_abi.ArmCpuProfile( + "qualcomm.oryon-x1.v1", + "qualcomm", + "a" * 64, + 36, + ("ID_AA64PFR0_EL1",), + ), + ) + self.assertEqual( + set(time_abi.openvmm_cpu_generations(checkout)), + {icelake, alderlake, sapphire_rapids}, + ) # A CPU that only the checkout's profiles cover is benchmarked with # them, and not with NVX's copy of the catalog. sapphire_rapids_host = time_abi.HostCpu("GenuineIntel", 6, 143, 8) @@ -434,6 +480,21 @@ def test_reads_the_cpu_profiles_of_an_openvmm_checkout(self): ("not-json", None, "cannot read the CPU profile .*not-json.json"), ("list", [], "it is not a JSON object"), ("no-generation", {"vendor": "GenuineIntel"}, "names no vendor"), + ( + "arm-schema", + {**arm, "profile": {**arm_profile, "schema": "unknown"}}, + "ARM profile schema is unsupported", + ), + ( + "arm-digest", + {**arm, "sha256": "sha256:bad"}, + "ARM profile identity is malformed", + ), + ( + "arm-width", + {**arm, "profile": {**arm_profile, "physical_address_bits": True}}, + "physical address bits is not an integer", + ), ( "no-cpus", {**valid, "generation": {"name": "icelake-sp", "cpus": []}}, @@ -1029,6 +1090,14 @@ def test_normal_arm_cli_uses_architected_counter_not_x86_frequency_or_lapic(self arm_line = BOOT_LINE.replace("tsc_hz=2194804000", "tsc_hz=19200000").replace( "lapic_hz=1000000000", "lapic_hz=0" ) + explicit = TimeAbiMonitor( + ["openvmm", "--hypervisor", "whp", "--kernel", "custom-kernel-name"], + architecture="aarch64", + ) + explicit.feed(arm_line.encode() + STATUS_OK.encode()) + self.assertEqual(explicit.require_boot("explicit ISA")["tsc_hz"], "19200000") + with self.assertRaisesRegex(ValueError, "unsupported counter architecture"): + TimeAbiMonitor(architecture="unknown") for profile in ("auto", "host"): command = [ "nvx-rs.exe", @@ -2198,6 +2267,9 @@ class DoctorTests(unittest.TestCase): def setUp(self): self.temporary = tempfile.TemporaryDirectory() self.root = Path(self.temporary.name) + architecture = patch.object(doctor, "host_architecture", return_value="x86_64") + architecture.start() + self.addCleanup(architecture.stop) def tearDown(self): self.temporary.cleanup() @@ -2271,6 +2343,34 @@ def test_cpu_check_names_the_generation_and_records_invariant_tsc_as_evidence( self.assertEqual( context.facts["invariant_tsc"], "no (missing nonstop_tsc)" ) + arm = doctor_context(self.root, "whp") + arm.architecture = "aarch64" + arm.no_openvmm = True + counter = ( + "cpu", + { + "architecture": "aarch64", + "counter": "cntvct_el0", + "counter_hz": "19200000", + }, + ) + with ( + patch.object(doctor, "run_probe", return_value=[counter]), + patch.object(doctor, "host_cpu") as legacy, + patch.object(doctor.subprocess, "run") as process, + ): + for fingerprint in (None, self.root / "arm-fingerprint.json"): + arm.fingerprint = fingerprint + result = doctor.check_cpu(arm) + self.assertFalse(result.passed) + self.assertIn("unsupported", result.detail) + self.assertIn("evidence only", result.detail) + legacy.assert_not_called() + process.assert_not_called() + self.assertEqual(arm.facts["host_counter_hz"], "19200000") + self.assertEqual(arm.facts["profile"], "unverified") + self.assertNotIn("profile_digest", arm.facts) + self.assertFalse((self.root / "arm-fingerprint.json").exists()) def test_cpu_check_verifies_the_profile_with_openvmm_fingerprint(self): fingerprint = self.root / "out" / "fingerprint.json" @@ -2598,6 +2698,14 @@ def registry(key: str, name: str) -> object: self.assertIsNone(doctor.host_cpu_signature()) def test_preflight_parses_openvmm_verification(self): + arm = doctor_context(self.root / "unavailable", "whp") + arm.architecture = "aarch64" + with patch.object(doctor.subprocess, "run") as process: + result = doctor.check_openvmm_preflight(arm) + self.assertFalse(result.passed) + self.assertIn("OpenVMM was not found", result.detail) + process.assert_not_called() + self.assertNotIn("tsc_hz", arm.facts) # The line format of OpenVMM's openvmm_entry verify.rs. line = ( "NVX-TIME-ABI-VERIFY: v=1 status=ok backend=kvm " @@ -2606,12 +2714,204 @@ def test_preflight_parses_openvmm_verification(self): "sync=CommonOffset\n" ) - def context_with_files(backend: str = "kvm") -> doctor.DoctorContext: + def context_with_files( + backend: str = "kvm", *, architecture: str = "x86_64" + ) -> doctor.DoctorContext: context = doctor_context(self.root, backend) + context.architecture = architecture for path in (context.openvmm, context.kernel, context.initrd): path.write_bytes(b"") + if architecture == "aarch64": + context.openvmm.write_bytes( + b"MZ" + + bytes(58) + + (64).to_bytes(4, "little") + + b"PE\0\0" + + (0xAA64).to_bytes(2, "little") + ) return context + arm_line = ( + "NVX-TIME-ABI-VERIFY: v=1 status=ok backend=whp architecture=aarch64 " + "cpu_profile=qualcomm.oryon-x1.v1 " + "cpu_profile_sha256=20960eafb1f3fb34304b876506e4345bd3fcfb626635d9927ac362898854394d " + "counter_hz=19200000 backend_usable_gpa_bits=39 configured_gpa_bits=36 " + "architectural_pa_bits=36 effective_parange=1 feature_bank_count=2 " + "feature_bank0=9214927272156348133 feature_bank1=1202595102644 " + "cpu_id_registers_verified=15 backend_readback=verified " + "effective_cpu=verified guest_started=false\n" + ) + arm = context_with_files("whp", architecture="aarch64") + arm.architecture = "aarch64" + with ( + patch.object( + doctor.subprocess, "run", return_value=completed(arm_line) + ) as process, + patch.object( + doctor, + "run_probe", + return_value=[ + ( + "cpu", + { + "architecture": "aarch64", + "counter": "cntvct_el0", + "counter_hz": "19200000", + }, + ) + ], + ), + patch.object(doctor, "host_cpu") as legacy, + ): + self.assertTrue(doctor.check_cpu(arm).passed) + self.assertTrue(doctor.check_openvmm_preflight(arm).passed) + process.assert_called_once() + legacy.assert_not_called() + self.assertNotIn("--cpu-fingerprint", process.call_args.args[0]) + self.assertEqual(arm.facts["profile"], "qualcomm.oryon-x1.v1") + for alias in ("tsc_hz", "native_tsc_hz", "lapic_hz", "sync"): + self.assertNotIn(alias, arm.facts) + # A second registered fixture proves this is not an Oryon/frequency gate. + with tempfile.TemporaryDirectory() as temporary: + catalog_root = Path(temporary) + catalog_path = ( + catalog_root + / "nvx-rs" + / "src" + / "host" + / "cli" + / "cpu_generations.json" + ) + catalog_path.parent.mkdir(parents=True) + original = json.loads( + ( + doctor.BuildConstants.REPO_ROOT + / "nvx-rs" + / "src" + / "host" + / "cli" + / "cpu_generations.json" + ).read_bytes() + ) + arm_identity = next( + document for document in original if "profile" in document + ) + another = { + **arm_identity, + "vendor": "example", + "sha256": "sha256:" + "b" * 64, + "profile": { + **arm_identity["profile"], + "id": "example.server-arm.v2", + "physical_address_bits": 40, + }, + } + catalog_path.write_text(json.dumps([*original, another]), encoding="utf-8") + other_report = ( + arm_line.replace("qualcomm.oryon-x1.v1", "example.server-arm.v2") + .replace(arm_identity["sha256"][7:], "b" * 64) + .replace("counter_hz=19200000", "counter_hz=24000000") + .replace("backend_usable_gpa_bits=39", "backend_usable_gpa_bits=48") + .replace("configured_gpa_bits=36", "configured_gpa_bits=40") + .replace("architectural_pa_bits=36", "architectural_pa_bits=40") + .replace("effective_parange=1", "effective_parange=2") + ) + other = context_with_files("whp", architecture="aarch64") + other.architecture = "aarch64" + other.facts["host_counter_hz"] = "24000000" + with ( + patch.object(doctor.BuildConstants, "REPO_ROOT", catalog_root), + patch.object( + doctor.subprocess, "run", return_value=completed(other_report) + ), + ): + result = doctor.check_openvmm_preflight(other) + self.assertTrue(result.passed, result.detail) + self.assertEqual(other.facts["profile"], "example.server-arm.v2") + for output, problem in ( + (arm_line.replace("v=1", "v=2"), "expected 1"), + ( + arm_line.replace("architecture=aarch64", "architecture=x86_64"), + "expected aarch64", + ), + ( + arm_line.replace("qualcomm.oryon-x1.v1", "qualcomm.host.v1"), + "no pinned ARM", + ), + (arm_line.replace("20960eaf", "00000000"), "profile digest"), + ( + arm_line.replace("counter_hz=19200000", "counter_hz=19200001"), + "CNTFRQ_EL0", + ), + ( + arm_line.replace("configured_gpa_bits=36", "configured_gpa_bits=40"), + "address-width", + ), + ( + arm_line.replace( + "backend_usable_gpa_bits=39", "backend_usable_gpa_bits=32" + ), + "address-width", + ), + ( + arm_line.replace("effective_parange=1", "effective_parange=2"), + "address-width", + ), + ( + arm_line.replace("feature_bank_count=2", "feature_bank_count=1"), + "expected 2", + ), + ( + arm_line.replace( + "feature_bank1=1202595102644", "feature_bank1=18446744073709551616" + ), + "bounded unsigned", + ), + ( + arm_line.replace( + "cpu_id_registers_verified=15", "cpu_id_registers_verified=14" + ), + "every pinned ID register", + ), + ( + arm_line.replace( + "backend_readback=verified", "backend_readback=missing" + ), + "expected verified", + ), + ( + arm_line.replace("guest_started=false", "guest_started=true"), + "expected false", + ), + (arm_line.rstrip() + " tsc_hz=19200000\n", "x86/UTC aliases"), + (arm_line + arm_line, "multiple verification"), + ( + "NVX-TIME-ABI-VERIFY: v=1 status=fail backend=whp code=E_PROFILE_UNKNOWN detail=unknown\n", + "E_PROFILE_UNKNOWN", + ), + ): + with self.subTest(arm=problem): + rejected = context_with_files("whp", architecture="aarch64") + rejected.architecture = "aarch64" + rejected.facts["host_counter_hz"] = "19200000" + with patch.object( + doctor.subprocess, "run", return_value=completed(output) + ): + result = doctor.check_openvmm_preflight(rejected) + self.assertFalse(result.passed, result.detail) + self.assertIn(problem, result.detail) + self.assertNotIn("profile_digest", rejected.facts) + emulated = context_with_files("whp", architecture="aarch64") + data = bytearray(emulated.openvmm.read_bytes()) + data[68:70] = (0x8664).to_bytes(2, "little") + emulated.openvmm.write_bytes(data) + with ( + patch.object(doctor.subprocess, "run") as process, + self.assertRaisesRegex(doctor.ScriptError, "expected native aarch64"), + ): + doctor.check_openvmm_preflight(emulated) + process.assert_not_called() + context = context_with_files() with patch.object( doctor.subprocess, "run", return_value=completed(line) @@ -2873,6 +3173,41 @@ def ci_context(backend: str = "kvm") -> doctor.DoctorContext: context.schedule = doctor.CI_SCHEDULE return context + arm = ci_context("whp") + arm.architecture = "aarch64" + counter = { + "architecture": "aarch64", + "counter": "cntvct_el0", + "counter_hz": "19200000", + } + arm_samples = records( + [19_200_000.0, 19_200_000.0], + interval_s=1.0, + bracket=0, + clock_hz=10_000_000, + resolution_ns=100.0, + names=("QueryPerformanceCounter", "QueryPerformanceCounter"), + ) + result = check(arm, [("cpu", counter), *arm_samples], windows=True) + self.assertTrue(result.passed, result.detail) + self.assertIn("cntvct_el0_hz=19200000", result.detail) + self.assertIn("host CNTFRQ_EL0's 19200000 Hz", result.detail) + self.assertEqual(arm.facts["host_counter_hz"], "19200000") + self.assertNotIn("tsc_hz", arm.facts) + for field, value in ( + ("architecture", "x86_64"), + ("counter", "tsc"), + ("counter_hz", "0"), + ("counter_hz", str(1 << 32)), + ): + with self.subTest(field=field, value=value): + with self.assertRaises(doctor.ScriptError): + check( + arm, + [("cpu", {**counter, field: value}), *arm_samples], + windows=True, + ) + steady = [2793437000.0 + jitter for jitter in (0, 200, -150, 100) * 3] context = doctor_context(self.root) context.facts["tsc_hz"] = "2793437000" @@ -3631,6 +3966,27 @@ def boot(cpus: int) -> str: # A newer guest also reports the boot check's CPU time. single = boot(1).replace("elapsed_us=1873", "elapsed_us=1873 cpu_us=1100") single += warp_output(pairs=0, offset=0) + arm = doctor_context(self.root, "whp") + arm.architecture = "aarch64" + arm_single = single.replace("tsc_hz=2194804000", "tsc_hz=24000000").replace( + "lapic_hz=1000000000", "lapic_hz=0" + ) + with ( + patch.object(doctor.os, "cpu_count", return_value=1), + patch.object(time_abi.platform, "machine", return_value="ARM64"), + patch.object( + doctor, "run_guest_script", return_value={"text": arm_single} + ) as guest, + patch.object(doctor, "check_utc") as utc, + contextlib.redirect_stdout(io.StringIO()), + ): + (arm_result,) = doctor.run_checks(arm, ("H6",)) + self.assertTrue(arm_result.passed, arm_result.detail) + guest.assert_called_once() + utc.assert_not_called() + self.assertEqual(arm.facts["counter_hz"], "24000000") + self.assertNotIn("sync", arm.facts) + self.assertNotIn("tsc_hz", arm.facts) with ( patch.object(doctor.os, "cpu_count", return_value=8), patch.object( @@ -3861,6 +4217,24 @@ def arithmetic(context: doctor.DoctorContext) -> doctor.CheckResult: 'check=H2 status=fail detail="float division by zero"', stdout.getvalue() ) self.assertIn("check=H5 status=pass", stdout.getvalue()) + for architecture in ("x86_64", "aarch64"): + for failed in ("H4", "H7"): + context = doctor_context(self.root, "whp") + context.architecture = architecture + checks = {check: passing(check) for check in doctor.CHECK_IDS} + checks[failed] = broken + with ( + self.subTest(architecture=architecture, failed=failed), + patch.dict(doctor.CHECKS, checks), + contextlib.redirect_stdout(io.StringIO()), + ): + results = doctor.run_checks(context, doctor.CHECK_IDS) + self.assertEqual( + [result.check for result in results], list(doctor.CHECK_IDS) + ) + self.assertEqual( + [result.check for result in results if not result.passed], [failed] + ) def test_warnings_reach_the_line_the_summary_and_ci_annotations(self): warning = "the host's clock correction uses 60% of the guest's 250 ppm budget" @@ -3901,10 +4275,12 @@ def warned(context: doctor.DoctorContext) -> doctor.CheckResult: def test_run_selects_the_cpu_fingerprint_or_runs_without_openvmm(self): seen: list[Path | None] = [] schedules: list[doctor.Schedule] = [] + artifacts: list[tuple[str, Path, Path]] = [] def cpu(context: doctor.DoctorContext) -> doctor.CheckResult: seen.append(context.fingerprint) schedules.append(context.schedule) + artifacts.append((context.architecture, context.kernel, context.initrd)) context.facts["surface_digest"] = "sha256:62" return doctor.CheckResult("H2", True, "ok") @@ -3939,6 +4315,26 @@ def cpu(context: doctor.DoctorContext) -> doctor.CheckResult: self.assertEqual(doctor.CI_SCHEDULE.rate_samples, 3) self.assertEqual(doctor.CI_SCHEDULE.rate_interval_ms, 1_000) self.assertIn("CPU surface digest: `sha256:62`", summary.read_text("utf-8")) + with ( + patch.object(doctor, "host_architecture", return_value="aarch64"), + patch.dict(doctor.CHECKS, {"H2": cpu}), + contextlib.redirect_stdout(io.StringIO()), + ): + arguments = doctor_parser().parse_args( + ["--backend", "whp", "--checks", "H2", "--no-openvmm"] + ) + self.assertEqual(doctor.run(arguments), 0) + self.assertEqual( + artifacts[-1], + ( + "aarch64", + doctor.BuildConstants.BUILD_DIR / "aarch64" / "Image", + doctor.BuildConstants.BUILD_DIR / "aarch64" / "initramfs.cpio.gz", + ), + ) + arguments.architecture = "x86_64" + with self.assertRaisesRegex(doctor.ScriptError, "native host architecture"): + doctor.run(arguments) arguments = doctor_parser().parse_args(["--backend", "kvm", "--no-openvmm"]) with self.assertRaisesRegex(doctor.ScriptError, "cannot run H3 and H6"): doctor.run(arguments) @@ -3949,7 +4345,11 @@ def cpu(context: doctor.DoctorContext) -> doctor.CheckResult: def test_builds_the_host_probe_once_per_source_version(self): target = doctor.probe_path(self.root) - self.assertRegex(target.name, r"^nvx-host-time-probe-[0-9a-f]{16}(\.exe)?$") + self.assertRegex( + target.name, r"^nvx-host-time-probe-x86_64-[0-9a-f]{16}(\.exe)?$" + ) + with patch.object(doctor, "host_architecture", return_value="aarch64"): + self.assertNotEqual(target, doctor.probe_path(self.root)) def rustc(command: list[str], **_kwargs: object): Path(command[command.index("-o") + 1]).write_bytes(b"probe") diff --git a/scripts/test_tool_versions.py b/scripts/test_tool_versions.py index b96dff16a..320743ac8 100644 --- a/scripts/test_tool_versions.py +++ b/scripts/test_tool_versions.py @@ -43,7 +43,7 @@ REPO_ROOT / ".github" / "copilot-instructions.md", ) -PLATFORMS = ("linux-x86_64", "windows-x86_64") +PLATFORMS = ("linux-x86_64", "windows-x86_64", "windows-aarch64") RELEASES = ("rust.toolchain", "cargo_nextest.version", "cargo_llvm_cov.version") ARTIFACT_TOOLS = ("rustup", "sccache", "actions_runner") # What the installers assume about each artifact: rustup's installer runs @@ -52,10 +52,13 @@ ARTIFACT_SUFFIXES = { ("rustup", "linux-x86_64"): "/rustup-init", ("rustup", "windows-x86_64"): "/rustup-init.exe", + ("rustup", "windows-aarch64"): "/rustup-init.exe", ("sccache", "linux-x86_64"): ".tar.gz", ("sccache", "windows-x86_64"): ".tar.gz", + ("sccache", "windows-aarch64"): ".tar.gz", ("actions_runner", "linux-x86_64"): ".tar.gz", ("actions_runner", "windows-x86_64"): ".zip", + ("actions_runner", "windows-aarch64"): ".zip", } # Words that name each pinned tool. A line that holds one of them and a # release hard-codes a pin. @@ -375,11 +378,11 @@ def _error(line: str) -> tuple[str, ...]: "tool_manifest_value", "tool_manifest_artifact", ) -# Resolves every pin of each manifest argument for both platforms. A failed +# Resolves every pin of each manifest argument for every platform. A failed # read ends only its subshell, so later cases still run. _SHELL_READER = """ for manifest in "$@"; do - for tool_platform in linux-x86_64 windows-x86_64; do + for tool_platform in linux-x86_64 windows-x86_64 windows-aarch64; do printf '### %s\\n' "$tool_platform" ( tool_manifest=$manifest @@ -410,7 +413,7 @@ def _error(line: str) -> tuple[str, ...]: if ($errors.Count -ne 0) { throw "setup script has parse errors" } -foreach ($name in "Read-ToolManifest", "Get-ToolManifestValue", "Get-ToolArtifact") { +foreach ($name in "Read-ToolManifest", "Get-ToolManifestValue", "Get-ToolArtifact", "Get-ToolPlatform") { $definition = $ast.Find({ param($node) $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and @@ -421,7 +424,7 @@ def _error(line: str) -> tuple[str, ...]: """ _POWERSHELL_READER = """ foreach ($path in $env:NVX_TEST_MANIFESTS.Split([char]10)) { - foreach ($platform in "linux-x86_64", "windows-x86_64") { + foreach ($platform in "linux-x86_64", "windows-x86_64", "windows-aarch64") { [Console]::Out.WriteLine("### $platform") try { $manifest = Read-ToolManifest $path @@ -755,11 +758,18 @@ def test_windows_setup_pins_its_tools_to_the_manifest(self): if not powershells: self.skipTest("PowerShell is unavailable") source = WINDOWS.read_text(encoding="utf-8") - start = source.index("\n$ToolPlatform = ") + 1 + start = source.index("\n$ToolManifest = ") + 1 block = source[start : source.index("\n\n", start) + 1] - self.assertIn('$ToolPlatform = "windows-x86_64"\n', block) + self.assertIn("$ToolPlatform = Get-ToolPlatform $NativeArchitecture\n", block) + native_architecture = ( + "[Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()" + ) + self.assertIn(native_architecture, block) + block = block.replace(native_architecture, "$env:NVX_TEST_ARCHITECTURE") self.assertEqual(block.count("$PSScriptRoot"), 1) block = block.replace("$PSScriptRoot", "$env:NVX_TEST_SETUP_DIRECTORY") + start = source.index("\n$VisualStudioToolsComponent = ") + 1 + block += source[start : source.index("\n$ExpectedRunnerLabels = ", start)] names = { "RustToolchain": "rust.toolchain", "CargoNextestVersion": "cargo_nextest.version", @@ -767,16 +777,34 @@ def test_windows_setup_pins_its_tools_to_the_manifest(self): } text = MANIFEST.read_text(encoding="utf-8") entries = parse_manifest(text) - expected = {name: entries[key] for name, key in names.items()} - for prefix, tool in ( - ("Rustup", "rustup"), - ("Sccache", "sccache"), - ("Runner", "actions_runner"), + expected_by_architecture: dict[str, tuple[str, dict[str, str]]] = {} + for architecture, tool_platform in ( + ("X64", "windows-x86_64"), + ("Arm64", "windows-aarch64"), ): - artifact = resolve_artifact(entries, tool, "windows-x86_64") - expected[f"{prefix}Version"] = artifact.version - expected[f"{prefix}Artifact"] = artifact.name - expected[f"{prefix}Sha256"] = artifact.sha256 + expected = {name: entries[key] for name, key in names.items()} + arm = architecture == "Arm64" + target_architecture = "aarch64" if arm else "x86_64" + expected.update( + VisualStudioToolsComponent="Microsoft.VisualStudio.Component.VC.Tools." + + ("ARM64" if arm else "x86.x64"), + VisualStudioArchitecture="arm64" if arm else "amd64", + RustHost=f"{target_architecture}-pc-windows-msvc", + RustTargets=f"{target_architecture}-unknown-none " + f"{target_architecture}-unknown-uefi", + GuestKernelName="Image" if arm else "vmlinux", + GuestBuildRelativeDirectory="build\\aarch64" if arm else "build", + ) + for prefix, tool in ( + ("Rustup", "rustup"), + ("Sccache", "sccache"), + ("Runner", "actions_runner"), + ): + artifact = resolve_artifact(entries, tool, tool_platform) + expected[f"{prefix}Version"] = artifact.version + expected[f"{prefix}Artifact"] = artifact.name + expected[f"{prefix}Sha256"] = artifact.sha256 + expected_by_architecture[architecture] = (tool_platform, expected) report = "".join( f'[Console]::Out.WriteLine("{name}=" + ${name})\n' for name in expected ) @@ -787,41 +815,51 @@ def test_windows_setup_pins_its_tools_to_the_manifest(self): " exit 1\n" "}\n" ) - cases = ( - ("canonical", text, None), - ( - "incomplete-linux", - _with_line(text, "sccache.artifacts.linux-x86_64.sha256", None), - None, - ), - ( - "incomplete-windows", - _with_line(text, "rustup.artifacts.windows-x86_64.sha256", None), - ("undefined", "rustup.artifacts.windows-x86_64.sha256"), - ), - ) for powershell in powershells: - for case, manifest, error in cases: - with self.subTest(powershell=Path(powershell).name, case=case): - directory = self.root / "windows" / case - _write_case(directory, manifest) - result = _run_powershell( - powershell, - script, - { - "NVX_TEST_SETUP_SCRIPT": str(WINDOWS), - "NVX_TEST_SETUP_DIRECTORY": str(directory), - }, - ) - if error is not None: - self.assertEqual(result.returncode, 1, result.stderr) - self.assertEqual(_error(result.stdout), error) - continue - self.assertEqual(result.returncode, 0, result.stderr) - self.assertEqual( - result.stdout.splitlines(), - [f"{name}={value}" for name, value in expected.items()], - ) + for architecture, ( + tool_platform, + expected, + ) in expected_by_architecture.items(): + missing_key = f"rustup.artifacts.{tool_platform}.sha256" + cases = ( + ("canonical", text, None), + ( + "incomplete-linux", + _with_line(text, "sccache.artifacts.linux-x86_64.sha256", None), + None, + ), + ( + "incomplete-windows", + _with_line(text, missing_key, None), + ("undefined", missing_key), + ), + ) + for case, manifest, error in cases: + with self.subTest( + powershell=Path(powershell).name, + architecture=architecture, + case=case, + ): + directory = self.root / "windows" / architecture / case + _write_case(directory, manifest) + result = _run_powershell( + powershell, + script, + { + "NVX_TEST_SETUP_SCRIPT": str(WINDOWS), + "NVX_TEST_SETUP_DIRECTORY": str(directory), + "NVX_TEST_ARCHITECTURE": architecture, + }, + ) + if error is not None: + self.assertEqual(result.returncode, 1, result.stderr) + self.assertEqual(_error(result.stdout), error) + continue + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual( + result.stdout.splitlines(), + [f"{name}={value}" for name, value in expected.items()], + ) def test_setups_never_let_rustup_update_itself(self): # A self-update would replace the pinned rustup with its latest @@ -1578,6 +1616,7 @@ def test_windows_extra_labels_keep_required_labels_and_reject_duplicates(self): try { [Console]::Out.WriteLine((Get-ExpectedRunnerLabels ` -AdditionalLabels $env:NVX_TEST_EXTRA_LABELS ` + -HostType $env:NVX_TEST_HOST_TYPE ` -BenchmarkRunner:($env:NVX_TEST_BENCHMARK -eq 'true'))) } catch { @@ -1606,9 +1645,21 @@ def test_windows_extra_labels_keep_required_labels_and_reject_duplicates(self): ("bad label", False, None), ) for powershell in powershells: - for extra, benchmark, expected in cases: + host_cases = [ + (extra, benchmark, expected, "virtual-machine") + for extra, benchmark, expected in cases + ] + [ + ("pool", False, "windows,whp,baremetal,general,pool", "baremetal"), + ("", True, "windows,whp,baremetal,benchmark", "baremetal"), + ("BAREMETAL", False, None, "baremetal"), + ("", False, None, "container"), + ] + for extra, benchmark, expected, host_type in host_cases: with self.subTest( - powershell=powershell, extra=extra, benchmark=benchmark + powershell=powershell, + extra=extra, + benchmark=benchmark, + host_type=host_type, ): result = _run_powershell( powershell, @@ -1617,6 +1668,7 @@ def test_windows_extra_labels_keep_required_labels_and_reject_duplicates(self): "NVX_TEST_SETUP_SCRIPT": str(WINDOWS), "NVX_TEST_EXTRA_LABELS": extra, "NVX_TEST_BENCHMARK": str(benchmark).lower(), + "NVX_TEST_HOST_TYPE": host_type, }, ) if expected is None: diff --git a/tests/runtime-adapter/README.md b/tests/runtime-adapter/README.md index 17a25768e..dc235c49e 100644 --- a/tests/runtime-adapter/README.md +++ b/tests/runtime-adapter/README.md @@ -38,7 +38,25 @@ Each configuration enables one side of `nvx`: | --- | --- | --- | --- | --- | | Protocol-only | none | none | `frame`, `root`, `probe`, `exec`, `template` | none | | Host-only | `--features host` | `host` | `frame`, `root`, `probe`, `exec`, `template`, `host`, `runtime`, `initramfs`, `staged`, `sharing`, `layered`, `capture`, `generations`, `hook` | `runtime-adapter-host` | -| Guest-only | `--features guest --target x86_64-unknown-linux-musl` | `guest` | `frame`, `root`, `probe`, `exec`, `template`, `guest`, `worker` | `runtime-adapter-guest`, a static executable | +| Guest-only | `--features guest --target x86_64-unknown-linux-musl` (or `aarch64-unknown-linux-musl`) | `guest` | `frame`, `root`, `probe`, `exec`, `template`, `guest`, `worker` | `runtime-adapter-guest`, a static executable | + +The consolidated runner's `--architecture` selects and checks the guest +agent's static ELF ISA and requires a matching native host. Its default remains +x86_64. ARM64 runtime runs require Windows/WHP and explicit `--cold-only`; +the runner uses the native ARM64 MSVC target for the host tests. + +Cold selection reuses the same registry, Cargo targets and assertions. Its +explicit target inventory classifies `template_capture`, `template_operations`, +`clone_start`, `host_session`, `staged_images` and `layered_launch` as portable +host-side checks; `vm_restart`, `vm_steps` and `vm_layered` as cold-domain +checks; and `vm_template` and `vm_clone` as deferred snapshot-domain checks. +Cold-domain targets include prelaunch refusals, so their test count is not a +VM-launch count. Every target remains in the exhaustive naming/ignored-test +check, including deferred targets. A stale classification, an unregistered +test, a zero-cold selection, or a selected test that does not run and pass +fails the command. `--check-only` checks this inventory and runs no scenario; +it is not native guest qualification. Normal x86 runs still select the full +suite. ## Framing From 03465b63b4c0c6865900efef244fcc3e029c3f85 Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:17:50 -0800 Subject: [PATCH 2/9] ci: trial one pinned OpenVMM evidence exception temporarily Admit only the authorized upstream-hosted run 43109699910 for PR 5045 and pin 38016, checking the live PR tuple and audited workflow blob. Keep trusted upstream admission and every selected latest-job verdict unchanged. Revert this isolated commit only after the coordinator ends the trial. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- doc/ci.md | 17 ++- scripts/nvx_tools/openvmm_ci.py | 86 ++++++++++++- scripts/test_nvx_tools.py | 219 +++++++++++++++++++++++++++++++- 3 files changed, 316 insertions(+), 6 deletions(-) diff --git a/doc/ci.md b/doc/ci.md index 843cf6519..cf7c9d8f5 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -1828,8 +1828,21 @@ revision, in a run of either workflow whose head is the revision in All six x86 requirements remain, and the standalone command still defaults to x86-only coverage. Both ISAs use the same latest-attempt assessment and missing/pending/failure rules; a skipped ARM job is not a pass. This extends -coverage, not trust: the existing fork-headed run rejection remains intact, -including for the selected PR until an exception is explicitly approved. +coverage, not trust, except for the following explicitly authorized trial. +**TEMPORARY:** the isolated Phase 3 trial admits only upstream-hosted run +`43109699910` of microsoft/openvmm#5045, while that PR is open/unmerged with +head `38016f6637f0c61fb55c9ee31033ceec428e346c` in +`ahuja-gautam/openvmm:openvmm-arm64-microvm-dev-20261111`, targeting +`microsoft/openvmm:feature/microvm/dev`. Its event must be `pull_request` and +its workflow `.github/workflows/openvmm-pr.yaml`, whose file at that exact +pin must have the audited Git blob `2cabb910cd6d8c974b809a30870502f69ac68e83` +(421776 bytes), identical to the workflow reviewed at upstream +`174da3a0d236b4b01182a8d73a47598e4fcb1eca`. No moving base SHA is trusted. +Missing, malformed or mismatched proof fails closed. All selected latest-job +requirements remain mandatory; failed, skipped or missing jobs are not waived, +and no other fork/run/PR/revision is admitted. The coordinator will direct a +separate revert after the trial, not while its run is active. The ordinary +trusted-upstream path and default six-job x86 selection are unchanged. A pull request's run tests GitHub's merge of the pull request into the branch, which holds the tree of the head while the head descends from the branch, as landing it requires. The job reads the pin from diff --git a/scripts/nvx_tools/openvmm_ci.py b/scripts/nvx_tools/openvmm_ci.py index ec94c583a..76348f2c0 100644 --- a/scripts/nvx_tools/openvmm_ci.py +++ b/scripts/nvx_tools/openvmm_ci.py @@ -10,7 +10,8 @@ workflow, and waits while they run. The gates' other jobs, such as the VMM tests on TDX and SEV-SNP hosts, test OpenHCL and confidential VMs, which NVX does not use. ARM selection adds the existing native Windows ARM unit and VMM jobs, -without removing x86 coverage or changing workflow/repository trust. +without removing x86 coverage. A temporary, explicitly approved trial admits +one fork-headed run only after checking its pinned PR and workflow blob. See doc/ci.md, "OpenVMM CI". """ @@ -50,6 +51,14 @@ "unit tests [aarch64-windows]", "run vmm-tests [aarch64-windows]", ) +# TEMPORARY: revert this isolated trial after the coordinator records its outcome. +_TRIAL_REVISION = "38016f6637f0c61fb55c9ee31033ceec428e346c" +_TRIAL_RUN = 43109699910 +_TRIAL_PR = 5045 +_TRIAL_HEAD_REPOSITORY = "ahuja-gautam/openvmm" +_TRIAL_HEAD_REF = "openvmm-arm64-microvm-dev-20261111" +_TRIAL_WORKFLOW = ".github/workflows/openvmm-pr.yaml" +_TRIAL_WORKFLOW_BLOB = "2cabb910cd6d8c974b809a30870502f69ac68e83" # How long the check waits between two looks at runs that have not finished. # OpenVMM's gates take one and a half to two hours, so a look every five # minutes adds little to a wait, and keeps a wait's requests, three a look, @@ -65,6 +74,8 @@ class OpenVMMCiApi(Protocol): """The GitHub REST operation that the check uses.""" + def get(self, path: str, params: Mapping[str, str] | None = None) -> object: ... + def get_all( self, path: str, @@ -121,6 +132,76 @@ def _text(document: Mapping[str, object], field: str) -> str: return value +def _trial_mapping(value: object) -> Mapping[str, object]: + if not isinstance(value, Mapping): + raise ScriptError("GitHub returned invalid temporary OpenVMM CI trial proof") + return cast(Mapping[str, object], value) + + +def _temporary_fork_run( + api: OpenVMMCiApi, run: Mapping[str, object], revision: str +) -> bool: + """Admit only the authorized run, with live PR and immutable workflow proof.""" + if revision != _TRIAL_REVISION or run.get("id") != _TRIAL_RUN: + return False + for evidence in ( + run, + _trial_mapping( + api.get(f"/repos/{OPENVMM_REPOSITORY}/actions/runs/{_TRIAL_RUN}") + ), + ): + if ( + type(evidence.get("id")) is not int + or evidence.get("id") != _TRIAL_RUN + or evidence.get("head_sha") != _TRIAL_REVISION + or evidence.get("head_branch") != _TRIAL_HEAD_REF + or evidence.get("event") != "pull_request" + or evidence.get("path") != _TRIAL_WORKFLOW + or _trial_mapping(evidence.get("repository")).get("full_name") + != OPENVMM_REPOSITORY + or _trial_mapping(evidence.get("head_repository")).get("full_name") + != _TRIAL_HEAD_REPOSITORY + ): + raise ScriptError("Temporary OpenVMM CI trial run proof does not match") + pull = _trial_mapping(api.get(f"/repos/{OPENVMM_REPOSITORY}/pulls/{_TRIAL_PR}")) + head = _trial_mapping(pull.get("head")) + base = _trial_mapping(pull.get("base")) + if ( + type(pull.get("number")) is not int + or pull.get("number") != _TRIAL_PR + or pull.get("state") != "open" + or pull.get("merged") is not False + or head.get("sha") != _TRIAL_REVISION + or head.get("ref") != _TRIAL_HEAD_REF + or _trial_mapping(head.get("repo")).get("full_name") != _TRIAL_HEAD_REPOSITORY + or base.get("ref") != "feature/microvm/dev" + or _trial_mapping(base.get("repo")).get("full_name") != OPENVMM_REPOSITORY + ): + raise ScriptError("Temporary OpenVMM CI trial PR proof does not match") + workflow = _trial_mapping( + api.get( + f"/repos/{OPENVMM_REPOSITORY}/contents/{_TRIAL_WORKFLOW}", + {"ref": _TRIAL_REVISION}, + ) + ) + if ( + workflow.get("type") != "file" + or workflow.get("path") != _TRIAL_WORKFLOW + or workflow.get("sha") != _TRIAL_WORKFLOW_BLOB + or type(workflow.get("size")) is not int + or workflow.get("size") != 421776 + ): + raise ScriptError("Temporary OpenVMM CI trial workflow proof does not match") + print( + "::warning::TEMPORARY OpenVMM CI evidence trial: admitting only " + f"{OPENVMM_REPOSITORY} run {_TRIAL_RUN}, PR {_TRIAL_PR}, " + f"head {_TRIAL_REVISION}, workflow blob {_TRIAL_WORKFLOW_BLOB}; " + "all selected latest-attempt jobs must still pass", + flush=True, + ) + return True + + def openvmm_ci_runs(api: OpenVMMCiApi, revision: str) -> list[OpenVMMRun]: """Return the runs of OpenVMM's checkin gates whose head is `revision` in OpenVMM's repository, with the latest attempt of each of their jobs.""" @@ -142,7 +223,8 @@ def openvmm_ci_runs(api: OpenVMMCiApi, revision: str) -> list[OpenVMMRun]: or cast(Mapping[str, object], head_repository).get("full_name") != OPENVMM_REPOSITORY ): - continue + if not _temporary_fork_run(api, run, revision): + continue identifier = run.get("id") if not isinstance(identifier, int) or isinstance(identifier, bool): raise ScriptError("GitHub returned a workflow run without an id") diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index 0caa671a1..81b74c3aa 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -5553,10 +5553,28 @@ class _FakeOpenVMMCiApi: jobs of each run, one look after another, raises each look that is an exception instead, and records each request.""" - def __init__(self, *looks: _OpenVMMLook | Exception) -> None: + def __init__( + self, + *looks: _OpenVMMLook | Exception, + revision: str = _OPENVMM_REVISION, + documents: Mapping[str, Any] | None = None, + ) -> None: self.looks = list(looks) self.look = -1 self.requests: list[str] = [] + self.revision = revision + self.documents = dict(documents or {}) + + def get(self, path: str, params: Mapping[str, str] | None = None) -> object: + self.requests.append(f"get {path}") + if "/contents/" in path: + assert params == {"ref": self.revision}, params + else: + assert params is None, params + document = self.documents[path] + if isinstance(document, Exception): + raise document + return document def get_all( self, @@ -5568,7 +5586,7 @@ def get_all( ) -> list[object]: assert deadline is None if path == "/repos/microsoft/openvmm/actions/runs": - assert params == {"head_sha": _OPENVMM_REVISION}, params + assert params == {"head_sha": self.revision}, params assert key == "workflow_runs", key self.look = min(self.look + 1, len(self.looks) - 1) self.requests.append("runs") @@ -6089,6 +6107,203 @@ def test_arm_coverage_requires_both_existing_jobs_without_trusting_forks(self): sum(line.startswith("passed:") for line in verdicts), 7 ) + @staticmethod + def _trial_api() -> _FakeOpenVMMCiApi: + revision = "38016f6637f0c61fb55c9ee31033ceec428e346c" + identifier = 43109699910 + run = { + **_openvmm_run( + identifier, + head_sha=revision, + head_repository="ahuja-gautam/openvmm", + ), + "repository": {"full_name": "microsoft/openvmm"}, + "head_branch": "openvmm-arm64-microvm-dev-20261111", + "event": "pull_request", + "conclusion": "failure", + } + jobs = _openvmm_gate_jobs(identifier) + [ + _openvmm_job(identifier, name) + for name in openvmm_ci.OPENVMM_CI_ARM64_REQUIRED_JOBS + ] + return _FakeOpenVMMCiApi( + ([run], {identifier: jobs}), + revision=revision, + documents={ + f"/repos/microsoft/openvmm/actions/runs/{identifier}": dict(run), + "/repos/microsoft/openvmm/pulls/5045": { + "number": 5045, + "state": "open", + "merged": False, + "head": { + "sha": revision, + "ref": "openvmm-arm64-microvm-dev-20261111", + "repo": {"full_name": "ahuja-gautam/openvmm"}, + }, + "base": { + "ref": "feature/microvm/dev", + "repo": {"full_name": "microsoft/openvmm"}, + "sha": "9f10ce7a8e9632d79b1d26f5a18ea899481856bf", + }, + }, + "/repos/microsoft/openvmm/contents/.github/workflows/openvmm-pr.yaml": { + "type": "file", + "path": ".github/workflows/openvmm-pr.yaml", + "sha": "2cabb910cd6d8c974b809a30870502f69ac68e83", + "size": 421776, + }, + }, + ) + + def test_temporary_trial_admits_only_pinned_proof_with_all_selected_jobs(self): + for architecture, count in (("x86_64", 6), ("aarch64", 8)): + with self.subTest(architecture=architecture): + api = self._trial_api() + args = nvx.parse_args( + [ + "check-openvmm-ci", + "--revision", + api.revision, + "--architecture", + architecture, + ] + ) + with ( + patch.object(openvmm_ci, "GitHubClient", return_value=api), + contextlib.redirect_stdout(io.StringIO()) as output, + ): + args.handler(args) + self.assertEqual(output.getvalue().count("passed:"), count) + self.assertIn("TEMPORARY OpenVMM CI evidence trial", output.getvalue()) + self.assertEqual(api.requests[-1], "jobs 43109699910") + + def test_temporary_trial_rejects_mismatched_or_malformed_proof(self): + run_path = "/repos/microsoft/openvmm/actions/runs/43109699910" + pull_path = "/repos/microsoft/openvmm/pulls/5045" + workflow_path = ( + "/repos/microsoft/openvmm/contents/.github/workflows/openvmm-pr.yaml" + ) + cases: tuple[tuple[str, tuple[str, ...], object], ...] = ( + (run_path, ("id",), 43109699911), + (run_path, ("id",), 43109699910.0), + (run_path, ("head_sha",), "b" * 40), + (run_path, ("head_branch",), "another-branch"), + (run_path, ("head_repository", "full_name"), "another/openvmm"), + (run_path, ("repository", "full_name"), "ahuja-gautam/openvmm"), + (run_path, ("event",), "pull_request_target"), + (run_path, ("path",), ".github/workflows/openvmm-ci.yaml"), + (run_path, ("head_repository",), None), + (pull_path, ("number",), 5046), + (pull_path, ("number",), 5045.0), + (pull_path, ("state",), "closed"), + (pull_path, ("merged",), True), + (pull_path, ("merged",), None), + (pull_path, ("head", "sha"), "b" * 40), + (pull_path, ("head", "ref"), "another-branch"), + (pull_path, ("head", "repo", "full_name"), "another/openvmm"), + (pull_path, ("base", "repo", "full_name"), "another/openvmm"), + (pull_path, ("base", "ref"), "main"), + (pull_path, ("head",), []), + (workflow_path, ("sha",), "b" * 40), + (workflow_path, ("sha",), None), + (workflow_path, ("type",), "symlink"), + (workflow_path, ("path",), ".github/workflows/another.yaml"), + (workflow_path, ("size",), 0), + (workflow_path, ("size",), 421776.0), + ) + for path, fields, value in cases: + with self.subTest(path=path, fields=fields, value=value): + api = self._trial_api() + document = api.documents[path] + for field in fields[:-1]: + document = document[field] + document[fields[-1]] = value + with self.assertRaises(common.ScriptError): + openvmm_ci.openvmm_ci_runs(api, api.revision) + self.assertNotIn("jobs 43109699910", api.requests) + malformed: tuple[object, ...] = ( + None, + {}, + common.ScriptError("proof unavailable"), + ) + for path in (run_path, pull_path, workflow_path): + for document in malformed: + with self.subTest(path=path, document=document): + api = self._trial_api() + api.documents[path] = document + with self.assertRaises(common.ScriptError): + openvmm_ci.check_openvmm_ci(api, api.revision, wait_seconds=0) + self.assertNotIn("jobs 43109699910", api.requests) + + def test_temporary_trial_never_admits_another_listed_run_or_revision(self): + for changes, revision in ( + ({"id": 43109699911}, None), + ({"id": "43109699910"}, None), + ({"head_sha": "b" * 40}, None), + ({"path": ".github/workflows/openvmm-pr.yaml@refs/heads/main"}, None), + ({}, "b" * 40), + ): + with self.subTest(changes=changes, revision=revision): + api = self._trial_api() + look = api.looks[0] + assert not isinstance(look, Exception) + run = dict(look[0][0]) + run.update(changes) + api.looks[0] = ([run], look[1]) + if revision is not None: + api.revision = revision + if changes.get("head_sha") or changes.get("path"): + with self.assertRaises(common.ScriptError): + openvmm_ci.openvmm_ci_runs(api, api.revision) + else: + self.assertEqual(openvmm_ci.openvmm_ci_runs(api, api.revision), []) + self.assertNotIn("jobs 43109699910", api.requests) + + def test_temporary_trial_preserves_every_required_latest_job_verdict(self): + required = ( + openvmm_ci.OPENVMM_CI_REQUIRED_JOBS + + openvmm_ci.OPENVMM_CI_ARM64_REQUIRED_JOBS + ) + for target in required: + for state in ("failure", "skipped", "missing", "pending"): + with self.subTest(target=target, state=state): + api = self._trial_api() + look = api.looks[0] + assert not isinstance(look, Exception) + jobs: list[Mapping[str, Any]] = [] + for job in look[1][43109699910]: + if openvmm_ci.covers(job["name"], target): + if state == "missing": + continue + job = { + **job, + "status": "in_progress" + if state == "pending" + else "completed", + "conclusion": None if state == "pending" else state, + } + jobs.append(job) + api.looks[0] = (look[0], {43109699910: jobs}) + args = nvx.parse_args( + [ + "check-openvmm-ci", + "--revision", + api.revision, + "--architecture", + "aarch64", + ] + ) + with ( + patch.object(openvmm_ci, "GitHubClient", return_value=api), + contextlib.redirect_stdout(io.StringIO()) as output, + self.assertRaises(common.ScriptError), + ): + args.handler(args) + expected = "failed" if state in ("failure", "skipped") else state + self.assertIn(f"{expected}: {target}:", output.getvalue()) + self.assertEqual(output.getvalue().count("passed:"), 7) + self.assertEqual(api.requests[-1], "jobs 43109699910") + def test_command_checks_the_pin_with_any_token(self): args = nvx.parse_args(["check-openvmm-ci"]) self.assertEqual(args.architecture, "x86_64") From d0e72070e9a9225e2cf0150ff2d9bd4f499944ec Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:20:33 -0800 Subject: [PATCH 3/9] ci: bind correctness arguments without Bash on Windows Run the existing shared Python binder directly with the native Python custom shell. Preserve its Python AST, environment, guards, argument JSON and step outputs. Execute the maintained binder tests with an empty PATH so a Bash dependency cannot be hidden by the test harness. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/run-nvx-microvm-tests.yml | 4 +- doc/ci.md | 3 + scripts/test_nvx_tools.py | 138 +++++++++++++++++++- 3 files changed, 138 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-nvx-microvm-tests.yml b/.github/workflows/run-nvx-microvm-tests.yml index 0bd4b18f4..ba6f92000 100644 --- a/.github/workflows/run-nvx-microvm-tests.yml +++ b/.github/workflows/run-nvx-microvm-tests.yml @@ -157,7 +157,7 @@ jobs: - name: Bind shared correctness arguments id: correctness - shell: bash + shell: ${{ runner.os == 'Windows' && 'python {0}' || 'python3 {0}' }} env: ARCHITECTURE: ${{ inputs.architecture }} BACKEND: ${{ inputs.backend }} @@ -177,7 +177,6 @@ jobs: SHARD_COUNT: ${{ inputs.shard-count }} RESULT_ID: ${{ inputs.result-id }} run: | - ${{ runner.os == 'Windows' && 'python' || 'python3' }} - <<'PY' import json import os import re @@ -243,7 +242,6 @@ jobs: "workload_artifacts": workload_artifacts}), encoding="utf-8", ) - PY # The guest artifacts that the steps below boot or read. Every job # qualifies its runner with the kernel and the Alpine initramfs, the diff --git a/doc/ci.md b/doc/ci.md index cf7c9d8f5..18ab27026 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -1069,6 +1069,9 @@ ISA, scenarios, processors, memory, root and cycles, downloads only the guest components those selections read, and retains recursive per-cycle durations and distinct ISA/root/cell failure artifacts. No ARM duration partition has been measured; ARM cold reports cannot rebalance the existing full x86 shards. +The shared argument binder runs directly with the native Python custom shell +(`python` on Windows, `python3` on Linux), so self-hosted Windows runners need +no Bash to validate the same inputs and emit the same JSON and step outputs. ARM producer, CLI, VMM, cold and adapter results feed `Required status check`; the repetition result is required for full runs and explicitly skipped for diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index 81b74c3aa..d9ffde72d 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -630,12 +630,22 @@ def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, **{name: _resolve_inputs(value, inputs) for name, value in step["env"].items()}, "RUNNER_OS": system, "PYTHONPATH": str(BuildConstants.REPO_ROOT / "scripts"), + "PATH": "", } - script = step["run"].split("<<'PY'\n", 1)[1].rsplit("\nPY", 1)[0] + shell = shlex.split( + _interpolate_expressions(step["shell"], {"runner": {"os": system}}, {}) + ) + expected = "python" if system == "Windows" else "python3" + if shell != [expected, "{0}"]: + raise AssertionError(f"binder needs the native Python custom shell: {shell}") with tempfile.TemporaryDirectory() as directory: - environment["GITHUB_OUTPUT"] = str(Path(directory) / "outputs") + output = Path(directory) / "outputs" + environment["GITHUB_OUTPUT"] = str(output) + script = Path(directory) / "correctness arguments.py" + script.write_text(step["run"], encoding="utf-8") + # Use this interpreter for the runner's Python alias, with no shell tools. result = subprocess.run( - [sys.executable, "-c", script], + [sys.executable, str(script)], cwd=directory, env=environment, capture_output=True, @@ -645,11 +655,17 @@ def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, ) if result.returncode: raise AssertionError(result.stderr) - return json.loads( + selected = json.loads( (Path(directory) / "build" / "nvx-correctness-arguments.json").read_text( encoding="utf-8" ) ) + expected_output = ( + f"workload-artifacts={str(selected['workload_artifacts']).lower()}\n" + ) + if output.read_text(encoding="utf-8") != expected_output: + raise AssertionError("binder's workload-artifacts output does not match") + return selected def _runner_system(runner: str | list[str]) -> str: @@ -11008,6 +11024,120 @@ def uploads_in(upload: Mapping[str, Any], leg: Mapping[str, Any]) -> bool: ], ) + def test_correctness_binder_executes_without_shell_tools_on_each_platform(self): + cases = ( + ( + "Linux", + {"backend": "kvm", "shard": 1, "shard-count": 2}, + [ + "test-microvm", + "--backend", + "kvm", + "--architecture", + "x86_64", + "--guest", + "alpine", + "--shard", + "1/2", + ], + 1, + "build/test-results/microvm-kvm", + False, + ), + ( + "Windows", + {"backend": "whp", "guests-and-sandboxes": True}, + [ + "test-microvm", + "--backend", + "whp", + "--architecture", + "x86_64", + "--guest", + "alpine", + ], + 1, + "build/test-results/microvm-whp", + True, + ), + ( + "Windows", + { + "backend": "whp", + "architecture": "aarch64", + "cold-only": True, + "scenarios": '["sandbox-lifecycle"]', + "processors": "[1]", + "start-stop-cycles": 10, + "memory-mib": 1024, + "cycles": 2, + "managed-root": "scratch", + "output-dir": "build/test-results/trial-arm", + "result-id": "scratch-10", + }, + [ + "test-microvm", + "--backend", + "whp", + "--architecture", + "aarch64", + "--guest", + "alpine", + "--scenario", + "sandbox-lifecycle", + "--processors", + "1", + "--start-stop-cycles", + "10", + "--memory-mib", + "1024", + "--cold-only", + "--managed-root", + "scratch", + ], + 2, + "build/test-results/trial-arm", + True, + ), + ) + for system, inputs, arguments, cycles, directory, artifacts in cases: + with self.subTest(system=system, inputs=inputs): + self.assertEqual( + _correctness_arguments(inputs, system), + { + "arguments": arguments, + "cycles": cycles, + "output_dir": directory, + "workload_artifacts": artifacts, + }, + ) + + def test_correctness_binder_retains_input_guards_without_shell_tools(self): + cases: tuple[tuple[str, Mapping[str, Any], str], ...] = ( + ("Windows", {"scenarios": "{}"}, "JSON string array"), + ("Windows", {"processors": "[true]"}, "JSON integer array"), + ("Windows", {"result-id": "../cell"}, "artifact-safe"), + ("Windows", {"cycles": 0}, "positive integer"), + ("Linux", {"cycles": 2}, "serial cycles require Windows"), + ("Windows", {"memory-mib": -1}, "must be nonnegative"), + ( + "Windows", + {"architecture": "aarch64"}, + "explicit Windows/WHP cold scope", + ), + ( + "Windows", + {"architecture": "aarch64", "cold-only": True}, + "explicit existing scenarios", + ), + ) + for system, inputs, message in cases: + with ( + self.subTest(system=system, inputs=inputs), + self.assertRaisesRegex(AssertionError, message), + ): + _correctness_arguments({"backend": "whp"} | dict(inputs), system) + def test_ci_runs_each_default_microvm_suite_in_its_shards(self): # #696: each backend runs its default suite in the shards that # microvm_shards.json plans, one leg of the default-suite job's matrix From 21c4d223997cf8a66413b3fc07b1b552cac0571d Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:28:08 -0800 Subject: [PATCH 4/9] ci: select the Python shell from the declared backend GitHub cannot resolve runner context while validating a step shell. Use the existing backend input, whose WHP jobs run on Windows, to select native Python. Restrict the regression harness to the same available input context and use the Linux backend for the Linux refusal case. Retain the failed startup run as evidence; do not rewrite either isolated commit. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/run-nvx-microvm-tests.yml | 2 +- scripts/test_nvx_tools.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-nvx-microvm-tests.yml b/.github/workflows/run-nvx-microvm-tests.yml index ba6f92000..798b6434a 100644 --- a/.github/workflows/run-nvx-microvm-tests.yml +++ b/.github/workflows/run-nvx-microvm-tests.yml @@ -157,7 +157,7 @@ jobs: - name: Bind shared correctness arguments id: correctness - shell: ${{ runner.os == 'Windows' && 'python {0}' || 'python3 {0}' }} + shell: ${{ inputs.backend == 'whp' && 'python {0}' || 'python3 {0}' }} env: ARCHITECTURE: ${{ inputs.architecture }} BACKEND: ${{ inputs.backend }} diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index d9ffde72d..2a44f2460 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -632,9 +632,7 @@ def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, "PYTHONPATH": str(BuildConstants.REPO_ROOT / "scripts"), "PATH": "", } - shell = shlex.split( - _interpolate_expressions(step["shell"], {"runner": {"os": system}}, {}) - ) + shell = shlex.split(_interpolate_expressions(step["shell"], {"inputs": inputs}, {})) expected = "python" if system == "Windows" else "python3" if shell != [expected, "{0}"]: raise AssertionError(f"binder needs the native Python custom shell: {shell}") @@ -11136,7 +11134,10 @@ def test_correctness_binder_retains_input_guards_without_shell_tools(self): self.subTest(system=system, inputs=inputs), self.assertRaisesRegex(AssertionError, message), ): - _correctness_arguments({"backend": "whp"} | dict(inputs), system) + _correctness_arguments( + {"backend": "whp" if system == "Windows" else "kvm"} | dict(inputs), + system, + ) def test_ci_runs_each_default_microvm_suite_in_its_shards(self): # #696: each backend runs its default suite in the shards that From 4ed3ef0ab0afc5563f7da6706eeae85e2e1caf08 Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:31:53 -0800 Subject: [PATCH 5/9] ci: use literal native shells for shared correctness binding GitHub also rejects inputs context in the shell field. Use two mutually exclusive OS-guarded literal Python shells, sharing one anchored script and environment. Preserve the binder AST and JSON and coalesce the selected step output for its existing artifact consumer. Retain both failed startup receipts; do not rewrite history. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/run-nvx-microvm-tests.yml | 16 ++++++++++++---- doc/ci.md | 2 ++ scripts/test_nvx_tools.py | 21 ++++++++++++++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-nvx-microvm-tests.yml b/.github/workflows/run-nvx-microvm-tests.yml index 798b6434a..f93c8be49 100644 --- a/.github/workflows/run-nvx-microvm-tests.yml +++ b/.github/workflows/run-nvx-microvm-tests.yml @@ -157,8 +157,9 @@ jobs: - name: Bind shared correctness arguments id: correctness - shell: ${{ inputs.backend == 'whp' && 'python {0}' || 'python3 {0}' }} - env: + if: runner.os == 'Windows' + shell: python {0} + env: &correctness-environment ARCHITECTURE: ${{ inputs.architecture }} BACKEND: ${{ inputs.backend }} SCENARIOS: ${{ inputs.scenarios }} @@ -176,7 +177,7 @@ jobs: SHARD: ${{ inputs.shard }} SHARD_COUNT: ${{ inputs.shard-count }} RESULT_ID: ${{ inputs.result-id }} - run: | + run: &correctness-script | import json import os import re @@ -243,6 +244,13 @@ jobs: encoding="utf-8", ) + - name: Bind shared correctness arguments on Linux + id: correctness-linux + if: runner.os != 'Windows' + shell: python3 {0} + env: *correctness-environment + run: *correctness-script + # The guest artifacts that the steps below boot or read. Every job # qualifies its runner with the kernel and the Alpine initramfs, the # shards of the default suite boot only those, and the debug-kernel jobs @@ -286,7 +294,7 @@ jobs: # The layer, its manifest, and the sandbox scratch template, which the # public sandbox scenarios of an unsharded default run read. - name: Download Ubuntu distro layer for the whole default run - if: ${{ !inputs.guests-and-sandboxes && !inputs.runtime-adapter && !inputs.debug-kernel && !inputs.shard && steps.correctness.outputs.workload-artifacts == 'true' }} + if: ${{ !inputs.guests-and-sandboxes && !inputs.runtime-adapter && !inputs.debug-kernel && !inputs.shard && (steps.correctness.outputs.workload-artifacts || steps.correctness-linux.outputs.workload-artifacts) == 'true' }} uses: actions/download-artifact@v8 with: name: ${{ inputs.architecture == 'aarch64' && 'guest-aarch64-ubuntu-distro' || 'guest-ubuntu-distro' }} diff --git a/doc/ci.md b/doc/ci.md index 18ab27026..006b39ac2 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -1072,6 +1072,8 @@ been measured; ARM cold reports cannot rebalance the existing full x86 shards. The shared argument binder runs directly with the native Python custom shell (`python` on Windows, `python3` on Linux), so self-hosted Windows runners need no Bash to validate the same inputs and emit the same JSON and step outputs. +OS-guarded steps share one anchored script and environment, with literal shell +commands rather than expressions in the workflow's shell field. ARM producer, CLI, VMM, cold and adapter results feed `Required status check`; the repetition result is required for full runs and explicitly skipped for diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index 2a44f2460..f1cf22250 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -615,11 +615,15 @@ def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, BuildConstants.REPO_ROOT / ".github" / "workflows" / "run-nvx-microvm-tests.yml" ) workflow = yaml.safe_load(path.read_text(encoding="utf-8")) - step = next( + selected_steps = [ step for step in workflow["jobs"]["test"]["steps"] - if step["name"] == "Bind shared correctness arguments" - ) + if step["name"].startswith("Bind shared correctness arguments") + and _evaluate_expression(step["if"], {"runner": {"os": system}}, {}) + ] + if len(selected_steps) != 1: + raise AssertionError(f"expected exactly one native binder on {system}") + step = selected_steps[0] defaults = { name: definition.get("default") for name, definition in workflow[True]["workflow_call"]["inputs"].items() @@ -632,7 +636,7 @@ def _correctness_arguments(inputs: Mapping[str, Any], system: str) -> dict[str, "PYTHONPATH": str(BuildConstants.REPO_ROOT / "scripts"), "PATH": "", } - shell = shlex.split(_interpolate_expressions(step["shell"], {"inputs": inputs}, {})) + shell = shlex.split(step["shell"]) expected = "python" if system == "Windows" else "python3" if shell != [expected, "{0}"]: raise AssertionError(f"binder needs the native Python custom shell: {shell}") @@ -6676,6 +6680,13 @@ def consume( "steps.correctness.outputs.workload-artifacts": str( selected["workload_artifacts"] ).lower() + if context["runner.os"] == "Windows" + else "", + "steps.correctness-linux.outputs.workload-artifacts": str( + selected["workload_artifacts"] + ).lower() + if context["runner.os"] != "Windows" + else "", } for step in steps: arguments = step.get("with", {}) @@ -10858,7 +10869,7 @@ def selected( "inputs.runtime-adapter": adapter, "!inputs.runtime-adapter": single or not adapter, "!inputs.shard": not sharded, - "steps.correctness.outputs.workload-artifacts == 'true'": True, + "(steps.correctness.outputs.workload-artifacts || steps.correctness-linux.outputs.workload-artifacts) == 'true'": True, "(inputs.guests-and-sandboxes || inputs.guest == 'ubuntu')": guests, } chosen: list[str] = [] From 9f732c0237b308525acafc98044788b8988b0f94 Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:59:05 -0800 Subject: [PATCH 6/9] ci: revert the temporary pinned evidence exception This reverts commit 19d29ebc7a6b4d825fb070317f4d534be5d59b3c after the coordinator ended the bounded trial. Restore the exact pretrial evidence policy, tests and documentation while retaining all permanent native-Python correctness binder repairs. The immutable a0 workflow-dispatch evidence remains valid for that historical branch-only trial; do not cancel or redispatch it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- doc/ci.md | 17 +-- scripts/nvx_tools/openvmm_ci.py | 86 +------------ scripts/test_nvx_tools.py | 219 +------------------------------- 3 files changed, 6 insertions(+), 316 deletions(-) diff --git a/doc/ci.md b/doc/ci.md index 006b39ac2..739156533 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -1833,21 +1833,8 @@ revision, in a run of either workflow whose head is the revision in All six x86 requirements remain, and the standalone command still defaults to x86-only coverage. Both ISAs use the same latest-attempt assessment and missing/pending/failure rules; a skipped ARM job is not a pass. This extends -coverage, not trust, except for the following explicitly authorized trial. -**TEMPORARY:** the isolated Phase 3 trial admits only upstream-hosted run -`43109699910` of microsoft/openvmm#5045, while that PR is open/unmerged with -head `38016f6637f0c61fb55c9ee31033ceec428e346c` in -`ahuja-gautam/openvmm:openvmm-arm64-microvm-dev-20261111`, targeting -`microsoft/openvmm:feature/microvm/dev`. Its event must be `pull_request` and -its workflow `.github/workflows/openvmm-pr.yaml`, whose file at that exact -pin must have the audited Git blob `2cabb910cd6d8c974b809a30870502f69ac68e83` -(421776 bytes), identical to the workflow reviewed at upstream -`174da3a0d236b4b01182a8d73a47598e4fcb1eca`. No moving base SHA is trusted. -Missing, malformed or mismatched proof fails closed. All selected latest-job -requirements remain mandatory; failed, skipped or missing jobs are not waived, -and no other fork/run/PR/revision is admitted. The coordinator will direct a -separate revert after the trial, not while its run is active. The ordinary -trusted-upstream path and default six-job x86 selection are unchanged. +coverage, not trust: the existing fork-headed run rejection remains intact, +including for the selected PR until an exception is explicitly approved. A pull request's run tests GitHub's merge of the pull request into the branch, which holds the tree of the head while the head descends from the branch, as landing it requires. The job reads the pin from diff --git a/scripts/nvx_tools/openvmm_ci.py b/scripts/nvx_tools/openvmm_ci.py index 76348f2c0..ec94c583a 100644 --- a/scripts/nvx_tools/openvmm_ci.py +++ b/scripts/nvx_tools/openvmm_ci.py @@ -10,8 +10,7 @@ workflow, and waits while they run. The gates' other jobs, such as the VMM tests on TDX and SEV-SNP hosts, test OpenHCL and confidential VMs, which NVX does not use. ARM selection adds the existing native Windows ARM unit and VMM jobs, -without removing x86 coverage. A temporary, explicitly approved trial admits -one fork-headed run only after checking its pinned PR and workflow blob. +without removing x86 coverage or changing workflow/repository trust. See doc/ci.md, "OpenVMM CI". """ @@ -51,14 +50,6 @@ "unit tests [aarch64-windows]", "run vmm-tests [aarch64-windows]", ) -# TEMPORARY: revert this isolated trial after the coordinator records its outcome. -_TRIAL_REVISION = "38016f6637f0c61fb55c9ee31033ceec428e346c" -_TRIAL_RUN = 43109699910 -_TRIAL_PR = 5045 -_TRIAL_HEAD_REPOSITORY = "ahuja-gautam/openvmm" -_TRIAL_HEAD_REF = "openvmm-arm64-microvm-dev-20261111" -_TRIAL_WORKFLOW = ".github/workflows/openvmm-pr.yaml" -_TRIAL_WORKFLOW_BLOB = "2cabb910cd6d8c974b809a30870502f69ac68e83" # How long the check waits between two looks at runs that have not finished. # OpenVMM's gates take one and a half to two hours, so a look every five # minutes adds little to a wait, and keeps a wait's requests, three a look, @@ -74,8 +65,6 @@ class OpenVMMCiApi(Protocol): """The GitHub REST operation that the check uses.""" - def get(self, path: str, params: Mapping[str, str] | None = None) -> object: ... - def get_all( self, path: str, @@ -132,76 +121,6 @@ def _text(document: Mapping[str, object], field: str) -> str: return value -def _trial_mapping(value: object) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise ScriptError("GitHub returned invalid temporary OpenVMM CI trial proof") - return cast(Mapping[str, object], value) - - -def _temporary_fork_run( - api: OpenVMMCiApi, run: Mapping[str, object], revision: str -) -> bool: - """Admit only the authorized run, with live PR and immutable workflow proof.""" - if revision != _TRIAL_REVISION or run.get("id") != _TRIAL_RUN: - return False - for evidence in ( - run, - _trial_mapping( - api.get(f"/repos/{OPENVMM_REPOSITORY}/actions/runs/{_TRIAL_RUN}") - ), - ): - if ( - type(evidence.get("id")) is not int - or evidence.get("id") != _TRIAL_RUN - or evidence.get("head_sha") != _TRIAL_REVISION - or evidence.get("head_branch") != _TRIAL_HEAD_REF - or evidence.get("event") != "pull_request" - or evidence.get("path") != _TRIAL_WORKFLOW - or _trial_mapping(evidence.get("repository")).get("full_name") - != OPENVMM_REPOSITORY - or _trial_mapping(evidence.get("head_repository")).get("full_name") - != _TRIAL_HEAD_REPOSITORY - ): - raise ScriptError("Temporary OpenVMM CI trial run proof does not match") - pull = _trial_mapping(api.get(f"/repos/{OPENVMM_REPOSITORY}/pulls/{_TRIAL_PR}")) - head = _trial_mapping(pull.get("head")) - base = _trial_mapping(pull.get("base")) - if ( - type(pull.get("number")) is not int - or pull.get("number") != _TRIAL_PR - or pull.get("state") != "open" - or pull.get("merged") is not False - or head.get("sha") != _TRIAL_REVISION - or head.get("ref") != _TRIAL_HEAD_REF - or _trial_mapping(head.get("repo")).get("full_name") != _TRIAL_HEAD_REPOSITORY - or base.get("ref") != "feature/microvm/dev" - or _trial_mapping(base.get("repo")).get("full_name") != OPENVMM_REPOSITORY - ): - raise ScriptError("Temporary OpenVMM CI trial PR proof does not match") - workflow = _trial_mapping( - api.get( - f"/repos/{OPENVMM_REPOSITORY}/contents/{_TRIAL_WORKFLOW}", - {"ref": _TRIAL_REVISION}, - ) - ) - if ( - workflow.get("type") != "file" - or workflow.get("path") != _TRIAL_WORKFLOW - or workflow.get("sha") != _TRIAL_WORKFLOW_BLOB - or type(workflow.get("size")) is not int - or workflow.get("size") != 421776 - ): - raise ScriptError("Temporary OpenVMM CI trial workflow proof does not match") - print( - "::warning::TEMPORARY OpenVMM CI evidence trial: admitting only " - f"{OPENVMM_REPOSITORY} run {_TRIAL_RUN}, PR {_TRIAL_PR}, " - f"head {_TRIAL_REVISION}, workflow blob {_TRIAL_WORKFLOW_BLOB}; " - "all selected latest-attempt jobs must still pass", - flush=True, - ) - return True - - def openvmm_ci_runs(api: OpenVMMCiApi, revision: str) -> list[OpenVMMRun]: """Return the runs of OpenVMM's checkin gates whose head is `revision` in OpenVMM's repository, with the latest attempt of each of their jobs.""" @@ -223,8 +142,7 @@ def openvmm_ci_runs(api: OpenVMMCiApi, revision: str) -> list[OpenVMMRun]: or cast(Mapping[str, object], head_repository).get("full_name") != OPENVMM_REPOSITORY ): - if not _temporary_fork_run(api, run, revision): - continue + continue identifier = run.get("id") if not isinstance(identifier, int) or isinstance(identifier, bool): raise ScriptError("GitHub returned a workflow run without an id") diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index f1cf22250..f446b1e84 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -5571,28 +5571,10 @@ class _FakeOpenVMMCiApi: jobs of each run, one look after another, raises each look that is an exception instead, and records each request.""" - def __init__( - self, - *looks: _OpenVMMLook | Exception, - revision: str = _OPENVMM_REVISION, - documents: Mapping[str, Any] | None = None, - ) -> None: + def __init__(self, *looks: _OpenVMMLook | Exception) -> None: self.looks = list(looks) self.look = -1 self.requests: list[str] = [] - self.revision = revision - self.documents = dict(documents or {}) - - def get(self, path: str, params: Mapping[str, str] | None = None) -> object: - self.requests.append(f"get {path}") - if "/contents/" in path: - assert params == {"ref": self.revision}, params - else: - assert params is None, params - document = self.documents[path] - if isinstance(document, Exception): - raise document - return document def get_all( self, @@ -5604,7 +5586,7 @@ def get_all( ) -> list[object]: assert deadline is None if path == "/repos/microsoft/openvmm/actions/runs": - assert params == {"head_sha": self.revision}, params + assert params == {"head_sha": _OPENVMM_REVISION}, params assert key == "workflow_runs", key self.look = min(self.look + 1, len(self.looks) - 1) self.requests.append("runs") @@ -6125,203 +6107,6 @@ def test_arm_coverage_requires_both_existing_jobs_without_trusting_forks(self): sum(line.startswith("passed:") for line in verdicts), 7 ) - @staticmethod - def _trial_api() -> _FakeOpenVMMCiApi: - revision = "38016f6637f0c61fb55c9ee31033ceec428e346c" - identifier = 43109699910 - run = { - **_openvmm_run( - identifier, - head_sha=revision, - head_repository="ahuja-gautam/openvmm", - ), - "repository": {"full_name": "microsoft/openvmm"}, - "head_branch": "openvmm-arm64-microvm-dev-20261111", - "event": "pull_request", - "conclusion": "failure", - } - jobs = _openvmm_gate_jobs(identifier) + [ - _openvmm_job(identifier, name) - for name in openvmm_ci.OPENVMM_CI_ARM64_REQUIRED_JOBS - ] - return _FakeOpenVMMCiApi( - ([run], {identifier: jobs}), - revision=revision, - documents={ - f"/repos/microsoft/openvmm/actions/runs/{identifier}": dict(run), - "/repos/microsoft/openvmm/pulls/5045": { - "number": 5045, - "state": "open", - "merged": False, - "head": { - "sha": revision, - "ref": "openvmm-arm64-microvm-dev-20261111", - "repo": {"full_name": "ahuja-gautam/openvmm"}, - }, - "base": { - "ref": "feature/microvm/dev", - "repo": {"full_name": "microsoft/openvmm"}, - "sha": "9f10ce7a8e9632d79b1d26f5a18ea899481856bf", - }, - }, - "/repos/microsoft/openvmm/contents/.github/workflows/openvmm-pr.yaml": { - "type": "file", - "path": ".github/workflows/openvmm-pr.yaml", - "sha": "2cabb910cd6d8c974b809a30870502f69ac68e83", - "size": 421776, - }, - }, - ) - - def test_temporary_trial_admits_only_pinned_proof_with_all_selected_jobs(self): - for architecture, count in (("x86_64", 6), ("aarch64", 8)): - with self.subTest(architecture=architecture): - api = self._trial_api() - args = nvx.parse_args( - [ - "check-openvmm-ci", - "--revision", - api.revision, - "--architecture", - architecture, - ] - ) - with ( - patch.object(openvmm_ci, "GitHubClient", return_value=api), - contextlib.redirect_stdout(io.StringIO()) as output, - ): - args.handler(args) - self.assertEqual(output.getvalue().count("passed:"), count) - self.assertIn("TEMPORARY OpenVMM CI evidence trial", output.getvalue()) - self.assertEqual(api.requests[-1], "jobs 43109699910") - - def test_temporary_trial_rejects_mismatched_or_malformed_proof(self): - run_path = "/repos/microsoft/openvmm/actions/runs/43109699910" - pull_path = "/repos/microsoft/openvmm/pulls/5045" - workflow_path = ( - "/repos/microsoft/openvmm/contents/.github/workflows/openvmm-pr.yaml" - ) - cases: tuple[tuple[str, tuple[str, ...], object], ...] = ( - (run_path, ("id",), 43109699911), - (run_path, ("id",), 43109699910.0), - (run_path, ("head_sha",), "b" * 40), - (run_path, ("head_branch",), "another-branch"), - (run_path, ("head_repository", "full_name"), "another/openvmm"), - (run_path, ("repository", "full_name"), "ahuja-gautam/openvmm"), - (run_path, ("event",), "pull_request_target"), - (run_path, ("path",), ".github/workflows/openvmm-ci.yaml"), - (run_path, ("head_repository",), None), - (pull_path, ("number",), 5046), - (pull_path, ("number",), 5045.0), - (pull_path, ("state",), "closed"), - (pull_path, ("merged",), True), - (pull_path, ("merged",), None), - (pull_path, ("head", "sha"), "b" * 40), - (pull_path, ("head", "ref"), "another-branch"), - (pull_path, ("head", "repo", "full_name"), "another/openvmm"), - (pull_path, ("base", "repo", "full_name"), "another/openvmm"), - (pull_path, ("base", "ref"), "main"), - (pull_path, ("head",), []), - (workflow_path, ("sha",), "b" * 40), - (workflow_path, ("sha",), None), - (workflow_path, ("type",), "symlink"), - (workflow_path, ("path",), ".github/workflows/another.yaml"), - (workflow_path, ("size",), 0), - (workflow_path, ("size",), 421776.0), - ) - for path, fields, value in cases: - with self.subTest(path=path, fields=fields, value=value): - api = self._trial_api() - document = api.documents[path] - for field in fields[:-1]: - document = document[field] - document[fields[-1]] = value - with self.assertRaises(common.ScriptError): - openvmm_ci.openvmm_ci_runs(api, api.revision) - self.assertNotIn("jobs 43109699910", api.requests) - malformed: tuple[object, ...] = ( - None, - {}, - common.ScriptError("proof unavailable"), - ) - for path in (run_path, pull_path, workflow_path): - for document in malformed: - with self.subTest(path=path, document=document): - api = self._trial_api() - api.documents[path] = document - with self.assertRaises(common.ScriptError): - openvmm_ci.check_openvmm_ci(api, api.revision, wait_seconds=0) - self.assertNotIn("jobs 43109699910", api.requests) - - def test_temporary_trial_never_admits_another_listed_run_or_revision(self): - for changes, revision in ( - ({"id": 43109699911}, None), - ({"id": "43109699910"}, None), - ({"head_sha": "b" * 40}, None), - ({"path": ".github/workflows/openvmm-pr.yaml@refs/heads/main"}, None), - ({}, "b" * 40), - ): - with self.subTest(changes=changes, revision=revision): - api = self._trial_api() - look = api.looks[0] - assert not isinstance(look, Exception) - run = dict(look[0][0]) - run.update(changes) - api.looks[0] = ([run], look[1]) - if revision is not None: - api.revision = revision - if changes.get("head_sha") or changes.get("path"): - with self.assertRaises(common.ScriptError): - openvmm_ci.openvmm_ci_runs(api, api.revision) - else: - self.assertEqual(openvmm_ci.openvmm_ci_runs(api, api.revision), []) - self.assertNotIn("jobs 43109699910", api.requests) - - def test_temporary_trial_preserves_every_required_latest_job_verdict(self): - required = ( - openvmm_ci.OPENVMM_CI_REQUIRED_JOBS - + openvmm_ci.OPENVMM_CI_ARM64_REQUIRED_JOBS - ) - for target in required: - for state in ("failure", "skipped", "missing", "pending"): - with self.subTest(target=target, state=state): - api = self._trial_api() - look = api.looks[0] - assert not isinstance(look, Exception) - jobs: list[Mapping[str, Any]] = [] - for job in look[1][43109699910]: - if openvmm_ci.covers(job["name"], target): - if state == "missing": - continue - job = { - **job, - "status": "in_progress" - if state == "pending" - else "completed", - "conclusion": None if state == "pending" else state, - } - jobs.append(job) - api.looks[0] = (look[0], {43109699910: jobs}) - args = nvx.parse_args( - [ - "check-openvmm-ci", - "--revision", - api.revision, - "--architecture", - "aarch64", - ] - ) - with ( - patch.object(openvmm_ci, "GitHubClient", return_value=api), - contextlib.redirect_stdout(io.StringIO()) as output, - self.assertRaises(common.ScriptError), - ): - args.handler(args) - expected = "failed" if state in ("failure", "skipped") else state - self.assertIn(f"{expected}: {target}:", output.getvalue()) - self.assertEqual(output.getvalue().count("passed:"), 7) - self.assertEqual(api.requests[-1], "jobs 43109699910") - def test_command_checks_the_pin_with_any_token(self): args = nvx.parse_args(["check-openvmm-ci"]) self.assertEqual(args.architecture, "x86_64") From deedb1f327c9fbfaa58f0b551de11b5affd544c8 Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:23:18 -0800 Subject: [PATCH 7/9] test: preserve original x86 correctness behavior Keep the original x86 fixed-NIC command-line assertion, guest-file adapter admission, and one-VP guest-boot/managed dispatch even with explicit SMP processor selections. Apply added native-ISA/static-ELF admission and processor expansion only to ARM, retaining its MMIO/DT and negative admission coverage. Restore the strict unresolved-template assertion over its original template scope. Add focused regression cases for both architectures and document the separate contracts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- doc/usage.md | 14 +- .../microvm_test_scripts/virtio-net.sh | 9 +- scripts/nvx_tools/microvm_tests.py | 6 +- scripts/nvx_tools/runtime_adapter_tests.py | 15 +- scripts/test_microvm_tests.py | 129 +++++++++++++++++- scripts/test_nvx_tools.py | 47 ++++++- tests/runtime-adapter/README.md | 9 +- 7 files changed, 208 insertions(+), 21 deletions(-) diff --git a/doc/usage.md b/doc/usage.md index 6334fbe11..77057938b 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -1199,6 +1199,9 @@ traffic, trigger, and exclusive-handler checks; ARM additionally checks the DT's SPI index and rising-edge cells against the GIC hardware INTID, not Linux's dynamically allocated IRQ number. ARM requires `--cold-only` for these mixed scenarios. Snapshot-only cases are not silently replaced or reported as passing. +`virtio-net` retains the original x86 fixed-window command-line assertion, +without adding an IRQ-number constraint; ARM checks the MMIO resource and +DT binding. The maintained cold inventory includes `command-line-limit`, whose effective command line uses the shared 2,048-byte binding on both ISAs. The complete inventory and explicit deferral reasons are @@ -1249,9 +1252,11 @@ the boot to the managed agent, and runs the ignored `nvx-rs` test scenario's command line and drives the guest's control session; the scenario then checks OpenVMM's outcome report and the guest console. The default managed fixture remains a single-vCPU initramfs boot. Explicit -`--processors` counts also select its and `guest-boot`'s VP counts, without changing the existing -SMP/restore defaults of 1, 2, 4 and 8. `--managed-root scratch` and -`--managed-root ram` require `--guest ubuntu` and reuse its maintained EROFS +`--processors` counts also select its and `guest-boot`'s VP counts on ARM. +On x86, both scenarios retain their one-VP execution even when explicit counts +select SMP/restore tests, whose defaults remain 1, 2, 4 and 8. +`--managed-root scratch` and `--managed-root ram` require `--guest ubuntu` +and reuse its maintained EROFS layer and the same authenticated Rust test. Both make two cold boots per VP count: scratch requires absent/present previous state and a clean journal after each boot; RAM requires absent/absent state and attaches no scratch. @@ -1490,6 +1495,9 @@ from `--guest-agent` (default `tests/runtime-adapter/target/x86_64-unknown-linux-musl/release/runtime-adapter-guest`), and fails unless each of them ran and passed. `--check-only` checks the names alone, and needs neither a hypervisor nor the guest agent. +The default x86 path retains its guest-agent file admission. Selecting ARM +additionally requires a matching native Windows/WHP host and a static ARM ELF +guest agent; runtime execution requires explicit `--cold-only`. ### `test-adversarial` diff --git a/scripts/nvx_tools/microvm_test_scripts/virtio-net.sh b/scripts/nvx_tools/microvm_test_scripts/virtio-net.sh index 93788bb3e..ad56916ec 100644 --- a/scripts/nvx_tools/microvm_test_scripts/virtio-net.sh +++ b/scripts/nvx_tools/microvm_test_scripts/virtio-net.sh @@ -20,7 +20,14 @@ while [ -z "$device" ] && [ "$tries" -lt 200 ]; do tries=$((tries + 1)) done [ -n "$device" ] || fail 20 -fixed_virtio_present d0000000 16 || fail 21 +case "$(uname -m)" in + x86_64) + grep -q 'virtio_mmio.device=0x1000@0xd0000000:' /proc/cmdline + ;; + *) + fixed_virtio_present d0000000 16 + ;; +esac || fail 21 grep -q 'virtnet_ip=10.0.0.2' /proc/cmdline || fail 22 grep -q 'virtnet_mask=255.255.255.0' /proc/cmdline || fail 23 grep -q 'virtnet_gw=10.0.0.1' /proc/cmdline || fail 24 diff --git a/scripts/nvx_tools/microvm_tests.py b/scripts/nvx_tools/microvm_tests.py index 6eef029ee..74ae7cad4 100644 --- a/scripts/nvx_tools/microvm_tests.py +++ b/scripts/nvx_tools/microvm_tests.py @@ -11563,7 +11563,11 @@ def run(args: argparse.Namespace) -> int: "select maintained cold scenarios explicitly and use --cold-only " "for mixed scenarios" ) - managed_processors = tuple(dict.fromkeys(args.processors or (1,))) + managed_processors = ( + tuple(dict.fromkeys(args.processors or (1,))) + if architecture == "aarch64" + else (1,) + ) args.processors = args.processors or list(MICROVM_PROCESSOR_COUNTS) managed_root = getattr(args, "managed_root", "initramfs") start_stop_cycles = getattr(args, "start_stop_cycles", None) diff --git a/scripts/nvx_tools/runtime_adapter_tests.py b/scripts/nvx_tools/runtime_adapter_tests.py index 33a5faa1f..625215358 100644 --- a/scripts/nvx_tools/runtime_adapter_tests.py +++ b/scripts/nvx_tools/runtime_adapter_tests.py @@ -320,7 +320,7 @@ def command_test_runtime_adapter(args: argparse.Namespace) -> int: check_only = cast(bool, args.check_only) architecture = getattr(args, "architecture", "x86_64") cold_only = getattr(args, "cold_only", False) - if architecture != host_architecture(): + if architecture == "aarch64" and architecture != host_architecture(): raise ScriptError("runtime adapter validation requires its native host ISA") if architecture == "aarch64" and (backend != "whp" or sys.platform != "win32"): raise ScriptError( @@ -372,12 +372,13 @@ def command_test_runtime_adapter(args: argparse.Namespace) -> int: cast(Path | None, args.guest_agent) or GUEST_AGENTS[architecture], "runtime adapter guest agent", ) - try: - check_static_executables([guest], architecture=architecture) - except ValueError as error: - raise ScriptError( - f"invalid runtime adapter guest agent: {error}" - ) from error + if architecture == "aarch64": + try: + check_static_executables([guest], architecture=architecture) + except ValueError as error: + raise ScriptError( + f"invalid runtime adapter guest agent: {error}" + ) from error environment["NVX_HYPERVISOR"] = backend # Cargo runs the tests in the adapter's directory, so a relative directory of # artifacts is the caller's, and NVX takes an empty one for none. diff --git a/scripts/test_microvm_tests.py b/scripts/test_microvm_tests.py index cb8036b50..5e9a4fc62 100644 --- a/scripts/test_microvm_tests.py +++ b/scripts/test_microvm_tests.py @@ -9262,6 +9262,59 @@ def test_virtio_net_uses_portable_endpoint_policy(self): microvm_tests.VIRTIO_NET_COMPLETION_MARKER, ) + def test_virtio_net_preserves_the_x86_binding_assertion(self): + shell = _posix_shell() + if shell is None: + self.skipTest("POSIX shell is unavailable") + script = microvm_tests._read_script("virtio-net.sh") + check = script[ + script.index('[ -n "$device" ] || fail 20\n') : script.index( + "grep -q 'virtnet_ip=10.0.0.2'" + ) + ].replace("/proc/cmdline", "cmdline") + prelude = microvm_tests._read_script("virtio-mmio.sh").replace( + "/proc/cmdline", "cmdline" + ) + for architecture, cmdline, binding, expected in ( + ("x86_64", "virtio_mmio.device=0x1000@0xd0000000:16", "present", 0), + ("x86_64", "virtio_mmio.device=0x1000@0xd0000000:99", "present", 0), + ("x86_64", "virtio_mmio.device=0x1000@0xd0001000:16", "present", 21), + ("aarch64", "", "present", 0), + ("aarch64", "virtio_mmio.device=0x1000@0xd0000000:16", "absent", 21), + ): + with ( + self.subTest(architecture=architecture, cmdline=cmdline), + tempfile.TemporaryDirectory() as temporary, + ): + root = Path(temporary) + (root / "cmdline").write_text(cmdline, encoding="ascii") + stubs = ( + f'uname() {{ echo "{architecture}"; }}\n' + 'fail() { exit "$1"; }\ndevice=eth0\n' + ) + if architecture == "aarch64": + stubs += ( + "fixed_virtio_present() {\n" + ' echo "$*"\n' + ' [ "$*" = "d0000000 16" ] && ' + f'[ "{binding}" = present ]\n' + "}\n" + ) + result = subprocess.run( + [shell], + cwd=root, + input=prelude + stubs + check, + text=True, + capture_output=True, + timeout=10, + check=False, + ) + self.assertEqual( + result.returncode, expected, result.stdout + result.stderr + ) + if architecture == "aarch64": + self.assertEqual(result.stdout, "d0000000 16\n") + def test_command_line_limit_fills_the_guest_kernel_buffer(self): self.assertIn("command-line-limit", microvm_tests.MICROVM_TEST_SCENARIOS) # The tokens that OpenVMM reports around the caller's, ending with its @@ -12259,7 +12312,9 @@ def test_interrupt_map_attaches_the_control_console_to_its_broker(self): len(microvm_tests.INTERRUPT_MAP_SNAPSHOT_DEVICES), ): script = microvm_tests._interrupt_map_script(devices, capture="") - self.assertNotRegex(script, r"@[A-Z][A-Z_]*@") + prelude = microvm_tests._read_script("virtio-mmio.sh") + self.assertTrue(script.startswith(prelude)) + self.assertNotIn("@", script.removeprefix(prelude)) # The control console's step writes the record, once, to the # console held open, raw, and silent until its interrupt. steps = re.findall( @@ -16667,9 +16722,10 @@ def require(path: Path, _description: str) -> Path: self.assertEqual(microvm_tests.run(args), 0) run_lifecycle.assert_not_called() + run_guest_boot.assert_called_once() + self.assertNotIn("processors", run_guest_boot.call_args.kwargs) self.assertEqual( - [entry.kwargs["processors"] for entry in run_guest_boot.call_args_list], - [2, 8], + run_guest_boot.call_args.kwargs["log_path"].name, "alpine-guest-boot.log" ) self.assertEqual( [entry.args[4] for entry in run_smp.call_args_list], @@ -16684,6 +16740,73 @@ def require(path: Path, _description: str) -> Path: [False, False, True, True], ) + def test_only_arm_expands_boot_and_managed_processor_selection(self): + def require(path: Path, _description: str) -> Path: + return path + + for architecture, selected, expected in ( + ("x86_64", [], [1]), + ("x86_64", ["2", "2", "8"], [1]), + ("aarch64", [], [1]), + ("aarch64", ["2", "2", "8"], [2, 8]), + ): + with ( + self.subTest(architecture=architecture, selected=selected), + tempfile.TemporaryDirectory() as temporary, + ): + args = nvx.parse_args( + [ + "test-microvm", + "--backend", + "whp", + "--architecture", + architecture, + "--scenario", + "guest-boot", + "--scenario", + "managed-lifecycle", + "--output-dir", + temporary, + *(["--processors", *selected] if selected else []), + ] + ) + with ( + patch.object(microvm_tests, "validate_openvmm_test_backend"), + patch.object( + microvm_tests, + "require_file", + side_effect=require, + ), + patch.object(microvm_tests, "run_guest_boot") as boot, + patch.object(microvm_tests, "run_managed_lifecycle") as managed, + redirect_stdout(io.StringIO()), + ): + self.assertEqual(microvm_tests.run(args), 0) + for scenario in (boot, managed): + self.assertEqual( + [ + entry.kwargs.get("processors", 1) + for entry in scenario.call_args_list + ], + expected, + ) + executions = [ + record + for record in _read_report( + Path(temporary) / microvm_durations.REPORT_NAME + ) + if record["record"] == "scenario" + ] + for scenario in ("guest-boot", "managed-lifecycle"): + self.assertEqual( + [ + entry["processors"] + for entry in executions + if entry["scenario"] == scenario + ], + [[processors] for processors in expected], + ) + def test_runner_dispatches_public_managed_exec_configuration(self): with tempfile.TemporaryDirectory() as temporary: output_dir = Path(temporary) diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index f446b1e84..f696dd1cc 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -21964,6 +21964,8 @@ def _run( architecture: str = "x86_64", cold_only: bool = False, scopes: Mapping[str, str] | None = None, + guest_data: bytes | None = None, + native_architecture: str | None = None, ) -> tuple[int, list[tuple[list[str], dict[str, str]]], str, str]: """Runs the handler on the scenarios at `path`, for an adapter whose Cargo metadata holds the test targets `targets`, by name with their sources, and @@ -22015,7 +22017,7 @@ def fake_streamed( header[18:20] = (183 if architecture == "aarch64" else 62).to_bytes(2, "little") header[20:24] = (1).to_bytes(4, "little") header[52:54] = (64).to_bytes(2, "little") - guest.write_bytes(header) + guest.write_bytes(header if guest_data is None else guest_data) args = argparse.Namespace( backend="whp" if architecture == "aarch64" else "kvm", cargo="cargo", @@ -22031,7 +22033,9 @@ def fake_streamed( ), patch.object(runtime_adapter_tests, "ADAPTER_DIRECTORY", path.parent), patch.object( - runtime_adapter_tests, "host_architecture", return_value=architecture + runtime_adapter_tests, + "host_architecture", + return_value=native_architecture or architecture, ), patch.object( runtime_adapter_tests.sys, @@ -22332,6 +22336,45 @@ def test_the_handler_takes_a_relative_directory_of_artifacts_from_the_caller(sel self.assertEqual(status, 0, stderr) self.assertEqual(Path(runs[0][1]["NVX_ARTIFACTS_DIR"]), expected) + def test_arm_admission_does_not_change_the_x86_handler(self): + path = self._scenarios("vm_a a\n") + listings = { + ("vm_a", "--list"): "a: test\n", + ("unit", "--ignored"): "", + ("lib", "--ignored"): "", + ("other", "--ignored"): "", + } + for native_architecture in ("x86_64", "aarch64"): + with self.subTest(native_architecture=native_architecture): + status, runs, _, stderr = self._run( + path, + listings, + guest_data=b"legacy x86 fixture", + native_architecture=native_architecture, + ) + self.assertEqual(status, 0, stderr) + self.assertEqual(len(runs), 1) + self.assertNotIn("--target", runs[0][0]) + with self.assertRaisesRegex(common.ScriptError, "native host ISA"): + self._run( + path, + listings, + architecture="aarch64", + cold_only=True, + native_architecture="x86_64", + ) + with self.assertRaisesRegex( + common.ScriptError, "invalid runtime adapter guest agent" + ): + self._run( + path, + listings, + architecture="aarch64", + cold_only=True, + scopes={"vm_a": "cold"}, + guest_data=b"not an ELF", + ) + def test_the_handler_runs_nothing_once_the_names_are_not_the_tests(self): path = self._scenarios("vm_a a\nvm_a gone\ngone x\n") listings = { diff --git a/tests/runtime-adapter/README.md b/tests/runtime-adapter/README.md index dc235c49e..416b2a24c 100644 --- a/tests/runtime-adapter/README.md +++ b/tests/runtime-adapter/README.md @@ -40,10 +40,11 @@ Each configuration enables one side of `nvx`: | Host-only | `--features host` | `host` | `frame`, `root`, `probe`, `exec`, `template`, `host`, `runtime`, `initramfs`, `staged`, `sharing`, `layered`, `capture`, `generations`, `hook` | `runtime-adapter-host` | | Guest-only | `--features guest --target x86_64-unknown-linux-musl` (or `aarch64-unknown-linux-musl`) | `guest` | `frame`, `root`, `probe`, `exec`, `template`, `guest`, `worker` | `runtime-adapter-guest`, a static executable | -The consolidated runner's `--architecture` selects and checks the guest -agent's static ELF ISA and requires a matching native host. Its default remains -x86_64. ARM64 runtime runs require Windows/WHP and explicit `--cold-only`; -the runner uses the native ARM64 MSVC target for the host tests. +The consolidated runner's `--architecture` selects the guest agent ISA. Its +default x86_64 path retains the existing guest-agent file admission. ARM64 +additionally checks the agent's static ELF ISA and requires a matching native +Windows/WHP host and explicit `--cold-only` for runtime runs; the runner uses +the native ARM64 MSVC target for the host tests. Cold selection reuses the same registry, Cargo targets and assertions. Its explicit target inventory classifies `template_capture`, `template_operations`, From 2000aa078713467add77565acdae688a6d6ecfcf Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:56:00 -0800 Subject: [PATCH 8/9] ci: stage selected guests and order ARM host counter reads Download the Azure Linux initramfs for an explicit Azure Linux correctness selection while retaining the debug-kernel exclusion. Preserve both native-Python correctness binder steps unchanged. Match the maintained guest CNTVCT_EL0 read with leading and trailing ISB and a compiler memory barrier, leaving the x86 probe unchanged. Extend the existing artifact-binding and source-version probe regression tests. The exact native ARM probe passed H5 across all 66 CPU pairs at the unchanged 1000 ns bound. Full-schedule H4 rate measurements met their existing limits but H4 still failed because the host publishes a free-running UTC clock (disabled=1); retain that failure, without retries or clock/service changes. This is host-diagnostic evidence, not OpenVMM backend or full host qualification. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/run-nvx-microvm-tests.yml | 5 ++- doc/ci.md | 4 ++ scripts/nvx_tools/host_time_probe.rs | 5 ++- scripts/test_nvx_tools.py | 45 +++++++++++++++++++++ scripts/test_time_abi.py | 24 +++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-nvx-microvm-tests.yml b/.github/workflows/run-nvx-microvm-tests.yml index f93c8be49..728116323 100644 --- a/.github/workflows/run-nvx-microvm-tests.yml +++ b/.github/workflows/run-nvx-microvm-tests.yml @@ -255,7 +255,8 @@ jobs: # qualifies its runner with the kernel and the Alpine initramfs, the # shards of the default suite boot only those, and the debug-kernel jobs # run only Alpine scenarios on the debug kernel, so only the guest and - # sandbox steps take the Ubuntu and Azure Linux artifacts, and the + # sandbox steps or an explicit guest selection take the matching + # Ubuntu and Azure Linux artifacts, and the # runtime adapter scenarios and an unsharded default run the Ubuntu # distro layer of their layered roots and public sandbox scenarios. - name: Download guest kernel @@ -311,7 +312,7 @@ jobs: path: ${{ inputs.architecture == 'aarch64' && 'build/aarch64' || 'build' }} - name: Download Azure Linux initramfs - if: ${{ inputs.guests-and-sandboxes && !inputs.debug-kernel }} + if: ${{ (inputs.guests-and-sandboxes || inputs.guest == 'azurelinux') && !inputs.debug-kernel }} uses: actions/download-artifact@v8 with: name: guest-azurelinux diff --git a/doc/ci.md b/doc/ci.md index 739156533..335508403 100644 --- a/doc/ci.md +++ b/doc/ci.md @@ -2339,6 +2339,10 @@ also need the guest artifacts; `--openvmm`, `--kernel`, and `--initrd` override their default build paths. `--no-openvmm` qualifies a host without OpenVMM: H2 then checks the CPU identity and generation only, and H3 and H6 cannot run. +On ARM, the host probe brackets `CNTVCT_EL0` with `ISB` on both sides and +retains the assembly's compiler memory barrier, matching the guest's maintained +counter-read ordering. This host diagnostic does not change OpenVMM's counter +or UTC backend. The doctor gates on measured properties, alike on every backend: the guest warp probe at 1 µs with its idle gaps (H6), the TSC rate stability (H4), and diff --git a/scripts/nvx_tools/host_time_probe.rs b/scripts/nvx_tools/host_time_probe.rs index 420570d7d..1e17d170d 100644 --- a/scripts/nvx_tools/host_time_probe.rs +++ b/scripts/nvx_tools/host_time_probe.rs @@ -35,13 +35,14 @@ fn tsc() -> u64 { #[cfg(target_arch = "aarch64")] fn tsc() -> u64 { let counter: u64; - // SAFETY: qualification reads the unprivileged architected counter, ordered by ISB. + // SAFETY: ISB brackets the unprivileged counter read and orders compiler accesses. unsafe { core::arch::asm!( "isb", "mrs {counter}, cntvct_el0", + "isb", counter = out(reg) counter, - options(nomem, nostack, preserves_flags), + options(nostack, preserves_flags), ); } counter diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index f696dd1cc..a74846620 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -6611,6 +6611,51 @@ def consume( ) self.assertIn("guest-ubuntu-distro", downloaded) + for guest in ("alpine", "ubuntu", "azurelinux"): + selected = context | { + "inputs.guest": guest, + "inputs.scenarios": '["guest-boot"]', + } + with self.subTest(system=system, selected_guest=guest): + result = consume(microvm_steps, selected) + assert result is not None + downloaded, _ = result + self.assertEqual( + downloaded, + {"guest-kernel", "guest-alpine", f"guest-{guest}"}, + ) + azure = next( + step + for step in microvm_steps + if step["name"] == "Download Azure Linux initramfs" + ) + for selected_guest, all_guests, debug, expected in ( + ("azurelinux", False, False, True), + ("alpine", False, False, False), + ("ubuntu", False, False, False), + ("alpine", True, False, True), + ("azurelinux", False, True, False), + ("alpine", True, True, False), + ): + with self.subTest( + system=system, + guest=selected_guest, + all_guests=all_guests, + debug=debug, + ): + self.assertEqual( + holds( + azure["if"], + context + | { + "inputs.guest": selected_guest, + "inputs.guests-and-sandboxes": all_guests, + "inputs.debug-kernel": debug, + }, + ), + expected, + ) + # test-openvmm boots the kernel and the Alpine initramfs. requested: list[str] = [] diff --git a/scripts/test_time_abi.py b/scripts/test_time_abi.py index 0da61f084..5ec5f104a 100644 --- a/scripts/test_time_abi.py +++ b/scripts/test_time_abi.py @@ -4344,6 +4344,30 @@ def cpu(context: doctor.DoctorContext) -> doctor.CheckResult: ) def test_builds_the_host_probe_once_per_source_version(self): + source = doctor.PROBE_SOURCE.read_text(encoding="utf-8") + arm = re.search( + r'#\[cfg\(target_arch = "aarch64"\)\]\nfn tsc\(\) -> u64 \{(.*?)\n\}', + source, + re.DOTALL, + ) + assert arm is not None + maintained = ( + doctor.BuildConstants.REPO_ROOT + / "nvx-rs" + / "src" + / "guest" + / "sys" + / "aarch64.rs" + ).read_text(encoding="utf-8") + counter = maintained.split("fn virtual_counter()", 1)[1].split("\n}", 1)[0] + self.assertEqual( + re.findall(r'"([^"]+)"', arm.group(1)), + re.findall(r'"([^"]+)"', counter), + ) + self.assertEqual( + re.findall(r"options\(([^)]+)\)", arm.group(1)), + re.findall(r"options\(([^)]+)\)", counter), + ) target = doctor.probe_path(self.root) self.assertRegex( target.name, r"^nvx-host-time-probe-x86_64-[0-9a-f]{16}(\.exe)?$" From 24bdced073a24418c1ebbf1d0775bb5ba42266ba Mon Sep 17 00:00:00 2001 From: Gautam Ahuja <47530525+ahuja-gautam@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:41:23 -0800 Subject: [PATCH 9/9] test: align workflow and x86 scenario expectations Recognize the explicit Azure Linux guest-download conjunct in the workflow selector map without weakening its strict expression check. Restore default-x86 progress and execution expectations: boot and managed lifecycle stay at one VP while console exit and SMP variants expand the selected counts. Retain the existing explicit ARM processor-expansion parameterization and exact report assertions. Production code, workflow policy and runtime inputs are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- scripts/test_microvm_tests.py | 14 +++++--------- scripts/test_nvx_tools.py | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/test_microvm_tests.py b/scripts/test_microvm_tests.py index 5e9a4fc62..794ce5032 100644 --- a/scripts/test_microvm_tests.py +++ b/scripts/test_microvm_tests.py @@ -17645,8 +17645,8 @@ def scenario(*_args: object, **_kwargs: object) -> None: stack.enter_context(redirect_stdout(stdout)) self.assertEqual(microvm_tests.run(args), 0) - # Boot, managed lifecycle, console exit and both SMP variants honor the explicit VPs. - self.assertEqual(len(progress), len(scenarios) + 5) + # On default x86, only console exit and both SMP variants expand the VPs. + self.assertEqual(len(progress), len(scenarios) + 3) for line in progress: self.assertRegex(line, r"^Running .+ on OpenVMM/kvm$") @@ -17700,14 +17700,10 @@ def require(path: Path, _description: str) -> Path: # Each execution names the processor counts that it covers, if any. expected: list[tuple[str, list[int] | None]] = [] for scenario in scenarios: - if scenario in ( - "guest-boot", - "managed-lifecycle", - "console-exit", - "smp", - "smp-lapic", - ): + if scenario in ("console-exit", "smp", "smp-lapic"): expected.extend((scenario, [processors]) for processors in (2, 1)) + elif scenario in ("guest-boot", "managed-lifecycle"): + expected.append((scenario, [1])) elif scenario in ( "smp-snapshot", "restore-processors", diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index a74846620..c6d777139 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -10701,6 +10701,7 @@ def selected( "!inputs.shard": not sharded, "(steps.correctness.outputs.workload-artifacts || steps.correctness-linux.outputs.workload-artifacts) == 'true'": True, "(inputs.guests-and-sandboxes || inputs.guest == 'ubuntu')": guests, + "(inputs.guests-and-sandboxes || inputs.guest == 'azurelinux')": guests, } chosen: list[str] = [] for step in steps: