fix(agc): release cached address space on device teardown #4849

Merged
MarcZX10 merged 1 commit from upstream-pr/4849 into main 2026-10-14 00:13:09 +00:00
MarcZX10 commented 2026-10-13 00:07:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T00:07:47Z.


What

GuestBufferMemory::AcquireRegistered can publish an address space that holds leases for every registered GPU allocation. ClearImageMirrors used to release that cache only after confirming the mirror table belonged to the device. When lease mirrors are disabled, the mirror table has no device, so teardown returned early and left the address-space cache pinning allocations after the Vulkan device was destroyed.

Clear the cached address space by its own device identity before the mirror-table early return. Add a focused mock-Vulkan regression that builds an address space with APS5_NO_LEASE_MIRROR=1, tears it down, and confirms freeing its allocation does not need the pin waiter's cache-drop fallback. The regression fails against the old teardown logic.

Related to #4846. The reported ProsperoEden exit hang also reproduces with APS5_NO_ADDRESS_SPACE_CACHE enabled, so this cache cleanup is not established as the cause or fix for that issue. The test covers a separate lease cleanup regression when lease mirrors are disabled.

Tested

Linux, GCC 12.2, Release, Ninja, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

  • agc_driver_address_space_teardown passes. Restoring the old cleanup order makes it fail with device teardown left the cached address space pinning guest allocations.
  • agc_driver_graphics passes (15.78 s).
  • python3 tools/check_conventions.py --base upstream/main and git diff --check pass.
  • Tests use the mock Vulkan context; no physical GPU was involved.

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 under Silent stubs in their library's technical debt file
  • 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 (not applicable)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none confirmed
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836470563 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4849). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T00:07:47Z. --- ### What `GuestBufferMemory::AcquireRegistered` can publish an address space that holds leases for every registered GPU allocation. `ClearImageMirrors` used to release that cache only after confirming the mirror table belonged to the device. When lease mirrors are disabled, the mirror table has no device, so teardown returned early and left the address-space cache pinning allocations after the Vulkan device was destroyed. Clear the cached address space by its own device identity before the mirror-table early return. Add a focused mock-Vulkan regression that builds an address space with `APS5_NO_LEASE_MIRROR=1`, tears it down, and confirms freeing its allocation does not need the pin waiter's cache-drop fallback. The regression fails against the old teardown logic. Related to #4846. The reported ProsperoEden exit hang also reproduces with `APS5_NO_ADDRESS_SPACE_CACHE` enabled, so this cache cleanup is not established as the cause or fix for that issue. The test covers a separate lease cleanup regression when lease mirrors are disabled. ### Tested Linux, GCC 12.2, Release, Ninja, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - `agc_driver_address_space_teardown` passes. Restoring the old cleanup order makes it fail with `device teardown left the cached address space pinning guest allocations`. - `agc_driver_graphics` passes (15.78 s). - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - Tests use the mock Vulkan context; no physical GPU was involved. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 (not applicable) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none confirmed - [x] AI-assisted: yes, Codex
github-actions[bot] commented 2026-10-13 05:52:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T05:52:25Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4446 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp L2882-2883, L5597
#4783 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp L5597
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139216591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4849#issuecomment-6139216591). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T05:52:25Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4446 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` [L2882-2883](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp#L2882-L2883), [L5597](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp#L5597) | | | | #4783 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` [L5597](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp#L5597) | | |
MarcZX10 commented 2026-10-13 05:55:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T05:55:56Z.


Validation on the rebased head abc997b0daf691918aa8ae681debdc10c43328d4:

  • Release Ninja build of agc_driver_graphics_tests completed.
  • agc_driver_address_space_teardown passed (1/1).
  • tools/check_test_registration.py, tools/check_conventions.py --base upstream/main --head HEAD, and git diff --check passed.
  • Hosted eligibility, conventions, and report checks pass; GitHub currently reports the PR mergeable.

The overlap report flags nearby changes to Graphics.cpp in #757 and #758. This fix does not depend on either; I’ll account for those edits if either lands first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139261907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4849#issuecomment-6139261907). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T05:55:56Z. --- Validation on the rebased head `abc997b0daf691918aa8ae681debdc10c43328d4`: - Release Ninja build of `agc_driver_graphics_tests` completed. - `agc_driver_address_space_teardown` passed (1/1). - `tools/check_test_registration.py`, `tools/check_conventions.py --base upstream/main --head HEAD`, and `git diff --check` passed. - Hosted eligibility, conventions, and report checks pass; GitHub currently reports the PR mergeable. The overlap report flags nearby changes to `Graphics.cpp` in #757 and #758. This fix does not depend on either; I’ll account for those edits if either lands first.
oneandonlydean commented 2026-10-13 08:05:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:05:05Z.


Please drop Fixes #4846. The issue reproduces with APS5_NO_ADDRESS_SPACE_CACHE set and with lease mirrors on, so this cache isn't what holds its lease; #4872 fixes the exit order and the title's run there goes from 134 to 0. The early return in ClearImageMirrors (GuestBufferMemory.cpp:1791) is still a real leak, so this stays open on its own. Which run reaches it without APS5_NO_LEASE_MIRROR?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141137714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4849#issuecomment-6141137714). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T08:05:05Z. --- Please drop `Fixes #4846`. The issue reproduces with `APS5_NO_ADDRESS_SPACE_CACHE` set and with lease mirrors on, so this cache isn't what holds its lease; #4872 fixes the exit order and the title's run there goes from 134 to 0. The early return in `ClearImageMirrors` (`GuestBufferMemory.cpp:1791`) is still a real leak, so this stays open on its own. Which run reaches it without `APS5_NO_LEASE_MIRROR`?
MarcZX10 commented 2026-10-13 08:11:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T08:11:51Z.


Thanks for the correction. The ProsperoEden report reproduces with APS5_NO_ADDRESS_SPACE_CACHE enabled and lease mirrors on, and #4872 addresses the reported exit-order failure. I removed “Fixes #4846” and clarified that this PR only tests cache lease cleanup when lease mirrors are disabled; the current evidence does not establish that this change fixes the reported ProsperoEden hang.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141244827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4849#issuecomment-6141244827). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T08:11:51Z. --- Thanks for the correction. The ProsperoEden report reproduces with `APS5_NO_ADDRESS_SPACE_CACHE` enabled and lease mirrors on, and #4872 addresses the reported exit-order failure. I removed “Fixes #4846” and clarified that this PR only tests cache lease cleanup when lease mirrors are disabled; the current evidence does not establish that this change fixes the reported ProsperoEden hang.
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!4849
No description provided.