Repository navigation
fix(agc): harden host import construction and mutation waits - #7339
Merged
Merged
Conversation
Guard incomplete imports and preserve mutation waiter errors and progress. Follow-up to boykopovar#2575; refs boykopovar#2352.
oneandonlydean
force-pushed
the
rescue/2779
branch
from
October 18, 2026 01:59
c6be977 to
3047980
Compare
11 tasks done
12 tasks done
This was referenced Oct 18, 2026
Open
12 tasks done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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(51cee90): 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 fix(agc): keep failed import handles out of cleanup #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)