agc_driver segfaults on RADV: a background registration preparation (#2583) outlives the driver's VulkanDevice and reads its freed SPIR-V extension list #2891

Closed
opened 2026-10-10 17:45:06 +00:00 by SleglJan · 2 comments
SleglJan commented 2026-10-10 17:45:06 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T17:45:06Z.


What

On main 57f96fd2, the agc_driver test (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 runs segmentation faults
RADV, main as is 7 of 8, and 3 of 8 in a second batch on a busier machine
RADV, APS5_SYNC_SHADER_PREPARE=1 0 of 8, and 0 of 2
RTX 3080, main as is 0 of 8

The 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=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with VK_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:

Thread 33 "agc_driver_test" received signal SIGSEGV, Segmentation fault.
=> appendInterface+1048: movzbl (%rbx),%esi        rbx = 0x1a4a175af3e8906a
#0  ShaderRecompiler::RecompileCacheKey::appendInterface(std::vector<unsigned long>&, ShaderRecompiler::RecompileRequest const&)
#1  ShaderRecompiler::PrepareShader(ShaderRecompiler::RecompileRequest const&, ShaderRecompiler::ShaderPreparationContext*)
#2  AgcDriver::DriverDetail::PrepareShaderWithDiagnostics(ShaderRecompiler::RecompileRequest const&, ShaderRecompiler::ShaderPreparationContext*)
#3  AgcDriver::DriverDetail::(anonymous namespace)::PrepareRegistered(RegisteredPreparation&)::{lambda()#1}::operator()() const
#4  AgcDriver::DriverDetail::(anonymous namespace)::PrepareRegistered(RegisteredPreparation&)
#5  AgcDriver::DriverDetail::(anonymous namespace)::RegistrationPreparePool::Main(void*)

The faulting load is in the inlined loop that appends a std::string_view byte by byte, and rbx is not a valid address. At the same moment the main thread is destroying the test's own device on the way out of main:

Thread 1 "agc_driver_test":
#0  ioctl () from /usr/lib/libc.so.6
#1–#5  ?? () from /usr/lib/libvulkan_radeon.so
#6  ?? () from /usr/lib/libvulkan.so.1
#7  vkDestroyDevice () from /usr/lib/libvulkan.so.1
#8  AgcDriver::VulkanDevice::State::~State()
#9  AgcDriver::VulkanDevice::~VulkanDevice()
#10 main[cold] ()

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):

  • The queued plan's RecompileRequest copies the device's SpirvTarget. Its supportedCapabilities and supportedExtensions are spans into the device's ShaderDeviceProfile, which is freed with the VulkanDevice.
  • The task keeps the snapshot and the plan alive, but not the profile.
  • 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 through LibcRunShutdown_nid_postfix.
  • RecompileCacheKey::appendInterface hashes request.target, including both spans (CacheKey.hpp, append(key, const SpirvTarget&)). A job still queued or running after Driver::stop therefore 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5793754460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2891). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-10T17:45:06Z. --- ### What On `main` 57f96fd2, the `agc_driver` test (`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 runs | segmentation faults | |---|---| | RADV, `main` as is | 7 of 8, and 3 of 8 in a second batch on a busier machine | | RADV, `APS5_SYNC_SHADER_PREPARE=1` | 0 of 8, and 0 of 2 | | RTX 3080, `main` as is | 0 of 8 | The 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=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with `VK_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: ``` Thread 33 "agc_driver_test" received signal SIGSEGV, Segmentation fault. => appendInterface+1048: movzbl (%rbx),%esi rbx = 0x1a4a175af3e8906a #0 ShaderRecompiler::RecompileCacheKey::appendInterface(std::vector<unsigned long>&, ShaderRecompiler::RecompileRequest const&) #1 ShaderRecompiler::PrepareShader(ShaderRecompiler::RecompileRequest const&, ShaderRecompiler::ShaderPreparationContext*) #2 AgcDriver::DriverDetail::PrepareShaderWithDiagnostics(ShaderRecompiler::RecompileRequest const&, ShaderRecompiler::ShaderPreparationContext*) #3 AgcDriver::DriverDetail::(anonymous namespace)::PrepareRegistered(RegisteredPreparation&)::{lambda()#1}::operator()() const #4 AgcDriver::DriverDetail::(anonymous namespace)::PrepareRegistered(RegisteredPreparation&) #5 AgcDriver::DriverDetail::(anonymous namespace)::RegistrationPreparePool::Main(void*) ``` The faulting load is in the inlined loop that appends a `std::string_view` byte by byte, and `rbx` is not a valid address. At the same moment the main thread is destroying the test's own device on the way out of `main`: ``` Thread 1 "agc_driver_test": #0 ioctl () from /usr/lib/libc.so.6 #1–#5 ?? () from /usr/lib/libvulkan_radeon.so #6 ?? () from /usr/lib/libvulkan.so.1 #7 vkDestroyDevice () from /usr/lib/libvulkan.so.1 #8 AgcDriver::VulkanDevice::State::~State() #9 AgcDriver::VulkanDevice::~VulkanDevice() #10 main[cold] () ``` 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](https://github.com/boykopovar/AnyPS5/pull/2583#issuecomment-6097529248), from reading the code; the merged commit has the same pool, task capture and target copy): - The queued plan's `RecompileRequest` copies the device's `SpirvTarget`. Its `supportedCapabilities` and `supportedExtensions` are spans into the device's `ShaderDeviceProfile`, which is freed with the `VulkanDevice`. - The task keeps the snapshot and the plan alive, but not the profile. - `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 through `LibcRunShutdown_nid_postfix`. - `RecompileCacheKey::appendInterface` hashes `request.target`, including both spans (`CacheKey.hpp`, `append(key, const SpirvTarget&)`). A job still queued or running after `Driver::stop` therefore 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)
Yuva1024 commented 2026-10-10 18:59:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Yuva1024 on 2026-10-10T18:59:10Z.


Tested PR #2909 (queeeef's pr2909 branch) on Windows, merged onto main 1476f769. 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_tests run alone, 4 copies in parallel, no CPU stress:

  • main 1476f769: 1 of 240 runs exits 127 (heap corruption, 0xc0000374). 0 of 120 with 3 copies in parallel.
  • main plus #2909: 1 of 400 runs exits 127. The build is clean and the new RegistrationPrepareShutdown test 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101066779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2891#issuecomment-6101066779). Originally posted by [Yuva1024](https://github.com/Yuva1024) on 2026-10-10T18:59:10Z. --- Tested PR #2909 (queeeef's `pr2909` branch) on Windows, merged onto `main` 1476f769. 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_tests` run alone, 4 copies in parallel, no CPU stress: - `main` 1476f769: 1 of 240 runs exits 127 (heap corruption, 0xc0000374). 0 of 120 with 3 copies in parallel. - `main` plus #2909: 1 of 400 runs exits 127. The build is clean and the new `RegistrationPrepareShutdown` test 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).
queeeef commented 2026-10-10 20:21:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-10T20:21:27Z.


Tested PR #2909 (queeeef's pr2909 branch) on Windows, merged onto main 1476f76. 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_tests run alone, 4 copies in parallel, no CPU stress:

* `main` [1476f76](https://github.com/boykopovar/AnyPS5/commit/1476f76941a789690fd0f9c84c1cc929bb6fe262): 1 of 240 runs exits 127 (heap corruption, 0xc0000374). 0 of 120 with 3 copies in parallel.

* `main` plus [fix(agc): drain the registration preparation pool before the device i… #2909](https://github.com/boykopovar/AnyPS5/pull/2909): 1 of 400 runs exits 127. The build is clean and the new `RegistrationPrepareShutdown` test 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).

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101796478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2891#issuecomment-6101796478). Originally posted by [queeeef](https://github.com/queeeef) on 2026-10-10T20:21:27Z. --- > Tested PR [#2909](https://github.com/boykopovar/AnyPS5/pull/2909) (queeeef's `pr2909` branch) on Windows, merged onto `main` [1476f76](https://github.com/boykopovar/AnyPS5/commit/1476f76941a789690fd0f9c84c1cc929bb6fe262). 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_tests` run alone, 4 copies in parallel, no CPU stress: > > * `main` [1476f76](https://github.com/boykopovar/AnyPS5/commit/1476f76941a789690fd0f9c84c1cc929bb6fe262): 1 of 240 runs exits 127 (heap corruption, 0xc0000374). 0 of 120 with 3 copies in parallel. > > * `main` plus [fix(agc): drain the registration preparation pool before the device i… #2909](https://github.com/boykopovar/AnyPS5/pull/2909): 1 of 400 runs exits 127. The build is clean and the new `RegistrationPrepareShutdown` test is built. > > > So on Windows the heap-corruption exit still happens with [#2909](https://github.com/boykopovar/AnyPS5/pull/2909) applied, at a rate (about 0.3%) too low to say whether [#2909](https://github.com/boykopovar/AnyPS5/pull/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). 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](https://github.com/boykopovar/AnyPS5/pull/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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#2891
No description provided.