GPU, HLE: an announced kernel read stays open until it lands #1025
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!1025
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1025/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?
@Dufftwt on GitHub · 2026-11-24 15:09 UTC · original
Dufftwt:fix/announced-kernel-reads-stay-open→main· +116 −11 · 4 files · 2 commits · closed without mergingFixes #723.
What's wrong
View memory (xmem's physical-page views) is tracked by making 64 KiB blocks read-only (
guard,crates/victory-gpu/src/watch.rs). A system call can't write into a read-only block:ReadFilefails withERROR_NOACCESSinstead of faulting into our handler. So the runtime announces its kernel reads first withvictory_gpu::kernel_will_write:ReadFileandfreadinfiles.rs, raw DirectStorage reads indstorage.rs.kernel_will_writeonly opened the blocks. The nextguard()covering them, from any thread, made them read-only again, and the submitting thread calls it at every refresh. If that came between the announcement and the kernel's write, the read failed. DirectStorage then returned the error to the title, andfreadcame back short. The window lasts as long as the read.What the fix does
watch.rskeeps one block range per announced read still to land (Guards::announced).kernel_will_writeopens the blocks and records the range.kernel_wroteremoves it.guard()still reports a block in a recorded range as written, but leaves it open.freadannounces the title's size times count, saturated, so a length can span the address space. The cost doesn't depend on the length, and few reads are in flight at a time.kernel_wroteonce each read returns: afterReadFileandfreadinfiles.rs, and after the raw DirectStorage fill indstorage.rs.shortcut:an overlappedReadFilethat returnsERROR_IO_PENDINGkeeps its range for good, since its end isn't seen. They're then copied at every refresh, which is correct, just slower. Grand Theft Auto VI's reads go through the synchronous path.watch::writing, which our own copy-back and texture writes use from the submitting thread, is unchanged and nowpub(crate).How it behaves after the fix
A kernel read into guarded view memory succeeds however many refreshes run on other threads before it lands. Once it's done, the next refresh guards the block again and copies what the read wrote.
Tests
an_announced_kernel_read_survives_a_refresh_before_it(watch.rs) replays the two threads' order on one thread, with a real pagefile view and a real file read:kernel_will_write.guard(), as another thread's refresh does for view memory.kernel_wrote: the nextguard()must report the block and guard it again, so a further unannounced read fails.an_announcement_as_long_as_the_address_space_is_cheap(watch.rs) announces and lands a read of saturated length, above user space so that no other test's blocks are in it.I ran
cargo test -p victory-gpu -p victory-hle -- --test-threads=1on GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml:victory-gpu: 52 passed, 1 ignored;victory-hle: 94 passed), also with the default parallel test threads.main(ffe310e, announcing with today'skernel_will_write): the read fails:the refresh guarded the block again under the read.8d7e3a0, one map entry per block): it hadn't finished when the step timed out after 5 minutes. TG0000 found this by reading.cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warningsis clean, with and without--all-features.Not tested: a title run, and overlapped reads (none known in the title).
Related: #393, #413, #464 and #490 change
guardortitle_memory_remappedwithout keeping an announced block open. #991 changeswatch::openon nearby lines, so whichever merges second needs a rebase.@ThomasHFWright on GitHub · 2026-11-24 15:15 UTC · original
Independent Wine validation of
8d7e3a0827198055555f372a4fc58022585d882eon baseffe310e, using Rust 1.98.1 and the Windows MSVC target. Linux host, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton30b0eb9bc12dc9f.The new
watch::tests::an_announced_kernel_read_survives_a_refresh_before_itpasses under Wine, including the final check that an unannounced read fails after completion and re-guarding. Negative control: I retained the new test/API but changedkernel_will_writeback to the original open-onlywriting(at, len)and madekernel_wrotea no-op. It failed atthe refresh guarded the block again under the read. The control edits were then removed.Full workspace unit/integration suite, all features, all 14 generated Windows test executables, offline and offscreen:
ffe310ebaselineGPU: 53 passed / 1 failed / 1 ignored; HLE: 93 passed / 1 failed. The failures are unchanged from baseline: empty pipeline library (#347), missing Wine Winsock export (#217), the shader-checksum rejection expectation, the nested Cargo fixture build, and Windows xtask's attempt to launch host Git. Native Linux xtask separately passes all 4 tests. The runtime/DLL configuration was identical in both full runs; native
d3dcompiler_47was supplied for the GPU shader fixtures.Windows-target workspace Clippy with all targets/features and
-D warningspasses. The changes were tested in an isolated checkout; no game data was used.Not tested: gameplay, pending/overlapped I/O completion, native Windows/WARP, or Wine doctests. Aggregate counts include existing tests that return early when optional console compilers or the DXIL validator are missing; the new memory-guard regression has no such skip.
AI-assisted testing with Codex.
@Zipettte on GitHub · 2026-11-24 15:40 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
8d7e3a0: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).
@TG0000 on GitHub · 2026-11-24 16:26 UTC · original
Thanks for this, holding the blocks open until the read lands makes sense. One defect at
8d7e3a0, found by reading, not run:kernel_will_writeandkernel_wrote(watch.rs) loop over every 64 KiB block of[at, at + len)and touch aBTreeMapentry for each, with the guards lock held.freadpassessize.saturating_mul(count), and the comment inwritingnotes that this length is the title's and may be saturated. With a saturated length that is about 2^48 iterations: a hang, with memory growing. On mainwritingstays cheap there becauseopenis a range query.Suggestions: keep the announced reads as ranges (a list of
(start, end), whichguardchecks), or clamp the loop to blocks that can be guarded (the mapped range, or the span ofprotected). The existing test that callswriting(top, PAGE)near the top of the address space would be a good place forkernel_will_write(at, usize::MAX).A smaller point, already marked as a shortcut: an overlapped
ReadFilethat stays pending leaves its blocks announced for good, so they are copied at every refresh. If such reads are frequent, that cost grows over a session. I did not measure it.AI-assisted (Claude Code).
@Dufftwt on GitHub · 2026-11-24 16:37 UTC · original
@TG0000 good catch, thanks: confirmed and fixed in
ece73bb.Guards::announcednow holds one block range per announced read ([first, end)).kernel_will_writepushes one,kernel_wroteremoves it, andguard()checks a block against the ranges in flight. The cost no longer depends on the length.an_announcement_as_long_as_the_address_space_is_cheap: it announces and lands a read of saturated length. I put it above user space rather than in the test near the top: an announcement that covered user space would keep the other tests' blocks open while they run in parallel.8d7e3a0that test hadn't finished when the CI step timed out after 5 minutes. With the fix it passes instantly, and so does everything else (victory-gpu52 passed, 1 ignored;victory-hle94), with the default parallel test threads. Windows CI onwindows-latest.On the pending overlapped
ReadFile: agreed. It now leaves one range per read instead of one entry per block, but the range stays, and its blocks are copied at every refresh. No overlapped reads are known in the title yet. If some show up, the clean answer is to remove the range where their completion is seen, not to keep it forever.@465d6a0eac on GitHub · 2026-11-24 17:49 UTC · original
Thank you for this, @Dufftwt! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original.
Test results
cargo clippy(both variants) andcargo test --workspacepass (429 passed, 0 failed).@Marvisak on GitHub · 2026-11-25 00:30 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: an announced kernel write returns a guard that keeps its blocks open until dropped (watch::Writing, used by files.rs and dstorage.rs).
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