Repository navigation
Conversation
When replacing an existing entry in CHAINS, bind the returned Option<Arc<Chain>> and drop it after releasing the CHAINS mutex so dropping a replaced chain (and any COM/D3D12 pipeline objects inside, whose Release can re-enter forget_pso -> forget) never runs while holding CHAINS. Matches dispatch_chain::forget and adds a unit test verifying re-entrant lock acquisition during Drop. Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
|
merge-check |
|
Review (head 0e5223e, diff read, not a merge-check):
Fine: the deadlock is real. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
merge-check verdict: safe to merge |
bmjask
left a comment
There was a problem hiding this comment.
Review of 0e5223e6: 2 finding(s) (1 high, 1 medium), most severe first.
- High
crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:316: A key collision in CHAINS only happens in thepso_releaserace (the driver Release returns 0 beforeforget_psoruns, real.rs:2615-2620), and in that race the staleforget_psothen removes the newly built chain, so the PR turns the .... (inline) - Medium
crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:278:signature_forhas the same pattern this PR fixes:SIGNATURES.lock().unwrap().entry(key).or_insert(created)drops the losingcreatedroot signature (a COM Release) while SIGNATURES is still locked. (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| *result = first.into_raw(); | ||
| CHAINS.lock().unwrap().insert(*result as usize, chain); | ||
| // Drop any replaced chain outside `CHAINS`: releasing a tail PSO also goes through `forget_pso`. | ||
| replace_entry(&CHAINS, *result as usize, chain); |
There was a problem hiding this comment.
High: A key collision in CHAINS only happens in the pso_release race (the driver Release returns 0 before forget_pso runs, real.rs:2615-2620), and in that race the stale forget_pso then removes the newly built chain, so the PR turns the deadlock into silently wrong GPU work. Thread A releases split PSO P: f(this) returns 0, so the driver can reuse the address, but A hasn't reached forget_pso yet. Thread B creates a new split program, gets the same address P, and build calls replace_entry(&CHAINS, P, new_chain), dropping the old chain (no deadlock now). A then runs forget_pso(P) -> dispatch_chain::forget(P), which removes B's live chain and releases its tail PSOs. Every later dispatch(…, P, …) misses and falls back to dispatching the first piece alone (or remap_fallback), so the program's later pieces never run. Forgetting before the final Release, or keying CHAINS by (address, generation) like pso_manifest::ready_compute_generation, would fix the root cause. At minimum, logging when replaced.is_some() would make it visible.
| @@ -278,6 +278,11 @@ unsafe fn signature_for(dev: &ID3D12Device, samplers: &[pso::StaticSampler]) -> | |||
| Some(SIGNATURES.lock().unwrap().entry(key).or_insert(created).clone()) | |||
There was a problem hiding this comment.
Medium: signature_for has the same pattern this PR fixes: SIGNATURES.lock().unwrap().entry(key).or_insert(created) drops the losing created root signature (a COM Release) while SIGNATURES is still locked. When two preparation workers build split programs with the same device and samplers at once, both miss and create a root signature, and the second's or_insert drops its duplicate inside the SIGNATURES critical section. If that Release is hooked or re-enters XCL code that touches SIGNATURES, it deadlocks the way CHAINS did. Binding the duplicate and dropping it after unlocking would avoid it.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
Thanks @bmjask for the review notes — leaving
|
Drop any replaced
Arc<Chain>outside theCHAINSmutex when inserting intodispatch_chain::CHAINS.dispatch_chain::forgetalready binds the removedOption<Arc<Chain>>and drops it after unlockingCHAINS, because dropping aChainreleases its COM/D3D12 tail pipeline states (whoseReleasecan re-enterforget_pso->dispatch_chain::forget).dispatch_chain::buildcalledCHAINS.lock().unwrap().insert(...)directly, which would drop a replacedArc<Chain>while still holdingCHAINS.What is in it
replace_entryhelper incrates/xcl/src/hle/d3d12x/real/dispatch_chain.rsto bind and drop the previous map value after releasing the mutex, and use it when inserting intoCHAINSindispatch_chain::build.replacing_chain_entry_drops_previous_value_outside_lockverifying the map mutex is unlocked when a replaced entry'sDropruns.Tested
rustc 1.99.0 (b940084d7 2026-09-28), debug tests + release build (cargo build --release -p xcl: 0 new warnings vsmainbaseline of 39).scripts/test.ps1(workspace build,cargo bench -p xcl --bench '*' -- --test,cargo test --workspace -- --test-threads=4with DXC 1.9.2609): exit 0, 0 failed (replacing_chain_entry_drops_previous_value_outside_lockpassed; SKIPPED GPU tests: 22 no wave64, 2 no heap windows).Regression run
main:
PR:
Not tested
XCL_SAMPLE_*unset).dispatch_chain::buildend-to-end on a colliding key (the unit test exercises thereplace_entryhelper directly rather thanbuild).pso_release(real.rs) ordering whereReleaseruns beforeforget_pso(a concurrent key reuse in that window still drops the newer entry later; this PR only removes the self-deadlock on replacement).AI use
replace_entryhelper and unit test, ran the local build/test/smoke verification, and drafted this PR description.