Runtime: a helper that ends before its reply is kept as StageBreach::Ended, refused like Time

A stage helper that ends before its whole reply, with no end of the consumer's (no cap, no time
limit, no cancel), had no breach to be kept as. fill_stage answers StageFill::Ended and keeps
nothing, so every later make, prepare_dispatch and dispatch of that pipeline answered
Error::StageUnfilled again with no limit. A consumer that asks again meets the same end each time.
On the Iris Xe (ANV, Mesa 26.2.6) a heavy kernel at 1,024 threads a threadgroup ended its helper
eight times in a row that way (job m3-max-68748). The fault is in libvulkan_intel.so under the
helper's vkCreateComputePipelines (jobs m3-max-68793 and m3-max-68824).

StageBreach::Ended is that end. The consumer records it through record_stage_breach, the one way an
end is kept. It is kept and refused as Time is (Gap::StageSize, StageGap::Breach), with no helper
asked again: the first such end is the answer, and there is no count and no retry. A crash is not
StageBreach::Compile, which says the driver answered an error.

A kept end must not outlive a fix of ours to the helper. The entry holds, beside its byte, the
helper version it was kept under: HELPER_VERSION, 4 bytes, the way a Memory entry holds its
ceiling. An entry under a lower version is a miss and is removed, so the make asks for a fill
again. HELPER_VERSION starts at 1, and its doc says to bump it with every change to what the
helper's own code does (serve_stage, serve, compile, read_request). The stage key, WIRE_VERSION,
fills and the other breaches are unchanged.

Tests:
- an_ended_breach_holds_to_its_helper_version_and_is_a_miss_below_it: an ended entry kept under
  HELPER_VERSION is 62 bytes and reads back under every ceiling. One under a lower version, with
  no version, or with a cut version is a miss and is removed. The digest of the helper's code text
  must equal the pair recorded for the current HELPER_VERSION, so a change to the helper that
  misses the bump fails there.
- a_helper_that_ends_before_its_reply_is_kept_as_an_ended_breach (device): a helper that reads the
  request and ends with no reply gives StageFill::Ended. Once that is recorded, the next make, and
  a later device's on the same directory, answers Gap::StageSize(Breach(Ended)) with no fill.

The runtime README's stage section records the Iris end, as read with a debugger, and the Ended
breach's line. The signatures table gains the variant. docs/REFUSALS.md and basis.rs were
regenerated and did not change.
This commit is contained in:
Anees Iqbal committed 2026-11-22 14:30:24 -08:00
1 parent 722872edec
commit 165ef68096
5 files changed
+223 -31

No files matched your search

+20 -4
View File
@@ -3055,6 +3055,16 @@ partial-threadgroup one with a required subgroup size of 32; on the Iris Xe it i
So on the RTX 3090 and the RX 7900 XTX these kernels are made at 1,024 threads a threadgroup within
the cap, and on the Iris Xe none of them is made at either width.
The Iris Xe's end of b89e2e87392d4527 at 1,024 is a fault in ANV's compiler: a read at a null
base plus 0x40 inside a recursive function of `libvulkan_intel.so`, under the helper's
`vkCreateComputePipelines` (Mesa 26.2.6), at 1,289 MiB after 45 to 47 s, read with a debugger in
two asks (job m3-max-68793). Job m3-max-68748 ended the same fill eight times, its first after
48.8 s and seven re-asks after 1.2 to 1.3 s each; the five ends read (both asks of m3-max-68793,
and the first and two re-asks of m3-max-68748 from their cores, job m3-max-68824) fault at
`libvulkan_intel.so + 0xc863` with the same stack: the re-asks read the driver's own cache
(inferred: same fault offset, 1.2 s against 46 s; not shown by a file listing). Such an end is
kept as `StageBreach::Ended` (below).
Render stages have a bound of their own, 99,109, as no helper compiles a render stage: a render
pipeline with a stage past it is refused (Known gaps of render pipeline states), and one at or
under it compiles in the process that runs the program with no cap, past the kernels' bound too.
@@ -3090,10 +3100,12 @@ heaviest such stage's weight.
`deviceUUID`, `driverUUID`, pipeline cache header and enables, so the helper opens the same
device with the same features; a helper whose device differs is answered `StageFill::NoDevice`
or `StageFill::Enables`, and one of another build of the runtime `StageFill::Version`.
- rt starts, caps, times and kills no process. A consumer that ends its helper for its memory cap
or its time limit keeps that with `Device::record_stage_breach` (`StageBreach::Memory`,
`StageBreach::Time`); a compile the driver failed is kept as `StageBreach::Compile` by
`fill_stage`. A breach is an entry of the same directory, and refuses the pipeline's makes
- rt starts, caps, times and kills no process, and asks no helper again. A consumer that ends its
helper for its memory cap or its time limit keeps that with `Device::record_stage_breach`
(`StageBreach::Memory`, `StageBreach::Time`), and one whose helper ended before its reply
(`StageFill::Ended`) with no end of the consumer's, as a helper whose driver faults in the
compile does, keeps that as `StageBreach::Ended`: the first such end is the answer. A compile
the driver failed is kept as `StageBreach::Compile` by `fill_stage`. A breach is an entry of the same directory, and refuses the pipeline's makes
(`Gap::StageSize`, `StageGap::Breach`) with no helper asked again. So does cache data the driver
answers compile-required for (`StageBreach::CompileRequired`): it is not filled a second time.
The stage key holds the driver's pipeline cache header, so a new driver version asks again.
@@ -3107,6 +3119,10 @@ heaviest such stage's weight.
below, it refuses as before. A memory breach entry that holds the breach's byte alone, with no
ceiling after it, counts as kept under 0. Time, compile and compile-required breaches hold no
ceiling.
- An ended breach holds the version of rt's helper code it was kept under (4 bytes), which rises
with each change to what `serve_stage` does. Under a later version its entry is a miss and is
removed, and the make is refused with `Error::StageUnfilled` again, so a fix of rt's helper asks
the helper again; a driver's fix asks again through the driver's header in the key.
- The entries are files of the cache directory only: nothing of an entry stays in memory past
the call that reads or writes it. Each holds its key again under a magic, its length and its
checksum; one that does not check, names another key or holds data that does not begin with the
+3 -1
View File
@@ -1517,7 +1517,9 @@ pub enum StageGap {
/// compile-required answer to the helper's cache data
/// ([`Device::record_stage_breach`](crate::Device::record_stage_breach)). Kept until the
/// driver's version changes; a memory breach, until a device is given a higher
/// [`DeviceOptions::stage_memory_ceiling`](crate::DeviceOptions::stage_memory_ceiling).
/// [`DeviceOptions::stage_memory_ceiling`](crate::DeviceOptions::stage_memory_ceiling); a
/// helper's own end before its reply ([`StageBreach::Ended`](crate::StageBreach::Ended)),
/// until the runtime's helper code changes.
Breach(crate::StageBreach),
/// The device has no cache directory
/// ([`DeviceOptions::pipeline_cache_dir`](crate::DeviceOptions::pipeline_cache_dir)) to keep a
+58 -21
View File
@@ -34,7 +34,9 @@
//! header, so a new driver version asks again. A [`StageBreach::Memory`] entry also holds the
//! memory ceiling of the consumer's helper it was kept under
//! ([`DeviceOptions::stage_memory_ceiling`]), 0 where it holds the breach's byte alone: on a
//! device given a higher ceiling it is a miss, and removed.
//! device given a higher ceiling it is a miss, and removed. A [`StageBreach::Ended`] entry, a
//! helper that ended before its reply with no end of the consumer's, holds the [`HELPER_VERSION`]
//! it was kept under: under a later version it is a miss, and removed.
//!
//! **The wire.** [`Device::fill_stage`] writes one request frame to the helper and reads one reply
//! frame back: each the magic `m2vstage`, the wire version, the payload's length and its checksum,
@@ -87,6 +89,12 @@ const DONE: u32 = 0;
const COMPILE: u32 = 1;
const NO_DEVICE: u32 = 2;
const ENABLES: u32 = 3;
/// The version of the helper's own code ([`serve_stage`] and what it runs in this module: `serve`,
/// `compile`, `read_request`), which a [`StageBreach::Ended`] entry holds: one kept under a lower
/// version is a miss and removed, so a fix of ours to a helper that ended asks the helper again.
/// Bump it with every change to that code that changes what the helper does; a driver's fix needs
/// none, as the stage key holds the driver's header.
pub(crate) const HELPER_VERSION: u32 = 1;
/// No Metal counterpart: what ended a helper's compile of a kernel past the stage bound, kept as
/// the pipeline's entry ([`Device::record_stage_breach`], [`Device::fill_stage`]) so its makes are
@@ -105,14 +113,21 @@ pub enum StageBreach {
/// The driver answered compile-required for the helper's cache data
/// (`VK_PIPELINE_COMPILE_REQUIRED`): it would compile again in this process.
CompileRequired,
/// No Metal counterpart, as Metal compiles in its own compiler service: the helper ended
/// before its whole reply ([`StageFill::Ended`]) and the consumer did not end it (no cap, no
/// time limit, no cancel), as a helper whose driver faults in the compile does. Kept with the
/// version of the runtime's helper code it ended under: a later runtime whose helper code
/// changed asks the helper again.
Ended,
}
impl StageBreach {
const ALL: [StageBreach; 4] = [
const ALL: [StageBreach; 5] = [
StageBreach::Memory,
StageBreach::Time,
StageBreach::Compile,
StageBreach::CompileRequired,
StageBreach::Ended,
];
fn byte(self) -> u8 {
@@ -121,6 +136,7 @@ impl StageBreach {
StageBreach::Time => 1,
StageBreach::Compile => 2,
StageBreach::CompileRequired => 3,
StageBreach::Ended => 4,
}
}
}
@@ -143,8 +159,10 @@ pub struct StageSpans {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StageFill {
/// The helper's reply did not come whole: it ended, was killed (a cap, a time limit, a
/// cancel) or closed its pipes first. Nothing is kept; the consumer keeps a cap's or a time
/// limit's end with [`Device::record_stage_breach`].
/// cancel) or closed its pipes first. Nothing is kept; the consumer keeps the end with
/// [`Device::record_stage_breach`]: a cap's as [`StageBreach::Memory`], a time limit's as
/// [`StageBreach::Time`], and the helper's own end, one the consumer did not cause, as
/// [`StageBreach::Ended`]. A cancel keeps nothing.
Ended,
/// The helper speaks another wire version: a helper of another build of the runtime.
Version,
@@ -505,14 +523,22 @@ impl Device {
/// No Metal counterpart: keeps `breach` as the entry of `request`'s pipeline, so its makes are
/// refused ([`Gap::StageSize`]) with no helper asked again, until the driver's version changes:
/// what the consumer ended its helper for ([`StageBreach::Memory`], [`StageBreach::Time`]).
/// A memory breach is kept with the device's [`DeviceOptions::stage_memory_ceiling`], and a
/// device given a higher ceiling asks the helper again. A directory that takes no entry keeps
/// what the consumer ended its helper for ([`StageBreach::Memory`], [`StageBreach::Time`]),
/// or the helper's own end before its reply ([`StageBreach::Ended`]), the first such end being
/// the answer. A memory breach is kept with the device's
/// [`DeviceOptions::stage_memory_ceiling`], and a device given a higher ceiling asks the
/// helper again; an ended one is kept with the version of this runtime's helper code, and a
/// runtime whose helper code changed asks again. A directory that takes no entry keeps
/// nothing.
pub fn record_stage_breach(&self, request: &StageRequest, breach: StageBreach) {
let core = self.core();
if let Some(dir) = core.caches.dir() {
let entry = Entry::Breach(breach, core.stage_memory_ceiling);
let kept = match breach {
StageBreach::Memory => core.stage_memory_ceiling,
StageBreach::Ended => u64::from(HELPER_VERSION),
_ => 0,
};
let entry = Entry::Breach(breach, kept);
keep_entry(&dir.join(STAGES), &request.0.key, &entry, STAGE_BOUNDS);
}
}
@@ -671,15 +697,17 @@ unsafe fn compile(core: &Core, request: &Request) -> Result<(Vec<u8>, u64), vk::
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum Entry {
Data(Vec<u8>),
/// A breach, with the memory ceiling ([`DeviceOptions::stage_memory_ceiling`]) a
/// [`StageBreach::Memory`] was kept under: written after the breach's byte for a memory breach
/// alone, and read as 0 where no ceiling follows the byte.
/// A breach, with what it was kept under: for a [`StageBreach::Memory`], the memory ceiling
/// ([`DeviceOptions::stage_memory_ceiling`]), 8 bytes after the breach's byte, read as 0 where
/// none follow it; for a [`StageBreach::Ended`], the [`HELPER_VERSION`], 4 bytes after it; 0
/// and nothing after the byte for the others.
Breach(StageBreach, u64),
}
/// The entry of key `key` in `dir`, where it checks for a device of `header` given the memory
/// ceiling `ceiling`, touched as used; a file that does not check, or a memory breach kept under a
/// ceiling below `ceiling`, is a miss and removed (the module docs).
/// ceiling `ceiling`, touched as used; a file that does not check, a memory breach kept under a
/// ceiling below `ceiling`, or an ended one kept under a helper version below [`HELPER_VERSION`],
/// is a miss and removed (the module docs).
pub(crate) fn read_entry(
dir: &Path,
key: &[u8; 32],
@@ -697,13 +725,20 @@ pub(crate) fn read_entry(
(BREACH, [byte, kept @ ..]) => {
let breach =
(StageBreach::ALL.into_iter()).find(|breach| breach.byte() == *byte)?;
let memory = breach == StageBreach::Memory;
let kept = match kept {
[] => 0,
kept if memory => u64::from_le_bytes(kept.try_into().ok()?),
let (kept, holds) = match (breach, kept) {
(StageBreach::Memory, []) => (0, ceiling == 0),
(StageBreach::Memory, kept) => {
let kept = u64::from_le_bytes(kept.try_into().ok()?);
(kept, kept >= ceiling)
}
(StageBreach::Ended, kept) => {
let kept = u32::from_le_bytes(kept.try_into().ok()?);
(u64::from(kept), kept >= HELPER_VERSION)
}
(_, []) => (0, true),
_ => return None,
};
(!memory || kept >= ceiling).then_some(Entry::Breach(breach, kept))
holds.then_some(Entry::Breach(breach, kept))
}
_ => None,
}
@@ -729,10 +764,12 @@ pub(crate) fn keep_entry(dir: &Path, key: &[u8; 32], entry: &Entry, bounds: Stag
body.push(DATA);
body.extend_from_slice(data);
}
Entry::Breach(breach, ceiling) => {
Entry::Breach(breach, kept) => {
body.extend([BREACH, breach.byte()]);
if *breach == StageBreach::Memory {
body.extend(ceiling.to_le_bytes());
match breach {
StageBreach::Memory => body.extend(kept.to_le_bytes()),
StageBreach::Ended => body.extend(u32::try_from(*kept).unwrap_or(0).to_le_bytes()),
_ => {}
}
}
}
+141 -5
View File
@@ -1,10 +1,11 @@
//! Kernels past the stage bound: the `stages/` directory holds at most its bounds, the most
//! recently used kept; an entry cut short, of another key or another driver's header is a miss and
//! removed; a memory breach holds up to the memory ceiling it was kept under; the wire reads its
//! own version alone; and on a device, a kernel past the bound is refused until its helper fills
//! its entry, then made from that entry alone, leaving the device's own pipeline cache as it was
//! and its content holding no shader module, and a breach refuses it with no helper asked again,
//! a memory breach on a device given its ceiling or a lower one.
//! removed; a memory breach holds up to the memory ceiling it was kept under, and a helper's own
//! end down to the helper version it was kept under; the wire reads its own version alone; and on
//! a device, a kernel past the bound is refused until its helper fills its entry, then made from
//! that entry alone, leaving the device's own pipeline cache as it was and its content holding no
//! shader module, and a breach refuses it with no helper asked again, a memory breach on a device
//! given its ceiling or a lower one, and a helper that ended before its reply once kept.
use crate::stage::{keep_entry, read_entry, read_frame, write_frame, Entry, Framing, StageBounds};
use crate::StageBreach;
@@ -229,6 +230,81 @@ fn a_memory_breach_holds_to_its_ceiling_and_is_a_miss_above_it() {
assert_eq!(read, Some(Entry::Data(data(64))));
}
/// The helper version this file last saw the helper's code at, with that code's digest
/// ([`helper_code`]). A change to the helper's code fails
/// [`an_ended_breach_holds_to_its_helper_version_and_is_a_miss_below_it`] until
/// `HELPER_VERSION` is bumped and the pair here is the new one.
const HELPER_CODE: (u32, &str) = (
1,
"e07cb0488c4727ba561f38bd47ba8e978ddffececb964a5762d5e6b7384ef0d6",
);
/// The helper's own code as stage.rs holds it: `serve_stage` through `compile`, and
/// `read_request`, each line trimmed, blank and comment lines left out.
fn helper_code() -> String {
use sha2::{Digest, Sha256};
let source = include_str!("../stage.rs");
let span = |from: &str, to: &str| {
let start = source
.find(from)
.unwrap_or_else(|| panic!("stage.rs: {from}"));
let end = source[start..]
.find(to)
.unwrap_or_else(|| panic!("stage.rs: {to}"));
&source[start..start + end]
};
let code = [
span("pub fn serve_stage(", "\n/// What an entry holds."),
span("fn read_request(", "\n}\n"),
];
let lines: Vec<&str> = (code.iter().flat_map(|text| text.lines()))
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with("//"))
.collect();
let digest = Sha256::digest(lines.join("\n").as_bytes());
digest.iter().map(|byte| format!("{byte:02x}")).collect()
}
/// A helper's own end kept as a breach holds the helper version it was kept under, 4 bytes after
/// its byte, under every memory ceiling; one kept under a lower version, or with no version or
/// another length after its byte, is a miss and removed. The helper's code is the code the
/// version was last bumped for, so a fix of it that misses the bump fails here.
#[test]
fn an_ended_breach_holds_to_its_helper_version_and_is_a_miss_below_it() {
let scratch = Scratch::new("stage-ended");
let dir = &scratch.0;
let bounds = crate::stage::STAGE_BOUNDS;
let path = |at: u8| dir.join(crate::cache::hex(&key(at)));
let version = crate::stage::HELPER_VERSION;
let ended = Entry::Breach(StageBreach::Ended, u64::from(version));
assert!(keep_entry(dir, &key(1), &ended, bounds));
let len = fs::metadata(path(1)).expect("the entry").len();
assert_eq!(
len, 62,
"the frame, the key, the breach and its helper version"
);
for ceiling in [0, 8 << 30, u64::MAX] {
let read = read_entry(dir, &key(1), &HEADER, ceiling);
assert_eq!(read.as_ref(), Some(&ended), "at {ceiling}");
}
let lower = (version - 1).to_le_bytes();
for kept in [
&[1, 4, lower[0], lower[1], lower[2], lower[3]][..],
&[1, 4],
&[1, 4, 1],
] {
write_raw(dir, 2, kept);
assert_eq!(read_entry(dir, &key(2), &HEADER, 0), None, "{kept:?}");
assert!(!path(2).exists(), "{kept:?} is removed");
}
let code = helper_code();
assert_eq!(
(version, code.as_str()),
HELPER_CODE,
"the helper's code changed since HELPER_VERSION was bumped: bump it and record the new pair"
);
}
/// A frame reads back whole; one of another wire version is refused as such; one cut short or
/// changed in one byte reads as cut.
#[test]
@@ -456,6 +532,66 @@ mod on_device {
}
}
/// A helper that ends before its reply, as one whose driver faults in the compile does, gives
/// the fill [`crate::StageFill::Ended`]; the consumer keeps that end as
/// [`StageBreach::Ended`], and the next make, and a later device's on the same directory, is
/// refused ([`Gap::StageSize`]) with no helper asked again and no fill counted.
#[test]
fn a_helper_that_ends_before_its_reply_is_kept_as_an_ended_breach() {
let Some(descriptor) = tiled() else {
return;
};
crate::stage::TEST_BOUND.store(1, Relaxed);
let instance = crate::tests::validation::instance(&[]);
let devices = devices_of_the_cfgs_kind(&instance);
assert!(!devices.is_empty(), "no device of this cfg's kind");
let make = |device: &Device| {
device.new_compute_pipeline_state(&descriptor, crate::tests::no_constexpr_samplers)
};
let refused_as_ended = |name: &str, device: &Device| {
let refused = make(device).err();
assert!(
matches!(
refused,
Some(Error::Unsupported(Gap::StageSize {
cause: StageGap::Breach(StageBreach::Ended),
..
}))
),
"{name}: {refused:?}"
);
};
for (name, physical) in &devices {
let scratch = Scratch::new("stage-ended-device");
let device = on(name, physical, Some(&scratch.0), 0);
if !crate::tests::keeps_a_blob(name, &device) {
continue;
}
let request = match make(&device) {
Err(Error::StageUnfilled(request)) => request,
other => panic!("{name}: {:?}", other.err()),
};
// The helper reads the request whole and ends with no reply.
let (mut helper_in, to_helper) = std::io::pipe().expect("a pipe");
let (from_helper, helper_out) = std::io::pipe().expect("a pipe");
let filled = std::thread::scope(|scope| {
scope.spawn(move || {
std::io::copy(&mut helper_in, &mut std::io::sink()).expect("the request");
drop(helper_out);
});
device.fill_stage(&request, to_helper, from_helper)
});
assert_eq!(filled.err(), Some(crate::StageFill::Ended), "{name}");
device.record_stage_breach(&request, StageBreach::Ended);
refused_as_ended(name, &device);
drop(device);
let device = on(name, physical, Some(&scratch.0), 0);
refused_as_ended(name, &device);
assert_eq!(device.counters().metrics().stage_fills, 0, "{name}");
println!("{name}: a helper's own end before its reply kept, the make refused twice");
}
}
/// With the kernels' stage bound below every stage's weight, a render state is still made in
/// this process, as a render stage is refused only past the render stages' own bound, and it
/// is counted: one translated render pipeline past the kernels' bound, at its heaviest stage's
@@ -8625,6 +8625,7 @@ variant metal2vulkan-runtime::Stage::Object Object
variant metal2vulkan-runtime::Stage::Vertex Vertex
variant metal2vulkan-runtime::StageBreach::Compile Compile
variant metal2vulkan-runtime::StageBreach::CompileRequired CompileRequired
variant metal2vulkan-runtime::StageBreach::Ended Ended
variant metal2vulkan-runtime::StageBreach::Memory Memory
variant metal2vulkan-runtime::StageBreach::Time Time
variant metal2vulkan-runtime::StageFill::Compile Compile(vk::Result)
Can't render this file because it is too large.