GPU: a released view heap takes its title memory page table with it #2234

Manually merged
github merged 1 commit from gh-pr/2234/head into gh-pr/2234/base 2026-11-26 04:59:21 +00:00
Owner

@⁠denkencar-sketch on GitHub · 2026-11-25 08:31 UTC · original
denkencar-sketch:fix/view-heap-shared → main · +48 −0 · 2 files · 1 commits · merged 2026-11-25 21:55 UTC

Summary

A view heap that is released keeps its title memory page table. Heap::drop removes the heap from SHADER_HEAPS but never from memory::SHARED, so:

  • the table (a 16.8 MiB mapping) and the Arc<Shadow> copies it names live on for the rest of the process, and
  • a heap allocated later at the same address finds the stale table. Shared::host is meant to tell the two heaps apart ("a heap made later at a released one's address is another"), but it is the address of the HostHeap, which sits inline in Heap::host (OnceLock<Option<HostHeap>>), so it is the heap's address plus a constant and always equal. The old view pairs, null slot and generation are then reused on the new host heap.

Change

memory::release(key) drops the heap's SHARED entry; Heap::drop calls it after letting go of the SHADER_HEAPS lock (bind and prepare take the table's lock inside the heaps' lock, so it is not taken the other way round). Lists that named the table hold their own clone of it, as the existing comment in bind says.

Testing

descriptor::tests::a_released_view_heap_drops_its_page_table creates a shader-visible view heap, binds a list (making its table), releases the heap and checks the table is gone. It fails on main ("released with its heap") and passes with this change. cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean.

Not tried: a run in the game, and the address-reuse case itself (the test shows the table outliving its heap, which is what makes the reuse possible). modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too (5 of 20 runs of cargo test -p victory-hle --lib); it is unrelated.

AI-assisted.

**@⁠denkencar-sketch** on GitHub · 2026-11-25 08:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2234) `denkencar-sketch:fix/view-heap-shared` → `main` · +48 −0 · 2 files · 1 commits · merged 2026-11-25 21:55 UTC ## Summary A view heap that is released keeps its title memory page table. `Heap::drop` removes the heap from `SHADER_HEAPS` but never from `memory::SHARED`, so: - the table (a 16.8 MiB mapping) and the `Arc<Shadow>` copies it names live on for the rest of the process, and - a heap allocated later at the same address finds the stale table. `Shared::host` is meant to tell the two heaps apart ("a heap made later at a released one's address is another"), but it is the address of the `HostHeap`, which sits inline in `Heap::host` (`OnceLock<Option<HostHeap>>`), so it is the heap's address plus a constant and always equal. The old view pairs, `null` slot and `generation` are then reused on the new host heap. ## Change `memory::release(key)` drops the heap's `SHARED` entry; `Heap::drop` calls it after letting go of the `SHADER_HEAPS` lock (`bind` and `prepare` take the table's lock inside the heaps' lock, so it is not taken the other way round). Lists that named the table hold their own clone of it, as the existing comment in `bind` says. ## Testing `descriptor::tests::a_released_view_heap_drops_its_page_table` creates a shader-visible view heap, binds a list (making its table), releases the heap and checks the table is gone. It fails on `main` ("released with its heap") and passes with this change. `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` is clean. Not tried: a run in the game, and the address-reuse case itself (the test shows the table outliving its heap, which is what makes the reuse possible). `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too (5 of 20 runs of `cargo test -p victory-hle --lib`); it is unrelated. AI-assisted.
Heap::drop removed the heap from SHADER_HEAPS but left its page table in memory::SHARED. The table (a 16.8 MiB mapping) and the copies it names then lived on, and a heap made later at the same address found the stale table: Shared::host is the address of the HostHeap inside the Heap, which is the heap's address plus a constant, so it cannot tell the two heaps apart.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:18 +00:00
github manually merged commit b4640273e9 into gh-pr/2234/base 2026-11-26 04:59:21 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:30 UTC · original

Automated triage for the maintainers.

Merge candidate (worth a look). Heap::drop in descriptor.rs now calls a new memory::release(key) that drops the heap's SHARED page-table entry, after letting go of the SHADER_HEAPS lock (matching the heaps-then-table order memory::bind uses). On main the entry outlives its heap, and the s.host check in bind cannot tell a later heap at the same address apart, since the HostHeap sits inline in Heap, so its address is the key plus a constant; lists keep their own clone of the table, so dropping the entry is safe. A test covers the release, and CI check passes on this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2234#issuecomment-7163873462) <!-- victory-triage v1 head=b4640273e9b2f6761a6ad13439dbee67ecbfcf6e verdict=merge-candidate at=2026-11-25T13:41:00Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** `Heap::drop` in `descriptor.rs` now calls a new `memory::release(key)` that drops the heap's `SHARED` page-table entry, after letting go of the `SHADER_HEAPS` lock (matching the heaps-then-table order `memory::bind` uses). On `main` the entry outlives its heap, and the `s.host` check in `bind` cannot tell a later heap at the same address apart, since the `HostHeap` sits inline in `Heap`, so its address is the key plus a constant; lists keep their own clone of the table, so dropping the entry is safe. A test covers the release, and CI `check` passes on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2234
No description provided.