GPU: drop overlapping write-watch pins on title_memory_remapped (#174) #175
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/Belobug--VIctory-Belobug-AMD!175
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-175"
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?
@KernelSmoker on GitHub · 2026-11-25 19:10 UTC · original
KernelSmoker:fix/watch-drop-pins-on-remap→main· +133 −12 · 1 files · 1 commits · openFixes #174.
What
crates/victory-gpu/src/watch.rs:Guards::drop_pins(from, to) -> bool, which removes remapped block range[from, to)from activewriting()pins, splitting any pin that extends outside[from, to)so neighboring still-live blocks stay pinned.g.drop_pins(from, to)intitle_memory_remappedalongside clearingprotected,clean,holes, andaliased, and includeddropped_pinsinchangedso region epochs bump consistently.remapping_drops_overlapping_pins_and_keeps_adjacent_ones(pure unit test for disjoint, wholly contained, partial left/right overlap, and middle-split pin ranges)remapped_view_does_not_inherit_pins_from_earlier_writing(maps a 2-block pagefile view, callswriting(), unmaps + callstitle_memory_remapped, verifies the pin is cleared, and verifies a fresh view is guarded cleanly rather than staying pinned).Why
As diagnosed in #174,
title_memory_remappedclearedprotected,clean,holes, andaliased, but left 2-secondwriting()pins ing.pins. When a new view was mapped at the same virtual address within 2 seconds (for example in parallelwatch::testsruns afterkernel_reads_into_guarded_blocks_after_opening),guard()found the stale pin, kept the new view writable, and falsely reported it written on every check.Dropping only the remapped
[from, to)block range ensures an unmapped/remapped virtual range never leaks stale pins onto a newly mapped view, while keeping pins intact on any neighboring blocks outside the remapped range.Tested
Bazzite Linux 45 (x86_64), Rust 1.98.1, cross-targeting
x86_64-pc-windows-gnu(tested under GE-Proton 10-34 / Wine 10.0; not a native Windows 11 run):cargo check --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnu: passed.cargo clippy -p victory-gpu --no-deps --all-targets --locked --target x86_64-pc-windows-gnu: 0 new warnings inwatch.rs.cargo xtask policy --staged:asset policy: 1 files ok.victory_gpu ... watch::tests(default parallel test threads): 30/30 runs passed (9 passed, 0 failed per run).victory_gpu ... watch::tests --test-threads=1: 5/5 runs passed (9 passed, 0 failed per run).No game files were used and the title was not run for this patch.
@adrianmjim on GitHub · 2026-11-25 21:56 UTC · original
I measured this on native Windows 11 (build 26300) with an RX 7900 XT and Rust 1.98.1. The description's runs were under Wine with
watch::only, and in #174 these tests never failed withwatch::alone. So I ran the fullvictory-gpulib test binary with default test threads, for main (000ffdd) and for this branch (66c6d4f), each built in its own tree. That was 140 runs each, interleaved, with the first one in each round alternating (100 in one session, 40 in a second).The three tests from #174:
a_view_mapped_beside_a_guarded_one_makes_it_check_again12,a_write_through_another_view_is_reported_at_the_guarded_one5,a_write_is_reported_at_every_checked_view2). One more main run stopped without a result.Other failures I saw on both trees (this branch / main):
pipeline::depth_bounds_test::depth_bounds_control_a_title_draw("host refused the depth bounds pipeline"): 17 / 11watch::tests::written_pages_are_reported_to_every_askeratbefore.is_empty(): 11 / 9frame::tests::waits_end_on_ticks_and_count_framesfailed more often on this branch in the full runs: 80 vs 59. In 29 rounds only this branch failed it, and in 8 rounds only main did. The machine was under heavy CPU load from other work during most of these runs, but the two trees were interleaved, so load alone does not explain the 29 against 8. Run on its own (frame::, 60 runs each, interleaved), it failed 34 times here and 35 on main.frame.rsis not touched, and its failing assert (line 252) checks flip ticks 5 ms apart. My guess is timing between the tests running at the same time in the full binary, not a path from the pins toframe, but I have not found what makes the difference.On the rule: the local experiment in #174 dropped only pins wholly inside the range. This PR also trims pins that reach past the range, which matters more in the title than in the tests.
writing()pins every block a kernel read covers, while xmem callstitle_memory_remappedonce per view, and views can be a single 64 KiB page (the GPU's page mappings). With the wholly-inside rule, a read spanning several views would keep its pin on a remapped one. Here only the remapped blocks are cut out, and neighbouring blocks stay pinned. The floor/ceil edges are the same as forprotected,holesandaliased. The caveat from #174 now applies to a few more blocks: a block whose pin is dropped is guarded again at its next check, so an asynchronous read issued before the remap that lands after it could fail. I have not checked whether the title does that.Other open PRs that touch pins:
VecDeque): no textual conflict with this PR, but the merge does not build (checked locally withcargo check).self.pins = kept;indrop_pinsandpins: vec![...]in the new test areVecwhere aVecDequeis expected (E0308)..into()fixes both.drop_pinskeeps the order and each piece keeps itsuntil, so #67's dropping of ended pins from the front still holds.Guardsmethod afterpinnedand tests at the end of the module). With this PR, theguards().pins.retain(...)at the end of #60's new test is no longer needed.A minor point about
remapped_view_does_not_inherit_pins_from_earlier_writing: betweenUnmapViewOfFileand the!pinnedassert, another test could map a view at the freed address and callwriting()there, askernel_reads_into_guarded_blocks_after_openingdoes. That would fail the assert. It did not happen in 140 runs.Not tested: the title, and full runs with
--test-threads=1.@gut0to on GitHub · 2026-11-26 15:56 UTC · original · reviewed
AI-assisted review. I checked the changed test code and its stated address-reuse scenario; I did not run the test suite or a game.
@ -1161,0 +1260,4 @@// Map a fresh view; if it lands at the same address, guarding must// protect it rather than reporting it written on every check.// SAFETY: same live pagefile section, mapped read-write.let view2 = unsafe { MapViewOfFile(section, FILE_MAP_WRITE, 0, 0, 2 * BLOCK).Value as usize };@gut0to on GitHub · 2026-11-26 15:56 UTC · original
AI-assisted static review: I inspected the changed test and its address-reuse claim; I did not run the test or a game. Could this request the old base with MapViewOfFileEx (and assert view2 == view)? MapViewOfFile may return a different free address, so this test can pass without exercising the stale-pin-at-the-same-address regression it says it covers.
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.