Keep pinned blocks writable on guard()'s fast path too #60
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/60"
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?
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by romainhedouin on 2026-11-25T13:13:53Z.
Bug fix. Commit
579a8d9made blocks the kernel is about to write (an asynchronous read) stay writable for two seconds ("pins"), because guarding them again made the kernel's write fail and the title stop. Butguard()has two paths, and only the slow one checked pins. When a checked range starts at an already-guarded block (the common case: part of a larger guarded buffer), the fast path guarded a pinned block again anyway. Now the fast path treats a pinned block exactly like the slow path does (left writable, reported written, its region marked changed), and both paths drop pins that have ended (the fast path never did, so pins could pile up).Adds
a_pinned_block_is_left_writable_by_a_check_from_a_guarded_one(a realReadFileinto the pinned block after a check from the guarded one). Type-checked for Windows (cargo clippy --target x86_64-pc-windows-msvc, with and without--all-features, no new warnings); the test needs Windows and was not run.🤖 Generated with Claude Code
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T20:10:37Z.
Ran this on Windows, since the description says the test was not run: RX 7900 XT, Windows 11 26300, Rust 1.98.1,
6f6e2aamerged onmain4f62c2a(no conflicts).a_pinned_block_is_left_writable_by_a_check_from_a_guarded_one: passed 3 of 3 runs.g.pinned(block)branch taken out (keeping the test), it fails 3 of 3 withthe kernel can still write it. So the test catches the race.watch::with--test-threads=1: 8 passed, 0 failed.victory-gpu --lib, default threads, two runs: 114 passed / 0 failed, then 113 / 1. That one failure wasframe::tests::waits_end_on_ticks_and_count_frames, which also fails onmainunder load.The same race is what #211 reports. A local reproduction on
4f62c2adoes the following: guard a two-block view,writing()into the second block, check the range again (fast path), thenReadFileinto that block. On4f62c2atheReadFilefails with 998 (ERROR_NOACCESS) every time; with this change it succeeds. #237 works around the same symptom from the DirectStorage side, by retrying a rejected read through a staging buffer. This PR fixes the cause inguard(), so the two don't conflict, but with this one the retry should rarely be needed. Not tested in the game.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T21:47:05Z.
Follow-up on #237: measured there (https://github.com/Belobug/VIctory-Belobug-AMD/pull/237#issuecomment-7203987009), it restages only on 1784, not on 998, and the reproduction of this race still fails with 998 on it (3 of 3). So the two are not alternatives: #60 removes the race in
guard(), #237 covers a rejected read whose protection changed mid-read.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by romainhedouin on 2026-11-26T22:24:30Z.
Closing:
a-publierhas no time-based pins. Kernel writes are scoped (kernel_writing, watch.rs:3249), andleft_aloneis checked on every path that makes a block read-only again,guard's fast path included.Pull request closed