fix(libc): leave a range that a mutation waits for out of new leases #6565
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6565"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-15T20:51:03Z.
What
Brigandine Abyss (PPSA27752) aborts 5 to 6 minutes after start with
(lines 132 and 135 of the stderr of the first run and lines 131 and 136 of the second show it for
0x11a6000000+0x1a00000, after[gpu] storage image …: memory no longer registered; 1 pending ranges dropped. Storage images listed at lines 124-128 of the first run lie inside the pinned allocation.)GuestAllocationsRequireUnpinnedwaits for the GPU work that leases a range through the driver's waiter.GuestAllocationsAcquireAllandGuestAllocationsAcquirecopy every registered range into each new lease, including the range that is being released. A driver worker that starts an address-based build between the waiter's return and the re-lock therefore pins the range again; the comment inRequireUnpinneddescribes this as rare. A title that draws every frame repeats it each round, and afterAPS5_PIN_WAIT_MSthe free fails.AcquireandAcquireAllleave retiring ranges out and do not cache the lease while one is recorded; the caches are cleared when the record is removed.GuestAllocationsAcquireRegisteredreturns a readable lease that still lists the ranges a mutation waits on;RegisteredReadableCovers,RegisteredReadableEndand the two retire loops inGuestBufferMemory.cppuse it, because the new lease without the range hid it from code that only asks what is registered (thehost_importlifetime test andagc_unit_shadowsaw it). The mutation race test now asserts that an import of the waiting extent is refused.GuestAllocationsAcquireandGuestAllocationsAcquireAllleave out a range a mutation waits on, whileGuestAllocationsAcquireRegisteredstill lists it; whether the console keeps that memory visible is unknown.GuestAllocationsAcquireMapped_nid_no_patch, added tomainafter this change was written, builds its lease without the retiring check, soImportMappedRangescan still lease a range a mutation waits on; this pull request does not change it.guest_memorygainsCheckPinnedRangeIsLeftOutOfNewLeases: a pin waiter replaces the lease with a newAcquireAlllease the way a worker does, and the range is unmapped. Without the change the unmap fails with the line above (still pinned after 8 recorder syncs, see Tested); with it the unmap succeeds, the old lease no longer holds the range, and a laterAcquireAlllease holds a new mapping.This shows the mechanism, not that Brigandine hangs this way: a diagnostic run of the title ended earlier in a different stop (the engine's 120 s watchdog on the render thread) and did not reach the pin, so the lease source in the title is not measured.
Tested
Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Release, on
mainb54849f5a0+ these 4 commits rebased onto it (head2e9dcf0e35; four conflicts in the first rebase:docs/dev/debt/libc.mdthree times, andGuestAllocations.cpponce, wheremain'sGuestAllocationsAcquireMapped_nid_no_patchand this change'sGuestAllocationsAcquireRegistered_nid_postfixare both kept); ninja exit code 0 read for each arm:ctest -R ^guest_memory$: passes with the change (3 of 3 runs); fails without it in 3 of 3 runs (GuestAllocations.hpp,GuestAllocations.cppandGuestBufferMemory.cpptaken back tomainb54849f5a0, tests kept):[gpu] leased allocation 0x200f70000+0x8000 still pinned after 8 recorder syncs,Guest memory check failed at core/libs/tests/GuestMemory.cpp:2404, exit code0xc0000409.ctest -R '^guest_memory$|agc_host_import|agc_driver_host_import|agc_unit_shadow|agc_driver_unit_shadow'(18 tests), on an NVIDIA GeForce RTX 4080 SUPER withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, one run each onmain66d362c782and on the head: ctest reports 0 failed out of 18 in both,agc_host_import_sparseis skipped (udmabuf imports are Linux only), andagc_host_import_cut_lifetimepasses in both.mainand on the previous head that did setVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationwithout a layer printed nowas not found but was requestedline and noVUID-line, which says nothing about validation. A locally builtVkLayer_khronos_validation.dllloaded throughVK_LAYER_PATHcrashes 11 of the 18 tests inside the layer during device creation (VkLayer_khronos_validation.dll+0xe66a41) onmainand on this head alike, so noVUID-comparison exists from it either.python tools/check_conventions.py --base upstream/mainpasses;git merge-treeof the head against currentmainb54849f5a0is clean.guest_memorytest now setsAPS5_PIN_WAIT_MSthere too, not built), a console, the title with this change. Measured by others on earlier heads: jotitadev on Ubuntu 26.04 (Intel i7-8700, GCC 15.2, Release) at head46d11782e:guest_memorypasses 3 of 3 with the change and aborts atGuestMemory.cpp:1497withGuestAllocations.cppofmain; blawesom on CachyOS (kernel 7.2.9, GCC 16.2.1, AMD RX 9070 XT / RADV) at the rebased heada850691ed: full suite 1338 of 1339, the failure isagc_driver_tessellation(#4727) as onmain; TheSovietWaffle on Windows 10 Pro 22H2 (RTX 3080, NVIDIA 617.42) with #6182 and #6565 merged together: a title run that aborted on the lease wait after about 7 minutes without them ran about 2 h 14 min without that abort with them, which does not show which of the two PRs is needed. hugodearaujo on Linux 7.2.11 (RX 9070 XT, RADV, Mesa 26.2.5, GCC 16.2.1, Release) with ASTRO BOT (PPSA21567): the same lease-wait stop onmainand onmainplus this PR (one run), because the range is held by window imports and not by a lease; with #6182 the title got past the wait in 2 of 2 runs.Checklist
main; no other open PR implements the same changeNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (docs/dev/debt/libc.md).mdfiles or images added to the repositorydocs/dev/debt/libc.md)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T21:48:32Z.
Review: COMMENTED
Linux run, since the description lists Linux as not built.
Ubuntu 26.04, Intel i7-8700, GCC 15.2, Ninja, Release,
BUILD_TESTING=ON, full build.main31cbb55d7with head 46d11782e merged on top.guest_memorypasses 3 runs of 3 (0.6 s each).core/libs/prx/libc/src/GuestAllocations.cppreverted tomain:guest_memoryaborts with the same failure as on Windows: It fails in about 2 s, so the newsetenv("APS5_PIN_WAIT_MS", "1000", 1)for non-Windows hosts is what keeps it short.ctest -E "^agc|gpu|vulkan|video_out" -j8): 648/650, same asmainon this machine. The 2 failures (file_writer_binary,file_writer_text) also fail onmainhere.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-16T03:33:32Z.
@adriadam10 a short request for review of this PR. Head
46d11782eisMERGEABLE/CLEAN, the Conventions, Eligibility and Intake checks are green. The newguest_memorycaseCheckPinnedRangeIsLeftOutOfNewLeasespasses with the change and fails without it (still pinned after 8 recorder syncs). The description names the title (Brigandine Abyss, PPSA27752) and the log lines, and says what is shown (the mechanism) and what is not (that the title hangs this way). The overlap bot lists #6499 nearGuestAllocations.cppL40-L47; the topics differ, and I will rebase whichever of the two lands second if asked.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T11:31:54Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One docs-debt conflict, unioned.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
a850691ed.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T01:58:52Z.
Rebased onto
main324e0e48e; the only conflict was indocs/dev/debt/libc.md(both lines kept). The code is unchanged: the patch id of the changes toGuestAllocations.cppandGuestMemory.cppis89ba80ecc119, the same as before the rebase and as in blawesom'srebase/6565(thanks for the handoff; it is based on an oldermain, so I rebased the same commit myself instead of fast-forwarding).Tested on
main324e0e48e+ head95fabdbef(Windows 10, MinGW-w64 GCC 15.2.0, Release, rebuilt after the submodules ofmainwere fetched):ctest -R ^guest_memory$passes with the change (4.0 s) and fails without it (GuestAllocations.cpptaken frommain, test kept):[gpu] leased allocation 0x200d60000+0x8000 still pinned after 8 recorder syncs,Guest memory check failed at core/libs/tests/GuestMemory.cpp:1622, exit code 8. The earlier run on4eb91eacdgave the same result. The head commit author address is the account's noreply address.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T05:35:19Z.
Rebased onto
main4ffb0cd12(new headb2dbb48bb). One conflict, incore/libs/prx/libc/src/GuestAllocations.cpp: #6917 made the registry keep its lease snapshots (std::shared_ptr) until the registry changes, where this change hadstd::weak_ptr. I kept the shared snapshots and added the list of retiring ranges next to them. A retiring range is only added after the snapshots were reset in the scan loop and no snapshot is stored while that list is not empty;unmarkresets them again, so a snapshot never holds a range that is being waited for.Tested on
main4ffb0cd12+ headb2dbb48bb(Windows 10, NVIDIA GeForce RTX 4080 SUPER, driver 610.74, MinGW-w64 GCC 15.2.0, Release):ctest -R ^guest_memory$passes with the change (4.9 s). Without it (GuestAllocations.cpptaken frommain, test kept) the test aborts (exit code 0xc0000409) after[gpu] leased allocation 0x200d60000+0x8000 still pinned after 8 recorder syncs.python tools/check_conventions.py --base upstream/mainpasses. The head commit author address is the account's noreply address; the previous head95fabdbefis kept as tagbackup/6565-95fabdbefon the fork.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T07:45:11Z.
Rebased again onto
mainfb0dc118f(new headb10615d5e;merge-treeagainst the newermaind8d0222d0is clean). The conflict was incore/libs/prx/libc/src/GuestAllocations.cpp, in three places: #6917-follow-upf9caa0974addedbackingSerials/renewBackingnext to the lease snapshots, andRequireUnpinnednow recordsstate->unpinned. I kept those and added the list of retiring ranges beside them; the range is removed again (unmark) beforeunpinnedis recorded, so the snapshots are reset and never hold a range that is being waited for.Tested on
mainfb0dc118f+ headb10615d5e(Windows 10, NVIDIA GeForce RTX 4080 SUPER, driver 610.74, MinGW-w64 GCC 15.2.0, Release):ctest -R ^guest_memory$passes with the change (3.1 s). Without it (GuestAllocations.cpptaken frommain, test kept) the test aborts (exit code 0xc0000409) after[gpu] leased allocation 0x200d60000+0x8000 still pinned after 8 recorder syncs.python tools/check_conventions.py --base upstream/mainpasses. The head commit author is the account's noreply address; the previous headb2dbb48bbis kept as tagbackup/6565-b2dbb48bbon the fork.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T08:32:33Z.
Pushed
2ca591f5d(docs only, no force): the technical-debt entry for the lease change now states the gap first, per the new CONTRIBUTING rule: whether the console keeps memory visible to GPU work submitted while a release or reprotect is pending is unknown and not measured on hardware; the implemented behaviour (a mutation leaves its leased range out of every lease taken until it ends) follows as far as the gap needs.python tools/check_conventions.py --base upstream/mainpasses andmerge-treeagainstmain3fdd1f52eis clean; code unchanged sinceb10615d5e.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T17:47:29Z.
Rebased onto
maine90a1d180(new head0c5cee488, two commits;merge-treeagainst the newermain844450824is clean). The only conflict was indocs/dev/debt/libc.md, wheremainadded theios_base standard streamsentry in the same place as this change's entry; both are kept.core/libs/prx/libc/src/GuestAllocations.cppandcore/libs/tests/GuestMemory.cpprebased without conflict (recentmaincommits touching libc/GuestAllocations: #7878, #7906, #6985, #6975, #7039 — none overlapped the changed lines).Tested on
maine90a1d180+ head0c5cee488(Windows 10.0.19045, NVIDIA GeForce RTX 4080 SUPER, driver 610.74, MinGW-w64 GCC 15.2.0, Release):ctest -N -R ^guest_memory$lists the test, andctest -R ^guest_memory$passes with the change (3.3 s). Without it (GuestAllocations.cpptaken frommain, test kept) the test aborts (exit code 0xc0000409) after[gpu] leased allocation 0x200d60000+0x8000 still pinned after 8 recorder syncs.python tools/check_conventions.py --base upstream/mainpasses. Both commits carry the account's noreply address; the previous head2ca591f5dis kept as tagbackup/6565-2ca591f5don the fork.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T21:58:40Z.
Rebased onto
maineaa5c9238(new head4e57c4c84, two commits;merge-treeagainst the newermainis clean). The only conflict was incore/libs/tests/GuestMemory.cpp, in the list of test calls inmain():mainadded the direct-memory release checks (CheckReleaseKeepsPhysicalUntilViewsUnmapped,CheckConcurrentCheckedReleasesUnmapViewsOnce) at the place where this change'sCheckPinnedRangeIsLeftOutOfNewLeases()went; both are kept.core/libs/prx/libc/src/GuestAllocations.cppanddocs/dev/debt/libc.mdrebased without conflict. Themaincommits that touched these files since the previous head are #7448 (direct memory release order,libkernel) and #7872 (std::_Throw_bad_optional_access,libc); neither overlaps the changed lines.Tested on
maineaa5c9238+ head4e57c4c84(Windows 10.0.19045, NVIDIA GeForce RTX 4080 SUPER, driver 610.74, MinGW-w64 GCC 15.2.0, Release):ctest -N -R ^guest_memory$lists the test, andctest -R ^guest_memory$passes with the change (3.1 s). Without it (GuestAllocations.cpptaken frommain, test kept) the test aborts (exit code 0xc0000409) after[gpu] leased allocation 0x200d60000+0x8000 still pinned after 8 recorder syncs.python tools/check_conventions.py --base upstream/mainpasses. Both commits carry the account's noreply address; the previous head0c5cee488is kept as tagbackup/6565-0c5cee488on the fork.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T01:02:12Z.
Rebased onto
main57fdffd91(new head4b8125641, two commits, author unchanged). The only conflict was indocs/dev/debt/libc.md, wheremainchanged thestd::_Pad, _Thrd_join, ...line next to this change's entry; both are kept. The patch id of the changes undercore/is7e4fd6dbc235, the same as before the rebase, so the code is unchanged.tools/check_conventions.py --base upstream/mainpasses;merge-treeagainstmainis clean.Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release, on that base:
ctest -N -R '^guest_memory$'lists exactly that one test;ctest --no-tests=error -R '^guest_memory$'was run three times per tree.guest_memory_pool_statspasses.core/libs/prx/libc/src/GuestAllocations.cpprestored tomain(the test kept): fails 3 of 3, exit code0xc0000409.Not tested: Linux, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-21T09:33:05Z.
Title data point for this together with #6182: Onimusha: Way of the Sword (PPSA27836), owned, Windows 10 Pro 22H2, RTX 3080 (NVIDIA 617.42), WinLibs GCC 15.2.0, Release,
APS5_NO_HOST_IMPORT=1. Tree:main1d4164552plus a few open AGC/shader PRs and local workarounds for the #6570 and stencil-mask stops; the only change between the two runs below is #6182 + #6565 merged in.guest allocation 0xe82bf60000+0x1a0000 is still pinned by GPU work or an import (waited 60000 ms for the lease (APS5_PIN_WAIT_MS))(from a guest mutation inlibc).I merged both together, so this does not say which of the two is needed for this title; one run each.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T20:52:10Z.
Linux data point for this PR (data only, from our own run; WSL2 Ubuntu 24.04, GCC 13.3, Release, software Vulkan llvmpipe; a virtualised kernel, not bare-metal Linux). Base
394170059and head561f90687a, each built and run 3 times (ctest --repeat until-fail:3):agc_driver_host_import_lifetimepasses 3 of 3 on the base and fails on the head withAGC graphics: guest pages became inaccessible before vkFreeMemory returned.agc_driver_host_import_mutation_racepasses 3 of 3 on the base and fails on the head.I have not found the cause yet. Not tested: Windows for these two tests, bare-metal Linux, the current
maintip. We are looking into it and will update this PR.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T21:09:11Z.
Windows data point for the current head
561f90687, merged ontomain0c6a5bd59(clean,git merge-treerc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. For each test,ctest -Nlists exactly that one test andctest --no-tests=errorwas run three times per tree. This confirms the Linux result B posted above on a second platform:agc_driver_host_import_lifetime: fails 3 of 3 with this PR; passes 3 of 3 on the same tree withcore/libs/prx/libc/src/GuestAllocations.cpprestored tomain. The failing run's output (kept withctest -V) hasAGC graphics: guest pages became inaccessible before vkFreeMemory returned.agc_driver_host_import_mutation_race: fails 3 of 3 with this PR; passes 3 of 3 withGuestAllocations.cpprestored tomain(failure message not kept).I have not found the cause. Until it is understood this PR should not be merged; I will follow up here.
Not tested: other platforms, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T01:20:01Z.
Windows data point for the head
1c750d771, merged ontomaina6dcea927(clean,git merge-treerc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release; every test target was rebuilt on this tree, each test run three times (ctest -Nlists exactly one test per name). The GPU was not recorded in these logs, so no device is claimed.561f90687(my Windows comment above):agc_driver_host_import_lifetimeandagc_driver_host_import_mutation_racenow pass 3 of 3.agc_unit_shadow,agc_driver_unit_shadowandagc_driver_unit_shadow_budgetpass 3 of 3.agc_driver_recorder_tests(74 in this tree, including the ones above) andguest_memory/guest_memory_pool_stats: all pass 3 of 3.agc_rect_list_position_invariant,agc_command_batch_fence_failureandagc_driver_host_import_failure_handles/_at_map/_teardown/_windowsreported "Not Run" in the first pass because their executables were not built; after building them they pass 3 of 3 as well.In total 83 tests selected (77 in the first pass, the 6 above in the second), none failed. Not tested: Linux (B's run), other GPUs, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:52:34Z.
Review: COMMENTED
Points on 6565:
Comments in code.
GuestAllocations.cppadds a comment block ("Ranges a mutation is waiting to see unpinned (RequireUnpinned): new leases leave them out..."). The rule is no comments except#endifand namespace ends.Starvation / ordering. Leaving a range out of new leases while a mutation waits means a caller asking for that range gets a different result (a copy or nothing) than one asking a moment earlier. Please say what a lease taker sees in that case, and whether the mutation wait is bounded; if the pinned holder never releases, does the waiter block forever while new leases keep failing?
Negative control. Does the new test fail with the exclusion removed (i.e. a lease taken while a mutation waits keeps the mutation waiting)? Please show the failing output.