fix(agc): harden host import construction and mutation waits #7339
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7339"
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 oneandonlydean on 2026-10-18T01:07:06Z.
Repost of #2779 by @nikhilpanchal1, which the intake bot closed on 2026-10-10 under the open-PR limit ("intake paused").
mainhas moved a lot since (GuestBufferMemory.cpphas doubled), so this is a hand re-apply of the same change onto currentmain; the commit keeps the original author.What
Follow-up to #2575 (MarcZX100's fix for #2352). Incomplete Vulkan host imports are cleaned up before their allocation pin is released: a guard owns the buffer, memory and Windows alias of an import under construction until the entry is published in the table, so a throw in between (a failed settle, a bad_alloc on insert) cannot leak them. The mutation waiter no longer swallows errors:
WaitForLeasesAndImportspropagates them, the registry lock is restored before the error leaves the pin loop, and a pinned mutation requested from inside an active GPU completion is rejected instead of waiting on itself. The waiter is installed centrally when an import is built, so descriptor-first imports are covered. New tests (HostImportLifetime.cpp,GuestMemoryLifetime.cpp,test_guest_memory_lifetime.py, plus fixtures) cover each of these.Changed versus the original #2779
GuestBufferMemory.cpp: re-applied by hand on top ofmain's current code. Taken over: theImportConstructionguard inimportAllocation,WaitForLeasesAndImportswithoutnoexceptand without its two try/catch wrappers, theRecorder::InCompletion()rejection, andensurePinWaiter()at the start ofimportAllocation.libc/GuestAllocations.cppis unchanged from the original (restores the registry lock when the waiter throws).Recorder::ReleaseCompletedKeeps()(mainalready releases throughFlushDeferredReleases(), whichWaitForLeasesAndImportsnow calls); thestd::exchangechange inbindImport, whichmain's code does not need; and the two edits inimportChunk/createChunkedDmaBufImport, because publishing the buffer handle only after a successful create (asmaindoes) is safer than writing it straight into the entry, and setting the chunk's free callback beforevkAllocateMemorycould free an undefined handle after a failed allocation.tests/Recorder.cpp: only theHostImportLifetime.hppinclude and the two new--host-import-*-onlymodes are added. The original also madeunitShadowTestsskip instead of silently pass, butmain's version of that test and its retire assertions have since changed, so that part is left out.tests/HostImportLifetime.cpp: one line added todeferredRetirement,fixture.recorder->FlushDeferredReleases()after the sync.mainnow keeps a retired import through the GPU hold until a flush, so the test has to flush before it expects the Vulkan free on the release thread.CMakeLists.txt: the original's test registrations are kept; the two conflicts were adjacent additions and both sides are kept.bindImportand overlaps this only in that area; nothing here conflicts with it textually.Tested
Linux x86-64, GCC, Release, NVIDIA GeForce RTX 4090 (real Vulkan), on this branch rebased onto
main(51cee9031): build OK; 24 of 24 tests passed (agc_driver_host_import_lifetime,agc_driver_host_import_mutation_race,agc_driver_guest_memory_lifetimein copy/direct/locked/heap/heap_uncached/converted modes,agc_unit_shadow,agc_driver_unit_shadow,agc_host_import_retire(ment)and the other host-import tests). Control: withGuestBufferMemory.cppandGuestAllocations.cppreverted tomain,--host-import-lifetime-onlyfails ("still pinned ... waited 2000 ms") and--host-import-mutation-race-onlyfails ("a failed pin waiter did not restore the registry lock"). Not run: the full suite, Windows, DMA-buf chunk paths, Linux write-watch tests that needuserfaultfd.Checklist
main; no other open PR implements the same functions (the open #7082 covers only the failed-handle cleanup inbindImport, which this does not touch)NotImplemented_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)