Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c24a4c1
feat: __vm-run runs a command under a virtual CPU that presents a target
HaoZeke Nov 26, 2026
81b7353
fix: __vm-run checks the EESSI version eb-local itself defaults to
HaoZeke Nov 26, 2026
9d8b3ec
test: __vm-run refusals everywhere, VM runs behind EB_LOCAL_VM_TESTS=1
HaoZeke Nov 26, 2026
9ae9110
fix: copy NUL-terminated strings with dupeSentinel in __vm-run
HaoZeke Nov 26, 2026
e2ccef5
fix: __vm-run states a refusal once and names the compiler it asked
HaoZeke Nov 26, 2026
2318bd8
docs: __vm-run reference, environment variables and the QEMU how-to
HaoZeke Nov 26, 2026
a1cf3da
docs: document every public declaration of the __vm-run helper
HaoZeke Nov 26, 2026
5299733
test: define the __vm-run VM runs only under EB_LOCAL_VM_TESTS=1, so …
HaoZeke Nov 26, 2026
f796950
test: run the __vm-run unit tests
HaoZeke Nov 26, 2026
cdc5efe
test: index the -smp and -m arguments where qemuArgv puts them
HaoZeke Nov 26, 2026
a665423
Merge feat/cpu-target into feat/cpu-target-vm
HaoZeke Nov 27, 2026
cfeb705
feat(cpu-target): map __vm-run statuses, add --mask-allow-archspec-mi…
HaoZeke Nov 27, 2026
c2457d9
docs: name EB_LOCAL_ALLOW_ARCHSPEC on the environment page
HaoZeke Nov 27, 2026
6a786d2
Merge branch 'stack/cpu-target' into stack/cpu-target-vm
HaoZeke Nov 27, 2026
9260998
fix(cpu-target): the kvm and tcg routes see the built-in __vm-run helper
HaoZeke Nov 27, 2026
2a48f85
fix(cpu-target): the kvm and tcg preflight reads the guest vendor fro…
HaoZeke Nov 27, 2026
e662685
fix(cpu-target): the aarch64 preflight reads the CPU name before the …
HaoZeke Nov 27, 2026
f157f6b
fix(secrets): redact logs written within one second before the build …
HaoZeke Nov 27, 2026
9bf34e4
Merge remote-tracking branch 'origin/feat/cpu-target' into tmp/feat/c…
HaoZeke Nov 27, 2026
b62dc43
ci(workstation): fetch the pigz source with retries and a checksum ch…
HaoZeke Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/workstation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ jobs:
run: |
! command -v sbatch
! env | grep -q '^SLURM_'
- name: fetch the pigz source, checked
# The download from zlib.net intermittently gives the runner a file
# that fails EasyBuild's checksum; fetch it here with retries and put
# the verified tarball where eb-local's source path looks first.
run: |
want=eb872b4f0e1f0ebe59c9f7bd8c506c4204893ba6a8492de31df416f0d5170fd0
dir="$HOME/eessi/.eb-local/sources/p/pigz"
mkdir -p "$dir"
for i in 1 2 3 4 5 6; do
curl -fsSL --retry 3 -o "$dir/pigz-2.8.tar.gz" https://zlib.net/pigz/pigz-2.8.tar.gz || true
if [ "$(sha256sum "$dir/pigz-2.8.tar.gz" | cut -d' ' -f1)" = "$want" ]; then exit 0; fi
echo "attempt $i: checksum mismatch"; sleep $((i * 10))
done
exit 1
- name: build pigz on the runner
run: |
export PATH="$RUNNER_TEMP/eb-local/bin:$PATH"
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+cpu-target-vm.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The internal helper `eb-local __vm-run --mode kvm|tcg --cpu-target TARGET -- COMMAND` runs COMMAND inside a QEMU virtual CPU that presents an EESSI target, as the caller, in the caller's working directory, and refuses, before COMMAND starts, when EESSI archdetect, archspec, `gcc -march=native`, the CPU vendor or `/dev/fd` do not name the target.
1 change: 1 addition & 0 deletions changelog.d/+mask-vm-routes.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`--mask kvm` and `--mask tcg` run the build through `eb-local __vm-run`, and report its statuses 2, 125 and 126 as a refused request, a virtual machine that did not run and a guest CPU that did not read as the target. `--mask-allow-archspec-mismatch` passes `--allow-archspec-mismatch` to the helper and lets the build's preflight accept an archspec name other than the target's, which an aarch64 `--mask tcg` build needs because archspec reads `aarch64` under qemu-user.
4 changes: 4 additions & 0 deletions docs/howto/build-for-another-cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ The audit, `eb-local audit-isa DIR --target TARGET`, looks for instructions the
| `this CPU lacks avx512_fp16` | A mask removes features and cannot add them. `sapphirerapids` needs a host that has AVX512-FP16 and AMX. |
| `no mask profile exists for ...` | Only the virtual machine routes can present that target. |
| `preflight FAILED: archspec names ...` | An easyblock that asks archspec would build for another CPU than the tree is labelled for. |
| `the kvm route could not run the build ...` | `__vm-run` exited 125: the virtual machine failed to start or reported no status. The console log path is in the lines above. |
| `the tcg guest did not read as ...` | `__vm-run` exited 126: the guest CPU did not read as the target, and the build command did not run. |
| `the kvm route refused the request ...` | `__vm-run` exited 2: it refused the request; the line above says why. |
| `--mask-allow-archspec-mismatch` | Under `--mask tcg` archspec reads `aarch64` for `aarch64/neoverse_n1`, because qemu-user's feature line lacks `evtstrm`. The option passes `--allow-archspec-mismatch` to `__vm-run` and lets the preflight accept that name. An easyblock that keys on archspec then sees a generic Arm CPU, so give it only for a recipe that does not. |
| `/dev/fd is missing` | EESSI's `eessi_archdetect.sh` fails without it and EESSI falls back to the generic target. |
| `__vm-run` | This eb-local has no virtual machine helper; the `kvm` and `tcg` routes refuse. |

Expand Down
105 changes: 105 additions & 0 deletions docs/howto/build-under-qemu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!-- Generated from docs/orgmode/howto/build-under-qemu.org by docs/export.el; edit that file. -->

# Build under a virtual CPU with QEMU

A build that detects the CPU it runs on gets the host's view, so a Zen 5 node builds for Zen 5 whatever target you want.
`eb-local __vm-run` runs a command inside QEMU with a CPU that presents the target instead, and checks that every detector agrees before the command starts.
It is an internal helper: [the command reference](../reference/cli.md) lists its options and exit statuses, and the builds that mask the CPU view call it.
These steps run it by hand, to see what a target looks like or to debug a masked build.

## Before you start

For `--mode kvm`, a target of the host's architecture:

- `/dev/kvm`, readable and writable by you.
- `qemu-system-x86_64` and `virtiofsd` on `PATH`, or in a directory that `EB_LOCAL_QEMU_DIR` names, with `EB_LOCAL_VIRTIOFSD` for a `virtiofsd` elsewhere. On a Nix host the directory is the `bin` of the QEMU store path.
- A host kernel that has virtiofs, virtio-pci and devtmpfs built in. The helper boots `/lib/modules/$(uname -r)/vmlinuz`, then `/boot/vmlinuz-$(uname -r)`; `EB_LOCAL_VM_KERNEL` names another image.
- `bash`, `setpriv` and `stty` from util-linux and coreutils on the host: the guest runs the host's own root file system, read-only.
- A temporary directory on the root file system: `EB_LOCAL_VM_DIR`, `TMPDIR`, `/var/tmp` or `/tmp`, the first that is.
- EESSI mounted at `/cvmfs/software.eessi.io`.

For `--mode tcg`, a target of the other architecture:

- `qemu-aarch64` (or `qemu-x86_64` on an aarch64 host), found as above.
- A kernel that lets you create user and mount namespaces, 6.7 or later, unless the host already has a `qemu-aarch64` entry in `binfmt_misc`. Without the entry, the helper registers the emulator in a namespace of its own, which needs no root.
- The EESSI compatibility layer of the target's architecture under `/cvmfs/software.eessi.io`.

`EESSI_VERSION` names the EESSI version both modes check; it defaults to `2026.06`.

## Run a command as a Zen 4

```bash
eb-local __vm-run --mode kvm --cpu-target x86_64/amd/zen4 -- \
bash -c 'gcc -march=native -Q --help=target | grep -- -march='
```

The guest boots in a few seconds, checks the CPU, and prints one line before the command output:

```text
eb-local: vm-run: x86_64/amd/zen4 presented: vendor=AuthenticAMD archdetect=x86_64/amd/zen4 archspec=zen4 gcc=znver4
```

The compiler then names `znver4` on a Zen 5 host.
The command runs in your working directory, as your user and group, and its exit status is the helper's.
Files it creates there belong to you.

The guest mounts these writable: your working directory and the directories `HOME`, `TMPDIR`, `EASYBUILD_PREFIX`, `EASYBUILD_BUILDPATH`, `EASYBUILD_INSTALLPATH`, `EASYBUILD_SOURCEPATH`, `EASYBUILD_REPOSITORYPATH` and the `EESSI_*_INSTALL` variables name.
Everything else on the host root is read-only, and `/tmp` is memory.
`--share DIR` mounts another writable directory; `--share-ro DIR` mounts a read-only one that lies on a file system other than `/`, such as `/nix`.
`--memory` and `--cpus` size the guest.

## Run a command as an Intel Ice Lake

```bash
eb-local __vm-run --mode kvm --cpu-target x86_64/intel/icelake -- grep -m1 vendor_id /proc/cpuinfo
```

The vendor reads `GenuineIntel`; QEMU keeps the host's vendor unless the model sets it, and every detector goes wrong on an Intel model with an AMD vendor.

## Run a command as a Neoverse N1

```bash
eb-local __vm-run --mode tcg --cpu-target aarch64/neoverse_n1 --allow-archspec-mismatch -- \
bash -c 'uname -m; gcc -mcpu=native -### -c x.c 2>&1 | grep -o -- -mcpu=[^\ ]*'
```

The command runs on the EESSI aarch64 compatibility layer, whose directories come first in `PATH`, in qemu user mode with `QEMU_CPU=neoverse-n1`.
`uname -m` reads `aarch64`, and the compiler names `neoverse-n1`.
No guest kernel boots, and no memory or CPU count applies.

QEMU's user mode writes its own `/proc/cpuinfo` for the program, with the CPU part of the model, which EESSI archdetect and GCC read correctly.
Its feature line lacks `evtstrm`, the one feature archspec 0.2.5 requires for `neoverse_n1` that the line leaves out, so archspec reads `aarch64` and the helper refuses without `--allow-archspec-mismatch`.
An easyblock that keys on archspec then sees a generic Arm CPU while the EESSI subdirectory and the compiler see `neoverse_n1`; pass the option only for a command that does not use archspec's answer.

## What the helper refuses

The guest checks, before the command, that:

1. `/dev/fd` exists; without it EESSI archdetect fails on its process substitution and EESSI selects the generic target.
2. The CPU vendor (`vendor_id` or the Arm implementer) names the target's.
3. EESSI archdetect and the EESSI software subdirectory both name the target.
4. `gcc -march=native` (`-mcpu=native` on aarch64) names the target's compiler architecture.
5. archspec, from the EasyBuild module's Python, names the target.

Any other reading exits 126, names the check on stderr, and does not start the command.
The helper also never uses the host CPU: `enforce` makes QEMU refuse a model the host cannot present, and the helper then exits 125 and says so, where a hand-run QEMU would fall back to `-cpu host` and report the host's target.

| Situation | Status | Why |
|---|---|---|
| `x86_64/amd/zen5`, an Arm target under `kvm` | 2 | KVM offers no Zen 5 guest on another CPU, and on Arm only the host CPU. |
| An AVX-512 target under `tcg` | 2 | TCG has no AVX-512, so the guest would be a Zen 3 to every tool. |
| A target of the host's architecture under `tcg` | 2 | `kvm` presents it at native speed. |
| `x86_64/intel/sapphirerapids` on a host without AMX | 125 | `enforce` refuses the model: its instructions are real, and no guest can supply them. |

## What it costs

Wall times on a Ryzen 9 9950X (Zen 5) host under load, from the helper's start to its exit, EESSI 2026.06, 8 vCPUs, 8 GiB:

| Target | Mode | Wall time | What ran |
|---|---|---|---|
| `x86_64/amd/zen4` | kvm | 9 to 15 s | boot, the five checks, `gcc -march=native` |
| `x86_64/intel/icelake` | kvm | 10 to 13 s | the same |
| `aarch64/neoverse_n1` | tcg | 16 to 21 s | the checks, `uname -m`, a one-line C compile and run under emulation |

Most of the time goes to the checks, which load EESSI, GCC and EasyBuild modules.
A build is another matter: a guest on 4 KiB host pages and a virtiofs root costs a compile about 1.45 to 2.3 times its native time, and emulation costs 16 to 28 times.
1 change: 1 addition & 0 deletions docs/howto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ eb-without-a-site-file
build-for-every-node-type
build-against-a-site-gpu-module
build-for-profiling
build-under-qemu
build-for-another-cpu
install-what-eessi-lacks
find-what-is-wrong
Expand Down
4 changes: 4 additions & 0 deletions docs/orgmode/howto/build-for-another-cpu.org
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ The audit, =eb-local audit-isa DIR --target TARGET=, looks for instructions the
| =this CPU lacks avx512_fp16= | A mask removes features and cannot add them. =sapphirerapids= needs a host that has AVX512-FP16 and AMX. |
| =no mask profile exists for ...= | Only the virtual machine routes can present that target. |
| =preflight FAILED: archspec names ...= | An easyblock that asks archspec would build for another CPU than the tree is labelled for. |
| =the kvm route could not run the build ...= | =__vm-run= exited 125: the virtual machine failed to start or reported no status. The console log path is in the lines above. |
| =the tcg guest did not read as ...= | =__vm-run= exited 126: the guest CPU did not read as the target, and the build command did not run. |
| =the kvm route refused the request ...= | =__vm-run= exited 2: it refused the request; the line above says why. |
| =--mask-allow-archspec-mismatch= | Under =--mask tcg= archspec reads =aarch64= for =aarch64/neoverse_n1=, because qemu-user's feature line lacks =evtstrm=. The option passes =--allow-archspec-mismatch= to =__vm-run= and lets the preflight accept that name. An easyblock that keys on archspec then sees a generic Arm CPU, so give it only for a recipe that does not. |
| =/dev/fd is missing= | EESSI's =eessi_archdetect.sh= fails without it and EESSI falls back to the generic target. |
| =__vm-run= | This eb-local has no virtual machine helper; the =kvm= and =tcg= routes refuse. |

Expand Down
103 changes: 103 additions & 0 deletions docs/orgmode/howto/build-under-qemu.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#+title: Build under a virtual CPU with QEMU

A build that detects the CPU it runs on gets the host's view, so a Zen 5 node builds for Zen 5 whatever target you want.
=eb-local __vm-run= runs a command inside QEMU with a CPU that presents the target instead, and checks that every detector agrees before the command starts.
It is an internal helper: [[file:../reference/cli.org][the command reference]] lists its options and exit statuses, and the builds that mask the CPU view call it.
These steps run it by hand, to see what a target looks like or to debug a masked build.

* Before you start

For =--mode kvm=, a target of the host's architecture:

- =/dev/kvm=, readable and writable by you.
- =qemu-system-x86_64= and =virtiofsd= on =PATH=, or in a directory that =EB_LOCAL_QEMU_DIR= names, with =EB_LOCAL_VIRTIOFSD= for a =virtiofsd= elsewhere. On a Nix host the directory is the =bin= of the QEMU store path.
- A host kernel that has virtiofs, virtio-pci and devtmpfs built in. The helper boots =/lib/modules/$(uname -r)/vmlinuz=, then =/boot/vmlinuz-$(uname -r)=; =EB_LOCAL_VM_KERNEL= names another image.
- =bash=, =setpriv= and =stty= from util-linux and coreutils on the host: the guest runs the host's own root file system, read-only.
- A temporary directory on the root file system: =EB_LOCAL_VM_DIR=, =TMPDIR=, =/var/tmp= or =/tmp=, the first that is.
- EESSI mounted at =/cvmfs/software.eessi.io=.

For =--mode tcg=, a target of the other architecture:

- =qemu-aarch64= (or =qemu-x86_64= on an aarch64 host), found as above.
- A kernel that lets you create user and mount namespaces, 6.7 or later, unless the host already has a =qemu-aarch64= entry in =binfmt_misc=. Without the entry, the helper registers the emulator in a namespace of its own, which needs no root.
- The EESSI compatibility layer of the target's architecture under =/cvmfs/software.eessi.io=.

=EESSI_VERSION= names the EESSI version both modes check; it defaults to =2026.06=.

* Run a command as a Zen 4

#+begin_src bash
eb-local __vm-run --mode kvm --cpu-target x86_64/amd/zen4 -- \
bash -c 'gcc -march=native -Q --help=target | grep -- -march='
#+end_src

The guest boots in a few seconds, checks the CPU, and prints one line before the command output:

#+begin_src text
eb-local: vm-run: x86_64/amd/zen4 presented: vendor=AuthenticAMD archdetect=x86_64/amd/zen4 archspec=zen4 gcc=znver4
#+end_src

The compiler then names =znver4= on a Zen 5 host.
The command runs in your working directory, as your user and group, and its exit status is the helper's.
Files it creates there belong to you.

The guest mounts these writable: your working directory and the directories =HOME=, =TMPDIR=, =EASYBUILD_PREFIX=, =EASYBUILD_BUILDPATH=, =EASYBUILD_INSTALLPATH=, =EASYBUILD_SOURCEPATH=, =EASYBUILD_REPOSITORYPATH= and the =EESSI_*_INSTALL= variables name.
Everything else on the host root is read-only, and =/tmp= is memory.
=--share DIR= mounts another writable directory; =--share-ro DIR= mounts a read-only one that lies on a file system other than =/=, such as =/nix=.
=--memory= and =--cpus= size the guest.

* Run a command as an Intel Ice Lake

#+begin_src bash
eb-local __vm-run --mode kvm --cpu-target x86_64/intel/icelake -- grep -m1 vendor_id /proc/cpuinfo
#+end_src

The vendor reads =GenuineIntel=; QEMU keeps the host's vendor unless the model sets it, and every detector goes wrong on an Intel model with an AMD vendor.

* Run a command as a Neoverse N1

#+begin_src bash
eb-local __vm-run --mode tcg --cpu-target aarch64/neoverse_n1 --allow-archspec-mismatch -- \
bash -c 'uname -m; gcc -mcpu=native -### -c x.c 2>&1 | grep -o -- -mcpu=[^\ ]*'
#+end_src

The command runs on the EESSI aarch64 compatibility layer, whose directories come first in =PATH=, in qemu user mode with =QEMU_CPU=neoverse-n1=.
=uname -m= reads =aarch64=, and the compiler names =neoverse-n1=.
No guest kernel boots, and no memory or CPU count applies.

QEMU's user mode writes its own =/proc/cpuinfo= for the program, with the CPU part of the model, which EESSI archdetect and GCC read correctly.
Its feature line lacks =evtstrm=, the one feature archspec 0.2.5 requires for =neoverse_n1= that the line leaves out, so archspec reads =aarch64= and the helper refuses without =--allow-archspec-mismatch=.
An easyblock that keys on archspec then sees a generic Arm CPU while the EESSI subdirectory and the compiler see =neoverse_n1=; pass the option only for a command that does not use archspec's answer.

* What the helper refuses

The guest checks, before the command, that:

1. =/dev/fd= exists; without it EESSI archdetect fails on its process substitution and EESSI selects the generic target.
2. The CPU vendor (=vendor_id= or the Arm implementer) names the target's.
3. EESSI archdetect and the EESSI software subdirectory both name the target.
4. =gcc -march=native= (=-mcpu=native= on aarch64) names the target's compiler architecture.
5. archspec, from the EasyBuild module's Python, names the target.

Any other reading exits 126, names the check on stderr, and does not start the command.
The helper also never uses the host CPU: =enforce= makes QEMU refuse a model the host cannot present, and the helper then exits 125 and says so, where a hand-run QEMU would fall back to =-cpu host= and report the host's target.

| Situation | Status | Why |
|--------------------------------------------+--------+--------------------------------------------------------------------------------|
| =x86_64/amd/zen5=, an Arm target under =kvm= | 2 | KVM offers no Zen 5 guest on another CPU, and on Arm only the host CPU. |
| An AVX-512 target under =tcg= | 2 | TCG has no AVX-512, so the guest would be a Zen 3 to every tool. |
| A target of the host's architecture under =tcg= | 2 | =kvm= presents it at native speed. |
| =x86_64/intel/sapphirerapids= on a host without AMX | 125 | =enforce= refuses the model: its instructions are real, and no guest can supply them. |

* What it costs

Wall times on a Ryzen 9 9950X (Zen 5) host under load, from the helper's start to its exit, EESSI 2026.06, 8 vCPUs, 8 GiB:

| Target | Mode | Wall time | What ran |
|--------------------------------------+------+--------------+-----------------------------------------------------------------------|
| =x86_64/amd/zen4= | kvm | 9 to 15 s | boot, the five checks, =gcc -march=native= |
| =x86_64/intel/icelake= | kvm | 10 to 13 s | the same |
| =aarch64/neoverse_n1= | tcg | 16 to 21 s | the checks, =uname -m=, a one-line C compile and run under emulation |

Most of the time goes to the checks, which load EESSI, GCC and EasyBuild modules.
A build is another matter: a guest on 4 KiB host pages and a virtiofs root costs a compile about 1.45 to 2.3 times its native time, and emulation costs 16 to 28 times.
1 change: 1 addition & 0 deletions docs/orgmode/howto/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eb-without-a-site-file
build-for-every-node-type
build-against-a-site-gpu-module
build-for-profiling
build-under-qemu
build-for-another-cpu
install-what-eessi-lacks
find-what-is-wrong
Expand Down
Loading
Loading