Skip to content

Recompiler: serialize dxc::wait_for_memory slot admission (#2463) - #2652

Open
fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/dxc-wait-for-memory-race
Open

fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/dxc-wait-for-memory-race

Conversation

@fixgep

@fixgep fixgep commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes the TOCTOU admission race in dxc::wait_for_memory (crates/xcl/src/gpu/recomp/dxc.rs) where concurrent DXC worker wakeups read WORKING without synchronization before calling fetch_add(1), admitting bursts past both the commit headroom check and WANTED_AT_ONCE. Part of #2463, Part of #1566, Part of #1269.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: wrap WORKING admission checks (plenty, timed_out, cur == 0, and cur < WANTED_AT_ONCE && wanted()) and fetch_add(1) in a MemoryGate mutex while keeping MemorySlot::drop lock-free and sleeping outside the mutex; add synthetic multi-threaded unit tests in memory_gate_tests.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 3060 (driver 32.0.15.9144), AMD Ryzen 5 7500F, Windows 11 Pro 10.0.26200, rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), debug & release builds on commit 88d7b0a1.
  • cargo test -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4: 24 passed, 0 failed, 0 ignored (0 SKIPPED); also 24 passed, 0 failed under XCL_ADAPTER=warp.
  • cargo test -p xcl --lib -- --test-threads=4: 1312 passed, 1 failed (gpu::recomp::tests::gpu_clamp_and_omod_per_instruction, v_pk_add_i16 clamp mismatch on RTX 3060), 27 ignored (25 SKIPPED: 21 no wave64, 3 wave32 per-lane refused, 1 cannot disable the driver cache).
  • XCL_ADAPTER=warp cargo test -p xcl --lib -- --test-threads=4: 1312 passed, 1 failed (hle::d3d12x::list_x::tests::mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares under parallel adapter/UMA init; passed on default GPU), 27 ignored.
  • cargo test -p xcl --test '*' -- --test-threads=4: 126 passed, 0 failed, 20 ignored across 33 integration test suites (1 SKIPPED: no heap windows).

Regression run


xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1600 (PresentX 1600)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14006 MB


xcl-smoke v1
commit: 88d7b0a19a276f81491e8430acb5d7dd501ebb1e
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13964 MB

Not tested

AI use

  • Antigravity (Gemini 4 Hydrogen): GitHub REST API pre-flight check, root-cause inspection, implementation of MemoryGate and memory_gate_tests, test/smoke execution, and PR description drafting.

wait_for_memory previously checked WORKING against commit headroom and WANTED_AT_ONCE with an unlocked load before calling fetch_add(1), allowing concurrent worker wakeups to admit an unbounded burst past both limits.

Wrap the admission check and working-slot increment in a MemoryGate mutex while keeping MemorySlot::drop lock-free and sleeping outside the mutex, and add multi-threaded unit tests verifying tight-headroom, WANTED_AT_ONCE, low-commit single-slot, and timeout behavior.

Part of xcl-dev#2463
Part of xcl-dev#1566
Part of xcl-dev#1269
Assisted-by: Antigravity (Gemini 4 Hydrogen)
@pickles976

Copy link
Copy Markdown

Tested: exact clean head 88d7b0a19a276f81491e8430acb5d7dd501ebb1e, Windows MSVC target under Wine 11.0 on Linux, 16 GiB RAM / RTX 4060 Laptop GPU host. Fresh Compiling xcl .../xcl-pr2652/crates/xcl provenance confirmed.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib memory_gate_tests -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored, 0.14 s. This covers tight synthetic commit headroom, the wanted burst limit, draining concurrent waiters, and the single unwanted progress slot. Tests internally spawn concurrent callers despite the serial test harness. Run through the local Wine wrapper in a scope with MemoryMax=9G / MemorySwapMax=512M.

Not tested: real compiler-memory peaks, Windows-native execution, GPU dispatch, retail title, or matched-parent regression. These are CPU synchronization tests with supplied memory values, not proof of Wine's commit telemetry or a hard memory budget. The existing 60-second escape remains; this addresses #2463 item 2, not its separate title-thread driver-compile bypass. No title-safety or FPS claim.

Local log: .compat-xcl/logs/verify-pr2652-wine-memory-gate.log. AI use: omp / OpenAI Codex GPT-6 Astra, test execution and report; no source changes.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.
Targeted run of low_commit_unwanted_admits_only_one_progress_slot, tight_commit_headroom_bounds_concurrent_admissions, wait_for_memory_drains_concurrent_waiters_within_cap, wanted_burst_never_exceeds_wanted_at_once: 4 passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

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.

3 participants