Watch: a kernel write into title memory refused by a guard set again is opened and made #1007

Closed
cmt8 wants to merge 1 commit from upstream-pr/1009 into main
cmt8 commented 2026-11-25 15:57:25 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cmt8 on 2026-11-25T15:57:25Z.


What breaks today

Since 8dd30ab4, a copy over one view of a physical page guards every view of it. Our own writes into title memory go through the kernel (the copy-back's write_mapped, copy_mapped into title memory, a title's synchronous ReadFile). A guard set again between writing and the kernel's write makes the kernel refuse it. Under Wine it does not fault into our handler: NtWriteVirtualMemory/NtReadVirtualMemory/NtReadFile check the buffer with virtual_check_buffer_for_write and copy under their own exception guard (dlls/ntdll/unix/virtual.c, file.c). So a copy-back is lost, and copy_mapped's piece-by-piece fallback writes zeros over the title's bytes.

The change

One commit, cherry-picked from our 738f7148. watch::kernel_write_refused(at, len) opens whatever is guarded there now and says whether anything was. write_mapped and copy_mapped (title destination, and its 64 KiB / 4 KiB fallback) retry a refused piece once before writing zeros. A synchronous ReadFile that fails with ERROR_NOACCESS/ERROR_INVALID_USER_BUFFER while a guard lay over its buffer is made again, up to three times. Overlapped reads are left alone, because a refused one still posts a completion. The refused writes are counted on a status line next to the page-writes one. VICTORY_READ_BESIDE=0 turns this off, together with 8dd30ab4's read-beside of fread and DirectStorage file reads, for A/B testing.

Evidence

  • In-game, one user's observation on one machine (cmt8: RX 7900 XTX, RADV Mesa 26.3, Proton Experimental): on a build with 8dd30ab4's view guard, the walls and floors of the first interior were missing. With this change and a second one they rendered: the second (DirectStorage page writes also making placed textures due under Wine) is held back, because main's new guards default covers part of it and we have not isolated what is left. So this observation does not show this commit's effect on its own.
  • New test watch::tests::a_kernel_write_refused_under_a_guard_set_again_is_made: a copy-back write into a view that was opened, then guarded again through the other view, lands. It passes under Wine. With VICTORY_READ_BESIDE=0 it fails ("the write landed"), which is the lost write.
  • Windows test binaries under Wine 11.22 with Proton Experimental's vkd3d-proton, using the wine-test xtask from Marvisak/VIctory #1218 (not part of this PR): the watch:: tests pass on this commit. The full run was made with the held-back commit on top: victory-gpu 164 passed, 8 failed, the same 8 that fail on 0b0074e0; victory-hle 97 passed, 1 failed, unchanged.

Not verified

  • Not run on Windows (we have none). The change is not gated on Wine, but it acts only after a kernel write has already failed. Where a write succeeds the path is unchanged. On Windows a kernel write into a read-only page also fails without a fault, so the retry is the same fix there if it ever happens.
  • The game has not been run with exactly this branch.
  • #571 (arminkhaleghirod; cause found by Yorivel) reports page-destination writes at every mapped address, on by default. It now conflicts with main, which has 8dd30ab4's form of the same report.
  • #426/#552 (YeokiNoewChi) read a plain DirectStorage read refused for its buffer through a bounce buffer. main now reads beside instead. This PR covers ReadFile, write_mapped and copy_mapped.
  • #154 (BitWuehler) and VICTORY_COPY_PLAIN copy in-process so writes fault into the guard. That is another way around the same refusal, off by default.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6608429263 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1009). Originally posted by [cmt8](https://github.com/cmt8) on 2026-11-25T15:57:25Z. --- ## What breaks today Since 8dd30ab4, a copy over one view of a physical page guards every view of it. Our own writes into title memory go through the kernel (the copy-back's `write_mapped`, `copy_mapped` into title memory, a title's synchronous `ReadFile`). A guard set again between `writing` and the kernel's write makes the kernel refuse it. Under Wine it does not fault into our handler: `NtWriteVirtualMemory`/`NtReadVirtualMemory`/`NtReadFile` check the buffer with `virtual_check_buffer_for_write` and copy under their own exception guard (dlls/ntdll/unix/virtual.c, file.c). So a copy-back is lost, and `copy_mapped`'s piece-by-piece fallback writes zeros over the title's bytes. ## The change One commit, cherry-picked from our 738f7148. `watch::kernel_write_refused(at, len)` opens whatever is guarded there now and says whether anything was. `write_mapped` and `copy_mapped` (title destination, and its 64 KiB / 4 KiB fallback) retry a refused piece once before writing zeros. A synchronous `ReadFile` that fails with `ERROR_NOACCESS`/`ERROR_INVALID_USER_BUFFER` while a guard lay over its buffer is made again, up to three times. Overlapped reads are left alone, because a refused one still posts a completion. The refused writes are counted on a status line next to the page-writes one. `VICTORY_READ_BESIDE=0` turns this off, together with 8dd30ab4's read-beside of `fread` and DirectStorage file reads, for A/B testing. ## Evidence - In-game, one user's observation on one machine (cmt8: RX 7900 XTX, RADV Mesa 26.3, Proton Experimental): on a build with 8dd30ab4's view guard, the walls and floors of the first interior were missing. With this change and a second one they rendered: the second (DirectStorage page writes also making placed textures due under Wine) is held back, because `main`'s new `guards` default covers part of it and we have not isolated what is left. So this observation does not show this commit's effect on its own. - New test `watch::tests::a_kernel_write_refused_under_a_guard_set_again_is_made`: a copy-back write into a view that was opened, then guarded again through the other view, lands. It passes under Wine. With `VICTORY_READ_BESIDE=0` it fails ("the write landed"), which is the lost write. - Windows test binaries under Wine 11.22 with Proton Experimental's vkd3d-proton, using the `wine-test` xtask from Marvisak/VIctory #1218 (not part of this PR): the `watch::` tests pass on this commit. The full run was made with the held-back commit on top: victory-gpu 164 passed, 8 failed, the same 8 that fail on `0b0074e0`; victory-hle 97 passed, 1 failed, unchanged. ## Not verified - Not run on Windows (we have none). The change is not gated on Wine, but it acts only after a kernel write has already failed. Where a write succeeds the path is unchanged. On Windows a kernel write into a read-only page also fails without a fault, so the retry is the same fix there if it ever happens. - The game has not been run with exactly this branch. ## Related - #571 (arminkhaleghirod; cause found by Yorivel) reports page-destination writes at every mapped address, on by default. It now conflicts with `main`, which has 8dd30ab4's form of the same report. - #426/#552 (YeokiNoewChi) read a plain DirectStorage read refused for its buffer through a bounce buffer. `main` now reads beside instead. This PR covers `ReadFile`, `write_mapped` and `copy_mapped`. - #154 (BitWuehler) and `VICTORY_COPY_PLAIN` copy in-process so writes fault into the guard. That is another way around the same refusal, off by default. AI-assisted (Claude Code); no game data.
upstream-sync closed this pull request 2026-11-26 03:06:44 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!1007
No description provided.