agc_driver segfaults on RADV: a background registration preparation (#2583) outlives the driver's VulkanDevice and reads its freed SPIR-V extension list #2891
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 SleglJan on 2026-10-10T17:45:06Z.
What
On
main57f96fd2, theagc_drivertest (agc_driver_tests) crashes with a segmentation fault on RADV now and then. With background preparation turned off it doesn't crash:ctest -R '^agc_driver$', standalone runsmainas isAPS5_SYNC_SHADER_PREPARE=1mainas isThe crash comes at exit, after every check has passed. The test's final
puts("AGC driver submit tests passed")has already run, but its output is lost because stdout is buffered when ctest captures it.Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected withVK_DRIVER_FILES=/usr/share/vulkan/icd.d/radeon_icd.json. The RTX 3080 runs NVIDIA 615.71.09.Backtrace
gdb caught the crash in one of three runs. Symbols only; the build has no debug info:
The faulting load is in the inlined loop that appends a
std::string_viewbyte by byte, andrbxis not a valid address. At the same moment the main thread is destroying the test's own device on the way out ofmain:The other 15 pool threads are idle, waiting in
RegistrationPreparePool::Main.Where it points
This matches the shutdown lifetime issue Celegans12 raised on #2583 after it merged (comment, from reading the code; the merged commit has the same pool, task capture and target copy):
RecompileRequestcopies the device'sSpirvTarget. ItssupportedCapabilitiesandsupportedExtensionsare spans into the device'sShaderDeviceProfile, which is freed with theVulkanDevice.RegistrationPreparePool(Execution/src/Driver/Shaders/ShaderRegistry.cpp) runs detached threads.Driver::stop(Driver/Lifecycle.cpp) resets the driver's device without draining them. The test's last check reaches it throughLibcRunShutdown_nid_postfix.RecompileCacheKey::appendInterfacehashesrequest.target, including both spans (CacheKey.hpp,append(key, const SpirvTarget&)). A job still queued or running afterDriver::stoptherefore reads the freed extension names. The crash site and the garbage pointer in the string loop fit that.No open pull request drains the pool or changes who owns the target's spans. #2589 (open) adds more submissions to the same pool.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Yuva1024 on 2026-10-10T18:59:10Z.
Tested PR #2909 (queeeef's
pr2909branch) on Windows, merged ontomain1476f769. Result for the shutdown ordering on Windows: it does not change what I see there, but my numbers are too small to tell.Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, RTX 4060 (driver 617.42).agc_driver_testsrun alone, 4 copies in parallel, no CPU stress:main1476f769: 1 of 240 runs exits 127 (heap corruption, 0xc0000374). 0 of 120 with 3 copies in parallel.mainplus #2909: 1 of 400 runs exits 127. The build is clean and the newRegistrationPrepareShutdowntest is built.So on Windows the heap-corruption exit still happens with #2909 applied, at a rate (about 0.3%) too low to say whether #2909 lowers it. I did not run a heavier load to separate the two. I did not find the cause of the Windows exit; I did not look at RADV.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-10T20:21:27Z.
AddressSanitizer on Linux (lavapipe), agc_driver_tests:
main: heap-use-after-free on the first run. A registration preparation thread reads the ShaderDeviceProfile (RecompileCacheKey::append) after Driver::stop freed it through DevicePointer::Reset.
main + this PR: 120 of 120 runs clean, 4 copies in parallel. agc_driver_registration_prepare_shutdown is clean too.
On Windows, reading freed heap memory like this can end in a heap-corruption exit, so this PR removes one candidate cause of the 0xc0000374 exit on #2891. Whether a second cause remains needs a Windows run with full page heap (gflags /p /enable agc_driver_tests.exe /full): it turns a bad heap write into an access violation, which the crash reporter prints with a backtrace.
The write-watch (macos-15-intel) failure is unrelated: that job builds only WriteWatch.cpp and GuestWriteWatch.cpp, and it failed the same way on boykopovar/AnyPS5#2990.
AI-assisted: yes (Claude Code).
Are you able to do such a run?
The way to settle it is one more Windows run with full page heap on (gflags /p /enable agc_driver_tests.exe /full). That turns any remaining bad heap write into an immediate crash, which the existing crash reporter prints with a backtrace.