dstorage: retry raw file read on ERROR_INVALID_USER_BUFFER #50

Open
jmal423 wants to merge 1 commit from upstream-pr/50 into main
jmal423 commented 2026-11-25 13:01:36 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by jmal423 on 2026-11-25T13:01:36Z.


Fixes intermittent ERROR_INVALID_USER_BUFFER (Win32 error 1784) during DirectStorage raw file reads (request.options == 0) on Windows when reading directly into guest/pinned memory buffers.

  • Retries read_into via a temporary heap buffer on ERROR_INVALID_USER_BUFFER and copies the result into the destination slice.

Tested on Windows 11 / AMD Radeon RX 9070 XT:

  • cargo test -p victory-hle: 103 passed, 0 failed, 1 ignored
  • Live GTA 6 Series X session (24m35s up to the heist): 0 dstorage 1784 failures, 0 crashes.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6605075016 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/50). Originally posted by [jmal423](https://github.com/jmal423) on 2026-11-25T13:01:36Z. --- Fixes intermittent `ERROR_INVALID_USER_BUFFER` (Win32 error 1784) during DirectStorage raw file reads (`request.options == 0`) on Windows when reading directly into guest/pinned memory buffers. - Retries `read_into` via a temporary heap buffer on `ERROR_INVALID_USER_BUFFER` and copies the result into the destination slice. Tested on Windows 11 / AMD Radeon RX 9070 XT: - `cargo test -p victory-hle`: 103 passed, 0 failed, 1 ignored - Live GTA 6 Series X session (24m35s up to the heist): 0 `dstorage` 1784 failures, 0 crashes.
copilot-pull-request-reviewer[bot] commented 2026-11-25 13:01:51 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T13:01:51Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6058087389 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/50#pullrequestreview-6058087389). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T13:01:51Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
gut0to commented 2026-11-26 15:35:56 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T15:35:56Z.

Review: COMMENTED


AI-assisted review; I inspected the retry path and the PR test changes. I did not run the tests or game.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6076860716 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/50#pullrequestreview-6076860716). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:35:56Z. **Review:** COMMENTED --- AI-assisted review; I inspected the retry path and the PR test changes. I did not run the tests or game.
gut0to commented 2026-11-26 15:35:56 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T15:35:56Z.

Code review location: crates/victory-hle/src/modules/dstorage.rs; line 950

@@ -934,13 +934,25 @@ fn read_into(request: &Request, out: &mut [u8]) -> Result<(), HRESULT> {
         .file;
     let started = std::time::Instant::now();
     let mut done = 0;
+    let mut retries = 0;
     let result = loop {
         if done == out.len() {
+            if retries > 0 {
+                tracing::warn!(offset = request.offset, retries, "dstorage: raw file read recovered");
+            }
             break Ok(());
         }
         match file.seek_read(&mut out[done..], request.offset + done as u64) {
             Ok(0) => break Err(END_OF_FILE),
             Ok(n) => done += n,
+            // Retry only the raw file-to-title path on ERROR_INVALID_USER_BUFFER.
+            // Keep any bytes already read and report the original error on exhaustion.
+            Err(error) if request.options == 0 && error.raw_os_error() == Some(1784) && retries < 3 => {

Could a deterministic regression exercise a partial seek_read, then Win32 1784, then a successful retry? It would protect the key invariant here: the retry starts at request.offset + done, preserves the bytes already read, and only retries the remaining slice. A retry-exhaustion case would also pin down the final error behavior.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4710529112 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/50#discussion_r4710529112). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:35:56Z. **Code review location:** `crates/victory-hle/src/modules/dstorage.rs`; line 950 ~~~~diff @@ -934,13 +934,25 @@ fn read_into(request: &Request, out: &mut [u8]) -> Result<(), HRESULT> { .file; let started = std::time::Instant::now(); let mut done = 0; + let mut retries = 0; let result = loop { if done == out.len() { + if retries > 0 { + tracing::warn!(offset = request.offset, retries, "dstorage: raw file read recovered"); + } break Ok(()); } match file.seek_read(&mut out[done..], request.offset + done as u64) { Ok(0) => break Err(END_OF_FILE), Ok(n) => done += n, + // Retry only the raw file-to-title path on ERROR_INVALID_USER_BUFFER. + // Keep any bytes already read and report the original error on exhaustion. + Err(error) if request.options == 0 && error.raw_os_error() == Some(1784) && retries < 3 => { ~~~~ --- Could a deterministic regression exercise a partial `seek_read`, then Win32 1784, then a successful retry? It would protect the key invariant here: the retry starts at `request.offset + done`, preserves the bytes already read, and only retries the remaining slice. A retry-exhaustion case would also pin down the final error behavior.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/50:upstream-pr/50'
git switch 'upstream-pr/50'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/50'
git switch 'upstream-pr/50'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/50'
git switch 'upstream-pr/50'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/50'
git switch 'main'
git merge --squash 'upstream-pr/50'
git switch 'main'
git merge --ff-only 'upstream-pr/50'
git switch 'main'
git merge 'upstream-pr/50'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Belobug/VIctory-Belobug-AMD!50
No description provided.