You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(agc): keep registered-range queries from pinning guest ranges - #1973
Source commit: 67c8e0fba8c96eb58235a5cd3106d3bc3bc0e6f7. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.
What
RegisteredReadableCovers and RegisteredReadableEnd ask whether readable registered memory covers a span. Storage-image stores, sampled lookups, DMA copy destinations and the texture segment walk call them per dispatch or per lookup. Both took GuestAllocationsAcquireRegistered, a lease that holds a shared_ptr to every readable registered range. While a mutation waits in GuestAllocationsRequireUnpinned for a range's use count to drop to 1, that lease is not cached, so every query builds a new one and the range the mutation waits on stays pinned while any query is in flight. The pin waiter then syncs the recorder round after round (leased allocation ... still pinned after 8 recorder syncs). When no mutation waits, the query fills the cached readable lease instead, which keeps a reference to every range until the next mutation.
libc gets GuestAllocationsRegisteredReadableEnd(address, bytes, pieces). Under the registry lock it walks the registered ranges that cover the span and returns the end of the last one, or 0 when a byte is not covered; with pieces it copies the covering ranges out by value. It takes no reference to any range. Registered ranges do not overlap, so only the range starting at or before an address can hold it, as lookupLocked already assumes. Like GuestAllocationsAcquireRegistered, it still lists a range a mutation waits on, which 71427a8 requires (the host import lifetime test queries the registry from inside vkFreeMemory). The two queries now call it. GuestAllocationsAcquireRegistered stays for the unit shadow retire loops and the address-based builds, which hold their lease.
The header comment that described the query as one registry lease is removed, and a debt fragment updates the libc entry "Leases while a mutation waits for an unpinned range" to name the new function.
Related open PRs: boykopovar#12157 removes a different source of these pins (imports of other parts of an arena), and boykopovar#26802 and boykopovar#6481 add RegisteredReadableRunEnd and RegisteredReadableOverlaps next to these two queries, both on a lease; either could move to this walk once both land.
Tested
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, NVIDIA GeForce RTX 2080 Ti with driver 621.40, Vulkan SDK 1.4.363.1.
Two new test cases. In registeredReadableCoverTests (agc_graphics_profile_draw), a query must leave no reference to the range it answered for; main's queries fail it (a registered query kept a reference to the range it answered for: the cached readable lease holds it). The new entry agc_registered_readable_retiring (--registered-readable-retiring) removes a pinned range on one thread. Its pin waiter, which the removal calls while the range is retiring, checks that the range has left new GuestAllocationsAcquire leases but is still covered for both queries, then drops the pin. A walk that skips retiring ranges fails it (an allocation a removal waits on must stay covered for registered queries). It runs in its own process, so the driver's pin waiter of the shared suite is not replaced, and nothing in it depends on timing; it passed 100 of 100 repeated runs.
The ctest entries that exercise these queries and the pin wait (agc_graphics_profile_draw, agc_registered_readable_retiring on this change, agc_host_import_validity, the six agc_driver_guest_memory_lifetime* entries, the host import lifetime, other family, mutation race, cut lifetime, unmap, retirement and second mapping entries, the four unit shadow entries, guest_memory, guest_sync_on_address and guest_allocations_changes) ran with ctest --test-dir build -R <those names> -V on main fa6e12b and on this change, both with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer (validation layer 1.4.363.1). 22 of 22 pass on main and 23 of 23 on this change. In both logs the loader inserts the layer in the same 17 tests, the ones that create a Vulkan instance (the other five are the mock-Vulkan graphics suite and three libc and libkernel tests), neither log has was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has a VUID- line.
The cached-lease mutant ran on main 6100e07, before main moved to fa6e12b (none of the five commits between them touches these files); the skip-retiring mutant ran against agc_registered_readable_retiring on fa6e12b.
PPSA38500 on a bring-up tree (main 1632904 plus 14 open PRs and local changes): 8 still pinned after 8 recorder syncs lines within 170 s without this change, none in 244 s with it. These are counts of that log line from one run each, not trace summaries.
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 and the licence notice of code adapted from upstream (see AGENTS.md)
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
No actionable comments were generated in the recent review.
Walkthrough
Changes: Registered-readable coverage
Layer / File(s)
Summary
Add the libc coverage query core/libs/prx/libc/include/GuestAllocations.hpp, core/libs/prx/libc/src/GuestAllocations.cpp
The new API returns the end of contiguous host-readable registered coverage, or zero when the request is invalid or coverage is absent.
Integrate the query and test retiring allocations core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp, core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp, core/libs/prx/libSceAgcDriver/tests/Graphics.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake, docs/dev/debt/changes/fix-agc-registered-queries-unpinned.md
AGC registered-readable checks use the libc query. Tests check coverage while an allocation retires and after its pin is released. The graphics test runner and change note are updated.
This change stops frequent registered-range queries from pinning guest ranges. No merge-blocking risk was identified in the supplied evidence.
Security architecture risk: Minimal · up to 67c8e
AGC can check whether guest memory is still registered without keeping that memory pinned. The check still recognizes readable ranges while release is pending, but it does not grant permission to use the memory or replace the leases that protect in-flight GPU work.
Security review details
Security Blast Radius
observed — The inspected production path takes guest-derived addresses and sizes through existing AGC helpers to the in-process libc registry. For example, shader-buffer sizing uses the returned bound to limit or reject a descriptor. The new helper reads registry metadata, not the memory at the supplied address.
Trust Boundaries and Controls
observed — A retiring range can still be reported as covered while it remains registered and host-readable. That answer is distinct from admission to new ordinary leases, which exclude retiring ranges. Existing pins still govern when the mutation may proceed.
Resilience and Maintainability Implications
observed — The waiter still releases the registry mutex for recorder progress, rescans after reacquiring it, and clears the retirement marker on normal return or exception unwinding. The added test checks that an ordinary lease excludes the marked range, that the coverage query still sees it, and that coverage disappears after removal.
Rollout and rollback
inferred — No operator migration is indicated by the inspected change. libc still controls when a mapping can be removed or reprotected; reverting AGC and libc together restores the old query path. Reverting libc alone would remove the helper that head AGC calls.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
Cppcheck (2.22.0)
Cppcheck (2.22.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Cppcheck interrupted; analysis of this file is incomplete
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: e41176fc-2ee5-406a-a8a9-6cc8f16257a0
Commits
Reviewing files that changed from the base of the PR and between 4131f51 and 67c8e0f.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
RegisteredReadableCoversandRegisteredReadableEndask whether readable registered memory covers a span. Storage-image stores, sampled lookups, DMA copy destinations and the texture segment walk call them per dispatch or per lookup. Both tookGuestAllocationsAcquireRegistered, a lease that holds ashared_ptrto every readable registered range. While a mutation waits inGuestAllocationsRequireUnpinnedfor a range's use count to drop to 1, that lease is not cached, so every query builds a new one and the range the mutation waits on stays pinned while any query is in flight. The pin waiter then syncs the recorder round after round (leased allocation ... still pinned after 8 recorder syncs). When no mutation waits, the query fills the cached readable lease instead, which keeps a reference to every range until the next mutation.libc gets
GuestAllocationsRegisteredReadableEnd(address, bytes, pieces). Under the registry lock it walks the registered ranges that cover the span and returns the end of the last one, or 0 when a byte is not covered; withpiecesit copies the covering ranges out by value. It takes no reference to any range. Registered ranges do not overlap, so only the range starting at or before an address can hold it, aslookupLockedalready assumes. LikeGuestAllocationsAcquireRegistered, it still lists a range a mutation waits on, which 71427a8 requires (the host import lifetime test queries the registry from insidevkFreeMemory). The two queries now call it.GuestAllocationsAcquireRegisteredstays for the unit shadow retire loops and the address-based builds, which hold their lease.The header comment that described the query as one registry lease is removed, and a debt fragment updates the libc entry "Leases while a mutation waits for an unpinned range" to name the new function.
Related open PRs: boykopovar#12157 removes a different source of these pins (imports of other parts of an arena), and boykopovar#26802 and boykopovar#6481 add
RegisteredReadableRunEndandRegisteredReadableOverlapsnext to these two queries, both on a lease; either could move to this walk once both land.Tested
registeredReadableCoverTests(agc_graphics_profile_draw), a query must leave no reference to the range it answered for; main's queries fail it (a registered query kept a reference to the range it answered for: the cached readable lease holds it). The new entryagc_registered_readable_retiring(--registered-readable-retiring) removes a pinned range on one thread. Its pin waiter, which the removal calls while the range is retiring, checks that the range has left newGuestAllocationsAcquireleases but is still covered for both queries, then drops the pin. A walk that skips retiring ranges fails it (an allocation a removal waits on must stay covered for registered queries). It runs in its own process, so the driver's pin waiter of the shared suite is not replaced, and nothing in it depends on timing; it passed 100 of 100 repeated runs.agc_graphics_profile_draw,agc_registered_readable_retiringon this change,agc_host_import_validity, the sixagc_driver_guest_memory_lifetime*entries, the host import lifetime, other family, mutation race, cut lifetime, unmap, retirement and second mapping entries, the four unit shadow entries,guest_memory,guest_sync_on_addressandguest_allocations_changes) ran withctest --test-dir build -R <those names> -Von main fa6e12b and on this change, both withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer(validation layer 1.4.363.1). 22 of 22 pass on main and 23 of 23 on this change. In both logs the loader inserts the layer in the same 17 tests, the ones that create a Vulkan instance (the other five are the mock-Vulkan graphics suite and three libc and libkernel tests), neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.agc_registered_readable_retiringon fa6e12b.still pinned after 8 recorder syncslines within 170 s without this change, none in 244 s with it. These are counts of that log line from one run each, not trace summaries.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit