GPU, HLE: marked pages go back beside the guards (VICTORY_COPY_BACK_BESIDE, opt-in) #3067

Open
moe-miau wants to merge 2 commits from upstream-pr/3069 into main
moe-miau commented 2026-11-26 06:17:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by moe-miau on 2026-11-26T06:17:33Z.


What

After a submission, every 64 KiB page shaders marked as written goes back into title memory in Shadow::copy_back_marked. Each page opens its guards (watch::writing), gets copied in by the kernel (host::write_mapped), then is guarded again (Tracked::taken). On the stack below that is about 2,250 pages a frame, 45 ms of a 60 ms copy-back: two protection changes per page, first-write faults on the newly writable page, and a kernel copy.

With VICTORY_COPY_BACK_BESIDE=1, a page that a view of physical pages shows is written through a view of our own of the whole section instead (xmem::write_beside, which victory_gpu::use_page_writer registers). No guard covers that view. The title's views stay guarded and show the new bytes, since they are the same pages. No protection calls, no first-write faults, no kernel write.

  • The write runs under the mapping lock (PHYSICAL), so no view there is mapped, unmapped or freed while it happens. The lock order PHYSICAL → GUARDS is the one map/unmap already use, when they call title_memory_remapped/title_memory_aliased.
  • As around a kernel write, the page and its other mappings (alias_of) are marked changed in every tracker holding them. The first mark comes before the write: armed trackers save their bytes. The second comes after it, for a tracker that took the page in between. changed() now shares that marking through mark_with_aliases. The copy's own tracker is unarmed first and taken afterwards, as before.
  • Memory no physical-page view shows (private memory, holes, a range past a view) and a failed whole-section mapping go back the old way. The whole view is mapped on first use and unmapped when the section is dropped.

The switch is off by default: nothing changes unless it is set.

The idea comes from avatarmanz/VIctory-7900XTX's landing beside the guards (66afb2b, 0d5e4c8, 2c982ee; GPL-3.0-or-later). This is a new, smaller implementation on main, not their code. It has no dword merge or worker pool. It works alongside #2914, which spreads the same loop over threads.

Measured

RTX 4070 SUPER, Windows 11. Local stack: main + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 + #2925 + #2958, with VICTORY_CARD_COPIES=1 and VICTORY_WAVE32_APPROX=1. Prologue cell, medians of the 5 s reports from 540 to 900 s of a 15-minute run (about 62 reports each):

run ms/frame copying back marked pages: ms protect calls/frame
stack (baseline) 291.6 60.6 45.4 (2,222 pages) 5,366
stack + #2914 299.8 62.6 45.2 (2,272) 5,528
stack + this, switch on 272.5 47.5 31.2 (2,232) 1,556
  • Copy-back is 13 ms lower a frame and the frame is about 7% shorter. In the same scene #2914's threads did not shorten the loop here, which suggests the per-page work is bound by the guard lock and protection calls.
  • Correctness check: a local diagnostic build (not in this PR) read every page back through the title's own address right after each write beside. 860,000 writes over 15 minutes, 0 differences.
  • Pictures: in this scene the stack has an intermittent artifact (stretched triangles), switch on or off. It shows at 720 and 780 s in the baseline run, at 900 s with #2914, and at 900 s in a second run with this change. The first run with this change showed it at more of the sampled times, the second at one. I see no difference in kind.

Tests

  • watch::tests::a_write_beside_keeps_the_guards_and_marks_the_trackers: three views of one section, two of them title mappings with trackers (one armed). A write beside leaves both mappings PAGE_READONLY, shows in both and marks both trackers. The armed one keeps the bytes from before. A writer that cannot write marks nothing.
  • xmem::tests::writes_beside_land_through_guarded_views: a write lands through a read-only title view and shows at the page's other mapping. A range past a view, or private memory, is not written.
  • cargo test -p victory-gpu --lib --locked: 230 passed. The 2 failures are the known heap-size pair on NVIDIA (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views), which fail on main too. cargo test -p victory-hle --lib --locked: 153 passed. cargo clippy --workspace --all-targets --locked -- -D warnings and cargo xtask policy are clean.

AI-assisted (Claude Code). Runs done on my machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5505062101 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069). Originally posted by [moe-miau](https://github.com/moe-miau) on 2026-11-26T06:17:33Z. --- ## What After a submission, every 64 KiB page shaders marked as written goes back into title memory in `Shadow::copy_back_marked`. Each page opens its guards (`watch::writing`), gets copied in by the kernel (`host::write_mapped`), then is guarded again (`Tracked::taken`). On the stack below that is about 2,250 pages a frame, 45 ms of a 60 ms copy-back: two protection changes per page, first-write faults on the newly writable page, and a kernel copy. With `VICTORY_COPY_BACK_BESIDE=1`, a page that a view of physical pages shows is written through a view of our own of the whole section instead (`xmem::write_beside`, which `victory_gpu::use_page_writer` registers). No guard covers that view. The title's views stay guarded and show the new bytes, since they are the same pages. No protection calls, no first-write faults, no kernel write. - The write runs under the mapping lock (`PHYSICAL`), so no view there is mapped, unmapped or freed while it happens. The lock order PHYSICAL → GUARDS is the one `map`/`unmap` already use, when they call `title_memory_remapped`/`title_memory_aliased`. - As around a kernel write, the page and its other mappings (`alias_of`) are marked changed in every tracker holding them. The first mark comes before the write: armed trackers save their bytes. The second comes after it, for a tracker that took the page in between. `changed()` now shares that marking through `mark_with_aliases`. The copy's own tracker is unarmed first and taken afterwards, as before. - Memory no physical-page view shows (private memory, holes, a range past a view) and a failed whole-section mapping go back the old way. The whole view is mapped on first use and unmapped when the section is dropped. The switch is off by default: nothing changes unless it is set. The idea comes from avatarmanz/VIctory-7900XTX's landing beside the guards (66afb2b, 0d5e4c8, 2c982ee; GPL-3.0-or-later). This is a new, smaller implementation on `main`, not their code. It has no dword merge or worker pool. It works alongside #2914, which spreads the same loop over threads. ## Measured RTX 4070 SUPER, Windows 11. Local stack: main + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 + #2925 + #2958, with `VICTORY_CARD_COPIES=1` and `VICTORY_WAVE32_APPROX=1`. Prologue cell, medians of the 5 s reports from 540 to 900 s of a 15-minute run (about 62 reports each): | run | ms/frame | copying back | marked pages: ms | protect calls/frame | |---|---|---|---|---| | stack (baseline) | 291.6 | 60.6 | 45.4 (2,222 pages) | 5,366 | | stack + #2914 | 299.8 | 62.6 | 45.2 (2,272) | 5,528 | | stack + this, switch on | **272.5** | **47.5** | **31.2** (2,232) | **1,556** | - Copy-back is 13 ms lower a frame and the frame is about 7% shorter. In the same scene #2914's threads did not shorten the loop here, which suggests the per-page work is bound by the guard lock and protection calls. - Correctness check: a local diagnostic build (not in this PR) read every page back through the title's own address right after each write beside. 860,000 writes over 15 minutes, 0 differences. - Pictures: in this scene the stack has an intermittent artifact (stretched triangles), switch on or off. It shows at 720 and 780 s in the baseline run, at 900 s with #2914, and at 900 s in a second run with this change. The first run with this change showed it at more of the sampled times, the second at one. I see no difference in kind. ## Tests - `watch::tests::a_write_beside_keeps_the_guards_and_marks_the_trackers`: three views of one section, two of them title mappings with trackers (one armed). A write beside leaves both mappings `PAGE_READONLY`, shows in both and marks both trackers. The armed one keeps the bytes from before. A writer that cannot write marks nothing. - `xmem::tests::writes_beside_land_through_guarded_views`: a write lands through a read-only title view and shows at the page's other mapping. A range past a view, or private memory, is not written. - `cargo test -p victory-gpu --lib --locked`: 230 passed. The 2 failures are the known heap-size pair on NVIDIA (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`), which fail on `main` too. `cargo test -p victory-hle --lib --locked`: 153 passed. `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo xtask policy` are clean. AI-assisted (Claude Code). Runs done on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Dukestar69 commented 2026-11-26 06:28:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:28:23Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • Diff review: Opt-in VICTORY_COPY_BACK_BESIDE writes marked pages back through separate physical-page views without disarming/rearming title write-watch guards, preserving guard protection while still marking trackers.
  • cargo test -p victory-gpu watch::tests -- --test-threads=1: 16 passed, 0 failed (including a_write_beside_keeps_the_guards_and_marks_the_trackers).
  • cargo test -p victory-gpu shadow::tests -- --test-threads=1 (RTX 5090): 9 passed, 0 failed.
  • cargo test -p victory-hle xmem::tests -- --test-threads=1: 13 passed, 0 failed (including writes_beside_land_through_guarded_views).
  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069501696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#pullrequestreview-6069501696). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:28:23Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - Diff review: Opt-in `VICTORY_COPY_BACK_BESIDE` writes marked pages back through separate physical-page views without disarming/rearming title write-watch guards, preserving guard protection while still marking trackers. - `cargo test -p victory-gpu watch::tests -- --test-threads=1`: 16 passed, 0 failed (including `a_write_beside_keeps_the_guards_and_marks_the_trackers`). - `cargo test -p victory-gpu shadow::tests -- --test-threads=1` (RTX 5090): 9 passed, 0 failed. - `cargo test -p victory-hle xmem::tests -- --test-threads=1`: 13 passed, 0 failed (including `writes_beside_land_through_guarded_views`). - `cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
kotekompotek commented 2026-11-26 06:35:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:35:17Z.

Review: APPROVED


Verified both halves: Section::whole lazily maps an unguarded full-section view (unmapped on Drop); write_beside resolves at->whole offset under the physical() lock (checked_add bound) so no remap mid-write; write_through marks pages+aliases changed with save before the write and again after (a tracker taking the page mid-way reads it), matching the writing-window semantics without opening any guard; fallback to writing+write_mapped preserved; opt-in env. Both tests use real sections+VirtualProtect and discriminate.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069559374 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#pullrequestreview-6069559374). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:35:17Z. **Review:** APPROVED --- Verified both halves: Section::whole lazily maps an unguarded full-section view (unmapped on Drop); write_beside resolves at->whole offset under the physical() lock (checked_add bound) so no remap mid-write; write_through marks pages+aliases changed with save before the write and again after (a tracker taking the page mid-way reads it), matching the writing-window semantics without opening any guard; fallback to writing+write_mapped preserved; opt-in env. Both tests use real sections+VirtualProtect and discriminate.
fuzeofficlal commented 2026-11-26 08:00:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:00:06Z.

Review: COMMENTED


Tested locally on Windows 11 x64 (rustc 1.98.1, RTX 5090 + WARP):

  • cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings (default and --all-features): clean.
  • RTX 5090 (default and VICTORY_COPY_BACK_BESIDE=1): victory-gpu watch::tests (16 passed), shadow::tests (9 passed); victory-hle xmem::tests (13 passed).
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1, VICTORY_COPY_BACK_BESIDE=1): watch::tests (16 passed), shadow::tests (9 passed).
  • cargo xtask policy: 191 files ok.
  • Verified lock ordering (PHYSICAL -> GUARDS matches xmem::map/xmem::unmap, no GUARDS -> PHYSICAL path) and confirmed with a standalone Windows 11 SEC_RESERVE probe that committing a new page via VirtualAlloc(MEM_COMMIT) on a MapViewOfFile3 title view after Section::whole() was already mapped immediately makes that page MEM_COMMIT | PAGE_READWRITE in the cached whole view without faulting.

One concurrency gap in crates/victory-gpu/src/watch.rs (write_through) should be tightened before merge:

  1. Missing g.busy tracking across the unlocked copy_nonoverlapping window (watch.rs:102-111):
    Unlike writing() (watch.rs:806), write_through releases GUARDS after mark_with_aliases(..., true), copies bytes without (first, last) in g.busy, and then re-acquires GUARDS for mark_with_aliases(..., false). Because the pages remain in g.protected and are not marked busy, a concurrent Tracked::take() / take_split() / taken() on the page or an alias (which the doc comment on write_beside anticipates, and which becomes reachable alongside parallel copy-back like #2914) succeeds during the copy:

    • Shadow::update_tracked can read torn mid-copy bytes via copy_mapped while copy_nonoverlapping is writing the same physical page; and
    • watch.rs:517 calls self.changed.taken(page), which drops saved.bytes[page] on an armed tracker—breaking the invariant guarded by watch::tests::a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes. When write_through then runs mark_with_aliases(..., false), the page is re-marked changed with saved == None, causing a subsequent Shadow::copy_back_marked to drop GPU writes on that page (MarkedKept).

    Pushing (first, last) into g.busy under the first guards() lock and removing it (via a small drop guard) under the second guards() lock closes both races cleanly with minimal overhead.

Minor non-blocking polish:

  • crates/victory-gpu/src/watch.rs:103: handle bytes.is_empty() early and use at.saturating_add(bytes.len()).div_ceil(PAGE) to match writing() (watch.rs:804) and avoid marking a page on an empty unaligned write or overflowing near usize::MAX.
  • crates/victory-gpu/src/shadow.rs:522: written can be Option<&[u8]> ((&*host) / title.as_slice()) directly, avoiding the raw pointer round-trip and extra unsafe from_raw_parts block.
<!-- greyfinch-sync:Marvisak/VIctory:review:6070370384 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#pullrequestreview-6070370384). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:00:06Z. **Review:** COMMENTED --- Tested locally on Windows 11 x64 (`rustc 1.98.1`, RTX 5090 + WARP): - `cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings` (default and `--all-features`): clean. - RTX 5090 (default and `VICTORY_COPY_BACK_BESIDE=1`): `victory-gpu` `watch::tests` (16 passed), `shadow::tests` (9 passed); `victory-hle` `xmem::tests` (13 passed). - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`, `VICTORY_COPY_BACK_BESIDE=1`): `watch::tests` (16 passed), `shadow::tests` (9 passed). - `cargo xtask policy`: 191 files ok. - Verified lock ordering (`PHYSICAL -> GUARDS` matches `xmem::map`/`xmem::unmap`, no `GUARDS -> PHYSICAL` path) and confirmed with a standalone Windows 11 `SEC_RESERVE` probe that committing a new page via `VirtualAlloc(MEM_COMMIT)` on a `MapViewOfFile3` title view after `Section::whole()` was already mapped immediately makes that page `MEM_COMMIT | PAGE_READWRITE` in the cached `whole` view without faulting. One concurrency gap in `crates/victory-gpu/src/watch.rs` (`write_through`) should be tightened before merge: 1. **Missing `g.busy` tracking across the unlocked `copy_nonoverlapping` window (`watch.rs:102-111`)**: Unlike `writing()` (`watch.rs:806`), `write_through` releases `GUARDS` after `mark_with_aliases(..., true)`, copies `bytes` without `(first, last)` in `g.busy`, and then re-acquires `GUARDS` for `mark_with_aliases(..., false)`. Because the pages remain in `g.protected` and are not marked busy, a concurrent `Tracked::take()` / `take_split()` / `taken()` on the page or an alias (which the doc comment on `write_beside` anticipates, and which becomes reachable alongside parallel copy-back like #2914) succeeds during the copy: - `Shadow::update_tracked` can read torn mid-copy bytes via `copy_mapped` while `copy_nonoverlapping` is writing the same physical page; and - `watch.rs:517` calls `self.changed.taken(page)`, which drops `saved.bytes[page]` on an armed tracker—breaking the invariant guarded by `watch::tests::a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes`. When `write_through` then runs `mark_with_aliases(..., false)`, the page is re-marked changed with `saved == None`, causing a subsequent `Shadow::copy_back_marked` to drop GPU writes on that page (`MarkedKept`). Pushing `(first, last)` into `g.busy` under the first `guards()` lock and removing it (via a small drop guard) under the second `guards()` lock closes both races cleanly with minimal overhead. Minor non-blocking polish: - `crates/victory-gpu/src/watch.rs:103`: handle `bytes.is_empty()` early and use `at.saturating_add(bytes.len()).div_ceil(PAGE)` to match `writing()` (`watch.rs:804`) and avoid marking a page on an empty unaligned write or overflowing near `usize::MAX`. - `crates/victory-gpu/src/shadow.rs:522`: `written` can be `Option<&[u8]>` (`(&*host)` / `title.as_slice()`) directly, avoiding the raw pointer round-trip and extra `unsafe` `from_raw_parts` block.
Marvisak commented 2026-11-26 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:23:19Z.


Automated triage for the maintainers.

Verdict: merge candidate. With VICTORY_COPY_BACK_BESIDE=1 (off by default), Shadow::copy_back_marked writes marked pages into title memory through a whole-section view of our own (xmem::write_beside via watch::write_beside/write_through). It no longer opens the guards and does a kernel write. Anything else falls back to the old path.

What I checked against main:

  • The address math: physical.views entries are single runs of one section starting at slice.index, so whole + slice.index * PAGE + (at - base) is right. Ranges past a view are refused.
  • Only committed pages are touched: they lie in a title view, and map→commit committed them.
  • Lock order PHYSICAL → GUARDS is the one map/unmap already use. watch doesn't call back into xmem under the guard lock.
  • The tracker marking before and after the write (mark_with_aliases) stands in for the busy window of writing.
  • The whole view is unmapped in Section::drop.

CI: check passing. The source of the idea is credited (same licence, GPL-3.0-or-later), and the PR states this is a new implementation.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186533395 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#issuecomment-7186533395). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:23:19Z. --- <!-- victory-triage v1 head=5454d415e8618f8f66f3bb22c62e6765c0e03da3 verdict=merge-candidate at=2026-11-26T08:18:50Z --> Automated triage for the maintainers. **Verdict: merge candidate.** With `VICTORY_COPY_BACK_BESIDE=1` (off by default), `Shadow::copy_back_marked` writes marked pages into title memory through a whole-section view of our own (`xmem::write_beside` via `watch::write_beside`/`write_through`). It no longer opens the guards and does a kernel write. Anything else falls back to the old path. What I checked against main: - The address math: `physical.views` entries are single runs of one section starting at `slice.index`, so `whole + slice.index * PAGE + (at - base)` is right. Ranges past a view are refused. - Only committed pages are touched: they lie in a title view, and `map`→`commit` committed them. - Lock order PHYSICAL → GUARDS is the one `map`/`unmap` already use. `watch` doesn't call back into xmem under the guard lock. - The tracker marking before and after the write (`mark_with_aliases`) stands in for the `busy` window of `writing`. - The whole view is unmapped in `Section::drop`. CI: `check` passing. The source of the idea is credited (same licence, GPL-3.0-or-later), and the PR states this is a new implementation. --- _Generated by [Claude Code](https://claude.ai/code)_
TheGrayOrange commented 2026-11-26 20:44:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-26T20:44:36Z.


I reproduced fuzeofficlal's concurrency concern at 5454d41 using a deterministic CPU-only fixture with a real 64 KiB Windows section.

By pausing write_through halfway through a 16-byte write, I confirmed:

  • Tracked::take_split can expose eight new bytes and eight old bytes.
  • The armed snapshot can be prematurely discarded.
  • The subsequent marked copy-back loses a simulated shader-written byte.

Both the original mapping and a physical alias exhibited these failures.

Adding the proposed busy-range guard preserved the snapshot and subsequent shader write while keeping both title views read-only. However, partial reads remained possible.

The remaining issue appears to be that take_split constructs its copy ranges from the original dirty-page list, independently of the busy-page acknowledgement filter.

Overlapping tracked reads need synchronization from range selection through the actual copy, or a retry mechanism before committing the refreshed host copy and baseline. Filtering busy pages during range selection alone would leave the opposite arrival order exposed.

Both reproduction patches are available if useful.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203026652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#issuecomment-7203026652). Originally posted by [TheGrayOrange](https://github.com/TheGrayOrange) on 2026-11-26T20:44:36Z. --- I reproduced fuzeofficlal's concurrency concern at `5454d41` using a deterministic CPU-only fixture with a real 64 KiB Windows section. By pausing `write_through` halfway through a 16-byte write, I confirmed: - `Tracked::take_split` can expose eight new bytes and eight old bytes. - The armed snapshot can be prematurely discarded. - The subsequent marked copy-back loses a simulated shader-written byte. Both the original mapping and a physical alias exhibited these failures. Adding the proposed busy-range guard preserved the snapshot and subsequent shader write while keeping both title views read-only. However, partial reads remained possible. The remaining issue appears to be that `take_split` constructs its copy ranges from the original dirty-page list, independently of the busy-page acknowledgement filter. Overlapping tracked reads need synchronization from range selection through the actual copy, or a retry mechanism before committing the refreshed host copy and baseline. Filtering busy pages during range selection alone would leave the opposite arrival order exposed. Both reproduction patches are available if useful.
moe-miau commented 2026-11-27 02:34:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by moe-miau on 2026-11-27T02:34:55Z.


@TheGrayOrange thanks, confirmed. Fixed in a18f50b (force-pushed: the first push of it carried an unrelated reformat by mistake): from the first mark to the second, write_through puts its pages and their aliases in busy, the same as writing does. A tracker that takes them meanwhile leaves them changed, keeps its saved bytes and doesn't guard them again. New test a_take_during_a_write_beside_leaves_the_pages_changed: half-writes, takes on both the mapping and its alias, then checks both stay changed and the saved bytes are the ones from before the write. It fails without the guard and passes with it.

You're right that take_split still copies a busy page mid-write. The old writing + kernel-write path does the same, because its pages are open while the kernel writes. In both, the page stays changed and is copied again on the next take, but one copy can still be torn. Closing that needs the take held from range selection through the copy (or a retry) for both paths, so I'd do it as a separate PR rather than grow this one. Happy to look at your reproduction patches for that.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208256065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#issuecomment-7208256065). Originally posted by [moe-miau](https://github.com/moe-miau) on 2026-11-27T02:34:55Z. --- @TheGrayOrange thanks, confirmed. Fixed in `a18f50b` (force-pushed: the first push of it carried an unrelated reformat by mistake): from the first mark to the second, `write_through` puts its pages and their aliases in `busy`, the same as `writing` does. A tracker that takes them meanwhile leaves them changed, keeps its saved bytes and doesn't guard them again. New test `a_take_during_a_write_beside_leaves_the_pages_changed`: half-writes, takes on both the mapping and its alias, then checks both stay changed and the saved bytes are the ones from before the write. It fails without the guard and passes with it. You're right that `take_split` still copies a busy page mid-write. The old `writing` + kernel-write path does the same, because its pages are open while the kernel writes. In both, the page stays changed and is copied again on the next take, but one copy can still be torn. Closing that needs the take held from range selection through the copy (or a retry) for both paths, so I'd do it as a separate PR rather than grow this one. Happy to look at your reproduction patches for that.
TheGrayOrange commented 2026-11-28 00:33:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-28T00:33:04Z.


Independently verified "a18f50b" using our original synthetic regression fixtures.

All four focused CPU-only checks passed. The saved snapshot survived through both the original mapping and its alias, and subsequent copy-back preserved the beside-written bytes and delivered the simulated shader write.

The inherited partial-read limitation remains reproducible, as expected, but it no longer causes the snapshot loss identified in our original finding.

Both reproduction patches have been checked against their documented revisions and are attached for reference.

Thanks for addressing this.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7231003288 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#issuecomment-7231003288). Originally posted by [TheGrayOrange](https://github.com/TheGrayOrange) on 2026-11-28T00:33:04Z. --- Independently verified "a18f50b" using our original synthetic regression fixtures. All four focused CPU-only checks passed. The saved snapshot survived through both the original mapping and its alias, and subsequent copy-back preserved the beside-written bytes and delivered the simulated shader write. The inherited partial-read limitation remains reproducible, as expected, but it no longer causes the snapshot loss identified in our original finding. Both reproduction patches have been checked against their documented revisions and are attached for reference. Thanks for addressing this.
akimfomin commented 2026-11-28 00:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T00:56:20Z.


PortBridge combined a18f50b with #3246 c2e4507 at common base 63bcca4. Git produced tree 2f379ab7b466cf425c913a525610c70cbab453bc with no conflicts. The recent four CPU checks cover #3069 by itself. An extra correctness check would run #3246’s partial-page-after-whole-page fixture on the pair, also enabling the beside-guards route if that fixture reaches it. Continued #2517 adds a complementary range control: a bridge must preserve its prefix and must not infer an uncovered byte was written. Pinned test request for the two heads.

Exact comparisons and controls. If this workflow is useful, your team or agent can send the next public PR URL, target SHA, and behavior to preserve via PortBridge #98. No install is needed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7231301348 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3069#issuecomment-7231301348). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-28T00:56:20Z. --- PortBridge combined `a18f50b` with #3246 `c2e4507` at common base `63bcca4`. Git produced tree `2f379ab7b466cf425c913a525610c70cbab453bc` with no conflicts. The recent four CPU checks cover #3069 by itself. An extra correctness check would run #3246’s partial-page-after-whole-page fixture on the pair, also enabling the beside-guards route if that fixture reaches it. [Continued #2517](https://github.com/ProjectLeonida/mandy/pull/2517#issuecomment-7231040752) adds a complementary range control: a bridge must preserve its prefix and must not infer an uncovered byte was written. [Pinned test request for the two heads](https://github.com/akimfomin/PortBridge/issues/142). [Exact comparisons and controls](https://github.com/akimfomin/PortBridge/tree/2b57ac90d61e3385a521dd70c1b7803bdb65fadc/audit/evidence/decision-followthrough/parallel-ops-wave-two-2026-11-28). If this workflow is useful, your team or agent can send the next public PR URL, target SHA, and behavior to preserve via [PortBridge #98](https://github.com/akimfomin/PortBridge/issues/98). No install is needed.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3069:upstream-pr/3069'
git switch 'upstream-pr/3069'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3069'
git switch 'upstream-pr/3069'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3069'
git switch 'upstream-pr/3069'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3069'
git switch 'main'
git merge --squash 'upstream-pr/3069'
git switch 'main'
git merge --ff-only 'upstream-pr/3069'
git switch 'main'
git merge 'upstream-pr/3069'
git push origin 'main'
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
Marvisak/VIctory!3067
No description provided.