Validation: the drm-shim recipe goes, with its image, its wrapper and its test

The runtime does not open the drm-shim devices as a guest's device (step 0's P2, ruled: the shim
has no venue), so the corpus-pipeline kernel rows that now run through the runtime have no
drm-shim sweep, and nothing else used the recipe. Gone: scripts/drm-shim.Dockerfile,
scripts/drm-shim-exec, scripts/linux-gate's `--recipe drm-shim` with its `--driver` and `--chip`
(and `--recipe` itself, which had only `gate` left), scripts/linux-gate-vulkan's shim ICD block,
and the integration test tests/integration/drm_shim.rs. Driver acceptance on RADV, ANV and NVIDIA
stays on the real cards.

Search at this commit: `git grep -n -i -E 'drm.?shim|M2V_DRM_SHIM'` gives 0 lines; `git grep -n
-e '--recipe'` gives 0. The consumer has no copy of these scripts (they are not part of a
published crate).

(cherry picked from commit 59693588b00825ed312beb67841fe5b8352a6508)
This commit is contained in:
Anees Iqbal committed 2026-11-22 07:37:15 -08:00
1 parent 0bf0195cfa
commit c1bcce40f5
8 files changed
+11 -597

No files matched your search

@@ -149,8 +149,8 @@ fn usage() -> String {
so N processes sweep disjoint parts; --after then names a row of that part.\n\
--profiles-layer P (on a device, naming --profile's P) restricts the device to\n\
P through VK_LAYER_KHRONOS_profiles, after checking that it has P and reports exactly P\n\
(validation spec 4.1.2's profile-restricted pipeline creation). A drm-shim gpu device requires scripts/drm-shim-exec inside the drm-shim\n\
container; cpu matches only a CPU Vulkan implementation."
(validation spec 4.1.2's profile-restricted pipeline creation). --device-type gpu opens a\n\
hardware or virtual GPU; cpu matches only a CPU Vulkan implementation."
.to_string()
}
@@ -577,8 +577,7 @@ mod tests {
use std::process::Stdio;
/// A member reaped while the group is sampled is gone, not a monitoring failure: on Linux the
/// `/proc/<pid>/status` a sampler opened before the reap reads `ESRCH` (a drm-shim sweep
/// stopped a compile on it).
/// `/proc/<pid>/status` a sampler opened before the reap reads `ESRCH`.
#[cfg(unix)]
#[test]
fn a_member_reaped_while_sampled_is_gone() {
@@ -1,296 +0,0 @@
//! The drm-shim recipe's two scripts, without docker or Mesa: `scripts/drm-shim-exec` preloads a
//! shim only inside the drm-shim image and refuses everywhere else, and `scripts/linux-gate
//! --recipe drm-shim` hands the command container the shim, chip variable, and ICD manifest the
//! pinned Mesa installs for the selected driver, refusing a chip spelling its shim cannot parse
//! before it touches docker.
use metal2vulkan_validation::ScratchDir;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
fn repo() -> PathBuf {
fs::canonicalize(metal2vulkan_devtools::workspace_dir()).unwrap()
}
#[cfg(unix)]
fn executable(path: &Path, text: &str) {
use std::os::unix::fs::PermissionsExt;
fs::write(path, text).unwrap();
fs::set_permissions(path, fs::Permissions::from_mode(0o755)).unwrap();
}
fn verdict(output: &Output) -> (Option<i32>, String) {
(
output.status.code(),
String::from_utf8_lossy(&output.stderr).into_owned(),
)
}
/// The first of `scripts/drm-shim-exec`'s conditions this process's environment fails, in the
/// wrapper's order and words, or `None` inside the drm-shim image (where it runs the command).
fn first_unmet_condition() -> Option<&'static str> {
if std::env::consts::OS != "linux" {
Some("not Linux")
} else if !Path::new("/.dockerenv").exists() && !Path::new("/run/.containerenv").exists() {
Some("not inside a container")
} else if !Path::new("/etc/m2v-drm-shim-image").is_file() {
Some("not the drm-shim image")
} else if Path::new("/dev/dri").exists() {
Some("/dev/dri exists")
} else {
None
}
}
/// Runs `scripts/drm-shim-exec` with `vars` (and no other `M2V_DRM_SHIM_*` variable) on a command
/// that writes its environment to `ran`.
fn drm_shim_exec(vars: &[(&str, String)], ran: &Path) -> Output {
let mut command = Command::new("bash");
command
.arg(repo().join("scripts/drm-shim-exec"))
.args(["sh", "-c", "env > \"$1\"", "sh"])
.arg(ran);
for var in [
"M2V_DRM_SHIM_LIBRARY",
"M2V_DRM_SHIM_CHIP_VAR",
"M2V_DRM_SHIM_CHIP",
"M2V_DRM_SHIM_ICD",
] {
command.env_remove(var);
}
for (key, value) in vars {
command.env(key, value);
}
command.output().unwrap()
}
/// Outside the drm-shim image the wrapper refuses with exit 69, names the first condition the
/// environment fails, and never starts the command, whether the `M2V_DRM_SHIM_*` variables name
/// real files or are unset: the environment is checked before them. Here that is macOS on a
/// developer's host or the macOS runner, "not inside a container" on the Linux runner, and "not
/// the drm-shim image" in the gate container. Inside the drm-shim image the command runs with
/// exactly the shim, the chip variable, the ICD, and the shader cache off, and a variable that
/// selects no shim GPU is refused.
#[cfg(unix)]
#[test]
fn drm_shim_exec_preloads_only_inside_the_drm_shim_image() {
let scratch = ScratchDir::new("drm-shim-exec").unwrap();
let library = scratch.path().join("libnoop_drm_shim.so");
let icd = scratch.path().join("icd.json");
fs::write(&library, "not a library\n").unwrap();
fs::write(&icd, "{}\n").unwrap();
let vars = [
("M2V_DRM_SHIM_LIBRARY", library.display().to_string()),
("M2V_DRM_SHIM_CHIP_VAR", "AMDGPU_GPU_ID".to_string()),
("M2V_DRM_SHIM_CHIP", "navi31".to_string()),
("M2V_DRM_SHIM_ICD", icd.display().to_string()),
];
let ran = scratch.path().join("ran");
match first_unmet_condition() {
Some(unmet) => {
let unset: &[(&str, String)] = &[];
for given in [&vars[..], unset] {
let (code, stderr) = verdict(&drm_shim_exec(given, &ran));
assert_eq!(code, Some(69), "{stderr}");
assert!(stderr.contains(unmet), "expected {unmet:?}: {stderr}");
assert!(!ran.exists(), "the command ran: {stderr}");
}
}
None => {
let (code, stderr) = verdict(&drm_shim_exec(&vars, &ran));
assert_eq!(code, Some(0), "{stderr}");
let env = fs::read_to_string(&ran).unwrap();
for want in [
format!("LD_PRELOAD={}", library.display()),
"AMDGPU_GPU_ID=navi31".to_string(),
format!("VK_DRIVER_FILES={}", icd.display()),
"MESA_SHADER_CACHE_DISABLE=true".to_string(),
] {
assert!(
env.lines().any(|line| line == want),
"{want} missing: {env}"
);
}
fs::remove_file(&ran).unwrap();
let mut other = vars.clone();
other[1].1 = "LD_LIBRARY_PATH".to_string();
let (code, stderr) = verdict(&drm_shim_exec(&other, &ran));
assert_eq!(code, Some(69), "{stderr}");
assert!(stderr.contains("selects no drm-shim GPU"), "{stderr}");
assert!(!ran.exists(), "the command ran: {stderr}");
}
}
}
/// A stand-in `docker` for `scripts/linux-gate`: the daemon runs, the image exists, `create`
/// logs its arguments one per line after a `CREATE` line, `container inspect` reports what the
/// policy accepts for a run without a private corpus, and `start` drains the streamed tree.
const STUB_DOCKER: &str = r#"#!/bin/sh
case "$1" in
create)
echo CREATE >> "$STUB_LOG"
for arg in "$@"; do printf '%s\n' "$arg" >> "$STUB_LOG"; done ;;
container)
case "$5" in *-cmd) role=cmd ;; *) role=fetch ;; esac
case "$4" in
*NetworkMode*) if [ "$role" = cmd ]; then echo none; else echo bridge; fi ;;
*AutoRemove*) echo true ;;
*Mounts*)
printf 'volume\037%s\037/var/lib/docker/volumes/%s/_data\037/cache\037true\n' \
"$STUB_VOLUME" "$STUB_VOLUME" ;;
esac ;;
start) cat > /dev/null ;;
esac
exit 0
"#;
/// Makes `command`'s git calls (its own, or `scripts/linux-gate`'s) read only the repository's
/// configuration, as `linux_gate_policy.rs`'s `own_git` does.
fn own_git<'a>(command: &'a mut Command, home: &Path) -> &'a mut Command {
command
.env("GIT_CONFIG_NOSYSTEM", "1")
.env("GIT_CONFIG_GLOBAL", "/dev/null")
.env("HOME", home)
.env("XDG_CONFIG_HOME", home.join(".config"))
.env_remove("GIT_CONFIG_PARAMETERS")
.env_remove("GIT_CONFIG_COUNT")
.env_remove("GIT_DIR")
.env_remove("GIT_WORK_TREE")
.env_remove("GIT_INDEX_FILE")
.env_remove("GIT_COMMON_DIR")
}
/// `scripts/linux-gate --recipe drm-shim` gives both containers the driver's shim under
/// /opt/mesa/lib, its chip variable and chip, and its ICD manifest's pattern under
/// /opt/mesa/share/vulkan/icd.d (the names the pinned Mesa installs), from the drm-shim image; a
/// chip its shim cannot parse (an Intel name in capitals, a chipset id that is not hexadecimal, a
/// name with a space or a line break) exits 64 before docker is touched. The scripts run from a
/// throwaway repository holding them and the Dockerfile, so the test needs git but no checkout of
/// its own.
#[cfg(unix)]
#[test]
fn linux_gate_hands_the_command_the_selected_drivers_shim() {
let scratch = ScratchDir::new("linux-gate-drm-shim").unwrap();
let base = fs::canonicalize(scratch.path()).unwrap();
let checkout = base.join("checkout");
let stub = base.join("bin");
let home = base.join("home");
for dir in [checkout.join("scripts"), stub.clone(), home.clone()] {
fs::create_dir_all(dir).unwrap();
}
for script in ["linux-gate", "linux-gate-policy"] {
let text = fs::read_to_string(repo().join("scripts").join(script)).unwrap();
executable(&checkout.join("scripts").join(script), &text);
}
fs::copy(
repo().join("scripts/drm-shim.Dockerfile"),
checkout.join("scripts/drm-shim.Dockerfile"),
)
.unwrap();
for args in [
&["init", "-q"][..],
&["add", "."],
&[
"-c",
"user.name=drm-shim test",
"-c",
"user.email=test@invalid",
"-c",
"commit.gpgsign=false",
"-c",
"core.hooksPath=/dev/null",
"commit",
"-q",
"-m",
"scripts",
],
] {
let output = own_git(&mut Command::new("git"), &home)
.arg("-C")
.arg(&checkout)
.args(args)
.output()
.unwrap();
assert!(
output.status.success(),
"git {args:?}: {}",
String::from_utf8_lossy(&output.stderr)
);
}
executable(&stub.join("docker"), STUB_DOCKER);
let path = format!(
"{}:{}",
stub.display(),
std::env::var("PATH").unwrap_or_default()
);
let log = base.join("docker.log");
let gate = |driver: &str, chip: &str| {
let _ = fs::remove_file(&log);
let output = own_git(&mut Command::new("bash"), &home)
.arg(checkout.join("scripts/linux-gate"))
.args(["--cpus", "1", "--slot", "stub", "--platform", "arm64"])
.args(["--recipe", "drm-shim", "--driver", driver, "--chip", chip])
.args(["--", "true"])
.env("PATH", &path)
.env_remove("CARGO_TARGET_DIR")
.env("STUB_LOG", &log)
.env("STUB_VOLUME", "m2v-linux-gate-stub-arm64")
.output()
.unwrap();
let (code, stderr) = verdict(&output);
(code, stderr, fs::read_to_string(&log).unwrap_or_default())
};
for (driver, chip, shim, variable, icd) in [
("radv", "navi31", "amdgpu", "AMDGPU_GPU_ID", "radeon"),
("radv", "rembrandt", "amdgpu", "AMDGPU_GPU_ID", "radeon"),
("anv", "tgl", "intel", "INTEL_STUB_GPU_PLATFORM", "intel"),
("anv", "arl", "intel", "INTEL_STUB_GPU_PLATFORM", "intel"),
("nvk", "1b3", "nouveau", "NOUVEAU_CHIPSET", "nouveau"),
("nvk", "136", "nouveau", "NOUVEAU_CHIPSET", "nouveau"),
] {
let (code, stderr, log) = gate(driver, chip);
assert_eq!(code, Some(0), "{driver} {chip}: {stderr}");
// The summary names the ICD drm-shim-exec selects, not only the command's lavapipe.
let summary = format!(
"driver={driver} chip={chip} icd={icd} under scripts/drm-shim-exec, lavapipe otherwise"
);
assert!(stderr.contains(&summary), "{driver} {chip}: {stderr}");
let created: Vec<&str> = log.split("CREATE\n").filter(|c| !c.is_empty()).collect();
assert_eq!(created.len(), 2, "{driver} {chip}: {log}");
for container in created {
let args: Vec<&str> = container.lines().collect();
let image = args
.iter()
.find(|arg| arg.starts_with("m2v-linux-gate:"))
.unwrap_or_else(|| panic!("no image: {container}"));
assert!(
image.starts_with("m2v-linux-gate:drm-shim-") && image.ends_with("-arm64"),
"{image}"
);
for want in [
format!("M2V_DRM_SHIM_LIBRARY=/opt/mesa/lib/lib{shim}_noop_drm_shim.so"),
format!("M2V_DRM_SHIM_CHIP_VAR={variable}"),
format!("M2V_DRM_SHIM_CHIP={chip}"),
format!("M2V_DRM_SHIM_ICD_GLOB=/opt/mesa/share/vulkan/icd.d/{icd}_icd.*.json"),
] {
assert!(
args.windows(2).any(|pair| pair == ["-e", want.as_str()]),
"{driver} {chip}: no -e {want} in {container}"
);
}
}
}
for (driver, chip) in [
("anv", "TGL"),
("nvk", "GB203"),
("nvk", "0x1b3"),
("radv", "navi 31"),
("radv", "navi31\nx"),
("amdgpu", "navi31"),
] {
let (code, stderr, log) = gate(driver, chip);
assert_eq!(code, Some(64), "{driver} {chip:?} was accepted: {stderr}");
assert!(log.is_empty(), "{driver} {chip:?} reached docker: {log}");
}
}
@@ -27,7 +27,6 @@ mod committed_public_cases_check;
mod committed_shards_keep_the_store_layout;
mod compile_worker;
mod device_worker;
mod drm_shim;
mod engine_linked_cases;
mod fast_trig_within_apples_bound;
mod fixtures_assemble_with_the_pinned_llvm;
-59
View File
@@ -1,59 +0,0 @@
#!/usr/bin/env bash
# Run one command against a Mesa drm-shim device, inside `scripts/linux-gate --recipe drm-shim`
# only.
#
# scripts/drm-shim-exec <command> [args...]
#
# scripts/linux-gate passes M2V_DRM_SHIM_{LIBRARY,CHIP_VAR,CHIP} for the selected driver and
# scripts/linux-gate-vulkan resolves its ICD manifest into M2V_DRM_SHIM_ICD. This wrapper applies
# them to exactly one process tree (never to cargo or rustc):
#
# - LD_PRELOAD the driver's noop drm-shim, which answers the kernel ioctls for the chosen GPU and
# never touches hardware (the container has no /dev/dri and no GPU passthrough);
# - select the GPU (`AMDGPU_GPU_ID`, `INTEL_STUB_GPU_PLATFORM`, or `NOUVEAU_CHIPSET`, the only
# variables accepted);
# - make the driver's ICD the only one the loader sees (VK_DRIVER_FILES);
# - turn Mesa's on-disk shader cache off (MESA_SHADER_CACHE_DISABLE), so every pipeline is
# compiled by the driver rather than served from an earlier compile.
#
# The shim stands in for real hardware, so this refuses (exit 69, before it reads any
# M2V_DRM_SHIM_* variable) unless every one of these holds, checked in this order: the kernel is
# Linux (on macOS /dev/dri is also absent, and MoltenVK is a real GPU), the process is inside a
# container (/.dockerenv or /run/.containerenv), the drm-shim image's marker
# /etc/m2v-drm-shim-image exists, and /dev/dri does not. Exporting the M2V_DRM_SHIM_* variables on
# a host therefore never preloads a shim next to a real GPU. crates/metal2vulkan-validation/tests/integration/drm_shim.rs checks
# the refusal wherever the tests run.
#
# Use it only for commands that create pipelines and never submit work (`corpus-pipeline`).
set -euo pipefail
[ "$#" -ge 1 ] || { echo "usage: scripts/drm-shim-exec <command> [args...]" >&2; exit 64; }
refuse() {
echo "drm-shim-exec: $1; it runs only inside scripts/linux-gate --recipe drm-shim" >&2
exit 69
}
[ "$(uname -s)" = Linux ] || refuse "not Linux ($(uname -s))"
[ -e /.dockerenv ] || [ -e /run/.containerenv ] || refuse "not inside a container"
[ -f /etc/m2v-drm-shim-image ] || refuse "not the drm-shim image (no /etc/m2v-drm-shim-image)"
if [ -e /dev/dri ]; then
refuse "/dev/dri exists; a shim is never preloaded next to real hardware"
fi
for var in M2V_DRM_SHIM_LIBRARY M2V_DRM_SHIM_CHIP_VAR M2V_DRM_SHIM_CHIP M2V_DRM_SHIM_ICD; do
if [ -z "${!var:-}" ]; then
echo "drm-shim-exec: $var is unset; run inside scripts/linux-gate --recipe drm-shim" >&2
exit 69
fi
done
case "$M2V_DRM_SHIM_CHIP_VAR" in
AMDGPU_GPU_ID|INTEL_STUB_GPU_PLATFORM|NOUVEAU_CHIPSET) ;;
*) echo "drm-shim-exec: $M2V_DRM_SHIM_CHIP_VAR selects no drm-shim GPU" >&2; exit 69 ;;
esac
[ -f "$M2V_DRM_SHIM_LIBRARY" ] || { echo "drm-shim-exec: no $M2V_DRM_SHIM_LIBRARY" >&2; exit 69; }
[ -f "$M2V_DRM_SHIM_ICD" ] || { echo "drm-shim-exec: no $M2V_DRM_SHIM_ICD" >&2; exit 69; }
exec env \
LD_PRELOAD="$M2V_DRM_SHIM_LIBRARY" \
"$M2V_DRM_SHIM_CHIP_VAR=$M2V_DRM_SHIM_CHIP" \
VK_DRIVER_FILES="$M2V_DRM_SHIM_ICD" \
MESA_SHADER_CACHE_DISABLE=true \
"$@"
-155
View File
@@ -1,155 +0,0 @@
# Pinned image for `scripts/linux-gate --recipe drm-shim`: L4 driver acceptance on real vendor
# compilers without hardware.
#
# - Two stages. `mesa` builds Mesa MESA_VERSION from its release tarball (checked against
# MESA_SHA256) with the RADV (amd), ANV (intel), and NVK (nouveau) Vulkan drivers and their noop
# drm-shims into /opt/mesa, and nothing else: no gallium, GL, EGL, GBM, or window system. The
# final stage is the Linux gate's toolchain (Ubuntu 26.04 by digest, LLVM, SPIR-V tools,
# lavapipe, the validation layer, Rust, cargo-nextest; not the profiles layer)
# plus vulkaninfo and a copy of /opt/mesa, so no Mesa build dependency or build tree is kept.
# - A drm-shim is an LD_PRELOAD library that answers the driver's DRM ioctls as a kernel would for
# a chosen GPU and never touches hardware: the driver compiles every pipeline for that GPU, and
# nothing executes. `scripts/linux-gate` selects the shim, the GPU, and the ICD;
# `scripts/drm-shim-exec` applies them to one process.
# - MESA_VERSION is 26.2.3: the release the RADV and ANV profiles were captured on
# (amd-rdna2-apu-radv, intel-arl-anv; intel-irisxe-anv on 26.2.2), and the first
# pinned release whose nouveau shim answers Ada and Blackwell (26.1.0's answers chipsets up to
# Ampere, so NVK took a later chip for Fermi and refused it). Re-read the facts below on a bump.
# - What the pin's sources say:
# - Shims, installed into the libdir (`install : true`): libamdgpu_noop_drm_shim.so
# (src/amd/drm-shim), libnouveau_noop_drm_shim.so (src/nouveau/drm-shim), and
# libintel_noop_drm_shim.so, which src/intel/tools/meson.build builds only when the Intel tools
# are built: hence `-Dtools=drm-shim,intel`. `--libdir=lib`, because meson's default libdir on
# Debian-like systems is lib/<multiarch triple>.
# - ICD manifests: <datadir>/vulkan/icd.d/{radeon,intel,nouveau}_icd.<cpu>.json
# (vulkan-manifest-per-architecture defaults to true), i.e. /opt/mesa/share/vulkan/icd.d.
# - GPU selection: AMDGPU_GPU_ID, a name from src/amd/common/amdgpu_devices.c, compared without
# case (an unknown name aborts); INTEL_STUB_GPU_PLATFORM, a name from the table in
# src/intel/dev/intel_device_info.c, compared exactly (an unknown name leaves the shim
# uninitialized); NOUVEAU_CHIPSET, a hexadecimal chipset id (strtol base 16, default f0).
# - Build dependencies are Ubuntu's own (its mesa source package builds these drivers with them):
# LLVM LLVM_VERSION with clang and the SPIRV-LLVM-Translator for mesa_clc (ANV's and NVK's
# internal OpenCL shaders), SPIRV-Tools, glslang, cbindgen, and bindgen (0.72.1, the version
# Mesa's CI builds). RADV compiles with ACO only (-Damd-use-llvm=false). NVK's compiler (NAK) is
# Rust: rustc MESA_RUST_VERSION (Mesa's CI toolchain for this release) and the crates syn,
# proc-macro2, quote, unicode-ident, paste, and rustc-hash, Mesa's meson wraps, each fetched by
# its pinned source hash while the image build has network; setup runs with
# --wrap-mode=nodownload, so nothing is fetched later or silently skipped.
# - libdrm: Mesa 26.2.3 needs libdrm and libdrm_amdgpu 2.4.133 (meson.build `_drm_amdgpu_ver`), and
# Ubuntu 26.04 has 2.4.131. Mesa's own libdrm wrap (2.4.133, fetched by its source hash like the
# crates) is built through Mesa's `allow-fallback-for` option, always (`--force-fallback-for`,
# so a newer system libdrm changes nothing), as a static library linked into the drivers and
# shims: they never load the system's libdrm, which lavapipe uses. No subproject is installed
# but the wrap's amdgpu.ids, the ASIC table libdrm_amdgpu reads at <prefix>/share/libdrm (the
# path compiled into it) to name the device: without it every process that opens the amdgpu
# device reports the missing file, and RADV's device name omits the marketing name.
# - Compile steps run with JOBS jobs: `scripts/linux-gate` passes its --cpus share, because
# BuildKit takes no per-build --cpus/--memory. The final stage copies /opt/mesa before anything
# else, so it starts only when the Mesa build has finished and the two stages never compile at
# once. Each compile step prints its peak memory (cgroup v2 memory.peak) last.
# - The image carries the marker /etc/m2v-drm-shim-image; scripts/drm-shim-exec refuses to run
# anywhere else (a preloaded shim must never sit next to real hardware).
FROM ubuntu:26.04@sha256:da6fc2be547864451aa253836dd926da33623312df4a9a243e35dc877c378a78 AS mesa
ARG MESA_VERSION=26.2.3
ARG MESA_SHA256=1628058a8d2c0615975de5a15ab7bbb9638c50000b5bed9456ff423ea034a81f
ARG MESA_RUST_VERSION=1.96.0
ARG LLVM_VERSION=21
ENV DEBIAN_FRONTEND=noninteractive \
RUSTUP_HOME=/opt/rustup \
CARGO_HOME=/opt/cargo \
PATH=/opt/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl xz-utils build-essential pkgconf python3 python3-mako \
python3-yaml python3-packaging meson ninja-build bison flex glslang-tools cbindgen \
bindgen libdrm-dev libelf-dev libexpat1-dev libzstd-dev zlib1g-dev \
"llvm-${LLVM_VERSION}-dev" "libclang-${LLVM_VERSION}-dev" \
"libclang-cpp${LLVM_VERSION}-dev" "libllvmspirvlib-${LLVM_VERSION}-dev" spirv-tools-dev; \
rm -rf /var/lib/apt/lists/*; \
meson --version; bindgen --version; cbindgen --version; glslangValidator --version; \
"llvm-config-${LLVM_VERSION}" --version
RUN set -eux; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh; \
sh /tmp/rustup-init.sh -y --no-modify-path --profile minimal \
--default-toolchain "${MESA_RUST_VERSION}" -c rustfmt; \
rm /tmp/rustup-init.sh; \
rustc --version
ARG JOBS=1
RUN set -eux; \
curl --proto '=https' --tlsv1.2 -sSfL \
"https://archive.mesa3d.org/mesa-${MESA_VERSION}.tar.xz" -o /tmp/mesa.tar.xz; \
echo "${MESA_SHA256} /tmp/mesa.tar.xz" | sha256sum -c -; \
mkdir /tmp/mesa; tar -xJf /tmp/mesa.tar.xz -C /tmp/mesa --strip-components=1; \
cd /tmp/mesa; \
meson subprojects download syn-2-rs proc-macro2-1-rs quote-1-rs unicode-ident-1-rs \
paste-1-rs rustc-hash-2-rs libdrm; \
printf "[binaries]\nllvm-config = '/usr/bin/llvm-config-%s'\n" "${LLVM_VERSION}" > native.ini; \
meson setup build --native-file native.ini --prefix=/opt/mesa --libdir=lib \
--buildtype=release --wrap-mode=nodownload \
-Dvulkan-drivers=amd,intel,nouveau -Dgallium-drivers= -Dtools=drm-shim,intel \
-Dplatforms= -Dglx=disabled -Degl=disabled -Dgbm=disabled -Dgles1=disabled \
-Dgles2=disabled -Dopengl=false -Dglvnd=disabled -Dvideo-codecs= -Dllvm=enabled \
-Damd-use-llvm=false \
-Dvalgrind=disabled -Dlibunwind=disabled -Dlmsensors=disabled \
-Dallow-fallback-for=libdrm --force-fallback-for=libdrm -Dlibdrm:default_library=static; \
ninja -j "${JOBS}" -C build; \
meson install -C build --no-rebuild --skip-subprojects; \
install -D -m 0644 subprojects/libdrm-*/data/amdgpu.ids /opt/mesa/share/libdrm/amdgpu.ids; \
cd /; rm -rf /tmp/mesa /tmp/mesa.tar.xz /opt/cargo/registry; \
ls -l /opt/mesa/lib/libamdgpu_noop_drm_shim.so /opt/mesa/lib/libintel_noop_drm_shim.so \
/opt/mesa/lib/libnouveau_noop_drm_shim.so; \
ls -l /opt/mesa/share/vulkan/icd.d/ /opt/mesa/share/libdrm/; \
cat /sys/fs/cgroup/memory.peak || true
FROM ubuntu:26.04@sha256:da6fc2be547864451aa253836dd926da33623312df4a9a243e35dc877c378a78
# First, so nothing below runs (or compiles) while the mesa stage builds.
COPY --from=mesa /opt/mesa /opt/mesa
ARG RUST_VERSION=nightly-2026-11-03
ARG NEXTEST_VERSION=0.9.140
ENV DEBIAN_FRONTEND=noninteractive \
RUSTUP_HOME=/opt/rustup \
PATH=/opt/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# The gate's packages, vulkaninfo, and the drivers' runtime libraries (libdrm is linked in). Every
# library the copied drivers and shims link must resolve.
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl build-essential pkg-config clang \
llvm spirv-tools mesa-vulkan-drivers libvulkan1 vulkan-validationlayers python3 \
vulkan-tools libelf1t64 libexpat1 libzstd1 zlib1g; \
rm -rf /var/lib/apt/lists/*; \
command -v llvm-dis; command -v llvm-as; command -v spirv-val; command -v spirv-as; \
command -v vulkaninfo; \
ls /usr/share/vulkan/icd.d/lvp_icd*.json; \
ls /usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json; \
for lib in /opt/mesa/lib/*.so; do \
if ldd "$lib" | grep 'not found'; then echo "unresolved: $lib" >&2; exit 1; fi; \
done; \
for icd in radeon intel nouveau; do ls "/opt/mesa/share/vulkan/icd.d/${icd}_icd".*.json; done; \
test -s /opt/mesa/share/libdrm/amdgpu.ids
ARG JOBS=1
RUN set -eux; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh; \
CARGO_HOME=/opt/cargo sh /tmp/rustup-init.sh -y --no-modify-path --profile minimal \
--default-toolchain "${RUST_VERSION}" -c rustfmt -c clippy; \
rm /tmp/rustup-init.sh; \
CARGO_HOME=/opt/cargo cargo install -j "${JOBS}" --locked cargo-nextest \
--version "${NEXTEST_VERSION}"; \
rm -rf /opt/cargo/registry /opt/cargo/git; \
rustc --version; cargo --version; cargo nextest --version; \
cat /sys/fs/cgroup/memory.peak || true; \
echo "m2v drm-shim image: no GPU, no /dev/dri; see scripts/drm-shim-exec" \
> /etc/m2v-drm-shim-image
+7 -75
View File
@@ -4,7 +4,6 @@
#
# scripts/linux-gate --cpus N [--slot NAME] [--platform amd64|arm64]
# [--icd lavapipe] [--profile P]
# [--recipe gate | --recipe drm-shim --driver radv|anv|nvk --chip ID]
# [--private-corpus DIR] [--scratch DIR]
# [-- <command> [args...]]
#
@@ -62,28 +61,9 @@
# §4.1.2), so the device reports P and the validation layer checks against it. It refuses P
# when P states anything the device lacks, and it enables the validation layer for every Vulkan
# instance of the command. scripts/linux-gate-vulkan, which applies the ICD and --profile inside
# the container, has the details. The gate recipe only. The validation crate's store refuses the
# the container, has the details. The validation crate's store refuses the
# rows of an executor the layer restricts without its request: to record rows
# under P, pass `--profiles-layer P` to corpus-vulkan or corpus-pipeline instead.
# - --recipe drm-shim (L4 driver acceptance) builds
# scripts/drm-shim.Dockerfile instead: the gate's toolchain plus Mesa's RADV/ANV/NVK and their
# noop drm-shims (Mesa 26.2.3). --driver and --chip pick the driver and the GPU it compiles for,
# in the shim's own spelling, as the pinned Mesa reads it:
# radv AMDGPU_GPU_ID, a device name of src/amd/common/amdgpu_devices.c (navi31, rembrandt,
# ...; any case);
# anv INTEL_STUB_GPU_PLATFORM, a platform name of src/intel/dev/intel_device_info.c (tgl,
# arl, ...);
# nvk NOUVEAU_CHIPSET, a hexadecimal chipset id (1b3 for GB203, 136 for GP106).
# This script checks the spelling's form; a name the shim does not know fails when the driver
# opens the device (the amdgpu shim aborts, the Intel shim leaves the device uninitialized).
# The chip each committed profile maps to is in docs/VALIDATION.md. That image has no profiles
# layer, and the command sees lavapipe; only a process started
# through scripts/drm-shim-exec sees the shimmed driver, so cargo and rustc never load the
# shim. Example:
# scripts/linux-gate --cpus 2 --recipe drm-shim --driver radv --chip rembrandt -- bash -c \
# 'cargo build --release -p metal2vulkan-validation --bin corpus-pipeline &&
# scripts/drm-shim-exec "$CARGO_TARGET_DIR/release/corpus-pipeline" \
# --profile amd-rdna2-apu-radv --device-type gpu --fixtures'
# - The command container gets one capability beyond Docker's default, SYS_PTRACE, for kcmp: the
# per-attempt memory accounting compares a worker's address space with its parent's, so a member
# still running in its parent's memory is charged once. Docker's default seccomp
@@ -99,7 +79,6 @@ set -euo pipefail
usage() {
echo "usage: scripts/linux-gate --cpus N [--slot NAME] [--platform amd64|arm64]" \
"[--icd lavapipe] [--profile P]" \
"[--recipe gate | --recipe drm-shim --driver radv|anv|nvk --chip ID]" \
"[--private-corpus DIR] [--scratch DIR] [-- <command> [args...]]" >&2
exit 64
}
@@ -107,11 +86,8 @@ usage() {
cpus=${CARGO_BUILD_JOBS:-}
slot=
platform=
recipe=gate
icd=lavapipe
profile=
driver=
chip=
private=
scratch=
if [ -n "${CARGO_TARGET_DIR:-}" ]; then
@@ -125,13 +101,10 @@ while [ "$#" -gt 0 ]; do
--slot=*) slot=${1#--slot=}; shift ;;
--platform) [ "$#" -ge 2 ] || usage; platform=$2; shift 2 ;;
--platform=*) platform=${1#--platform=}; shift ;;
--recipe) [ "$#" -ge 2 ] || usage; recipe=$2; shift 2 ;;
--icd) [ "$#" -ge 2 ] || usage; icd=$2; shift 2 ;;
--icd=*) icd=${1#--icd=}; shift ;;
--profile) [ "$#" -ge 2 ] || usage; profile=$2; shift 2 ;;
--profile=*) profile=${1#--profile=}; shift ;;
--driver) [ "$#" -ge 2 ] || usage; driver=$2; shift 2 ;;
--chip) [ "$#" -ge 2 ] || usage; chip=$2; shift 2 ;;
--private-corpus) [ "$#" -ge 2 ] || usage; private=$2; shift 2 ;;
--private-corpus=*) private=${1#--private-corpus=}; shift ;;
--scratch) [ "$#" -ge 2 ] || usage; scratch=$2; shift 2 ;;
@@ -171,41 +144,6 @@ if [ -n "$scratch" ]; then
[ -d "$scratch" ] || { echo "linux-gate: --scratch $scratch is not a directory" >&2; exit 64; }
scratch=$(cd "$scratch" && pwd -P)
fi
shim_env=()
icd_label="icd=$icd"
case "$recipe" in
gate)
[ -z "$driver$chip" ] || { echo "linux-gate: --driver/--chip need --recipe drm-shim" >&2; exit 64; }
;;
drm-shim)
[ -n "$chip" ] || { echo "linux-gate: --recipe drm-shim needs --chip ID" >&2; exit 64; }
[ "$icd" = lavapipe ] && [ -z "$profile" ] || {
echo "linux-gate: the drm-shim image has lavapipe only and no profiles layer" >&2
exit 64
}
# The form each shim parses: a device name, a platform name, or a
# hexadecimal chipset id.
case "$driver" in
radv) shim=amdgpu; chip_var=AMDGPU_GPU_ID; shim_icd=radeon; form='[A-Za-z0-9_]+' ;;
anv) shim=intel; chip_var=INTEL_STUB_GPU_PLATFORM; shim_icd=intel; form='[a-z0-9-]+' ;;
nvk) shim=nouveau; chip_var=NOUVEAU_CHIPSET; shim_icd=nouveau; form='[0-9a-f]+' ;;
*) echo "linux-gate: --driver must be radv, anv, or nvk" >&2; exit 64 ;;
esac
[[ "$chip" =~ ^${form}$ ]] || {
echo "linux-gate: --chip $chip is not a $driver chip spelling ($form)" >&2
exit 64
}
shim_env=(
-e "M2V_DRM_SHIM_LIBRARY=/opt/mesa/lib/lib${shim}_noop_drm_shim.so"
-e "M2V_DRM_SHIM_CHIP_VAR=$chip_var"
-e "M2V_DRM_SHIM_CHIP=$chip"
-e "M2V_DRM_SHIM_ICD_GLOB=/opt/mesa/share/vulkan/icd.d/${shim_icd}_icd.*.json"
)
# The command itself sees lavapipe; only scripts/drm-shim-exec's process sees the driver.
icd_label="icd=$shim_icd under scripts/drm-shim-exec, $icd otherwise"
;;
*) echo "linux-gate: --recipe must be gate or drm-shim" >&2; exit 64 ;;
esac
case "$slot" in
*[!A-Za-z0-9_.-]*) echo "linux-gate: slot name must be [A-Za-z0-9_.-]+" >&2; exit 64 ;;
esac
@@ -238,18 +176,13 @@ docker info >/dev/null 2>&1 || {
exit 69
}
if [ "$recipe" = drm-shim ]; then
dockerfile="$root/scripts/drm-shim.Dockerfile"
else
dockerfile="$root/scripts/linux-gate.Dockerfile"
fi
dockerfile="$root/scripts/linux-gate.Dockerfile"
if command -v shasum >/dev/null; then
tag=$(shasum -a 256 "$dockerfile" | cut -c1-16)
else
tag=$(sha256sum "$dockerfile" | cut -c1-16)
fi
image="m2v-linux-gate:$tag-$platform"
[ "$recipe" = gate ] || image="m2v-linux-gate:$recipe-$tag-$platform"
volume="m2v-linux-gate-$slot-$platform"
private_volume="$volume-private"
memory="$((4 * cpus))g"
@@ -257,9 +190,9 @@ run_id="m2v-linux-gate-$slot-$$"
if ! docker image inspect "$image" >/dev/null 2>&1; then
echo "linux-gate: building $image" >&2
# BuildKit takes no per-build --cpus/--memory. Both images compile (cargo-nextest and the
# profiles layer; the drm-shim image also bindgen and Mesa), so their
# compile steps take the share as JOBS (cargo -j, ninja -j), which also bounds their memory.
# BuildKit takes no per-build --cpus/--memory. The image compiles (cargo-nextest and the
# profiles layer), so its compile steps take the share as JOBS (cargo -j, ninja -j), which
# also bounds their memory.
docker build --platform "linux/$platform" --build-arg "JOBS=$cpus" -t "$image" \
-f "$dockerfile" "$root/scripts" >&2
fi
@@ -344,7 +277,6 @@ common=(
-e LP_NUM_THREADS=1
-e M2V_GATE_ICD="$icd"
-e M2V_GATE_PROFILE="$profile"
"${shim_env[@]+"${shim_env[@]}"}"
)
# The volumes, the private corpus, and the scratch directory. A --private-corpus command
# container writes only the private volume and reads the slot's volume (crates, Cargo.lock).
@@ -422,8 +354,8 @@ run "$run_id-cmd" cmd --network none -e CARGO_NET_OFFLINE=true --cap-add SYS_PTR
cp /cache/Cargo.lock Cargo.lock
fi && exec "$@"' lock \
bash scripts/linux-gate-vulkan "$@" || status=$?
echo "linux-gate: slot=$slot platform=$platform recipe=$recipe" \
"${driver:+driver=$driver chip=$chip }$icd_label${profile:+ profile=$profile}" \
echo "linux-gate: slot=$slot platform=$platform" \
"icd=$icd${profile:+ profile=$profile}" \
"${private:+private-corpus=$private }${scratch:+scratch=$scratch }" \
"cpus=$cpus memory=$memory image=$image" \
"exit=$status wall=$(($(date +%s) - start)) s" >&2
+1 -7
View File
@@ -5,7 +5,7 @@
# scripts/linux-gate-vulkan <command> [args...]
#
# Reads what scripts/linux-gate passes: M2V_GATE_ICD (lavapipe), M2V_GATE_PROFILE (a
# crates/metal2vulkan-validation/profiles stem, or empty), and for the drm-shim recipe M2V_DRM_SHIM_ICD_GLOB.
# crates/metal2vulkan-validation/profiles stem, or empty).
#
# - The selected ICD becomes the only one the loader sees (VK_DRIVER_FILES).
# - With a profile P, VK_LAYER_KHRONOS_profiles is stacked between VK_LAYER_KHRONOS_validation and
@@ -129,10 +129,4 @@ PY
echo "linux-gate: VK_LAYER_KHRONOS_profiles with $name from $file" >&2
fi
if [ -n "${M2V_DRM_SHIM_ICD_GLOB:-}" ]; then
shims=($M2V_DRM_SHIM_ICD_GLOB)
[ "${#shims[@]}" -eq 1 ] && [ -f "${shims[0]}" ] ||
{ echo "linux-gate: expected one ICD at $M2V_DRM_SHIM_ICD_GLOB" >&2; exit 69; }
export M2V_DRM_SHIM_ICD=${shims[0]}
fi
exec "$@"