HLE: physical-page writes open the title's views before they write #2504
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!2504
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2504"
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?
@BastienRodz on GitHub · 2026-11-25 14:57 UTC · original
BastienRodz:hle/xmem-guard-before-physical-writes→main· +86 −8 · 5 files · 1 commits · openWhat's wrong
xmem::page_windowandxmem::write_physicalwrite DirectStorage page destinations through our own views of the physical pages, which the write watch's guards on the title's views cannot see. Since2921092,xmemtells the watch where the pages show when the write ends (report_written), which covers views mapped during the write. But it only tells the watch afterwards.kernel_will_writeis meant to come before the write too ("Before our own write into title memory [...] opens its guarded blocks, marks them changed and keeps them open while the result lives"), because that is when it saves an armed page's bytes. Told only afterwards, an armed page keeps the streamed bytes as its old ones, andcopy_back_markedputs the copy's stale bytes back over the streamed data.What the fix does
PhysicalWriteopens the title views showing the destination pages withkernel_will_writewhen the write begins, and holds them until it is done.write_physicalit is opened before the copy. InPageWindowit is a field, opened once the view is mapped (a failed map opens nothing) and released after main's end-of-write report.report_writtenwith the pages looked up at the end) is unchanged.victory-gpugets atest-hooksfeature that re-exportsTracked/track, sovictory-hle's test can use a real tracker. Onlyvictory-hle's dev-dependency enables it, so normal builds keep the same public API.Tests
New
modules::xmem::tests::physical_writes_guard_views_before_writing_and_catch_late_mappings: a title view of a physical page is tracked, taken and armed, then aPageWindowwrites the page. The saved bytes must be the old ones (0x11), not the streamed ones; a view mapped during the write must be marked changed; andwrite_physicalmust also save before it writes.main(da82e44) it fails: the saved byte is the streamed0x99(left: 153,right: 17).page_windows_report_where_the_pages_show_when_done.modules::xmem::12/12 andmodules::dstorage::16/16 pass (Wine 10, x86_64-pc-windows-msvc). Clippy is clean with and withouttest-hooks.Not tested
No title run. How often the title streams into pages a submission has armed is not measured. #2213 also changes
report_writtenand may conflict.Fixes #2503
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed it, moved the test access behind a feature, rebased it onto
2921092and verified it). No game data used.🤖 Generated with Claude Code
@BastienRodz on GitHub · 2026-11-25 15:49 UTC · original
Rebased onto main
da82e44, on top of2921092("writes into physical pages are reported where the pages show when the write ends"). That commit handles views mapped during the write and keeps reporting at the end. This PR now only adds the other half: the views showing the pages when the write begins are opened withkernel_will_writebefore it and held until it is done, so armed pages save their bytes from before the write. Main's report at the end is kept unchanged. On the new main the test still fails without the fix (the armed page saves the streamed0x99, not0x11) and passes with it; main'spage_windows_report_where_the_pages_show_when_donepasses too. xmem 12/12, dstorage 16/16.@Marvisak on GitHub · 2026-11-25 18:31 UTC · original · edited 2026-11-26 03:22 UTC
Automated triage for the maintainers.
Verdict: merge candidate. I reviewed the rebased head
4876663.PhysicalWrite::begin(crates/victory-hle/src/modules/xmem.rs) opens the title views showing the destination pages withkernel_will_writebeforewrite_physicalcopies and oncepage_windowhas mapped its view, and holds them until the write is done. Armed pages therefore save their bytes from before the streamed data. Main's end-of-writereport_writtenis unchanged.shown_atreturns title addresses, asreport_writtenalready assumes, and a failedView::mapreturns before anything is opened.The new test reproduces the bug (saved byte
0x99vs0x11). For the maintainer: the Cargo change only adds atest-hooksfeature tovictory-gpuand enables it fromvictory-hle's dev-dependency on the same workspace crate. No new dependency.CI:
checkpassing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 15:13 UTC · original · approved these changes
Reviewed all 5 files at
48766637merged ontoorigin/main(63bcca43) and verified acrossvictory-hle, RTX 5090, and WARP (VICTORY_D3D12_WARP=1) withVICTORY_D3D12_DEBUG=1.Lock ordering, write-watch &
#[cfg]auditPhysicalWrite::begin(crates/victory-hle/src/modules/xmem.rs:461-474) collects and deduplicates title view addresses viashown_at(pages)— releasingPHYSICALbefore callingvictory_gpu::kernel_will_write(page, PAGE)(GUARDS). Sincevictory-gpuhas no dependency onvictory-hle, there is noGUARDS -> PHYSICALpath.write_physical(xmem.rs:663) opens views before copying andpage_window(xmem.rs:729) opens them only afterView::mapsucceeds (so failed maps open nothing). Opening viakernel_will_writebefore the write saves armed pages' pre-write bytes and pins them ing.busy; whenPageWindowdrops,Drop::droprunsreport_written(&shown_at(&self.pages))first to catch late mappings, thenviewunmaps, then_write(xmem.rs:694) drops itsKernelWriteguards (clearingg.busyand marking changed once more).test-hooks(crates/victory-gpu/Cargo.toml:26) re-exportsTracked/trackstrictly behind#[cfg(all(windows, feature = "test-hooks"))](crates/victory-gpu/src/lib.rs:80-81) and is enabled only incrates/victory-hle/Cargo.toml:54under[dev-dependencies], keeping default builds and non-Windows targets unchanged.Verification
cargo run -p xtask -- policy: 191 files ok.cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings(default,--all-features, and-p victory-gpu --features test-hooks): all clean.cargo test -p victory-hle --lib -- --test-threads=1 modules::xmem:: modules::dstorage::: 31/31 passed (includingphysical_writes_guard_views_before_writing_and_catch_late_mappingsatxmem.rs:1506andpage_windows_report_where_the_pages_show_when_done).cargo test -p victory-gpu --lib watch:: shadow::withVICTORY_D3D12_DEBUG=1: 25/25 passed on RTX 5090 and 25/25 passed on WARP (--features diagnostics).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.