Guarded-view watch tests fail when a pin from an earlier test outlives its view #174

Closed
opened 2026-11-26 03:37:14 +00:00 by github-bot · 1 comment
Owner

@⁠adrianmjim on GitHub · 2026-11-25 18:57 UTC · original

On 01aadd1, three watch::tests fail now and then in full victory-gpu --lib runs with default test threads:

  • a_view_mapped_beside_a_guarded_one_makes_it_check_again (watch.rs:931/932)
  • a_write_through_another_view_is_reported_at_the_guarded_one (watch.rs:883/884, e.g. "nothing written yet" with left: Some([page]))
  • a_write_is_reported_at_every_checked_view (watch.rs:897/899, e.g. left: Some([b+1, b]), right: Some([b, b+1]))

RX 7900 XT, Windows 11 build 26300, Rust 1.98.1, lib test binary run directly: 25 of 96 runs had at least one of them. The rate was about the same on the #112, #115, #132 and #154 trees. They did not fail with watch:: alone (25 runs) or with --test-threads=1.

Cause, as far as I can tell:

  • kernel_reads_into_guarded_blocks_after_opening calls writing(view + 100, 13), which pins that block for PIN (2 s).
  • The test then unmaps its view and calls title_memory_remapped. That clears protected, clean, holes and aliased, but not pins.
  • If another test maps a new view at that address within 2 s, its first guard() takes the slow path. That path finds the block pinned, so the block is reported written at every check and never made read-only.
  • When the pinned block is the second one, it is pushed before the pending run is protected, which gives the reversed order [b+1, b].

With a probe in that branch, all 14 failures I captured had taken it for a block of the test's own new view. In the 3 where I logged who set the pin, it came from kernel_reads_into_guarded_blocks_after_opening.

#60 hits the same leak in its new test a_pinned_block_is_left_writable_by_a_check_from_a_guarded_one. It drops its own pins after unmapping, "so that a view another test maps here is not left writable by it", but the older test above does not do this. #60 also makes guard()'s fast path honor pins, so after it a leaked pin would affect more checks. #67 changes how ended pins are dropped, but no open PR drops pins when memory is remapped.

As a local experiment, I made title_memory_remapped drop pins wholly inside the range:

let (from_block, to_block) = (at.div_ceil(BLOCK), end / BLOCK);
g.pins.retain(|&(first, last, _)| first < from_block || last > to_block);

Interleaved with main, the failures went from 20/56 runs to 0/56. A test-only alternative is to clear the pins at the end of kernel_reads_into_guarded_blocks_after_opening, the way #60's test does. I have not checked whether dropping pins on remap matters in a title run, where an asynchronous read could in principle still land after the remap.

Not tested: the title.

**@⁠adrianmjim** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/174) On `01aadd1`, three `watch::tests` fail now and then in full `victory-gpu --lib` runs with default test threads: - `a_view_mapped_beside_a_guarded_one_makes_it_check_again` (`watch.rs:931`/`932`) - `a_write_through_another_view_is_reported_at_the_guarded_one` (`watch.rs:883`/`884`, e.g. "nothing written yet" with `left: Some([page])`) - `a_write_is_reported_at_every_checked_view` (`watch.rs:897`/`899`, e.g. `left: Some([b+1, b])`, `right: Some([b, b+1])`) RX 7900 XT, Windows 11 build 26300, Rust 1.98.1, lib test binary run directly: 25 of 96 runs had at least one of them. The rate was about the same on the #112, #115, #132 and #154 trees. They did not fail with `watch::` alone (25 runs) or with `--test-threads=1`. Cause, as far as I can tell: - `kernel_reads_into_guarded_blocks_after_opening` calls `writing(view + 100, 13)`, which pins that block for `PIN` (2 s). - The test then unmaps its view and calls `title_memory_remapped`. That clears `protected`, `clean`, `holes` and `aliased`, but not `pins`. - If another test maps a new view at that address within 2 s, its first `guard()` takes the slow path. That path finds the block `pinned`, so the block is reported written at every check and never made read-only. - When the pinned block is the second one, it is pushed before the pending run is protected, which gives the reversed order `[b+1, b]`. With a probe in that branch, all 14 failures I captured had taken it for a block of the test's own new view. In the 3 where I logged who set the pin, it came from `kernel_reads_into_guarded_blocks_after_opening`. #60 hits the same leak in its new test `a_pinned_block_is_left_writable_by_a_check_from_a_guarded_one`. It drops its own pins after unmapping, "so that a view another test maps here is not left writable by it", but the older test above does not do this. #60 also makes `guard()`'s fast path honor pins, so after it a leaked pin would affect more checks. #67 changes how ended pins are dropped, but no open PR drops pins when memory is remapped. As a local experiment, I made `title_memory_remapped` drop pins wholly inside the range: ```rust let (from_block, to_block) = (at.div_ceil(BLOCK), end / BLOCK); g.pins.retain(|&(first, last, _)| first < from_block || last > to_block); ``` Interleaved with main, the failures went from 20/56 runs to 0/56. A test-only alternative is to clear the pins at the end of `kernel_reads_into_guarded_blocks_after_opening`, the way #60's test does. I have not checked whether dropping pins on remap matters in a title run, where an asynchronous read could in principle still land after the remap. Not tested: the title.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:14 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 09:25 UTC · original

Closing: this was about the time-based write-watch pins on main (#175 fixed them there). a-publier has no such pins: kernel writes are scoped with kernel_writing, and every path that guards a block checks left_alone. So the cause described here doesn't exist on that line. The watch:: test flakes seen on a-publier are handled in #450.

**@⁠adrianmjim** on GitHub · 2026-11-27 09:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/174#issuecomment-7214669694) Closing: this was about the time-based write-watch pins on `main` (#175 fixed them there). `a-publier` has no such pins: kernel writes are scoped with `kernel_writing`, and every path that guards a block checks `left_alone`. So the cause described here doesn't exist on that line. The `watch::` test flakes seen on `a-publier` are handled in #450.
This discussion has been locked. Commenting is limited to contributors.
No description provided.