Skip to content

XGameRuntime: a save read sees all of an update or none of it - #2132

Open
dhillonjagdeep650-boop wants to merge 1 commit into
xcl-dev:mainfrom
dhillonjagdeep650-boop:xgamesave-read-during-update
Open

dhillonjagdeep650-boop wants to merge 1 commit into
xcl-dev:mainfrom
dhillonjagdeep650-boop:xgamesave-read-during-update

Conversation

@dhillonjagdeep650-boop

@dhillonjagdeep650-boop dhillonjagdeep650-boop commented Nov 25, 2026 •

Copy link
Copy Markdown

XGameSaveReadBlobData and XGameSaveReadBlobDataAsync read a container's blobs without the lock that XGameSaveSubmitUpdate holds while it replaces them one file at a time. A read that runs during an update can return some blobs from before the update and some from after it. It can also make the update fail: while the read has a blob open, MoveFileExW cannot replace that file, and apply returns E_FAIL with part of the update written (the half-applied state of #324, reached without a disk error). Found by reading the code and reproduced with a unit test; not seen in a title.

What is in it

  • crates/xcl/src/hle/xgameruntime/gamesave.rs: read_layout takes SAVE_MUTATION, as apply and delete_container do (one line, plus the lock's comment).
  • Same file, test reads_during_an_update_see_all_of_it_or_none: one thread reads two blobs in a loop while another rewrites both in 30 updates. It counts failed updates, reads whose two blobs come from different updates, and failed reads; all three must be 0.

Rebased on main e1d84b7 as 8be0c36: a18c180 conflicted with main after #2165 (both add a test at the same place in gamesave.rs). Nothing in the fix changed; the test now sits after #2165's.

Tested

  • On 8be0c36 unless said otherwise.
  • NVIDIA GeForce RTX 3080 Ti 12 GB (32-lane waves), driver 617.42 (32.0.16.1742); Ryzen 7 5800X; 48 GB RAM; Windows 11 Pro 26300.9974; rustc 1.98.1 msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); tests in debug, smoke runs in release.
  • cargo test --locked -p xcl --lib -- gamesave: 12 passed, 0 failed.
  • The new test without the read_layout line (on the rebased tree before main e1d84b7, 81615a0): fails 5 of 5 runs (failed updates / mixed reads / failed reads per run: 21 / 68 / 0, 22 / 17 / 0, 15 / 6 / 0, 9 / 51 / 0, 16 / 47 / 0). With it: passes 5 of 5.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=1 (LOCALAPPDATA pointed at an empty folder, no XCL_* variable): 1424 passed, 0 failed, 46 ignored, no driver event in Windows' log. SKIPPED (29 lines): 21 no wave64 cases, 3 per-lane forms refused as unsupported (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (needs Windows Developer Mode), and the three debug-layer cases (no d3d12SDKLayers.dll).
  • Earlier, on a18c180: @luckyteagirl ran the gamesave tests on AMD (RX 6800M), 11 passed, and the new test 20 of 20 times; @DavidM1911 the lib tests on an RTX 3060 Ti.

Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 180 with scripted A presses at 16, 20, 24, 28, 32 and 36 s (XCL_PRESS_A_AT) and nothing else, each run with an empty data root and its own copy of the same DXIL cache, nobody at the controller. main first, then this PR, 10 minutes apart:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce RTX 3080 Ti
title: ab97764d
seconds: 180
exit: 0x0
frames shown: 3436 (PresentX 3436)
presents per 2 s (last 3): 48 50 46
device removals: 0
crashes: 0
peak commit: 16424 MB
xcl-smoke v1
commit: 8be0c3639f1df6e35d489bcf844227067d537f4f
gpu: NVIDIA GeForce RTX 3080 Ti
title: ab97764d
seconds: 180
exit: 0x0
frames shown: 3473 (PresentX 3473)
presents per 2 s (last 3): 43 42 43
device removals: 0
crashes: 0
peak commit: 16035 MB

Both reach the same screen and present to the end. No file was written under gamesave in either run, so these runs do not show that the title reaches the changed code. (A first run of the PR head was discarded: a real controller press at 98 s took it further than main's run.)

The earlier 60 s pair of 6020a33 / a18c180 had uncontrolled input; it is replaced by this pair.

Not tested

AI use

  • Claude Code. Claude Opus 5.5 found the race, wrote the fix and the test, and ran the fail-before / pass-after runs. Claude Fable 5.2 ran the full-suite and smoke runs and wrote this description; Claude Opus 5.5 wrote the corrections of 2026-11-25, rebased it and ran the 180 s pair and the suite on 8be0c36.

🤖 Generated with Claude Code

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows check of exact PR head a18c180ce39a1b407e964e541be7c68a8bf94f50.

Tested

  • Windows 11 build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5. These are save-file tests; the GPU was not used.
  • cargo test --locked -p xcl --lib -j 2 gamesave -- --test-threads=1 --show-output: 11 passed, 0 failed, 0 ignored, including reads_during_an_update_see_all_of_it_or_none.
  • The concurrent read/update regression was then run in a separate cargo test process 20 times, sequentially, with --test-threads=1: 20/20 runs passed, each reporting 1 passed, 0 failed and no SKIPPED line. The test performs its 30 update/read rounds each time, so this is 600 rounds across the repeated runs.

This checks the race regression and neighboring GameSave tests on this Windows machine. I did not run a pre-fix negative control here, the full workspace suite, or a retail title save operation. The short title startup available on this machine does not reach GameSave calls. No game data was used or uploaded.

AI-assisted testing and report drafting with OpenAI Codex (GPT-6); I checked the exact revision, per-run log, and aggregate counts before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@raylitebull

Copy link
Copy Markdown
Member

Code review on a18c180:

  • Acquiring SAVE_MUTATION inside read_layout (crates/xcl/src/hle/xgameruntime/gamesave.rs) cleanly prevents concurrent apply() updates from producing torn multi-blob reads, verified by reads_during_an_update_see_all_of_it_or_none.
  • Complementary to #2165 (1028ba5), which locks SAVE_MUTATION around each_blob enumeration.
  • Diff audited and CI workflow approved (running).

Remaining before merge: Build and test finishing green plus dual-vendor verification on a18c180.

XGameSaveSubmitUpdate replaces an update's blobs one file at a time under
SAVE_MUTATION, but XGameSaveReadBlobData (and its Async form) read the
blobs without it. A read that ran during an update could return one blob
from before the update and another from after it, and while it had a blob
open, MoveFileExW could not replace that file, so the update failed with
E_FAIL partway through.

read_layout now takes SAVE_MUTATION, like apply and delete_container.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…ream xcl-dev#543 + xcl-dev#2132, gamesave.rs verbatim reference-only)

Windows hle/xgameruntime/gamesave.rs only (hle is cfg(windows), Linux twin
has no gamesave path, 0 tests run on Linux):
- xcl-dev#543: write_atomic -> temp_path/write_temp; apply goes all-or-nothing
  (temps first, move-aside + move-in, failure moves everything back and
  removes temps, last-op-wins case-insensitive) + test
  a_failed_update_leaves_the_container_as_it_was; atomic test tail now
  drives apply() instead of write_atomic().
- xcl-dev#2132: read_layout takes SAVE_MUTATION (reads see all of an update or
  none, no open-file E_FAIL) + test reads_during_an_update_see_all_of_it_or_none.
Keeps landed xcl-dev#1247 null-out guards + merged xcl-dev#2165 each_blob snapshot;
does NOT replicate 2d94699 (sync owns it).
@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

Thanks!

— Devin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants