[pr-tests][memory] Check write-watch entries against the current asking #150

Open
tyr0nsur wants to merge 1 commit from tyr0nsur/Darner:codex/watch-reservation-asking-epoch into main
Contributor

Contributor role (optional)

What it changes

ask_once_by_res_splits_reservations_without_refusals now checks that the plain allocation has no write entry for the current asking. The write journal stores history by virtual address. When Windows reuses an address, an entry from an earlier asking can still be present. The test checks the two write-watched reservations against the current epoch and checks that the plain reservation is outside the set asked ahead.

On 57dea7f2367c, three grouped runs with a temporary trace failed when the plain allocation carried the same older epoch before and after the asking. A controlled repro used MEM_WRITE_WATCH for the first allocation, recorded its write through ask_once, and reserved the same address as plain memory. The older epoch stayed at 1 while the mixed asking used 2, and the unguarded writes_since call returned None for that reservation. The original assertion failed in all three controlled runs. With the new assertion, all three passed. Win32 GetWriteWatch

How it was tested

  • Tested revision: cdabf1c863201fe05cee1e2c544db5557f0ac232, based on 57dea7f2367c. Windows 11 build 26300, Rust 1.98.1 x86_64-pc-windows-msvc.
  • cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib watch:: -- --test-threads=1 passed 88/88 in each of three runs.
  • cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib -- --test-threads=1 passed 1,740 tests, with 81 ignored.
  • The separate D3D12 run of texture::ahead::tests::late_completion_keeps_a_newer_list_refresh passed with DARNER_UPLOAD_AHEAD=1 and DARNER_PRELUDE_UPLOADS=1 on an RTX 4060 8 GB, driver 621.40. Ran cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib texture::ahead::tests::late_completion_keeps_a_newer_list_refresh -- --exact --ignored --test-threads=1 --nocapture.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings passed.
  • cargo run --locked --quiet --package xtask -- policy checked 553 files. The staged variant checked the one changed file. Both passed.
  • Coverage gaps: full workspace tests, Wine/Proton, and gameplay. The write-watch reproduction uses synthetic Windows allocations.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #50 changes the same file for partial-mip uploads. The grouped failure also appeared in validation for #52, #104, #115, and #133.
Temporary diagnostic for the same-address reproduction

Apply this diagnostic to the base revision. Set the test switch and run the test below. Replace the original plain-entry assertion with the assertion from this PR to compare on the same fixture.

$env:DARNER_TEST_WATCH_REUSE='1'
cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib watch::tests::ask_once_by_res_splits_reservations_without_refusals -- --exact --test-threads=1 --nocapture
diff --git a/crates/darner-gpu/src/watch.rs b/crates/darner-gpu/src/watch.rs
index 60c2958..e9c7e72 100644
--- a/crates/darner-gpu/src/watch.rs
+++ b/crates/darner-gpu/src/watch.rs
@@ -8587,8 +8587,31 @@ mod tests {
         let plain = |n: usize| unsafe {
             VirtualAlloc(std::ptr::null(), n, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize
         };
-        let (a, b, p) = (ww(PAGE), ww(PAGE), plain(PAGE));
+        let reuse = crate::asked_for!("DARNER_TEST_WATCH_REUSE");
+        let (a, b, p) = (ww(PAGE), ww(PAGE), if reuse { ww(PAGE) } else { plain(PAGE) });
         assert!(a != 0 && b != 0 && p != 0);
+        let reused_asking = if reuse {
+            title_memory_freed(p, 0);
+            // SAFETY: this test owns the write-watched allocation at p.
+            unsafe { ((p + 8) as *mut u8).write(1) };
+            ask_once(&[(p, p + PAGE)]);
+            let earlier = {
+                let j = journal();
+                assert_eq!(j.written.get(&(p / PAGE)), Some(&j.ahead_asked));
+                j.ahead_asked
+            };
+            ask_once_end();
+            title_memory_freed(p, 0);
+            // SAFETY: the test owns this whole reservation, with no pending users.
+            unsafe {
+                assert_ne!(VirtualFree(p as *mut _, 0, MEM_RELEASE), 0);
+                let plain_at_p = VirtualAlloc(p as *const _, PAGE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize;
+                assert_eq!(plain_at_p, p, "reallocate the same address without write-watch");
+            }
+            Some(earlier)
+        } else {
+            None
+        };
         // A fresh address may have been another test's: clear what was noted of it.
         title_memory_freed(a, 0);
         title_memory_freed(b, 0);
@@ -8599,6 +8622,10 @@ mod tests {
             ((b + 8) as *mut u8).write(1);
             ((p + 8) as *mut u8).write(1);
         }
+        let prior = journal().written.get(&(p / PAGE)).copied();
+        if reuse {
+            assert_eq!(prior, reused_asking);
+        }
         ask_once(&[(a, a + PAGE), (b, b + PAGE), (p, p + PAGE)]);
         let (now, ahead) = {
             let j = journal();
@@ -8607,6 +8634,10 @@ mod tests {
         assert!(ahead_contains(&ahead, a / PAGE, a / PAGE + 1));
         assert!(ahead_contains(&ahead, b / PAGE, b / PAGE + 1));
         assert!(!ahead_contains(&ahead, p / PAGE, p / PAGE + 1));
+        let recorded = journal().written.get(&(p / PAGE)).copied();
+        let unguarded = writes_since(p, p + PAGE, false, prior.unwrap_or_default());
+        eprintln!("reuse={reuse} prior={prior:?} recorded={recorded:?} current_round={now} unguarded={unguarded:?}");
+        assert!(unguarded.is_none(), "an unguarded read must reject the plain reservation");
         {
             let j = journal();
             assert_eq!(j.written.get(&(a / PAGE)), Some(&now));
## Contributor role (optional) <!-- Fluxer ID omitted. --> ## What it changes `ask_once_by_res_splits_reservations_without_refusals` now checks that the plain allocation has no write entry for the current asking. The write journal stores history by virtual address. When Windows reuses an address, an entry from an earlier asking can still be present. The test checks the two write-watched reservations against the current epoch and checks that the plain reservation is outside the set asked ahead. On `57dea7f2367c`, three grouped runs with a temporary trace failed when the plain allocation carried the same older epoch before and after the asking. A controlled repro used `MEM_WRITE_WATCH` for the first allocation, recorded its write through `ask_once`, and reserved the same address as plain memory. The older epoch stayed at 1 while the mixed asking used 2, and the unguarded `writes_since` call returned `None` for that reservation. The original assertion failed in all three controlled runs. With the new assertion, all three passed. [Win32 GetWriteWatch](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-getwritewatch) ## How it was tested - Tested revision: `cdabf1c863201fe05cee1e2c544db5557f0ac232`, based on `57dea7f2367c`. Windows 11 build 26300, Rust 1.98.1 x86_64-pc-windows-msvc. - `cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib watch:: -- --test-threads=1` passed 88/88 in each of three runs. - `cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib -- --test-threads=1` passed 1,740 tests, with 81 ignored. - The separate D3D12 run of `texture::ahead::tests::late_completion_keeps_a_newer_list_refresh` passed with `DARNER_UPLOAD_AHEAD=1` and `DARNER_PRELUDE_UPLOADS=1` on an RTX 4060 8 GB, driver 621.40. Ran `cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib texture::ahead::tests::late_completion_keeps_a_newer_list_refresh -- --exact --ignored --test-threads=1 --nocapture`. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` passed. - `cargo run --locked --quiet --package xtask -- policy` checked 553 files. The staged variant checked the one changed file. Both passed. - Coverage gaps: full workspace tests, Wine/Proton, and gameplay. The write-watch reproduction uses synthetic Windows allocations. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #50 changes the same file for partial-mip uploads. The grouped failure also appeared in validation for #52, #104, #115, and #133. <details> <summary>Temporary diagnostic for the same-address reproduction</summary> Apply this diagnostic to the base revision. Set the test switch and run the test below. Replace the original plain-entry assertion with the assertion from this PR to compare on the same fixture. ```powershell $env:DARNER_TEST_WATCH_REUSE='1' cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib watch::tests::ask_once_by_res_splits_reservations_without_refusals -- --exact --test-threads=1 --nocapture ``` ```diff diff --git a/crates/darner-gpu/src/watch.rs b/crates/darner-gpu/src/watch.rs index 60c2958..e9c7e72 100644 --- a/crates/darner-gpu/src/watch.rs +++ b/crates/darner-gpu/src/watch.rs @@ -8587,8 +8587,31 @@ mod tests { let plain = |n: usize| unsafe { VirtualAlloc(std::ptr::null(), n, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize }; - let (a, b, p) = (ww(PAGE), ww(PAGE), plain(PAGE)); + let reuse = crate::asked_for!("DARNER_TEST_WATCH_REUSE"); + let (a, b, p) = (ww(PAGE), ww(PAGE), if reuse { ww(PAGE) } else { plain(PAGE) }); assert!(a != 0 && b != 0 && p != 0); + let reused_asking = if reuse { + title_memory_freed(p, 0); + // SAFETY: this test owns the write-watched allocation at p. + unsafe { ((p + 8) as *mut u8).write(1) }; + ask_once(&[(p, p + PAGE)]); + let earlier = { + let j = journal(); + assert_eq!(j.written.get(&(p / PAGE)), Some(&j.ahead_asked)); + j.ahead_asked + }; + ask_once_end(); + title_memory_freed(p, 0); + // SAFETY: the test owns this whole reservation, with no pending users. + unsafe { + assert_ne!(VirtualFree(p as *mut _, 0, MEM_RELEASE), 0); + let plain_at_p = VirtualAlloc(p as *const _, PAGE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize; + assert_eq!(plain_at_p, p, "reallocate the same address without write-watch"); + } + Some(earlier) + } else { + None + }; // A fresh address may have been another test's: clear what was noted of it. title_memory_freed(a, 0); title_memory_freed(b, 0); @@ -8599,6 +8622,10 @@ mod tests { ((b + 8) as *mut u8).write(1); ((p + 8) as *mut u8).write(1); } + let prior = journal().written.get(&(p / PAGE)).copied(); + if reuse { + assert_eq!(prior, reused_asking); + } ask_once(&[(a, a + PAGE), (b, b + PAGE), (p, p + PAGE)]); let (now, ahead) = { let j = journal(); @@ -8607,6 +8634,10 @@ mod tests { assert!(ahead_contains(&ahead, a / PAGE, a / PAGE + 1)); assert!(ahead_contains(&ahead, b / PAGE, b / PAGE + 1)); assert!(!ahead_contains(&ahead, p / PAGE, p / PAGE + 1)); + let recorded = journal().written.get(&(p / PAGE)).copied(); + let unguarded = writes_since(p, p + PAGE, false, prior.unwrap_or_default()); + eprintln!("reuse={reuse} prior={prior:?} recorded={recorded:?} current_round={now} unguarded={unguarded:?}"); + assert!(unguarded.is_none(), "an unguarded read must reject the plain reservation"); { let j = journal(); assert_eq!(j.written.get(&(a / PAGE)), Some(&now)); ``` </details>
First-time contributor

Independently tested cdabf1c86320 on Windows 11 build 26300, RTX 3060 Laptop GPU, driver 621.24, Rust 1.98.1 and Microsoft DXC 1.8.2505.32. I ran the compiled darner-gpu library test binary with --test-threads=1: 1,740 passed, 0 failed, 81 ignored. watch::tests::ask_once_by_res_splits_reservations_without_refusals passed in the full suite. On unmodified upstream ad070f0, the same assertion failed in the full suite on this machine and passed in isolation. This also explains the failure reported in #202.

Independently tested `cdabf1c86320` on Windows 11 build 26300, RTX 3060 Laptop GPU, driver 621.24, Rust 1.98.1 and Microsoft DXC 1.8.2505.32. I ran the compiled `darner-gpu` library test binary with `--test-threads=1`: 1,740 passed, 0 failed, 81 ignored. `watch::tests::ask_once_by_res_splits_reservations_without_refusals` passed in the full suite. On unmodified upstream `ad070f0`, the same assertion failed in the full suite on this machine and passed in isolation. This also explains the failure reported in #202.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'codex/watch-reservation-asking-epoch:tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'tyr0nsur-codex/watch-reservation-asking-epoch'

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 'tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'tyr0nsur-codex/watch-reservation-asking-epoch'
git rebase 'main'
git switch 'main'
git merge --ff-only 'tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'tyr0nsur-codex/watch-reservation-asking-epoch'
git rebase 'main'
git switch 'main'
git merge --no-ff 'tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'main'
git merge --squash 'tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'main'
git merge --ff-only 'tyr0nsur-codex/watch-reservation-asking-epoch'
git switch 'main'
git merge 'tyr0nsur-codex/watch-reservation-asking-epoch'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!150
No description provided.