GPU: keep a title guard page inside a range or in another view #67

Open
github-bot wants to merge 1 commit from github-bot/gh-67 into win10-test AGit
Owner

@⁠zocram4cc on GitHub · 2026-11-26 08:42 UTC · original
zocram4cc:up/guard-page-in-range → win10-test · +149 −30 · 1 files · 1 commits · open

What breaks

protect_here made a whole range PAGE_READONLY with one VirtualProtect call, and fell back to block by block only if that call failed. protect_alias made a whole 64 KiB block read-only without looking at it. VirtualProtect sets the protection of every page it covers, so a page the title had set PAGE_GUARD on inside that range or block lost its guard: no fault, no write seen, the guard gone.

Red on the unchanged code, with the two new tests (cargo xwin test, run under Proton Experimental 11.0-100):

thread 'watch::tests::a_page_the_title_guards_in_another_view_keeps_its_guard' (244) panicked at crates/victory-gpu/src/watch.rs:1892:9:
assertion `left == right` failed: the title's guard is gone
  left: 2
 right: 260
thread 'watch::tests::a_page_the_title_guards_inside_a_range_keeps_its_guard' (248) panicked at crates/victory-gpu/src/watch.rs:1869:9:
assertion `left == right` failed: the title's guard is gone
  left: 2
 right: 260

2 is PAGE_READONLY; 260 is PAGE_READWRITE | PAGE_GUARD.

The fix

  • alike(first, last), from VirtualQuery: a change of protection covers only blocks that are committed, in one region, and PAGE_READONLY or PAGE_READWRITE throughout.
  • protect_here: the whole range is asked for only if it is alike throughout. Otherwise each block is asked for alone; a block that is not alike gets no call and stays as it is. Uncommitted blocks are still noted absent, as before.
  • protect_alias: only alike blocks; it returns whether the block is read-only now.
  • A guarded block whose other view could not be made read-only is not clean. Without this, a write through that view would not fault, and the guarded copy would go stale. Such a block is told as written at every asking until its other views can be made read-only (aliases_protected, rechecked in guard).
  • The diagnostics line for a refused block now counts only blocks Windows called alike.

This PR is the alike() fix alone: no run batching and no counters.

Tests

  • watch::tests under Proton, --test-threads 1: all 13 pass (11 existing, the 2 new ones).
  • The whole run reports 14 passed; 1 failed; 1 ignored. The failure is drvwatch::tests::the_system_takes_the_subscription (a Windows event-log subscription); it fails the same way on the unchanged code.
  • Diagnostics build: cargo xwin build --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc builds target/x86_64-pc-windows-msvc/diag/victory.exe with 0 errors and no warnings from watch.rs.

The test target of victory-gpu does not compile on win10-test (42 errors, all in test code of descriptor/host.rs, indirect.rs and pipeline/host.rs). To run the watch tests, those three test modules were switched off in a local change that is not in this PR. This PR does not fix those errors, so CI's test step fails on this base with or without this change.

No frame-time claim

This changes which blocks get a protection call, and what is told as written when a block cannot be guarded. It makes no claim about frame time.

Windows untested

Windows is untested. The build is cross-compiled from Linux with cargo xwin, and the tests ran under Proton (Wine), not on Windows.

Not covered

  • open, the other direction, still sets a whole protected block to read-write. From reading the code (not tested): a guard the title sets on a page of a block already made read-only is lost when that block is opened.
  • The check (VirtualQuery) and the change (VirtualProtect) are two calls; a protection set in between is not seen.

Credits

  • alike(): our avatarmanz/VIctory-7900XTX PR #68.
  • The per-run idea that led to finding this bug: Marvisak/VIctory PR #2849 (Therecalloftheonion) and PR #2848 item 6 (pes7). Runs are not part of this change.

AI-assisted

AI-assisted: written with Claude Code; the build and tests above were run on the branch, with the test-target exclusion described above.

**@⁠zocram4cc** on GitHub · 2026-11-26 08:42 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/67) `zocram4cc:up/guard-page-in-range` → `win10-test` · +149 −30 · 1 files · 1 commits · open ## What breaks `protect_here` made a whole range `PAGE_READONLY` with one `VirtualProtect` call, and fell back to block by block only if that call failed. `protect_alias` made a whole 64 KiB block read-only without looking at it. `VirtualProtect` sets the protection of every page it covers, so a page the title had set `PAGE_GUARD` on inside that range or block lost its guard: no fault, no write seen, the guard gone. Red on the unchanged code, with the two new tests (`cargo xwin test`, run under Proton Experimental 11.0-100): ``` thread 'watch::tests::a_page_the_title_guards_in_another_view_keeps_its_guard' (244) panicked at crates/victory-gpu/src/watch.rs:1892:9: assertion `left == right` failed: the title's guard is gone left: 2 right: 260 thread 'watch::tests::a_page_the_title_guards_inside_a_range_keeps_its_guard' (248) panicked at crates/victory-gpu/src/watch.rs:1869:9: assertion `left == right` failed: the title's guard is gone left: 2 right: 260 ``` `2` is `PAGE_READONLY`; `260` is `PAGE_READWRITE | PAGE_GUARD`. ## The fix - `alike(first, last)`, from `VirtualQuery`: a change of protection covers only blocks that are committed, in one region, and `PAGE_READONLY` or `PAGE_READWRITE` throughout. - `protect_here`: the whole range is asked for only if it is alike throughout. Otherwise each block is asked for alone; a block that is not alike gets no call and stays as it is. Uncommitted blocks are still noted absent, as before. - `protect_alias`: only alike blocks; it returns whether the block is read-only now. - A guarded block whose other view could not be made read-only is not clean. Without this, a write through that view would not fault, and the guarded copy would go stale. Such a block is told as written at every asking until its other views can be made read-only (`aliases_protected`, rechecked in `guard`). - The diagnostics line for a refused block now counts only blocks Windows called alike. This PR is the `alike()` fix alone: no run batching and no counters. ## Tests - `watch::tests` under Proton, `--test-threads 1`: all 13 pass (11 existing, the 2 new ones). - The whole run reports `14 passed; 1 failed; 1 ignored`. The failure is `drvwatch::tests::the_system_takes_the_subscription` (a Windows event-log subscription); it fails the same way on the unchanged code. - Diagnostics build: `cargo xwin build --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc` builds `target/x86_64-pc-windows-msvc/diag/victory.exe` with 0 errors and no warnings from `watch.rs`. The test target of `victory-gpu` does not compile on `win10-test` (42 errors, all in test code of `descriptor/host.rs`, `indirect.rs` and `pipeline/host.rs`). To run the watch tests, those three test modules were switched off in a local change that is not in this PR. This PR does not fix those errors, so CI's test step fails on this base with or without this change. ## No frame-time claim This changes which blocks get a protection call, and what is told as written when a block cannot be guarded. It makes no claim about frame time. ## Windows untested Windows is untested. The build is cross-compiled from Linux with `cargo xwin`, and the tests ran under Proton (Wine), not on Windows. ## Not covered - `open`, the other direction, still sets a whole protected block to read-write. From reading the code (not tested): a guard the title sets on a page of a block already made read-only is lost when that block is opened. - The check (`VirtualQuery`) and the change (`VirtualProtect`) are two calls; a protection set in between is not seen. ## Credits - `alike()`: our avatarmanz/VIctory-7900XTX PR #68. - The per-run idea that led to finding this bug: Marvisak/VIctory PR #2849 (Therecalloftheonion) and PR #2848 item 6 (pes7). Runs are not part of this change. ## AI-assisted AI-assisted: written with Claude Code; the build and tests above were run on the branch, with the test-target exclusion described above.
protect_here made a whole range PAGE_READONLY with one VirtualProtect call,
and protect_alias made a whole 64 KiB block read-only; neither looked at what
was there. VirtualProtect sets the protection of every page it covers, so a
page the title had set PAGE_GUARD on inside that range or block lost its
guard silently: no fault, no write seen.

A change of protection now covers only blocks that VirtualQuery says are
alike: committed, one region, PAGE_READONLY or PAGE_READWRITE throughout
(`alike`). A range is asked for whole only when all of it is alike; otherwise
each block is asked for alone, and a block that is not alike gets no call and
is left as it is. An uncommitted block is still noted absent.

A block left as it is is not guarded, so it is told as written at every asking.
Each other view of a guarded block is made read-only if it can be
(`aliases_protected`). If one cannot, a write through it would not fault, so
the guarded block is not clean and is told as written at every asking until
all of its other views can be made read-only. The diagnostics line for a
refused block now counts only blocks Windows said were alike.

Tests (watch::tests): a_page_the_title_guards_inside_a_range_keeps_its_guard,
a_page_the_title_guards_in_another_view_keeps_its_guard.

Credits: alike() is the check of avatarmanz/VIctory-7900XTX PR #68. The
per-run idea that led to finding this bug is Marvisak/VIctory PR #2849
(Therecalloftheonion) and PR #2848 item 6 (pes7); runs are not part of this
change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:45:10 +00:00
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 08:57 UTC · original

Native Windows result at 7d8286d: all 13 watch::tests passed on Windows Server 2022 and 2025, including both new tests for preserving the title’s page guard. The Windows event-log subscription test that failed under Proton also passed on each runner. Server 2022 log · Server 2025 log

The diagnostics library compiled on the exact PR head first. To build the test target, I applied #37’s test repairs in the verification checkout and excluded the unrelated descriptor unit-test module, which still references APIs missing on win10-test. CI checked that watch.rs and drvwatch.rs matched the PR before running their tests.

**@⁠HandshakeHackin** on GitHub · 2026-11-26 08:57 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/67#issuecomment-7187233220) Native Windows result at `7d8286d`: all 13 `watch::tests` passed on Windows Server 2022 and 2025, including both new tests for preserving the title’s page guard. The Windows event-log subscription test that failed under Proton also passed on each runner. [Server 2022 log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45786655154/job/139794998430) · [Server 2025 log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45786655154/job/139794998055) The diagnostics library compiled on the exact PR head first. To build the test target, I applied #37’s test repairs in the verification checkout and excluded the unrelated descriptor unit-test module, which still references APIs missing on `win10-test`. CI checked that `watch.rs` and `drvwatch.rs` matched the PR before running their tests.
This pull request can be merged automatically.
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/67/head:github-bot/gh-67'
git switch 'github-bot/gh-67'

Merge

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