GPU: give back exactly the pages a placement locked, and place nothing under late waits #358
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!358
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-358"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@HailLucifer666 on GitHub · 2026-11-24 23:51 UTC · original
HailLucifer666:fix/inplace-budget-overflow-and-late-wait-guard→main· +292 −21 · 2 files · 2 commits · openProblem
Three defects in the
VICTORY_INPLACEzero-copy path, all reachable from the title's own addresses and switches.place_partcomputed the pages a span covers as(start + len.max(1)).next_multiple_of(K64). The add is unchecked, so a span whose end leaves the 64-bit address space wrapped, and the rounding after it panicked rather than declining. A span near the top of the space is not memory the title can hold, and it must not be able to take the loader down.place_forgated the budget onSTATS[1] + STATS[3] + len > most(): two counters read and compared, then the placement made later, so two threads could each see room for their own. It also compared the title'slen, while what the host locks is that length rounded out to 64 KiB pages — up to one page more per placement — and recorded the same short figure, soVICTORY_INPLACE_MBwas overrun by the rounding alone, every time, not only under a race.VICTORY_LATE_WAITbreaks that. Nothing enforced it, and setting both produced silent stale reads.Fix
aligned_span(start, len)is now the one place a span is rounded, returningNoneinstead of wrapping or panicking, and it is whatplace_part,place_forandgoneall go through.try_reserve_at/release_at, held inRESERVED), reserving the rounded bytes, released exactly once on every failure path and ingone.release_atsubtracts withchecked_subin every build: a wrapping subtraction would take the counter to about 2^64, after which every reservation is refused and the feature is silently off for the rest of the run.VICTORY_LATE_WAITor the relay is on: buffers and windows are copied instead, counted inSTATS[8], and warned about once.The window exemption was withdrawn during review, and that is the part worth reading. The first version exempted windows outside buffers, justified by "it is a copy, so the flights know its writes". That is false about this code: a placed window is a
Shadowwithplaceset, andShadow::gpu_writes,Shadow::writingandShadow::copy_back_withall return early on that, so nothing declares a placed window's writes to the flights either. The exemption kept the exact hazard it was meant to refuse. Whether a shader ever writes one is not something I can settle here, so both stages are refused together rather than keeping an unproven exemption.Verification
cargo test -p victory-gpu inplace:: --locked -- --test-threads=1— 10 passedcargo clippy --workspace --all-targets --locked -- -D warnings— cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings— cleancargo test -p xtask --locked— 4/4 passedaligned_spanpanics "attempt to add with overflow"; a two-step check-then-claim admits 8 of 8 racing threads instead of 4;refuses_in_placereturning false fails the rule assertion;release_atback to a wrappingfetch_subleaves the counter at 18446744073709486080 where 0 was expected.Known residual, and a pre-existing flake
One gap I could not close. The release-on-failure branches have no test of their own. I wrote one (
place_for_withagainst uncommitted memory, assertingRESERVEDunchanged) and removed it after measuring that it was the cause of a different failure: it initialises the process-global GPU device, and with it in the suitewarp_a_title_buffer_in_place_shows_its_bytes_at_its_offsetfailed to decommit a page about one run in three (6 of 6 clean with it isolated). A test that makes CI flaky is worse than the gap it closes. What remains tested isrelease_at's pairing and its underflow guard, plusplace_forandgonederiving their bytes from the same purealigned_span.cargo test -p victory-gpu --libcrashes before this change too. Under parallel execution the test binary intermittently dies withSTATUS_ACCESS_VIOLATIONnaming no test. Measured onvictory-fork/mainitself: 4 failures in 20 runs (20%). This branch: 5 in 30 (17%) — the same rate, so it is not introduced here. My earlier 5-in-5 and 10-in-10 clean base samples were luck. Related: PR #151 is an open fix for the decommit retry in the same test, which suggests the instability around these WARP tests is already known. I did not attempt to fix it; it is out of scope for this change.Review notes
gone's early return on an unrounded span is dead by construction and kept rather than anexpect, which would unwind out of aDrop; the comment names both consequences.inplace.rs/shadow.rs, most nearlet_go_idle. This touchesplace_part/place_for/goneand the onegonecall site inshadow.rs; the diff is small and additive.@HailLucifer666 on GitHub · 2026-11-25 13:55 UTC · original
Rebased onto current
mainand each of the three fixes probed separately, because a test that passes is not evidence until breaking the code makes it fail.aligned_spanoverflowwrapping_add+next_multiple_oftry_reserve_atatomicitystorerefuses_in_place() && windowAll three restored byte-identical afterwards (
inplace.rssha256ffe62947919e60d1).cargo test -p victory-gpu --lib inplace::: 10 passed, 0 failed.What each one is actually protecting, since they are three different failure shapes:
start + lenpast the top of the address space wrapped to a small number, and the placement then described memory that is not the memory asked for. Now the ask comes to nothing before the host is asked, counted where the cover refusal is counted.compare_exchange_weakmakes the decision and the claim one operation. This is the one a test can only catch under threads, which is why that test runs threads.VICTORY_LATE_WAIT, and the relay, which counts as stage 3) know about shader writes only from the ranges copies declare. A placed buffer has no copy to declare them from, so the assumption "nothing reads title memory that a submission not yet run writes" is false there. The branch refuses it for windows only; this refuses it for every placement.The part this does not cover: the refusal means
VICTORY_INPLACEdoes nothing whenever late waits are on, and it says so once. That is a behaviour change for anyone who had both switches set and was, unknowingly, racing. Their frame cost goes up; their corruption risk goes to zero. I think that is the right trade, but it is a trade, not a free fix.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.