Guard only title memory in vkback's live guards #141

Manually merged
github merged 1 commit from github-bot/gh-141 into gh-pr/141/base 2026-12-01 21:14:12 +00:00 AGit
Owner

@⁠firefloc on GitHub · 2026-12-01 20:54 UTC · original
firefloc:fix/live-guards-title-memory-only → main · +121 −3 · 2 files · 1 commits · merged 2026-12-01 21:13 UTC

What

Fixes #139. vkback's live guards (watch::live::live_protect) made blocks read-only whatever lay there. A texture range the title names at 0x1_0000_0000 covers two Wine thread stacks. The whole-run VirtualProtect failed across their views, and the block-by-block retry then made all 32 blocks read-only. The thread owning the upper stack faulted at once in __wine_syscall_dispatcher writing its syscall frame, and the process died.

live_protect now guards only the blocks that is_view accepts (umem's mappings, views, or nothing mapped now), as guard does. A block outside title memory stays writable; it is counted in LIVE_NOT_TITLE, and the first 16 are logged with their address (rule 9a). Guarding memory that is not the title's is not a console behaviour: on the console, a write the title makes there is not a write to a texture we must refill.

The reference

The D3D12 path's counterpart is watch::guard. It refuses a range is_view rejects (if !known && !is_view(start, end)) before protecting anything. live_protect now asks the same question per block. It leaves out guard's per-range known shortcut, because the live path keeps no such record. Carried over unchanged: the existing kernel/changing exclusions and gpu_only_blocks. is_view already counts umem's mappings as views (umem_has), so the guarded umem blocks stay guarded.

Evidence

Machine: RX 7900 XTX (RADV, Mesa 26.3.1), Ryzen 7 7800X3D, GE-Proton 11-14, Series X mode.

  • Before (5930321 plus fork commits that touch none of these files): three cores show the same first fault. A GDB probe on mprotect/mmap/munmap/mremap over [0x1_0000_0000, 0x1_0020_0000) caught the 32 mprotect(block, 0x10000, PROT_READ) calls from NtProtectVirtualMemory (kernelbase VirtualProtect), and /proc/<pid>/maps showed both stacks turn r--p the same second. Details are in #139 and docs/learnings/wine-unixlib.md.
  • After (the same base plus this change, only victory.exe rebuilt, the same scenario from a blank save): the refusals are logged from 0x1_0000_0000 on, as the first texture guards go up after entering the world. Both stacks stay rw-p in every /proc/<pid>/maps sample. The run passed the point where the earlier runs died and ended normally (EXIT 0), with no core.
  • New test watch::live::tests::live_guards_leave_memory_that_is_no_title_memory_writable calls live_protect on private memory and on a view. Private memory stays PAGE_READWRITE and is counted, while the view becomes PAGE_READONLY. Without the filter, the test fails on the private memory's protection.
  • cargo xwin clippy -p victory-gpu --target x86_64-pc-windows-msvc --all-targets -- -D warnings is clean. cargo xwin test -p victory-gpu --lib under tools/proton-run.sh (GE-Proton 11-14): 124 passed, 0 failed, 1 ignored.
  • No Vulkan validation run (rule 30): the change only decides which blocks the PE side passes to VirtualProtect. It changes no Vulkan call vkback or umem makes, and no SPIR-V.

What this does not prove: that no legitimate texture lived in title memory outside umem and the views, which would now lose its guard. On this run, every refused block was in the Wine stacks' range. The counter makes any other case visible.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the fixed item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits)
  • No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9)
  • Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b)
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2): no switch added
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): none touched
  • Every unsafe block has a // SAFETY: comment; no raw pointer around the borrow checker (rule 36): no unsafe added
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped if the translator's output changes (rule 27): translator untouched
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found (hard constraints)

The underlying overlap, Wine's stacks inside the title window and the title naming addresses there, is reported separately in #140 (rule 29).

https://claude.ai/code/session_01PNfsy7diUPSn7uaRkqv9iJ

**@⁠firefloc** on GitHub · 2026-12-01 20:54 UTC · [original](https://github.com/vktory6/VKtory/pull/141) `firefloc:fix/live-guards-title-memory-only` → `main` · +121 −3 · 2 files · 1 commits · merged 2026-12-01 21:13 UTC ## What Fixes #139. vkback's live guards (`watch::live::live_protect`) made blocks read-only whatever lay there. A texture range the title names at `0x1_0000_0000` covers two Wine thread stacks. The whole-run `VirtualProtect` failed across their views, and the block-by-block retry then made all 32 blocks read-only. The thread owning the upper stack faulted at once in `__wine_syscall_dispatcher` writing its syscall frame, and the process died. `live_protect` now guards only the blocks that `is_view` accepts (umem's mappings, views, or nothing mapped now), as `guard` does. A block outside title memory stays writable; it is counted in `LIVE_NOT_TITLE`, and the first 16 are logged with their address (rule 9a). Guarding memory that is not the title's is not a console behaviour: on the console, a write the title makes there is not a write to a texture we must refill. ## The reference The D3D12 path's counterpart is `watch::guard`. It refuses a range `is_view` rejects (`if !known && !is_view(start, end)`) before protecting anything. `live_protect` now asks the same question per block. It leaves out `guard`'s per-range `known` shortcut, because the live path keeps no such record. Carried over unchanged: the existing `kernel`/`changing` exclusions and `gpu_only_blocks`. `is_view` already counts umem's mappings as views (`umem_has`), so the guarded umem blocks stay guarded. ## Evidence Machine: RX 7900 XTX (RADV, Mesa 26.3.1), Ryzen 7 7800X3D, GE-Proton 11-14, Series X mode. - **Before** (5930321 plus fork commits that touch none of these files): three cores show the same first fault. A GDB probe on `mprotect`/`mmap`/`munmap`/`mremap` over `[0x1_0000_0000, 0x1_0020_0000)` caught the 32 `mprotect(block, 0x10000, PROT_READ)` calls from `NtProtectVirtualMemory` (kernelbase `VirtualProtect`), and `/proc/<pid>/maps` showed both stacks turn `r--p` the same second. Details are in #139 and `docs/learnings/wine-unixlib.md`. - **After** (the same base plus this change, only `victory.exe` rebuilt, the same scenario from a blank save): the refusals are logged from `0x1_0000_0000` on, as the first texture guards go up after entering the world. Both stacks stay `rw-p` in every `/proc/<pid>/maps` sample. The run passed the point where the earlier runs died and ended normally (`EXIT 0`), with no core. - New test `watch::live::tests::live_guards_leave_memory_that_is_no_title_memory_writable` calls `live_protect` on private memory and on a view. Private memory stays `PAGE_READWRITE` and is counted, while the view becomes `PAGE_READONLY`. Without the filter, the test fails on the private memory's protection. - `cargo xwin clippy -p victory-gpu --target x86_64-pc-windows-msvc --all-targets -- -D warnings` is clean. `cargo xwin test -p victory-gpu --lib` under `tools/proton-run.sh` (GE-Proton 11-14): 124 passed, 0 failed, 1 ignored. - No Vulkan validation run (rule 30): the change only decides which blocks the PE side passes to `VirtualProtect`. It changes no Vulkan call vkback or umem makes, and no SPIR-V. What this does not prove: that no legitimate texture lived in title memory outside umem and the views, which would now lose its guard. On this run, every refused block was in the Wine stacks' range. The counter makes any other case visible. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the fixed item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits) - [x] No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9) - [x] Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b) - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2): no switch added - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): none touched - [x] Every `unsafe` block has a `// SAFETY:` comment; no raw pointer around the borrow checker (rule 36): no `unsafe` added - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped if the translator's output changes (rule 27): translator untouched - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found (hard constraints) The underlying overlap, Wine's stacks inside the title window and the title naming addresses there, is reported separately in #140 (rule 29). https://claude.ai/code/session_01PNfsy7diUPSn7uaRkqv9iJ
vkback asks the PE side to guard every texture filled from title memory,
whether umem backs it or not. A texture the title names at 0x1_0000_0000,
below its first umem mapping, covered two Wine thread stacks.
live_protect's whole-run VirtualProtect failed across their views, its
block-by-block retry made all 32 blocks read-only, and the thread owning
the upper stack faulted at once in __wine_syscall_dispatcher writing its
syscall frame; Wine's segv_handler then took the process down.

live_protect now guards only blocks is_view accepts (umem's mappings,
views, or nothing mapped now). The others stay writable, are counted in
LIVE_NOT_TITLE and the first 16 are logged.

Reference: watch::guard, which refuses a range is_view rejects before
protecting it (`!known && !is_view(start, end)`). Carried over: the
is_view question, per block. Left out: guard's per-range `known`
shortcut (the live path keeps no such record). Kept as they were: the
kernel/changing exclusions and gpu_only_blocks.

Test: live_guards_leave_memory_that_is_no_title_memory_writable calls
live_protect on private memory and a view; it fails without the filter.

Claude-Session: https://claude.ai/code/session_01PNfsy7diUPSn7uaRkqv9iJ
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:58:12 +00:00
github-bot changed target branch from main to gh-pr/141/base 2026-12-01 21:14:10 +00:00
github manually merged commit a48ec4919c into gh-pr/141/base 2026-12-01 21:14:12 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 21:15 UTC · original

Merged as github.com/vktory6/VKtory@77a61b9, thanks. It follows guard's own question per block, the counter makes any other case visible, and the test calls the production code. Our check: build and tests pass, and a house validation run on an RX 9070 XT showed no new errors. On our machine (a different Proton build) Wine's stacks don't land at the bottom of the title window: 0 refusals, so the change is a no-op here and fixes your setup.

The overlap itself is a task now (from #140): "Wine's first thread stacks lie inside the title window".

If you're looking for a next topic: the anti-stutter tasks in docs/TASKS.md ("Texture fills on the GPU", "Renderer CPU: index slots", "Placed image creation in the streaming phase") have the largest measured payoff right now.

**@⁠vktory6** on GitHub · 2026-12-01 21:15 UTC · [original](https://github.com/vktory6/VKtory/pull/141#issuecomment-7325976960) Merged as https://github.com/vktory6/VKtory/commit/77a61b9, thanks. It follows `guard`'s own question per block, the counter makes any other case visible, and the test calls the production code. Our check: build and tests pass, and a house validation run on an RX 9070 XT showed no new errors. On our machine (a different Proton build) Wine's stacks don't land at the bottom of the title window: 0 refusals, so the change is a no-op here and fixes your setup. The overlap itself is a task now (from #140): "Wine's first thread stacks lie inside the title window". If you're looking for a next topic: the anti-stutter tasks in docs/TASKS.md ("Texture fills on the GPU", "Renderer CPU: index slots", "Placed image creation in the streaming phase") have the largest measured payoff right now.
This discussion has been locked. Commenting is limited to contributors.
No description provided.