fix(libc): give a read-trapped page back to a GPU mutex holder instead of waiting for the resolver #15729
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15729"
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 imellag on 2026-11-04T10:04:03Z.
What
On macOS a thread that holds
GpuMutexand faults on a read-trapped page deadlocks with the read trap resolver. #13499's debt entry already lists it: "A thread holdingGpuMutextouching a trapped image waits forever". Stray (PPSA02100) reaches it at the start of gameplay. Twosamplecaptures of the hang show the same two threads:StorageTexture::FlushAllPendingUntil(the idle store, through the CPU) ->FlushPending->writeBack->writeBackLayers->GuestMemory::ReadCommitted, holdingGpuMutexand faulting on a trapped page;ResolveLabelTrap->FlushForAccess->StorageTexture::AccessKeptByCpu->GpuMutexType::lock(), waiting for that mutex.writeBackLayersreleases the traps on its pages first (releaseReadTraps(true)). The release misses a trap the resolver already took for another reader:ReleaseReadsfinds it no longer in_traps, anduntrapskips pages that another thread is resolving. The page stays without access, the store's own read faults, its fault waits for the resolver, and the resolver waits for the store's mutex. The game's render thread then never finishes, and after 120 s UE4 aborts withGameThread timed out waiting for RenderThread.The resolver can only make progress through
GpuMutex, so a holder of that mutex must not wait for it.GuestWriteWatchSetReadTrapBypass_nid_postfixtakes a predicate. When it returns true for the faulting thread, the fault gives the page its untrapped protection back at once, as it already does for the resolver's own thread, instead of queuing for the resolver. The driver sets it, together with its resolver, toGuestMemory::GpuMutex().HeldByThisThread(). Only the faulting page is given back; the trap stays in place on the image's other pages and is released by the store as before. The debt entry now says what the holder gets: the page without the store.macOS only, like the read traps. Linux and Windows are unchanged.
Tested
macOS 27.2, Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2.
maindoesn't build on macOS on its own, so both sides use the support branchsupport/macos-boot-1103(5ac8a62297):main1e658521a0+ the macOS port PRs still open (#7631 direct memory, #7804 process and thread queries, #4630sceKernelRaiseException, #11437) and five local build fixes marked(support only). None of them touches the read traps. The change side is that branch + this commit.New
write_watch_read-trap-holderincore/libs/tests/WriteWatch.cpp: a resolver that needs a lock the test thread holds, a second thread that faults on the trapped page first, then a read by the lock holder.SIGALRMafter 20 s.write_watch_*tests pass, on the head rebased ontomainb11c7bf84fas well.Focused AGC tests,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R '^(agc_small_tiled_shadow_label|agc_driver_storage_flush_ordering|agc_driver_linear_readback_label|agc_recorder_completion_labels|agc_driver_unimported_label_order|agc_driver_alias_copy_label|agc_driver_label_after_import_copy|write_watch_.*)$' -V:agc_small_tiled_shadow_labelaborts on both sides witha label stored a small image inside a pending large tiled one instead of trapping its reads(#13678's check); unchanged by this PR.agc_driver_alias_copy_labelis flaky on both sides: 9 of 20 pass on the base, 11 of 20 with this change.VUID-VkDeviceCreateInfo-pProperties-044514 times (the device created withoutVK_KHR_portability_subset, #13942) and no otherVUID-; neither haswas not found but was requested by env var VK_INSTANCE_LAYERS.Stray,
main1e658521a0+ support branch + #11551 + #9356 (needed to reach gameplay on MoltenVK), 3840x2160:samplecaught this deadlock in both stops it was taken on.samplecaught are in a different deadlock that this PR does not touch:GuestMemory::ImportWatchedtakes the write tracker's lock, opens a host write over the import, andGuestWriteWatchBeginHostWriteresolves a trap inside it on the same thread, which reachescollectWritesand takes the tracker's lock again. That one gets its own PR.Astro Bot (PPSA21564), tested by @Gonic0 on macOS 27.3, M5 Pro, KosmicKrisp (comment): without this change the game hangs right after
hub_crashsite_tutorialloads in 3 of 3 runs, with the same pair of threads reached throughShaderResources::revalidateFull->StorageTexture::refresh->writeBackLayers->cpuLeftUnchanged; with headfa4ea09852merged onto the same base, 2 of 2 runs enterhub_crashsite_tutorialand keep presenting until the 300 s limit.tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.py --branch fix/libc-read-trap-mutex-holderfinds no overlapping lines among the PRs it could merge; it could not compare 87 PRs that conflict withmainand shareTexture.cppordocs/dev/debt/libSceAgcDriver.md.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)