GPU tests: forget a view's guard state before unmapping it #769

Open
github-bot wants to merge 1 commit from github-bot/gh-769 into main AGit
Owner

@⁠larelgit on GitHub · 2026-11-25 07:05 UTC · original
larelgit:fix/watch-test-race → main · +10 −3 · 1 files · 1 commits · open

watch::tests::kernel_reads_into_guarded_blocks_after_opening fails now and then with "the kernel does not fault into our handler": in 3 of 1200 runs of the whole victory-gpu test binary here on 310c6eb. On 8dd30ab the same thing hit the new a_view_mapped_beside_a_guarded_one_makes_it_check_again (its first guard() gave Some([]) instead of the two pages), once in 1200.

The cause is in the tests, not in watch.rs. Three of them unmap or free their memory first and call title_memory_remapped after:

  • kernel_reads_into_guarded_blocks_after_opening
  • a_range_that_begins_in_an_unmapped_block_is_guarded
  • unmapped_blocks_are_reported_once_until_mapped

In between, a test on another thread can get memory at the same address, and guard() finds its first block still noted protected and clean in GUARDS. It takes the range for a view whose blocks are all clean and returns at once, without making anything read-only. The other test's view is then never guarded.

This change calls title_memory_remapped before the memory goes, as drop_views and writes_in_partly_committed_view_blocks_are_reported already do. Test code only.

Checked

  • With a probe in the failing assert (not part of this change), the failures on 310c6eb that reached it printed (protected, clean, absent) = (true, true, false), guard returned Some([]) for the view's first block.
  • A scratch test (not part of this change) reproduces it every time. It guards a view, unmaps it without title_memory_remapped, and maps a view of another section at the same address with MapViewOfFileEx. guard() then returns Some([]) and leaves the new view writable.

Tested
The whole victory-gpu lib test binary, run in a loop, two loops at a time on a Ryzen 7 7800X3D:

Base Runs Watch tests failed Other failures
310c6eb 1200 3
310c6eb + this 1200 0 1 access violation
8dd30ab 1200 1 1 access violation, 2 frame::tests::waits_end_on_ticks_and_count_frames
8dd30ab + this 1200 0 1 access violation, 6 frame::tests::waits_end_on_ticks_and_count_frames

These were runs that panicked or died; the 310c6eb binary without this change carried the probe. The access violations (exit 139, one in 1200 with and without this change) are the known one: two GPU tests at once on WARP, as noted at ONE_AT_A_TIME in victory-shader. The frame test is a timing test, and it failed while a build ran beside the loops. cargo clippy -p victory-gpu --all-targets -- -D warnings gives only the errors already on main, in resource.rs, draw.rs and indirect.rs.

AI use

  • Claude Code with Claude Opus 5.5 found the race, wrote the change and this description, ran the tests, and opened this PR at the account owner's request.

🤖 Generated with Claude Code

**@⁠larelgit** on GitHub · 2026-11-25 07:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/769) `larelgit:fix/watch-test-race` → `main` · +10 −3 · 1 files · 1 commits · open `watch::tests::kernel_reads_into_guarded_blocks_after_opening` fails now and then with "the kernel does not fault into our handler": in 3 of 1200 runs of the whole `victory-gpu` test binary here on 310c6eb. On 8dd30ab the same thing hit the new `a_view_mapped_beside_a_guarded_one_makes_it_check_again` (its first `guard()` gave `Some([])` instead of the two pages), once in 1200. The cause is in the tests, not in `watch.rs`. Three of them unmap or free their memory first and call `title_memory_remapped` after: - `kernel_reads_into_guarded_blocks_after_opening` - `a_range_that_begins_in_an_unmapped_block_is_guarded` - `unmapped_blocks_are_reported_once_until_mapped` In between, a test on another thread can get memory at the same address, and `guard()` finds its first block still noted protected and clean in `GUARDS`. It takes the range for a view whose blocks are all clean and returns at once, without making anything read-only. The other test's view is then never guarded. This change calls `title_memory_remapped` before the memory goes, as `drop_views` and `writes_in_partly_committed_view_blocks_are_reported` already do. Test code only. **Checked** - With a probe in the failing assert (not part of this change), the failures on 310c6eb that reached it printed `(protected, clean, absent) = (true, true, false), guard returned Some([])` for the view's first block. - A scratch test (not part of this change) reproduces it every time. It guards a view, unmaps it without `title_memory_remapped`, and maps a view of another section at the same address with `MapViewOfFileEx`. `guard()` then returns `Some([])` and leaves the new view writable. **Tested** The whole `victory-gpu` lib test binary, run in a loop, two loops at a time on a Ryzen 7 7800X3D: | Base | Runs | Watch tests failed | Other failures | |---|---:|---:|---| | 310c6eb | 1200 | 3 | | | 310c6eb + this | 1200 | 0 | 1 access violation | | 8dd30ab | 1200 | 1 | 1 access violation, 2 `frame::tests::waits_end_on_ticks_and_count_frames` | | 8dd30ab + this | 1200 | 0 | 1 access violation, 6 `frame::tests::waits_end_on_ticks_and_count_frames` | These were runs that panicked or died; the 310c6eb binary without this change carried the probe. The access violations (exit 139, one in 1200 with and without this change) are the known one: two GPU tests at once on WARP, as noted at `ONE_AT_A_TIME` in victory-shader. The `frame` test is a timing test, and it failed while a build ran beside the loops. `cargo clippy -p victory-gpu --all-targets -- -D warnings` gives only the errors already on `main`, in `resource.rs`, `draw.rs` and `indirect.rs`. **AI use** - Claude Code with Claude Opus 5.5 found the race, wrote the change and this description, ran the tests, and opened this PR at the account owner's request. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Three watch tests unmapped or freed their memory first and called
`title_memory_remapped` after. In between, a test on another thread could
map memory at the same address; `guard()` then found its first block still
noted protected and clean, took the range for a view with nothing written,
and returned without making it read-only, so
`kernel_reads_into_guarded_blocks_after_opening` saw its `ReadFile` land
(a few runs of the whole test binary in a thousand). The other way round,
a late `title_memory_remapped` could drop the guard state of a view
another test had just mapped there. The state is now forgotten while the
memory is still mapped, as `writes_in_partly_committed_view_blocks_are_reported`
already did in its `Drop`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:44 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 07:05 UTC · original · edited 2026-11-25 07:07 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T07:07:22.319025Z 4d41247 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 07:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/769#issuecomment-7155486412) · edited 2026-11-25 07:07 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4d412474f1d197c2d79f1e1b86cbc5eef9f1d325","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T07:07:22.319025Z">2026-11-25T07:07:22.319025Z</relative-time> | `4d41247` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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/769/head:github-bot/gh-769'
git switch 'github-bot/gh-769'

Merge

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