Watch: range_lock's first read does not undo a set_range_lock that came in meanwhile #2650

Manually merged
github merged 1 commit from github-bot/gh-2650 into main 2026-11-30 14:15:01 +00:00 AGit
Owner

@⁠boraswim on GitHub · 2026-11-29 15:33 UTC · original
boraswim:fix/range-lock-first-use → main · +6 −2 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Part of #2420 (the switch race noted there from the review of #2439).

What it changes

victory_gpu::watch::range_lock() caches VICTORY_RANGE_LOCK in RANGE_LOCK (0 not asked yet, 1 off, 2 on). On its first call it did load → read the env var → store. A set_range_lock(true) from another thread that lands between that load and store was overwritten with the env var's answer, which is off by default.

In a run this is harmless, because the variable decides the switch once. But set_range_lock exists for tests of other crates (#[doc(hidden)], used by victory-hle's xmem tests), and there any thread's first range_lock() could switch it back off mid-test.

The first read now installs its answer with compare_exchange(0, ..). If something was set in the meantime, it returns that value instead. There is no change when nothing races: the same single env read, the same cached value.

How it was tested

  • GPU and profile: unit tests only (Windows 11, rustc 1.98.1, RTX 4070 SUPER)
  • Before / after: cargo test -p victory-gpu --lib -- watch:: 62 passed, 0 failed. cargo clippy -p victory-gpu --lib -- -D warnings reports nothing in watch.rs (main's other clippy errors are #2048's). There is no deterministic test for the interleaving without a hook inside the first read, so none was added.
  • For shader changes, the wave sizes tested: not a shader change
  • cargo test passed for the crates it touches: yes (victory-gpu watch tests)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2420, #2439 (the xmem test that turns the switch on, which holds its own lock now). No open PR changes range_lock or RANGE_LOCK.
**@⁠boraswim** on GitHub · 2026-11-29 15:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2650) `boraswim:fix/range-lock-first-use` → `main` · +6 −2 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC Part of #2420 (the switch race noted there from the review of #2439). ## What it changes `victory_gpu::watch::range_lock()` caches `VICTORY_RANGE_LOCK` in `RANGE_LOCK` (0 not asked yet, 1 off, 2 on). On its first call it did `load` → read the env var → `store`. A `set_range_lock(true)` from another thread that lands between that `load` and `store` was overwritten with the env var's answer, which is off by default. In a run this is harmless, because the variable decides the switch once. But `set_range_lock` exists for tests of other crates (`#[doc(hidden)]`, used by `victory-hle`'s xmem tests), and there any thread's first `range_lock()` could switch it back off mid-test. The first read now installs its answer with `compare_exchange(0, ..)`. If something was set in the meantime, it returns that value instead. There is no change when nothing races: the same single env read, the same cached value. ## How it was tested - GPU and profile: unit tests only (Windows 11, rustc 1.98.1, RTX 4070 SUPER) - Before / after: `cargo test -p victory-gpu --lib -- watch::` 62 passed, 0 failed. `cargo clippy -p victory-gpu --lib -- -D warnings` reports nothing in `watch.rs` (main's other clippy errors are #2048's). There is no deterministic test for the interleaving without a hook inside the first read, so none was added. - For shader changes, the wave sizes tested: not a shader change - `cargo test` passed for the crates it touches: yes (`victory-gpu` watch tests) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2420, #2439 (the xmem test that turns the switch on, which holds its own lock now). No open PR changes `range_lock` or `RANGE_LOCK`.
range_lock() read VICTORY_RANGE_LOCK and stored 1 or 2 when it found 0,
so a set_range_lock(true) on another thread between the load and the
store was overwritten with the variable's answer (off by default). A run
decides the switch once from the variable and is not affected; tests that
turn it on with set_range_lock could lose it to any thread's first read.
The first read now installs its answer with compare_exchange from 0 and
otherwise takes the value already set.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 15:35:53 +00:00
github manually merged commit 059e5a8e16 into main 2026-11-30 14:15:01 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2650
No description provided.