GPU: an announced kernel read (kernel_will_write) can be re-guarded before it lands, so ReadFile and DirectStorage fail #723
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#723
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 08:26 UTC · original
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:125). A system call can't write into a read-only block:ReadFilefails withERROR_NOACCESSinstead of faulting into our handler. So the HLE announces kernel writes first, withvictory_gpu::kernel_will_write:files.rs:531and:539(ReadFile,fread);dstorage.rs:954(DirectStorage reads).kernel_will_write(writing,watch.rs:212) only opens the blocks. The nextguard()call covering them, from any thread, sees them as written and makes them read-only again. The submitting thread calls it on every refresh. If that happens between the announcement and the kernel's write, the read fails.Example
ReadFileinto view memory.kernel_will_writeopens the block.guard()protects it again.ReadFilefails withERROR_NOACCESS. DirectStorage returns the error to the title, andfreadreturns short.The window is as long as the read: an overlapped read, or the whole DirectStorage read loop.
Evidence
A single-thread replay of the two threads' order, using a real pagefile view and a real file read:
writing(view + 100, 13)(the title thread's announcement).writes(view, view + 2 * BLOCK, true)(the render thread's refresh).read13 bytes from a temp file intoview + 100.On
main(dd54de2), on GitHub'swindows-latest, the read fails:Test (inside
crates/victory-gpu/src/watch.rs'smod tests)Suggested fix
Count in-flight kernel writes per block in
Guards:kernel_will_writeincrements the count.kernel_wrote(at, len)decrements it. The HLE calls it once the read returns.guard()reports a block with a nonzero count as written but doesn't protect it.A cruder alternative on the HLE side: on
ERROR_NOACCESS, announce again and retry.Related
#393, #413, #464 and #490 change
guard/title_memory_remapped, but none keeps an announced block open.@Hiiva on GitHub · 2026-11-24 09:05 UTC · original
I implemented a scoped kernel-write lease for this race, including overlapping ranges, synchronous ReadFile/fread/DirectStorage writes, and conservative treatment of pending overlapped reads. Synthetic Windows view tests pass (4/4), and the MSVC workspace tests passed before the latest shader change. Branch: https://github.com/Hiiva/VIctory/tree/hiiva/kernel-write-lease (commit 73429ef). Original game files were not changed. AI-assisted implementation and testing. External PR creation is currently collaborators-only.
@vladbondarenko97 on GitHub · 2026-11-24 09:46 UTC · original
Independent reproduction on another config — the symptom is "no request ever completes"
RTX 3080 Ti, Windows 11 26300, retail 1.0.2.1, VIctory main
58fed3704(diag build,cargo build --profile diag -p victory --features diagnostics, our local queue-assert skip present but inert — it never fires here).dstorage: submitlines, the last at 09:26:28.601.dstorage: laststats lines at all in 17 minutes, zero process file-read,dstorage: request failedalso 0 — the requests simply never land.Sleep(1)status poll and issues 3 clear-draws/frame at a steady 30 fps; all 18 captures (frames 1–24576) are 100%0xff000000, 6121-byte PNGs.victory-formatsBCPack decoder never runs: zerobcpack/unpacklines.no swap chain— onlya black frame after a frame that was not frame=1 (black_frames=1),host view heap capped at 1000000 (0x80070057, count 1245184)andview the host does not allow unordered=true format=53 flags=2, all in the first two seconds.That is consistent with this issue's race: the guest is waiting on reads that never satisfy, rather than on anything the title itself reports. For contrast, our earlier builds on
97c78d1/ PR #346 head did complete dstorage work on the same box (files opened, zlib requests finished, 46–55 draws/frame, full first-run flow).AI-assisted investigation (Claude Code); values are from our own retail run, package unmodified.
@Dufftwt on GitHub · 2026-11-24 15:10 UTC · original
Fixed in #1025:
kernel_will_writecounts the announced reads per block,guard()leaves a counted block open, and the newkernel_wroteuncounts it onceReadFile,freador the DirectStorage fill returns.@Marvisak on GitHub · 2026-11-25 01:48 UTC · original · edited 2026-11-26 06:42 UTC
Automated triage for the maintainers.
This is fixed on
main. #1025 was closed without merging; the tracking described here was replaced by a per-read lease instead:watch::writing(exported to the runtime askernel_will_write, incrates/victory-gpu/src/watch.rs) returns aWritingvalue. While it lives, its pages stay inGuards::busy, andprotect()skips busy pages, so no refresh on another thread can guard them again. Dropping it removes the range and marks the pages changed, so the next refresh copies what the kernel wrote.ReadFileandfreadincrates/victory-hle/src/modules/files.rs(let _writing = …before the host call), and the raw DirectStorage fill incrates/victory-hle/src/modules/dstorage.rs.One remaining edge: an overlapped
ReadFilethat returnsERROR_IO_PENDINGdrops its lease when the call returns, before the read lands. If that case matters, a new issue for it would be the place.The latest comment agrees the race is real and reports that the lease does not change a separate world-load stop on a GTX 1660 SUPER; that stop is discussed in #1063, not here. Disassembly of the title's own code (its function names and internal offsets) must not be posted in this repository.
This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
@roon9e on GitHub · 2026-11-26 05:51 UTC · original
Related measurement, in case it saves someone time: the announced-kernel-write race this issue describes is real but is not the cause of the GTX 1660 SUPER world-load stop (
+0x1330a44, codec0x817).I implemented the minimal lease on top of the affected revision (a
#[must_use]Writinglease invictory-gpu/src/watch.rs: a per-block count thatguard()skips while held, released on drop; held across the write inReadFile/fread, bothinto_destinationbranches indstorage.rs, and thehost.rs/shadow.rswrites). It builds and the reads still work, but it did not change the failing decode's input (still 128 zero bytes), so the.zmtproducer is on a different path.For the record, the runtime's own decode plumbing is healthy on this card:
dstorageoptions=0x1(ZLIB): 6,532 requests, allsize=65536, all completed, 0 failures; the inflated output is valid (wrote=65536).ReadFile: 24,278 calls, all real data (onegot=0).The stop is instead the title's own guard in
FUN_141330cd0([inst+0x40]+8 (46586) < [inst+8] (65536)→ fallback →return 0→ the streamer loops). Full write-up on #1063.AI-assisted; measured on the physical GTX 1660 SUPER.