Skip to content

feat :: __vm-run runs a command under a virtual CPU that presents an EESSI target - #452

Merged
HaoZeke merged 20 commits into
developfrom
feat/cpu-target-vm
Nov 27, 2026
Merged

HaoZeke merged 20 commits into
developfrom
feat/cpu-target-vm

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

feat :: __vm-run runs a command under a virtual CPU that presents an EESSI target

Base: develop. Last of three PRs that merge in this order: feat/isa-audit, feat/cpu-target, feat/cpu-target-vm (this one). The branch contains develop, feat/isa-audit and feat/cpu-target, so once those two have merged this PR shows only the helper and the glue below. It merges without conflicts after them.

An internal helper, absent from --help, for the builds that mask the CPU view:

eb-local __vm-run --mode kvm|tcg --cpu-target TARGET [--memory MiB] [--cpus N] -- COMMAND [ARG...]

COMMAND runs in the caller's working directory, as the caller's uid and groups, with the EasyBuild and EESSI variables, and its exit status is the helper's.

  • kvm: QEMU with KVM boots the host kernel with the host root read-only over virtiofs, /cvmfs/software.eessi.io shared, and the working directory, HOME and the build directories named by EASYBUILD_* and EESSI_*_INSTALL writable. The CPU is a named model plus the corrections measured for it (Genoa: flush-l1d, la57=off, pcid=off, the SRSO and TSA bits, tsc-deadline; Intel models: vendor=GenuineIntel and the non-ISA bits off) with enforce. No path uses -cpu host.
  • tcg: for a target of the other architecture, qemu user mode with QEMU_CPU=<model> on the EESSI compatibility layer. Without a binfmt_misc entry the helper registers the emulator in a user and mount namespace of its own.
  • Before COMMAND, the guest checks that the CPU vendor, EESSI archdetect, the EESSI subdirectory, gcc -march=native (-mcpu=native on aarch64), archspec and /dev/fd all name the target, and the helper refuses otherwise.
  • Statuses: 0 to 255 are COMMAND's; 2 refused before starting; 125 the VM failed or reported no status (an enforce refusal included); 126 the CPU view does not name the target.
  • QEMU and virtiofsd come from PATH or EB_LOCAL_QEMU_DIR and EB_LOCAL_VIRTIOFSD; EB_LOCAL_VM_KERNEL, EB_LOCAL_VM_DIR, EB_LOCAL_VM_KEEP, EB_LOCAL_VM_CVMFS_REPOS and EB_LOCAL_VM_GCC are documented in the environment reference.

Code is in src/vm.zig and src/vm/*.sh; main.zig gets the dispatch and a _ = vm; in the test block. Docs: a section in the command reference marked internal, howto/build-under-qemu, the environment variables, and a changelog fragment.

Tests

  • 15 Zig unit tests (194 in total, all pass on the build host): target to model mapping for Rome, Milan and Genoa with the corrections and for the Intel models with the vendor, aarch64 models, refusals, QEMU and virtiofsd command lines, mounts, argument parsing, exit-status mapping, job script quoting.
  • tests/test_vm_run.py: the refusals run everywhere. The VM runs exist only with EB_LOCAL_VM_TESTS=1, because GitHub-hosted runners do not offer nested KVM in general; without it they are not defined, so the zero-skip job sees no skipped test.
  • Full Python suite on the build host (Zen 5, kernel 7.0): the same 40 failure lines as develop, none added.

Measured on the build host (Ryzen 9 9950X, QEMU 11.1.2, EESSI 2026.06, 8 vCPUs, host under load), start to exit including the checks:

Target Mode Wall time Result
x86_64/amd/zen4 kvm 9.3 to 15.4 s gcc znver4, archdetect x86_64/amd/zen4, archspec zen4, vendor AuthenticAMD; exit status 7 passes through
x86_64/intel/icelake kvm 9.9 to 12.7 s gcc icelake-server, archspec icelake, GenuineIntel
aarch64/neoverse_n1 tcg 14.1 to 20.8 s archdetect aarch64/neoverse_n1, gcc neoverse-n1, a C compile and run inside
x86_64/intel/sapphirerapids kvm 1.2 s exit 125, enforce refuses the model on this host
x86_64/amd/zen4, bad compiler kvm 10.5 s exit 126, COMMAND not run

qemu user mode answers /proc/cpuinfo itself with the model's CPU part, so archdetect and GCC read neoverse_n1. Its feature line lacks evtstrm, the one feature archspec 0.2.5 needs for neoverse_n1 that is missing, so archspec reads aarch64 and the helper refuses with 126 unless --allow-archspec-mismatch is given (stderr then carries a warning).

How --cpu-target --mask kvm|tcg calls it

--mask kvm and --mask tcg (from feat/cpu-target) build with this prefix in front of the build command:

eb-local __vm-run --mode kvm|tcg --cpu-target TARGET [--allow-archspec-mismatch] -- COMMAND...
  • vmPrefix in main.zig builds that argument list, with a unit test of the words for both modes and for the opt-in.

  • The helper is dispatched before argument parsing and is not a Command, so --cpu-target finds it through the program's own build (the lookup by command name in feat/cpu-target never finds a hidden helper).

  • Statuses 2, 125 and 126 print a message that names the route and the target: a refused request, a virtual machine that did not run (console log named in the lines above), and a guest CPU that did not read as the target. A status of the build command itself passes through unchanged.

  • --mask-allow-archspec-mismatch (documented in the command reference) passes --allow-archspec-mismatch and sets EB_LOCAL_ALLOW_ARCHSPEC=1 for the preflight inside the guest, which then accepts an archspec name other than the target's and still refuses on every other check. An aarch64 --mask tcg build needs it; the option is an error on the cpuid route. Without it the tcg build stops with status 126 and says which option accepts the name.

  • Inside the guest the preflight reads the CPU vendor from /proc/cpuinfo (the cpuid route uses its compiled probe), and an aarch64 gcc -mcpu=native name such as neoverse-n1+crc+crypto matches on the part before the first +.

  • Log redaction reaches back one second before the build began (redact_since in main.zig). File times have one-second resolution, and test_secrets_refuse_hostile_input_files writes its logs just before it starts the build; on the aarch64 runner a second boundary between the two left a log unredacted.

End-to-end evidence (Zen 5 host, EESSI 2026.06, QEMU 11.1.2, job directories on the root filesystem)

  • --cpu-target x86_64/intel/icelake --mask kvm bzip2-1.0.8-GCCcore-15.2.0.eb --rebuild: 53 s. The guest presents vendor=GenuineIntel archdetect=x86_64/intel/icelake archspec=icelake gcc=icelake-server; the build installs under x86_64/intel/icelake; the audit passes (no instruction beyond x86_64/intel/icelake, 69722 instructions); eb-local-build-mode.json has "route": "kvm" and "isa_audit": "pass".
  • --cpu-target aarch64/neoverse_n1 --mask tcg zlib-2.3.2-GCCcore-15.2.0.eb --rebuild, first without the option: status 126 in 16 s, vm-run: refused: archspec reads 'aarch64', aarch64/neoverse_n1 needs 'neoverse_n1', then the eb-local message naming --mask-allow-archspec-mismatch. With --mask-allow-archspec-mismatch: the build ran under qemu-user and finished in 8 min 17 s (EasyBuild reports 7 min 6 s for the install itself); the preflight accepts archspec names 'aarch64' by the option and checks the rest; the audit passes against aarch64/neoverse_n1 (20893 instructions); the record has "route": "tcg".
  • cpuid route with the audit on, same binary: bzip2 for zen3 and zen4 pass; the zen4-built tree fails the audit against x86_64/amd/zen3 with exit 1 (see the feat/cpu-target PR).
  • zig build unit: 227 tests pass. zig build -Dtest-ops=true test: the same 43 failure lines as develop at aecc5a5 on this host, none new. EB_LOCAL_VM_TESTS=1 python3 -m unittest test_vm_run: 8 tests pass in 45 s. CI at the branch head: zig and shellcheck green (runs 45920555278 and 45920555182).

An internal helper. --mode kvm boots the host kernel under QEMU with a
named CPU model and enforce, the host root shared read-only over virtiofs;
--mode tcg runs the command in qemu user mode for a target of another
architecture. The guest checks archdetect, archspec, gcc -march=native,
the vendor and /dev/fd before the command starts, and the helper refuses
when one does not name the target.
…eck before the build

The zlib.net download intermittently handed the GitHub runner a file that
failed EasyBuild's checksum (PRs 450, 451 and 452); the same URL gives the
expected sha256 elsewhere. The job fetches it with retries, checks the
sha256, and places it in eb-local's source path.
@HaoZeke
HaoZeke merged commit 8f2c3bd into develop Nov 27, 2026
12 checks passed
@HaoZeke
HaoZeke deleted the feat/cpu-target-vm branch November 27, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant