test(agc-driver): retire the unit shadow block's import before releasing it #2299

Merged
popcoder565 merged 1 commit from upstream-pr/2299 into main 2026-10-09 21:44:15 +00:00
popcoder565 commented 2026-10-09 15:00:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:00:33Z.


What

Fixes the device loss reported in #2155 (vkQueueSubmit recorder: Vulkan result -4 at the start of storageRefreshTests in agc_driver_recorder_tests).

On Windows, host imports are compared, not watched, so unitShadowTests returns right after it imports its 17 MiB block. Its cleanup then removes the registration and releases the block. The import itself is only retired at the next lookup, which is the HostImportFor in storageRefreshTests. Its vkFreeMemory frees an import whose pages are already gone. The Vulkan spec requires an imported host range to stay valid for as long as the memory object exists.

Unregister now looks the range up once more after removing it, as the cleanups in keysFillTests and storageRefreshTests already do. The import is retired while the block is still committed.

Tested

Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. agc_driver_recorder_tests was built with --target.

tree runs device loss other result
main d70b8998 25 6 19 refresh store (#2155's other failure, fixed by #2248)
main + this PR 30 0 30 refresh store
main + #2248 30 7 23 pass
main + #2248 + this PR 30 0 30 pass

With vkQueueWaitIdle probes around each step, 7 of 20 runs lost the device. In all 7, the queue was healthy just before the retire's vkFreeMemory of the 17 MiB import and lost right after it.

A local probe mode (not part of this PR) imports a 17 MiB block, releases it, and lets the next lookup retire the import:

block released runs device lost
about 10 µs after the import 60 12
0.5 ms after the import 20 4
1 ms after the import 20 1
1.5, 2, 5, 20 or 100 ms after the import 20 each 0
after the retire (this PR's order) 60 0

The window fits the late NVIDIA marks on imported pages, about 1.2 to 2 ms after the import, from #1434.

  • Not run on Linux. There the test runs to its end, and the end's shrunk registration already retires the import before the cleanup runs.
  • tools/check_conventions.py passes.

The runtime unmap path has the same order: GuestAllocationsUnmap_nid_postfix releases the pages in apply before the registry changes, and refreshImports retires the import later. I haven't checked whether a title ever releases memory within that window. This PR only changes the test; the runtime order is filed as #2352.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802162924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2299). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:00:33Z. --- ### What Fixes the device loss reported in #2155 (`vkQueueSubmit recorder: Vulkan result -4` at the start of `storageRefreshTests` in `agc_driver_recorder_tests`). On Windows, host imports are compared, not watched, so `unitShadowTests` returns right after it imports its 17 MiB block. Its cleanup then removes the registration and releases the block. The import itself is only retired at the next lookup, which is the `HostImportFor` in `storageRefreshTests`. Its `vkFreeMemory` frees an import whose pages are already gone. The Vulkan spec requires an imported host range to stay valid for as long as the memory object exists. `Unregister` now looks the range up once more after removing it, as the cleanups in `keysFillTests` and `storageRefreshTests` already do. The import is retired while the block is still committed. ### Tested Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. `agc_driver_recorder_tests` was built with `--target`. | tree | runs | device loss | other result | |---|---|---|---| | `main` d70b8998 | 25 | 6 | 19 refresh store (#2155's other failure, fixed by #2248) | | `main` + this PR | 30 | 0 | 30 refresh store | | `main` + #2248 | 30 | 7 | 23 pass | | `main` + #2248 + this PR | 30 | 0 | 30 pass | With `vkQueueWaitIdle` probes around each step, 7 of 20 runs lost the device. In all 7, the queue was healthy just before the retire's `vkFreeMemory` of the 17 MiB import and lost right after it. A local probe mode (not part of this PR) imports a 17 MiB block, releases it, and lets the next lookup retire the import: | block released | runs | device lost | |---|---|---| | about 10 µs after the import | 60 | 12 | | 0.5 ms after the import | 20 | 4 | | 1 ms after the import | 20 | 1 | | 1.5, 2, 5, 20 or 100 ms after the import | 20 each | 0 | | after the retire (this PR's order) | 60 | 0 | The window fits the late NVIDIA marks on imported pages, about 1.2 to 2 ms after the import, from #1434. - Not run on Linux. There the test runs to its end, and the end's shrunk registration already retires the import before the cleanup runs. - `tools/check_conventions.py` passes. The runtime unmap path has the same order: `GuestAllocationsUnmap_nid_postfix` releases the pages in `apply` before the registry changes, and `refreshImports` retires the import later. I haven't checked whether a title ever releases memory within that window. This PR only changes the test; the runtime order is filed as #2352. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-09 17:07:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T17:07:56Z.


I reviewed the full diff. The cleanup retires the test import after removing the registry range but before ReleaseWatched releases its pages, which matches the reported Windows failure window. The exact-head targeted Windows evidence is strong, including the 30/30 combined run with #2248; Conventions is green. The full Linux/Windows Build matrix was skipped, though. Could an authorized collaborator dispatch it on this PR head before merge? Although both PRs touch Recorder.cpp, their changes cover separate tests and complementary failures from #2155; #2248 remains the canonical refresh-store regression change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085591768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2299#issuecomment-6085591768). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T17:07:56Z. --- I reviewed the full diff. The cleanup retires the test import after removing the registry range but before `ReleaseWatched` releases its pages, which matches the reported Windows failure window. The exact-head targeted Windows evidence is strong, including the 30/30 combined run with #2248; Conventions is green. The full Linux/Windows Build matrix was skipped, though. Could an authorized collaborator dispatch it on this PR head before merge? Although both PRs touch `Recorder.cpp`, their changes cover separate tests and complementary failures from #2155; #2248 remains the canonical refresh-store regression change.
MarcZX10 commented 2026-10-09 18:47:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T18:47:12Z.


I pushed a general guest-unmap lifetime fix to my fork branch, tracked in issue #2352. For guest ranges going through GuestAllocations::Mutation::Unmap, the pin waiter now receives the mutation range, drains pending GPU work, and retires every overlapping host import before the unmap callback releases its pages. A recorder regression check verifies the import is already gone inside that callback.

For the runtime unmap defect, this is broader than changing only the unitShadowTests cleanup. The targeted Linux/GCC 12.2 build and agc_driver_recorder_tests --host-import-unmap-only pass on lavapipe. Windows hardware and the required full upstream Build matrix have not been run for that branch.

I would keep the changes distinct pending maintainer review: this PR's cleanup may still be needed for the unitShadowTests fixture if its teardown does not use the public guest-unmap path. The production branch addresses the general runtime lifetime ordering rather than replacing this fixture-specific coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6087156052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2299#issuecomment-6087156052). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T18:47:12Z. --- ### Related production-path fix for #2352 I pushed a general guest-unmap lifetime fix to [my fork branch](https://github.com/MarcZX100/AnyPS5/commit/1d1e9896af269395e216a0477f179f451f38f8f3), tracked in [issue #2352](https://github.com/boykopovar/AnyPS5/issues/2352). For guest ranges going through `GuestAllocations::Mutation::Unmap`, the pin waiter now receives the mutation range, drains pending GPU work, and retires every overlapping host import before the unmap callback releases its pages. A recorder regression check verifies the import is already gone inside that callback. For the runtime unmap defect, this is broader than changing only the `unitShadowTests` cleanup. The targeted Linux/GCC 12.2 build and `agc_driver_recorder_tests --host-import-unmap-only` pass on lavapipe. Windows hardware and the required full upstream Build matrix have not been run for that branch. I would keep the changes distinct pending maintainer review: this PR's cleanup may still be needed for the `unitShadowTests` fixture if its teardown does not use the public guest-unmap path. The production branch addresses the general runtime lifetime ordering rather than replacing this fixture-specific coverage.
MarcZX10 commented 2026-10-09 21:32:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T21:32:53Z.


I consolidated the two complementary #2155 recorder-test fixes in Marc's existing #2248, which now targets the current main and includes both focused changes in separate commits. The unit-shadow import-retirement commit preserves this PR's original author and commit attribution.

The changes address separate failure modes in the same agc_driver_recorder_tests executable: #2248 covers untracked storage refresh visibility, and this PR covers retiring the unit-shadow host import before releasing its backing block. The existing combined Windows run reported 30/30 passes with both changes. On the rebased combined branch, Linux build and recorder executable also pass; that Linux runtime has no write watching and does not validate the Windows device-loss path.

Since #2248 now carries both changes and their combined evidence for #2155, it is the consolidated candidate for review. I have not changed this PR or its branch. Please coordinate with the author and maintainers whether this PR should be closed in favor of the combined #2248, or kept open for separate review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089614474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2299#issuecomment-6089614474). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T21:32:53Z. --- I consolidated the two complementary #2155 recorder-test fixes in Marc's existing [#2248](https://github.com/boykopovar/AnyPS5/pull/2248), which now targets the current `main` and includes both focused changes in separate commits. The unit-shadow import-retirement commit preserves this PR's original author and commit attribution. The changes address separate failure modes in the same `agc_driver_recorder_tests` executable: #2248 covers untracked storage refresh visibility, and this PR covers retiring the unit-shadow host import before releasing its backing block. The existing combined Windows run reported 30/30 passes with both changes. On the rebased combined branch, Linux build and recorder executable also pass; that Linux runtime has no write watching and does not validate the Windows device-loss path. Since #2248 now carries both changes and their combined evidence for #2155, it is the consolidated candidate for review. I have not changed this PR or its branch. Please coordinate with the author and maintainers whether this PR should be closed in favor of the combined #2248, or kept open for separate review.
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
boykopovar/AnyPS5!2299
No description provided.