Repository navigation
Conversation
…ites nothing
FIND-14 in the coordination thread: `watch.rs` documents that "memory freed and
allocated again while a tracker holds it is not seen", and nothing connects that
with `Shadow`'s pending snapshot - the copy holds the address it was registered
with and writes back through it. So a title range freed and re-used between a
submission and its copy-back can have that submission's shader bytes written
into whatever took the addresses.
Reproduced with no game and no AMD card, in the test this commit adds: register
a page of title memory, take the submission's snapshot, let a shader write one
byte into the copy, `unregister` and `VirtualFree` the range, take the same
addresses again with `VirtualAlloc` and fill them with 0xEE, then run the
copy-back. Before the change that byte is 0x99 - the shader's - inside the
title's new allocation:
left: 153 (0x99: what the shader wrote for a submission that is over)
right: 238 (0xEE: what the title's next use of the address held)
`Shadow` now carries a flag that `unregister` sets, and `copy_back_or_not`
returns before touching anything once it is set: a copy whose title buffer is
gone writes nothing back, and stays alive for the lists that still hold it - its
own bytes are the lists' to use, the title's memory is not.
cargo test -p victory-gpu --lib --profile diag --features diagnostics
245 passed, 2 failed, 1 ignored
(the 2 are the FIND-9 view-heap pair, which is Marvisak#2937's, not this commit's)
cargo clippy -p victory-gpu --all-features -- -D warnings: clean
Whether this is the mechanism behind Marvisak#2025's intermittent corruption is not
claimed: it is one way stale shader bytes reach re-used title memory, and Marvisak#2025
was AMD and intermittent. What it gives Marvisak#2025 is a reproduction of the class on
any host, with no game.
|
Verified ordinary path; remaining stale write through marked-page path. Exact runtime head Local test-only changes: require host buffer/mark allocation (no GPU skip), request the exact freed address with The marked case uses the actual
Root: the new Suggested fix: include marked-page writes in the same retirement/lifetime protocol; add this marked remap test alongside the existing ordinary one. A separate source-review concern, not concurrency-tested here: a single pre-write atomic check does not serialize an unregister/remap that happens after that check. Retirement needs a shared exclusion/generation protocol covering validation through the guest write, with consistent lock ordering; switching Relaxed to SeqCst alone would not close that interleaving. Preserve snapshot/pending cleanup when suppressing writes too (the new early return bypasses it until shadow destruction). Command through local Wine runner: |
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — real stale-write hazard closed: pending copy-backs held Arc'd shadows that still wrote through the released range's address. gone is set in unregister and short-circuits copy_back_or_not; the test replays VA reuse and asserts the new owner's byte survives. Graceful skip without a GPU and on non-reuse.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Good catch on suppressing stale write-backs after a buffer is unregistered, but there are a few issues in crates/victory-gpu/src/shadow.rs:
- Early return leaks snapshot buffers and leaves
pending/ armed state stuck (shadow.rs:418-420,478-488):
Returning0at the top ofcopy_back_or_notbypassespending.remove(&(address, address + len)),compared.clear(),segments.drain(..)->give_back(bytes), andt.disarm(). BecauseArc<Shadow>remains alive as long as command lists reference it, those snapshot buffers stay pinned out of the pool and the tracker remains armed. Gate only the write-back branch (e.g.back && !self.gone.load(Ordering::Acquire)) so cleanup at lines 478–488 always runs, just likekeep_writes. - Other title-memory write-back paths on
Shadoware uncovered (copy_back_pageatshadow.rs:208,copy_back_markedatshadow.rs:503):copy_back_marks(shadow.rs:926-956) upgradesWeak<Shadow>fromMARKS.owners, which still succeeds while any command list holdsArc<Shadow>afterunregister, and then callscopy.copy_back_marked(page).memory.rs:690iteratescopies[k]captured before submission and callscopies[k].copy_back_page(at as usize).
Both paths also write back to title memory viacrate::host::write_mappedand should checkself.gone(andcopy_back_markedshould still drop any saved bytes / avoid leaving stale armed state whengone).
- Non-deterministic regression test (
shadow.rs:1690-1732):
VirtualAlloc(std::ptr::null(), len, ...)at line 1709 is not guaranteed to reusep, and lines 1713–1721 return early without failing wheneverq != p— so the test can silently skipcopy.copy_back(p, 64)and theassert_eq!(after, 0xee)check. Passingp as *const _as the preferred address (or also testing directly onpwhile still mapped afterunregister, verifying both that bytes stay untouched and thatpending/snapshots are drained) would make it deterministic. - Minor: Prefer
Ordering::Releaseinunregister(shadow.rs:1024) andOrdering::Acquirein the copy-back checks for cross-thread visibility, and remove the unexplained(FIND-14)reference in the comment at line 417.
|
FIND-14: side-by-side check of #3036 and #2612 Hardware: NVIDIA GeForce RTX 4070, Windows 11 (native D3D12, MSVC). Base: In the cross-tests I added
#3036: defects
#2612: defects and gaps
Recommendation AI-assisted (Claude Code). |
…watch-and-file-sharing GPU, HLE: guard pending shadow copy-backs on buffer release and share DirectStorage file opens (Marvisak#3036, Marvisak#3018)
fyernald
left a comment
There was a problem hiding this comment.
A Windows 10 data point on whether the test observes the hazard, since it returns early when the address isn't reused: RTX 3080, Windows 10 22H2, a_pending_copy_back_does_not_write_into_memory_the_title_took_back run alone 10 times each.
| address reused | result | |
|---|---|---|
this PR (0014e65) |
10/10 | 10/10 pass |
same test with the gone check removed (= main's behaviour) |
10/10 | 10/10 fail, left: 153 (0x99), right: 238 (0xEE) |
So on Windows 10 too, VirtualAlloc(null, ...) returns the freed address every time and the test catches the stale write. This doesn't change the open points above (the marked and copy_back_page paths, and the cleanup the early return skips).
Memory the title frees with XMemFree (no hook) or XMemFreeDefault and gets back from the next allocation at the same address was never reported to title_memory_remapped: the host heap hands out a freed block again without a word. A copy-back still pending for the freed memory then put the shaders' bytes into the new memory, on all three paths (a declared range's snapshot, a marked page, a page at a computed address). Committed resources get their memory from XMemAlloc too, and give it back through XMemFree when released. XMemFreeDefault now reports the memory as remapped before it frees it, holding the mapping lock (title_memory_remapping) across the report and the free, as Upload's drop does: - a 32-bit block: its whole reservation, walked region by region (guards and protection changes split it); - a heap block: only the host pages it fills. Its first and last page may hold other blocks of the heap, still in use; a block inside one page reports nothing, so small frees cost nothing. Not covered: a title allocator hook (__XMemAllocationHooks__) frees and reuses memory we do not see, and so do the host's VirtualFree and NtFreeVirtualMemory. XMemFreePhysicalPages needs no report: freed pages stay shown by their views until unmapped, and unmapping reports. Tests: freed_memory_is_reported_to_the_gpu_side (xmem) checks each range reported; memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported (shadow, WARP) frees and reallocates a three-page copy at the same address while each copy-back path is pending. Reported, all three keep the title's new bytes and the next refresh takes them; unreported (the control), the shaders' bytes land in the new memory on all three. This commit also adds host::tests::no_submission, so that parallel submissions cannot take the marks the test sets. Thanks to pawrenity's comparison of Marvisak#2612 and Marvisak#3036 for the free-and-reuse case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One way to close the K case (release without free) and the marked-path report above, tried in another tree (Windows 11, RTX 3080 Ti,
Tests there: a pending ordinary copy-back after free and reuse writes nothing; a marked page writes nothing (without the check it wrote 65536 bytes into the freed page); a release whose memory stays still writes back; a view copy of freed bytes is marked and the next view gets a new copy. Not covered: a remap under a still registered buffer (M1/M2 above), memory the title unmaps itself, a copy-back already under way when the memory is freed, and there is no test that goes through a real placed-resource heap release. The tree differs from this branch (its marked path is organised differently), so this is a description rather than a patch. No title data in the tests. AI assistance: written and tested with Claude Code. |
Memory the title frees with XMemFree (no hook) or XMemFreeDefault and gets back from the next allocation at the same address was never reported to title_memory_remapped: the host heap hands out a freed block again without a word. A copy-back still pending for the freed memory then put the shaders' bytes into the new memory, on all three paths (a declared range's snapshot, a marked page, a page at a computed address). Committed resources get their memory from XMemAlloc too, and give it back through XMemFree when released. XMemFreeDefault now reports the memory as remapped before it frees it, holding the mapping lock (title_memory_remapping) across the report and the free, as Upload's drop does: - a 32-bit block: its whole reservation, walked region by region (guards and protection changes split it); - a heap block: only the host pages it fills. Its first and last page may hold other blocks of the heap, still in use; a block inside one page reports nothing, so small frees cost nothing. Not covered: a title allocator hook (__XMemAllocationHooks__) frees and reuses memory we do not see, and so do the host's VirtualFree and NtFreeVirtualMemory. XMemFreePhysicalPages needs no report: freed pages stay shown by their views until unmapped, and unmapping reports. Tests: freed_memory_is_reported_to_the_gpu_side (xmem) checks each range reported; memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported (shadow, WARP) frees and reallocates a three-page copy at the same address while each copy-back path is pending. Reported, all three keep the title's new bytes and the next refresh takes them; unreported (the control), the shaders' bytes land in the new memory on all three. This commit also adds host::tests::no_submission, so that parallel submissions cannot take the marks the test sets. Thanks to pawrenity's comparison of Marvisak#2612 and Marvisak#3036 for the free-and-reuse case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. The test is a useful reproduction of FIND-14, but the fix in
What would change the verdict: set the flag where memory is actually freed, or route it through Generated by Claude Code |
|
Closing in favour of #2612, and all three review points are right.
#2612 does the first and third at the right place (the runtime's What this PR has that #2612 does not, and I have handed over rather than dropped: the reproduction. On #2612's own head
Thanks to @pickles976, @pawrenity, @Machad3x and the triage for three independent reproductions of the same hole - the honest outcome is one fix, and #2612 is it. |
What this fixes
FIND-14 in the coordination thread:
watch.rsdocuments that "memory freed andallocated again while a tracker holds it is not seen", and nothing connected that
with
Shadow's pending snapshot. A copy holds the address it was registered withand writes back through it, so a title range freed and re-used between a
submission and its copy-back can have that submission's shader bytes written into
whatever took the addresses.
Reproduced with no game and no AMD card, in the test this PR adds: register a
page of title memory, take the submission's snapshot, let a shader write one byte
into the copy,
unregisterandVirtualFreethe range, take the same addressesagain with
VirtualAllocfilled with0xEE, then run the copy-back. Before thechange:
The change
Shadowcarries a flag thatunregistersets;copy_back_or_notreturns beforetouching anything once it is set. A copy whose title buffer is gone writes
nothing back, and stays alive for the lists that still hold it - its own bytes
are the lists' to use, the title's memory is not.
The 2 are the FIND-9 view-heap pair on this NVIDIA host, which is #2937's.
What this does not claim
#2025's intermittent corruption was AMD and intermittent. This is one way
stale shader bytes can land in re-used title memory, deterministically and on any
host; it is not proof that it is that report's mechanism. What it gives #2025 is
a reproduction of the class, with no game - which is what FIND-14 asked for
("a synthetic concurrency test exercising remap-during-pending-copy-back if
someone wants to pursue it without the game").
Note on the test's setup
It only observes the hazard when the allocator hands the same address back
(
q == p); when it does not, the test frees the new allocation, prints that itwas not observed and returns, rather than writing through an address that belongs
to nobody - which would be the same bug in the test. On this machine the same
address comes back every run.