GPU: a write through one view of physical pages opens the guards of all its views #1122
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1122
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1122/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tightfall on GitHub · 2026-11-24 15:56 UTC · original
tightfall:xmem-alias-guards→main· +201 −9 · 3 files · 1 commits · closed without mergingProblem
The title maps the same physical pages at more than one address: it writes them through one view (a pool) and the
GPU reads them through another (
map_alias).watch.rsguards view memory block by block, and the read-only guardsits only on the view a copy was taken from. So a write through the other view never faulted, and the host copy kept
what it first took. In the world this showed up as stale mesh data: one page was copied once and never again. After
that came page faults that look like the freed-texture/root-view faults in #59 and #597.
Change
xmemkeeps an index of the views that show each physical page (map_aliasand pool mappings) and answers"which other addresses show this page" through
watch::set_alias_lookup.watch::protectmakes a block's aliases read-only too. They are not marked clean, because no copy of an aliashas taken them yet.
watch::open(fault handler and announced kernel writes) also opens the aliases of a written block. Only blocksthat have guarded aliases get looked up, so a huge announced write range (the
freadcase thatec0d155tests)costs the same as before.
a_write_through_an_alias_view_is_seen_by_a_guard_on_the_othermaps one pagefile section twice and checksboth directions (a faulting write through either view, and a kernel write announced through
writing).Tested
cargo test --workspaceonffe310e+ this commit: all pass.cargo clippy --workspace --all-targetsclean.older stack (
d2a4bae+ #135 + local diagnostics), not this exact rebase:17:32 with TdrDelay=10, past the intro into the prologue.
This PR was AI-assisted (Claude Code). The hardware runs and the logs are mine.
🤖 Generated with Claude Code
@adamdotpy on GitHub · 2026-11-24 16:12 UTC · original
Reviewed on Windows 11 / Rust 1.98.1,
9ed6093onffe310e(currentmain, merges as it stands), with a throwaway target directory — sharingCARGO_TARGET_DIRbetween two worktrees of the same crate can hand you the other worktree's test binary, and the first count I got was wrong for exactly that reason.The test pins the fix. With the lookup suppressed (
ALIAS_LOOKUP.get().filter(|_| false)) and the test unchanged:Green as pushed:
cargo test -p victory-gpu --lib51 passed, 1 ignored (four watch tests), clippy--workspace --all-targets --all-features --locked -- -D warningsclean,cargo build --release -p victorybuilds. The test is a real two-view map too — one pagefile section mapped twice, a volatile write through one view, and the byte read back through the other — so it exercises the fault path rather than mocking it.Why the shape is right.
protectguards the aliases of every block it guards and records the pair both ways inaliased;openthen only looks up blocks already inaliased, which is what keeps a huge write range from paying a lookup per block — the same trick theprotectedrange already uses.unguard'sif g.protected.remove(&block)also fixes something on its own: a block we never protected no longer gets a strayVirtualProtect, so an alias that is unmapped at the time of a fault costs nothing.The scenario in the comment really is tracked.
map_aliasreachesnote_aliasesfor every page — it callsmap(&mut physical, to + k, PAGE, slice)per page, afterunmaphas removed the old entries — so the pool-write / tiled-heap-read case is covered by construction, not by luck. Andunmap'sby_address.get(&at) == Some(&key)check correctly leaves a repurposed page's fresh entry alone when the old section is unmapped under it.Lock order is acyclic, but it is now three locks and one of them is on the fault path. The edges are
PHYSICAL → GUARDS(mapcallstitle_memory_remappedwhile holding it),GUARDS → ALIASES(aliases_offromprotect/open), andPHYSICAL → ALIASES(note_aliases); nothing takesPHYSICALfrom insideALIASES, andother_viewscalls nothing, so there is no cycle. The comment says "its lock is taken last … nothing is called while it is held" — that sentence is now load-bearing: a fault handler that blocks cannot report a deadlock, so it is worth the same care the next timeother_viewsgrows a call.Two things I would tighten.
aliasedis the only state here that can go stale, andtitle_memory_remappedprunes it one-way: it drops the remapped blocks' own entries, but the other end of each pair keeps a reference to a block that is no longer an alias. That is harmless today —aliases_ofreturns an unmapped address,unguardskips it now that it checksprotected, and a lookup that finds nothing costs one hash probe — but it means the set grows and never shrinks back. Dropping the reverse direction intitle_memory_remapped(look up the aliases of the remapped blocks and remove those too) keeps it exact and is three lines.BLOCK == PAGE == 64 KiB, but three doc comments here say "all of a block's pages" (guard,protect, and the note onaliased). If blocks were meant to be bigger than a page, the loops are missing; if not, the comments should say block == page, because a reader will go looking for the loop that is not there.I cannot measure what this costs at runtime — it adds a hash probe per 64 KiB guarded and per block opened with aliases — and I have no title to check the pool/tiled-heap pattern against. The bug it closes is real on the mapping scheme it describes, so this is a correctness fix whose cost is bounded by the number of aliased blocks, which is the right place to spend it.
@tightfall on GitHub · 2026-11-24 16:27 UTC · original
In-game A/B on current
main, to replace the older-stack numbers in the description with ones for this exact commit.Setup: RX 9070, Windows 11, Adrenalin 26.11.2,
TdrDelay=10. Diag build,VICTORY_D3D12_DRED=1, one run each. Runs 2 and 3 use the same scripted input (VICTORY_KEYS, Enter every 3 s). Time is the first to the last log line.ffe310e+ this PR (manual input)ffe310e+ this PR + #493 (c48b240)37e19ccb…1x1x1, then the dispatch at command 4), no title memory copy below the addressffe310e+ #493, without this PRSo on today's
mainthis change makes no visible difference in the world: with #493 both builds end at the same later compute fault, and one run each is within noise. The longer runs I quoted came from an older stack (d2a4bae+ #135), where several copy paths have since changed onmain. I can no longer attribute them to this commit, and I won't claim them.What remains is the correctness case: a guard on one view of physical pages does not see writes through another view of them. The unit test
a_write_through_an_alias_view_is_seen_by_a_guard_on_the_othercovers both directions (a faulting write through either view, and an announced kernel write). Whether the title still needs this depends on whether it writes pool memory that the GPU reads through amap_aliasview without any other refresh. I'll look for that in the logs, and close this PR if it doesn't.AI-assisted (Claude Code); the runs and the hardware are mine.
@aycow on GitHub · 2026-11-24 16:34 UTC · original
@tightfall I reproduced a late-alias case on exact
9ed6093. The original view is guarded and clean, then a new virtual alias of the same page is mapped. A write through that new view changes the shared byte, while the original guard still reports clean. Focused patch and two-write regression. After opening the existing guards when the new view enters the mapping index, the next refresh saw the first write, rearmed the views, and saw a second write. All four watch tests and the HLE check passed on Windows. This was a CPU-side guard fixture. Would you prefer to fold this into #1122?@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
9ed6093:cargo test -p victory-gpu -p victory-hlepasses, 146 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:32 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Already in main: the runtime reports where physical pages are mapped (watch::title_memory_aliased) and a write through one mapping marks the trackers of all.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed