watch: clear BESIDE/opened on remap/free and fix parallel test flakes (#321) #347

Open
github-bot wants to merge 4 commits from github-bot/gh-347 into main AGit
Owner

@⁠ending3729 on GitHub · 2026-11-26 18:04 UTC · original
ending3729:fix/watch-beside-and-test-isolation → main · +289 −19 · 3 files · 4 commits · open

Fixes #321 (complements #277; leaves watch.rs:3628 untouched for #241 and views_are_made_beside_the_heap_and_copied_in untouched for #298).

Root causes & changes

  1. Stale BESIDE and g.opened across remap/unmap/free (crates/victory-gpu/src/watch.rs):
    • title_memory_changed (called by title_memory_remapped and title_memory_unmapping) clears PUBLISHED/BESIDE bits and g.opened entries in the affected block range.
    • title_memory_freed includes g.aliased, BESIDE, and g.opened in both its noted check and cleanup path (for both bounded len != 0 and len == 0 allocation_end paths), and runs open(&g, at, end * BLOCK) before clearing BESIDE/g.opened so still-mapped aliased views (VirtualFree failing on a view) still invalidate their sibling views via g.aliased (caught by Sr-0w/Victory-Native#162 in-game cutscene testing).
    • Added two regression tests: watch::tests::remapping_and_unmapping_clear_beside_and_opened_state and watch::tests::freeing_memory_clears_beside_opened_and_aliased_state (including sibling-view invalidation on title_memory_freed, a 30 s retry budget, and Beside::Full handling on PUT modulo-8192 collisions).
  2. ABA race in look_at_holes (crates/victory-gpu/src/watch.rs):
    • look_at_holes re-checks g.held.contains(block) && uncommitted_end(block) <= block after re-acquiring guards(), preventing a concurrent remap+unmap cycle from dropping a freshly registered placeholder hole from g.held and clearing its PUBLISHED bit.
  3. Recycled-address & handle-reuse races in watch::tests (crates/victory-gpu/src/watch.rs):
    • Added forget_test_range (waiting on title_memory_remapping() so any in-flight Remapping drops and clears g.changing before guarding fresh OS allocations) in two_views, a_refresh_leaves_open_what_the_kernel_is_writing, kernel_reads_into_guarded_blocks_after_opening (also closing the section handle), placeholder, writes_in_partly_committed_view_blocks_are_reported, a_range_that_begins_in_an_unmapped_block_is_guarded, and unmapped_blocks_are_reported_once_until_mapped.
    • Updated drop_views to call title_memory_section_gone(section) inside title_memory_remapping() before CloseHandle(section) so a recycled handle in a parallel test cannot be unregistered underneath it.
    • Added a Drop guard in a_block_just_written_rests to always restore REST_IN_TEST.
  4. Process-global standing-asking test race (watch.rs, host.rs):
    • Shared watch::lock_standing_asking() across host::refresh_tests::submission, host::refresh_tests::unchanged_ranges_are_known, watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own, and watch::port7_tests::no_write_is_lost_with_port_7 so concurrent tests do not clobber JOURNAL.ahead.
  5. 1-in-57 alignment flake in descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes (crates/victory-gpu/src/descriptor/host.rs):
    • Advances start past pages where (start + 8) % grid is a multiple of the 456-byte structured stride (456 = 8 * 57), which otherwise legitimately matched the 4 MiB loose window (4194304) instead of an exact copy (2048) when raw twins are enabled.

Verification (Windows 11, RX 6600 XT RDNA 2, latest commit 14cdb13)

  • Red baseline: the new sibling-view invalidation case in freeing_memory_clears_beside_opened_and_aliased_state failed before the title_memory_freed ordering fix (and both original watch::tests failed before 3407f67).
  • cargo test -p victory-gpu --lib --locked -- --skip views_are_made_beside_the_heap_and_copied_in: 20/20 consecutive parallel runs passed (382 passed, 0 failed per run; prior commit 3345a6d also passed 100/100).
  • cargo test -p victory-gpu --lib --features diagnostics --locked -- --test-threads=1 --skip views_are_made_beside_the_heap_and_copied_in: passed (434 passed, 0 failed).
  • cargo test -p xtask --locked: passed (9 passed, 0 failed).
  • cargo clippy -p victory-gpu --all-targets --locked --no-deps -- -D warnings (default & --all-features): 0 warnings/errors on touched code; only pre-existing upstream watch.rs:3628 (#241).
  • Independent checks: @kilolimaVI reported 100/100 clean parallel runs on 14cdb13 (Radeon 780M / Ryzen 7 8845HS, #321), and @akimfomin reported 100/100 clean parallel watch::tests runs (3,100/3,100) on 3345a6d.

AI-assisted: yes

**@⁠ending3729** on GitHub · 2026-11-26 18:04 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/347) `ending3729:fix/watch-beside-and-test-isolation` → `main` · +289 −19 · 3 files · 4 commits · open Fixes #321 (complements #277; leaves `watch.rs:3628` untouched for #241 and `views_are_made_beside_the_heap_and_copied_in` untouched for #298). ### Root causes & changes 1. **Stale `BESIDE` and `g.opened` across remap/unmap/free (`crates/victory-gpu/src/watch.rs`):** - `title_memory_changed` (called by `title_memory_remapped` and `title_memory_unmapping`) clears `PUBLISHED`/`BESIDE` bits and `g.opened` entries in the affected block range. - `title_memory_freed` includes `g.aliased`, `BESIDE`, and `g.opened` in both its `noted` check and cleanup path (for both bounded `len != 0` and `len == 0` `allocation_end` paths), and runs `open(&g, at, end * BLOCK)` **before** clearing `BESIDE`/`g.opened` so still-mapped aliased views (`VirtualFree` failing on a view) still invalidate their sibling views via `g.aliased` (caught by `Sr-0w/Victory-Native#162` in-game cutscene testing). - Added two regression tests: `watch::tests::remapping_and_unmapping_clear_beside_and_opened_state` and `watch::tests::freeing_memory_clears_beside_opened_and_aliased_state` (including sibling-view invalidation on `title_memory_freed`, a 30 s retry budget, and `Beside::Full` handling on `PUT` modulo-8192 collisions). 2. **ABA race in `look_at_holes` (`crates/victory-gpu/src/watch.rs`):** - `look_at_holes` re-checks `g.held.contains(block) && uncommitted_end(block) <= block` after re-acquiring `guards()`, preventing a concurrent remap+unmap cycle from dropping a freshly registered placeholder hole from `g.held` and clearing its `PUBLISHED` bit. 3. **Recycled-address & handle-reuse races in `watch::tests` (`crates/victory-gpu/src/watch.rs`):** - Added `forget_test_range` (waiting on `title_memory_remapping()` so any in-flight `Remapping` drops and clears `g.changing` before guarding fresh OS allocations) in `two_views`, `a_refresh_leaves_open_what_the_kernel_is_writing`, `kernel_reads_into_guarded_blocks_after_opening` (also closing the section handle), `placeholder`, `writes_in_partly_committed_view_blocks_are_reported`, `a_range_that_begins_in_an_unmapped_block_is_guarded`, and `unmapped_blocks_are_reported_once_until_mapped`. - Updated `drop_views` to call `title_memory_section_gone(section)` inside `title_memory_remapping()` before `CloseHandle(section)` so a recycled handle in a parallel test cannot be unregistered underneath it. - Added a `Drop` guard in `a_block_just_written_rests` to always restore `REST_IN_TEST`. 4. **Process-global standing-asking test race (`watch.rs`, `host.rs`):** - Shared `watch::lock_standing_asking()` across `host::refresh_tests::submission`, `host::refresh_tests::unchanged_ranges_are_known`, `watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own`, and `watch::port7_tests::no_write_is_lost_with_port_7` so concurrent tests do not clobber `JOURNAL.ahead`. 5. **1-in-57 alignment flake in `descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes` (`crates/victory-gpu/src/descriptor/host.rs`):** - Advances `start` past pages where `(start + 8) % grid` is a multiple of the 456-byte structured stride (`456 = 8 * 57`), which otherwise legitimately matched the 4 MiB loose window (`4194304`) instead of an exact copy (`2048`) when raw twins are enabled. ### Verification (Windows 11, RX 6600 XT RDNA 2, latest commit `14cdb13`) - Red baseline: the new sibling-view invalidation case in `freeing_memory_clears_beside_opened_and_aliased_state` failed before the `title_memory_freed` ordering fix (and both original `watch::tests` failed before `3407f67`). - `cargo test -p victory-gpu --lib --locked -- --skip views_are_made_beside_the_heap_and_copied_in`: **20/20 consecutive parallel runs passed** (382 passed, 0 failed per run; prior commit `3345a6d` also passed 100/100). - `cargo test -p victory-gpu --lib --features diagnostics --locked -- --test-threads=1 --skip views_are_made_beside_the_heap_and_copied_in`: passed (434 passed, 0 failed). - `cargo test -p xtask --locked`: passed (9 passed, 0 failed). - `cargo clippy -p victory-gpu --all-targets --locked --no-deps -- -D warnings` (default & `--all-features`): 0 warnings/errors on touched code; only pre-existing upstream `watch.rs:3628` (`#241`). - Independent checks: `@kilolimaVI` reported **100/100** clean parallel runs on `14cdb13` (Radeon 780M / Ryzen 7 8845HS, `#321`), and `@akimfomin` reported **100/100** clean parallel `watch::tests` runs (3,100/3,100) on `3345a6d`. AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:09:47 +00:00
Author
Owner

@⁠felicerosella on GitHub · 2026-11-26 18:25 UTC · original

NVIDIA results for this PR: cargo test -p victory-gpu --lib, parallel, RTX 4070 SUPER, Ryzen 7 7800X3D, Windows 11 26200, on main 2de9980.

  • 49/50 clean runs. The one failure was this PR's new watch::tests::freeing_memory_clears_beside_opened_and_aliased_state, in run 47. In 25 more suite runs it didn't fail again, so that's 1 in 75. Alone it passed 200/200. I didn't catch the panic message. One candidate: its 5 s budget for put_beside returning Cannot. Other tests hold mapping changes in the parallel suite, so #315 and #328 use 30 s.
  • For comparison, on the same machine: main 15/20, and #328 + #342 + #277 together 49/50 (numbers in #321).

This PR covers both #328 (BESIDE on remap/unmap/free) and #342 (one lock for the tests that play the submission, the same four tests). If the maintainer prefers this one, I'm happy to close #328 and #342 in its favour. #342's description has the bisection behind the submission part (refreshed_ranges_hold_title_memory made no_write_is_lost_with_port_7 fail 20/20), in case it helps review.

AI-assisted: yes (Claude Code)

**@⁠felicerosella** on GitHub · 2026-11-26 18:25 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/347#issuecomment-7200451812) NVIDIA results for this PR: `cargo test -p victory-gpu --lib`, parallel, RTX 4070 SUPER, Ryzen 7 7800X3D, Windows 11 26200, on `main` `2de9980`. - **49/50 clean runs.** The one failure was this PR's new `watch::tests::freeing_memory_clears_beside_opened_and_aliased_state`, in run 47. In 25 more suite runs it didn't fail again, so that's 1 in 75. Alone it passed 200/200. I didn't catch the panic message. One candidate: its 5 s budget for `put_beside` returning `Cannot`. Other tests hold mapping changes in the parallel suite, so #315 and #328 use 30 s. - For comparison, on the same machine: `main` 15/20, and #328 + #342 + #277 together 49/50 (numbers in #321). This PR covers both #328 (`BESIDE` on remap/unmap/free) and #342 (one lock for the tests that play the submission, the same four tests). If the maintainer prefers this one, I'm happy to close #328 and #342 in its favour. #342's description has the bisection behind the submission part (`refreshed_ranges_hold_title_memory` made `no_write_is_lost_with_port_7` fail 20/20), in case it helps review. AI-assisted: yes (Claude Code)
Author
Owner

@⁠ending3729 on GitHub · 2026-11-26 18:52 UTC · original

Thanks for the RTX 4070 SUPER runs and for pointing to #342's bisection!

Pushing a follow-up commit (8a86a45) to tighten up the new tests and address that 1-in-75 race:

  • Handle recycling in drop_views: drop_views was closing the section handle (CloseHandle) before calling title_memory_section_gone(section), and the two new tests inherited that order. Calling title_memory_section_gone(section) inside title_memory_remapping() before CloseHandle avoids having a recycled handle unregistered underneath a parallel test.
  • VA reuse while g.changing is still populated: forget_test_range now takes title_memory_remapping() before clearing a freshly mapped range, waiting for any in-flight Remapping whose UnmapViewOfFile just freed that address to drop and clear g.changing before guard() runs (which also caught a parallel flake in a_write_opens_the_view_it_goes_through during stress runs).
  • put_beside retries & smaller diff: Bumped the Beside::Cannot wait to 30 s with diagnostics, retry on Beside::Full in case of a PUT modulo-8192 collision with a parallel test, and extracted small helpers to trim the test diff down.

Re-verified locally with 20/20 clean parallel victory-gpu --lib runs (skipping only the pre-existing RDNA 2 views_are_made_beside_the_heap_and_copied_in failure), plus --features diagnostics and xtask.

**@⁠ending3729** on GitHub · 2026-11-26 18:52 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/347#issuecomment-7200942380) Thanks for the RTX 4070 SUPER runs and for pointing to `#342`'s bisection! Pushing a follow-up commit (`8a86a45`) to tighten up the new tests and address that 1-in-75 race: - **Handle recycling in `drop_views`:** `drop_views` was closing the section handle (`CloseHandle`) before calling `title_memory_section_gone(section)`, and the two new tests inherited that order. Calling `title_memory_section_gone(section)` inside `title_memory_remapping()` before `CloseHandle` avoids having a recycled handle unregistered underneath a parallel test. - **VA reuse while `g.changing` is still populated:** `forget_test_range` now takes `title_memory_remapping()` before clearing a freshly mapped range, waiting for any in-flight `Remapping` whose `UnmapViewOfFile` just freed that address to drop and clear `g.changing` before `guard()` runs (which also caught a parallel flake in `a_write_opens_the_view_it_goes_through` during stress runs). - **`put_beside` retries & smaller diff:** Bumped the `Beside::Cannot` wait to 30 s with diagnostics, retry on `Beside::Full` in case of a `PUT` modulo-8192 collision with a parallel test, and extracted small helpers to trim the test diff down. Re-verified locally with 20/20 clean parallel `victory-gpu --lib` runs (skipping only the pre-existing RDNA 2 `views_are_made_beside_the_heap_and_copied_in` failure), plus `--features diagnostics` and `xtask`.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 23:30 UTC · original

The current 3345a6de23af37c3c83dbbac074f450ade7eeb27 passed 100 fresh Windows processes running the 31 watch::tests in parallel, 3,100 test results with zero failures. I built cargo test --locked -p victory-gpu --lib --no-run with Rust 1.100.0 and ran the resulting binary with watch::tests:: --quiet once per process. This independently checks the follow-up after the 8a86a45 and 3345a6d race fixes. Exact head.

One next check is the full GPU lib suite under the same default test parallelism, since the subset cannot cover interference from other modules. No game input was used. PortBridge · AI-assisted test report.

**@⁠akimfomin** on GitHub · 2026-11-26 23:30 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/347#issuecomment-7205598633) The current `3345a6de23af37c3c83dbbac074f450ade7eeb27` passed 100 fresh Windows processes running the 31 `watch::tests` in parallel, 3,100 test results with zero failures. I built `cargo test --locked -p victory-gpu --lib --no-run` with Rust 1.100.0 and ran the resulting binary with `watch::tests:: --quiet` once per process. This independently checks the follow-up after the `8a86a45` and `3345a6d` race fixes. [Exact head](https://github.com/avatarmanz/VIctory-7900XTX/commit/3345a6de23af37c3c83dbbac074f450ade7eeb27). One next check is the full GPU lib suite under the same default test parallelism, since the subset cannot cover interference from other modules. No game input was used. [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted test report.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 11:50 UTC · original

I tested the four commits on the current Wine launcher branch. Both focused Windows MSVC tests passed under Wine 11.22, including the remap/unmap cleanup and sibling-view invalidation on free. I opened the Wine port with the original commits and credit intact. Wine follow-up

**@⁠UwUCammie** on GitHub · 2026-11-27 11:50 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/347#issuecomment-7217540146) I tested the four commits on the current Wine launcher branch. Both focused Windows MSVC tests passed under Wine 11.22, including the remap/unmap cleanup and sibling-view invalidation on free. I opened the Wine port with the original commits and credit intact. [Wine follow-up](https://github.com/borntofrag34/VIctory-7900XTX/pull/5)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/347/head:github-bot/gh-347'
git switch 'github-bot/gh-347'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-347'
git switch 'github-bot/gh-347'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-347'
git switch 'github-bot/gh-347'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-347'
git switch 'main'
git merge --squash 'github-bot/gh-347'
git switch 'main'
git merge --ff-only 'github-bot/gh-347'
git switch 'main'
git merge 'github-bot/gh-347'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.