AGC: ResourceCache keeps an index entry for a freed list node (MXGP 26 SIGSEGV in ResourceCache::Find) #9497

Open
opened 2026-10-21 23:25:59 +00:00 by milescoviello · 2 comments
milescoviello commented 2026-10-21 23:25:59 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T23:25:59Z.


MXGP 26 (PPSA30839) crashed once in 4 runs of the same 900 s menu-to-race route, with SIGSEGV on a GPU queue thread inside ResourceCache::Find. The core shows the cache's index holding an entry for a list node that had already been freed.

Setup: main a6dcea9279, release libraries, Ubuntu 26.04.1, RTX 4070 Ti, NVIDIA 615.71.09, 12 GB cap, scripted pad input. The crash came 366 s in, between the gamma and profile screens. The other three runs reached the race at 900 s.

Stack (queue thread):

#0 std::__detail::_List_node_base::_M_transfer   (libstdc++)
#1 AgcDriver::Graphics::ResourceCache::Find(std::vector<unsigned> const&)
#2 AgcDriver::VulkanDevice::PrepareDispatch(...)
#3 Driver::dispatch -> #4 Driver::dispatchIndirect -> #5 Driver::execute -> #6 Driver::run

It faulted on mov 0x8(%rdx),%rcx with rdx = 0x73d900000000, the next of the node Find spliced to the front.

What the core shows (gdb, walking SharedResourceCache()):

  • The cache mutex is held by the faulting thread, so this isn't an unlocked access.
  • entries is intact: 4096 nodes with consistent next/prev links and 4096 distinct keys, each matching its index entry.
  • index has 4097 entries. The extra one maps a 104-word compute key (starting 0, 0, 0x7ac, 0, 3, 1) to 0x73d7a80de590. That address is not in the list, and malloc's header marks it as a 32-byte chunk, while a node of this list needs a 64-byte one. It was freed and reused.

So one node left entries while its index entry stayed. Every removal in ShaderResources.cpp erases the index by the node's own key: the capacity loop and the table-element budget loop in Insert, RemoveImage, dropReleasedTextures, erase and Clear, all under the mutex. That leaves two explanations. Either the key stored in that list node changed after insertion, so the eviction's index.erase(key) missed, or something outside the cache wrote into it. I found nothing in the class that writes a stored key. That points to a stray write into the key's heap buffer from elsewhere, but I haven't caught the writer.

Not done: an AddressSanitizer run of the title (one crash in four runs, about 15 minutes per run). The 4.9 GB core and the relinked app.elf are on my machine if anyone wants specific values from them.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5970161022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9497). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T23:25:59Z. --- MXGP 26 (PPSA30839) crashed once in 4 runs of the same 900 s menu-to-race route, with SIGSEGV on a GPU queue thread inside `ResourceCache::Find`. The core shows the cache's index holding an entry for a list node that had already been freed. **Setup:** `main` a6dcea9279, release libraries, Ubuntu 26.04.1, RTX 4070 Ti, NVIDIA 615.71.09, 12 GB cap, scripted pad input. The crash came 366 s in, between the gamma and profile screens. The other three runs reached the race at 900 s. **Stack (queue thread):** ``` #0 std::__detail::_List_node_base::_M_transfer (libstdc++) #1 AgcDriver::Graphics::ResourceCache::Find(std::vector<unsigned> const&) #2 AgcDriver::VulkanDevice::PrepareDispatch(...) #3 Driver::dispatch -> #4 Driver::dispatchIndirect -> #5 Driver::execute -> #6 Driver::run ``` It faulted on `mov 0x8(%rdx),%rcx` with `rdx = 0x73d900000000`, the `next` of the node `Find` spliced to the front. **What the core shows** (gdb, walking `SharedResourceCache()`): - The cache mutex is held by the faulting thread, so this isn't an unlocked access. - `entries` is intact: 4096 nodes with consistent `next`/`prev` links and 4096 distinct keys, each matching its `index` entry. - `index` has **4097** entries. The extra one maps a 104-word compute key (starting `0, 0, 0x7ac, 0, 3, 1`) to `0x73d7a80de590`. That address is not in the list, and malloc's header marks it as a 32-byte chunk, while a node of this list needs a 64-byte one. It was freed and reused. So one node left `entries` while its `index` entry stayed. Every removal in `ShaderResources.cpp` erases the index by the node's own key: the capacity loop and the table-element budget loop in `Insert`, `RemoveImage`, `dropReleasedTextures`, `erase` and `Clear`, all under the mutex. That leaves two explanations. Either the key stored in that list node changed after insertion, so the eviction's `index.erase(key)` missed, or something outside the cache wrote into it. I found nothing in the class that writes a stored key. That points to a stray write into the key's heap buffer from elsewhere, but I haven't caught the writer. Not done: an AddressSanitizer run of the title (one crash in four runs, about 15 minutes per run). The 4.9 GB core and the relinked `app.elf` are on my machine if anyone wants specific values from them. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-21 23:31:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:31:08Z.


I checked the current ResourceCache removal paths. The list node and unordered_map each hold their own Key vector copy, and removals call index.erase(it->first) using the list copy; if that copy is corrupted after insertion, erase(key) can silently miss and leave the map value pointing at the freed list node, matching the extra entry in this core. This does not identify the writer, but it gives a concrete invariant to instrument: compare the map key and list key at insert/removal, or retain the map-entry iterator with the list entry so removal does not depend on re-reading the key. An ASan run of the scripted route would still be the most direct way to locate the overwrite if it reproduces.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328894396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9497#issuecomment-6328894396). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:31:08Z. --- I checked the current `ResourceCache` removal paths. The list node and `unordered_map` each hold their own `Key` vector copy, and removals call `index.erase(it->first)` using the list copy; if that copy is corrupted after insertion, `erase(key)` can silently miss and leave the map value pointing at the freed list node, matching the extra entry in this core. This does not identify the writer, but it gives a concrete invariant to instrument: compare the map key and list key at insert/removal, or retain the map-entry iterator with the list entry so removal does not depend on re-reading the key. An ASan run of the scripted route would still be the most direct way to locate the overwrite if it reproduces.
milescoviello commented 2026-10-21 23:37:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T23:37:34Z.


Thanks @MarcZX10, that's the check I'm running now. A local diagnostic build (not a PR) compares each node's list key with its index entry before every by-key erase: the capacity and table-budget evictions, RemoveImage and dropReleasedTextures. Find also compares the node's key with the lookup key before the splice. On a mismatch it prints the two copies word by word, with the key buffer's address, and aborts, so the core is taken when the corruption is first seen rather than at the later stale splice. I'll run the scripted MXGP route on it a few times and post the differing words and the overwritten offset here if it fires.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328983375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9497#issuecomment-6328983375). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T23:37:34Z. --- Thanks @MarcZX10, that's the check I'm running now. A local diagnostic build (not a PR) compares each node's list key with its index entry before every by-key erase: the capacity and table-budget evictions, `RemoveImage` and `dropReleasedTextures`. `Find` also compares the node's key with the lookup key before the splice. On a mismatch it prints the two copies word by word, with the key buffer's address, and aborts, so the core is taken when the corruption is first seen rather than at the later stale splice. I'll run the scripted MXGP route on it a few times and post the differing words and the overwritten offset here if it fires. AI-assisted: yes (Claude Code)
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#9497
No description provided.