Skip to content

Tests: avoid poisoning SYNC_GRAPH with an unmapped fake fence in queue_tests (#1978) - #2002

Open
zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:d3d12x/fix-parallel-test-race
Open

zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:d3d12x/fix-parallel-test-race

Conversation

@zondy1i

@zondy1i zondy1i commented Nov 25, 2026

Copy link
Copy Markdown

Fixes #1978.

hle::d3d12x::real::queue_tests::queue_slot_18_before_the_layout_is_known_writes_8_bytes pushed an unmapped sentinel address (0x5EED_0000) into real::FENCES and invoked queue_dispatch(14, this, fence, 1, 0, 0) with a mock signal returning 0 (S_OK). Because hr >= 0, queue_dispatch registered that bogus pointer in fence_x::FENCES (note_queue_signal) and list_x::SYNC_GRAPH.title_fences (note_title_queue_signal), while the test only removed it from real::FENCES.

Under --test-threads=1, hle::d3d12x::list_x::tests::* ran alphabetically before hle::d3d12x::real::queue_tests, hiding the bug. Under parallel cargo test, queue_tests finished first and left 0x5EED_0000 in SYNC_GRAPH.title_fences; as soon as any concurrent list_x test ran would_signal_close_cycle, prune_title_fence(0x5EED_0000, tf) called ID3D12Fence::GetCompletedValue() through the unmapped address and killed the test runner with 0xc0000005 STATUS_ACCESS_VIOLATION.

What is in it

  • Replace the unmapped 0x5EED_0000 sentinel in queue_tests (crates/xcl/src/hle/d3d12x/real.rs) with a valid minimal stack ID3D12Fence COM vtable whose GetCompletedValue returns u64::MAX, so any concurrent prune_title_fence call during the test executes safely without UB.
  • Add #[cfg(test)] cleanup helpers fence_x::forget_fence_for_test (crates/xcl/src/hle/d3d12x/fence_x.rs) and list_x::forget_title_fence_for_test (crates/xcl/src/hle/d3d12x/list_x.rs), invoked from a Drop guard in queue_tests under the respective locks before the stack mock objects go out of scope.
  • Test-only change (#[cfg(test)]); no runtime code paths modified.

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.01), AMD Ryzen 5 7500F, 64 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), debug tests + release smoke.
  • Before fix: cargo test -p xcl --lib -- hle::d3d12x::real::queue_tests hle::d3d12x::list_x crashed 3/3 runs with 0xc0000005 STATUS_ACCESS_VIOLATION.
  • After fix: cargo test -p xcl --lib -- hle::d3d12x::real::queue_tests hle::d3d12x::list_x passed 10/10 consecutive parallel runs (28 passed, 0 failed each).
  • cargo test -p xcl --lib -- hle::d3d12x: 5/5 parallel runs completed with 0 0xc0000005 crashes (160/160 passed on run 4; unrelated coherent_buffer_sanitizes_console_flags_and_state VirtualFree flake observed on runs 1–3, 5).

Regression run

main:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1622 (PresentX 1622)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16539 MB

PR:

xcl-smoke v1
commit: 4197910e7706d722ecbeac7701d345453dc6340a
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16963 MB

Not tested

  • Full workspace parallel test run; AMD / Intel GPUs; Linux / Wine + vkd3d-proton.

AI use

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Overlap note: #1523 (mine, opened earlier for #1487, mergeable, CI green) fixes the same crash. It replaces the 0x5EED_0000 integer in queue_slot_18_before_the_layout_is_known_writes_8_bytes with a static fake ID3D12Fence whose GetCompletedValue returns a completed value, so prune_title_fence no longer calls through an unmapped address. JJAutoCompare linked #1978 to it as well.

This PR goes a step further by also removing the test's entries from fence_x::FENCES and SYNC_GRAPH afterwards, which keeps the shared state clean for later tests. If the maintainers prefer that, I'm happy to close #1523 in its favour. Only one of the two should go in.

Separately confirmed here (RTX 3070, Windows 11): the parallel cargo test -p xcl --lib -- cpu_writes q_release queue run died with 0xc0000005 while list_x's cross-queue tests were running. Single-threaded, it passes on both main and another PR's head.

AI-assisted (Claude Code).

@raylitebull

Copy link
Copy Markdown
Member

Review note on 4197910:

  • Diff audited and CI workflow approved (currently running).
  • As noted by @upipibi, #1523 targets the same fake-fence SYNC_GRAPH issue in queue_slot_18_before_the_layout_is_known_writes_8_bytes. Depending on which approach is preferred, #2002 will still need Build and test green plus an AMD verification pass before merge.

@JoaoPauluu

Copy link
Copy Markdown

A run under Wine on Linux, with vkd3d-proton as the host D3D12. The 0xc0000005 from #1978 does not reproduce here, so this cannot confirm the fix. Another abort shows up in the same test pair, on main and on this PR alike.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257. Release lib test binaries, cross-built for x86_64-pc-windows-gnu: 4197910 as it is (based on 6567c5f) and main cbc296a, no uncommitted changes. Each run is one Wine process with --test-threads=4, 10 runs of each, main and this PR alternating.
  • hle::d3d12x::real::queue_tests hle::d3d12x::list_x (the pair from Test suite: parallel cargo test intermittently dies with 0xc0000005 (hle::d3d12x queue_tests × list_x race) #1978):
    • main: 8 of 10 runs ok. 30 passed. In 2, the process died.
    • this PR: 7 of 10 runs ok. 28 passed. In 3, the process died.
    • Every death prints glibc's double free or corruption (!prev) right after vkd3d-proton/DXVK report Found device: NVIDIA GeForce RTX 3060, i.e. while a device is being made. The last test reported before it was list_x::tests::a_mirrored_buffer_binds_its_mirror_without_asking_readable ... ok each time. No 0xc0000005 in any run.
  • hle::d3d12x as a whole:
    • main: 10 of 10 runs end 175 passed; 2 failed; 2 ignored.
    • this PR: 8 of 10 runs end 158 passed; 2 failed; 2 ignored. In 2, the same double free abort came after bind::tests::reset_and_clear_state_track_initial_pso_and_clear_root_args ... ok.
    • The 2 failures are the same on both and in every run: bind::tests::execute_indirect_reads_the_arguments_written_before_it (bind.rs:1086) and device_x::tests::gpu_depth_buffer_created_for_unordered_access_is_placed (device_x.rs:1126). They are unrelated to this PR.

The abort is in the host's C heap (Wine / vkd3d-proton / the Vulkan driver) while devices are made in parallel. It may be a vkd3d-proton or driver problem rather than XCL's, and I have not narrowed it down. It occurs with and without this PR at about the same rate.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@luckyteagirl

Copy link
Copy Markdown

AMD Windows verification for PR #2002 at 4197910e7706d722ecbeac7701d345453dc6340a

The maintainer requested an AMD pass on the parallel queue-test crash in #1978. I tested this PR's clean exact head against current main cbc296ab65a2661a61e3e2da109134bcd5319f60 on Windows 11 build 26200, Radeon RX 6800M (driver 30.0.13002.13003), Ryzen 9 5980HX, Rust 1.99.0 MSVC, with XCL_ADAPTER=6800M and 32 test threads.

Each invocation used cargo test -p xcl --lib --locked -j 2 -- --exact --test-threads=32 --show-output <queue_slot_18...> <list_x...>. The first exact test was hle::d3d12x::real::queue_tests::queue_slot_18_before_the_layout_is_known_writes_8_bytes; I paired it separately with:

  1. hle::d3d12x::list_x::tests::cross_queue_cycle_and_same_queue_fifo_do_not_deadlock
  2. hle::d3d12x::list_x::tests::cross_queue_wait64_before_signal_does_not_deadlock_submit_thread
Pair Current main PR #2002 head
Queue slot + cross-queue cycle 5/5 runs exited 0xc0000005 STATUS_ACCESS_VIOLATION before a test total 5/5 runs passed, 2 passed, 0 failed, 0 ignored each
Queue slot + Wait64 before signal 5/5 runs exited 0xc0000005 STATUS_ACCESS_VIOLATION before a test total 5/5 runs passed, 2 passed, 0 failed, 0 ignored each

cargo build --locked --workspace -j 2 also passed on the PR head. These runs exercise the reported test interaction and support the test-only crash fix on AMD. They do not establish that PR #2002 is preferable to the overlapping #1523, nor that the full workspace suite is green.

Not tested: Full library/workspace suite, retail title smoke, Intel/NVIDIA GPUs, or a merge of this older PR base with current main. No game data was used.

AI assistance: OpenAI Codex (GPT-6) ran the comparison and drafted this report.

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.

Test suite: parallel cargo test intermittently dies with 0xc0000005 (hle::d3d12x queue_tests × list_x race)

6 participants