Tests: an address freed during a change of mapping is not given to another test (flaky watch tests) #450
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!450
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-450"
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?
@lvndrpup on GitHub · 2026-11-27 02:26 UTC · original
lvndrpup:tests-no-address-reuse-in-a-change→a-publier· +25 −4 · 1 files · 2 commits · openSome
watchtests fail now and then in the parallelvictory-gpusuite. Each time, a check that should find nothing written reports a block:freed_memory_leaves_no_notes:noted(0) && noted(1) && noted(2)fails right after the firstguarda_view_mapped_beside_a_guarded_one_makes_it_check_again: "nothing written yet"what_the_kernel_writes_through_is_not_guarded_for_another_viewa_write_told_at_one_view_is_reported_at_the_othersa_view_being_split_leaves_its_pages_unguarded_elsewherewrites_in_partly_committed_view_blocks_are_reported: the reserved block is reported againThe cause is in another test, not in the code these tests check.
Cause. While a change of mapping is under way (
Remapping), the blocks the runtime unmaps stay inGuards::changinguntil the change ends.guardleaves them unguarded and reports them as written. Two tests free the address during the change:many_askers_tests::writes_to_views_are_not_lostunmaps its one-page view inside the change, 300 times a run.nothing_is_guarded_between_our_forgetting_it_and_its_unmappingunmaps its view before it drops the change.Windows gives the freed address to the next view mapped, which is often another test's view. That test's blocks are then in
changingtoo: they are not guarded and are reported as written at every check until the change ends.A throwaway test on
4eb6cfdshows this directly. It unmaps a block during a change, then maps a view on another thread. The view got the freed address 20 times out of 20, and every time its secondguardreported the block as written.Fix (test code only).
writes_to_views_are_not_lostmaps its view into a placeholder of its own (MapViewOfFile3) and unmaps it back into the placeholder (UnmapViewOfFile2withMEM_PRESERVE_PLACEHOLDER). The address stays reserved through the change, and the unmapping still happens inside the change as before. The placeholder is freed after the last round.nothing_is_guarded_between_our_forgetting_it_and_its_unmappingunmaps after the change ends. Its checks all come before that; the unmap is only cleanup.what_the_title_puts_in_beside_a_guard_is_toldretriedput_besidefor as long as it returnedCannot, which includes a block that lost its guard, so it could spin until the run timed out (adrianmjim saw that once with #462 alone). It now retries only while the block is still guarded, and otherwise fails with "the block lost its guard".The other tests that hold a
Remappingfree nothing during their change. The runtime itself is unchanged. Blocks inchangingare reported as written, which is the safe side.Results on
a-publierat4eb6cfd, RTX 3060 Ti 8 GB, Ryzen 5 5600X, 32 GB, Windows 11:cargo test -p victory-gpu --lib -- watch::, alternating runs4eb6cfdalone, without / with this change (30 runs each)Without #382 the failure did not show up in 30 runs on this machine. On an RX 6950 XT, MamaLeVrai measured the
writes_to_views_are_not_lostpart in #446:watch::alone failed 11 of 20 runs on4eb6cfdand 0 of 20 with it, and the whole suite failed 34 of 60 runs before and 0 of 60 after.With #382 this merges cleanly, and
cargo test -p victory-gpu --lib -- watch:: host::refresh_testsfailed 0 of 30 runs.cargo clippy -p victory-gpu --all-targets -- -D warningsis clean, with and without--all-features.This replaces #446, which makes the same placeholder change in
writes_to_views_are_not_lost; its author asked for this one to be taken, since it also covers the second test. #462 sits on #446's commit and can be rebased onto this one. It complements #382, which fixesno_write_is_lost_with_port_7failing besiderefreshed_ranges_hold_title_memory; the two touch different tests.In plain words: some tests failed at random because two tests gave memory back to Windows too early. Another test could then be handed the same memory, which still carried a "being changed" mark, so it saw writes that never happened. Both tests now hold on to their memory until the mark is gone.
@MamaLeVrai on GitHub · 2026-11-27 03:20 UTC · original
This overlaps #446 (opened a few minutes earlier, same cause and the same placeholder fix in
many_askers_tests::writes_to_views_are_not_lost). Yours also moves theUnmapViewOfFileafterdrop(changing)in the otherwatch::teststest that freed its view during a change, which #446 does not cover. So yours is the more complete of the two. My numbers on an RX 6950 XT for the shared part:watch::alone, 8 threads, failed 11 of 20 runs on4eb6cfdand 0 of 20 with the placeholder fix; 34 of 60 whole-suite runs before, 0 of 60 after.To the maintainer: take this one rather than #446. #462 (two other flaky tests) sits on #446's commit only to measure cleanly; it can be rebased onto this one.
AI-assisted (Claude Code); no game data.
Tests: an address freed during a change of mapping is not given to another test (flaky watch tests)to Tests: a view is unmapped after its change of mapping, not during it (flaky watch tests, with #446)391d2a9f87to1a833b2331Tests: a view is unmapped after its change of mapping, not during it (flaky watch tests, with #446)to Tests: an address freed during a change of mapping is not given to another test (flaky watch tests)1a833b2331to391d2a9f87@lvndrpup on GitHub · 2026-11-27 04:35 UTC · original
@MamaLeVrai thanks, and sorry for the back and forth: our messages crossed. I had cut this PR down to the second test in favour of #446 before I saw your comments here and on #446.
Since you'd rather it go here, the full fix is back: the head is
391d2a9again, the placeholder change inwrites_to_views_are_not_lost(which also releases the placeholder after the last round) plus the moved unmap innothing_is_guarded_between_our_forgetting_it_and_its_unmapping. So #446 can be closed, and #462 can sit on this commit. At391d2a9, the wholevictory-gpulib passed 3 of 3 runs here, and clippy is clean with and without--all-features.@MamaLeVrai on GitHub · 2026-11-27 07:32 UTC · original
More data for this one, on an RX 6950 XT (release, 8 threads,
refresh_tests watch::).watch::tests::other_memory_at_a_guarded_address_keeps_its_protectionalso comes from the cause this PR fixes. Without it the test failed 5 of 400 runs, always the same panic (expect("as a view")on theguardin its loop), because itsplaceholder(3)sometimes got an address another test freed during a change. With this PR and #462 together: 0 failures in 1,250 release runs and 100 debug runs. The whole suites came out clean too:victory-gpu --lib0 of 40 runs failed,victory-hle --lib0 of 30,victory-shader --lib0 of 10.AI-assisted (Claude Code); no game data.
@lvndrpup on GitHub · 2026-11-27 08:53 UTC · original
Thanks for the numbers. On NVIDIA (RTX 3060 Ti, debug) I ran
watch:: host::refresh_tests200 times with #462 and #450 together:other_memory_at_a_guarded_address_keeps_its_protectionnever failed, and there was one failure, inmany_askers_tests::no_mapping_is_lost_between_askers. I couldn't get it again (0 in 100 more runs, and 0 in 500 runs of that module alone), and I found no path from this change to that test. The table is in my review of #462.@adrianmjim on GitHub · 2026-11-27 15:10 UTC · original
Tested on an RX 7900 XT 20 GB (RDNA 3), driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1, release, 16 test threads. Builds:
a-publier4eb6cfd391d2a968fc506(on4eb6cfd, without this PR)391d2a9with281b850and68fc506cherry-picked, clean)The
victory-gpulib test binaries were run directly, with the four builds alternating. Other builds were running on the machine at the same time, so this is a loaded machine, not an idle one.watch:: host::refresh_tests descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes(55 tests), 30 runs each:4eb6cfdno_write_is_lost_with_port_722,watch::testsview/guard tests 4,unchanged_ranges_are_known1,views_off_their_elements_get_a_copy_of_their_bytes1no_write_is_lost_with_port_724, nothing elsewatch::testsview/guard tests 11, no port 7Whole
victory-gpulib, 20 runs each:4eb6cfd2 failed, this PR 0, #462 3, this PR + #462 0.watch::testsfailed on4eb6cfdor on #462 alone, and none failed with this PR. That includes five not listed above in this thread:a_write_opens_the_view_it_goes_throughwhat_is_put_in_beside_the_guards_is_told_at_every_viewa_write_through_another_view_is_reported_at_the_guarded_onea_block_just_written_restskernel_reads_into_guarded_blocks_after_openingwatch::tests::what_the_title_puts_in_beside_a_guard_is_toldnever finished, and the run hit a 15-minute timeout.what_the_kernel_writes_through_is_not_guarded_for_another_viewfailed in the same run. The hung test finished in the other 199 runs across the four builds, and passed 3 of 3 runs alone on4eb6cfdand on #462.putclosure retriesput_besidewith no limit for as long as it returnsBeside::Cannot. One of the cases whereput_besidereturnsCannotis a block not inPROTECTED. So when the block loses its guard, the test can spin instead of failing.many_askers_tests::no_mapping_is_lost_between_askersfailed 0 times in 200 runs (50 per build).other_memory_at_a_guarded_address_keeps_its_protectionfailed 0 times in 200 runs,4eb6cfdincluded. It did not show up on this machine.host::card_steps::tests::the_card_copies_what_is_recordedfailed 0 times in 80 whole-lib runs, 40 of them with #462.views_off_their_elements_get_a_copy_of_their_bytesfailed once in 50 runs on4eb6cfd(descriptor/host.rs:5594). It failed 0 times in 100 runs with281b850, and also 0 times in 50 runs with this PR alone, which lacks it. One failure says little.Not tested: debug builds, #382, the
victory-hleandvictory-shadersuites.@lvndrpup on GitHub · 2026-11-27 16:56 UTC · original
@adrianmjim Thanks, the spin is real. Of the ways
put_besidereturnsCannot,light()andview_guard()are read once per run and a held mapping lock goes away, so a block that leftPROTECTEDis the one case that never ends.57465c0makes theputclosure retry only whileguards_any(one, BLOCK)holds, and otherwise fail with "the block lost its guard".RTX 3060 Ti, debug,
cargo test -p victory-gpu --lib:391d2a957465c0putwatch:: host::refresh_tests, 3 runsno_write_is_lost_with_port_73 of 3,unchanged_ranges_are_known1no_write_is_lost_with_port_73 of 3281b850,68fc506) cherry-picked, 5 runs--all-features, 1 runno_write_is_lost_with_port_7onlyThe port 7 failure with this PR alone matches your 24 of 30. It comes from the test beside
refreshed_ranges_hold_title_memorythat #382 and #462 fix, not from this change.cargo clippy -p victory-gpu --all-targets --locked -- -D warningsis clean with and without--all-features.In short, that test could hang instead of failing when its memory lost its protection. It now fails right away with a message saying so.
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.