Files
metal2vulkan/docs
Anees Iqbal b1a1c67f68 Host memory: state when a program may unmap a no-copy object's pages, and test the order
A Radeon 780M under Linux 7.3.3 oopsed in amdgpu's mmu notifier (amdgpu_hmm_invalidate_gfx,
LIST_POISON2 in a bo_va's status list) while a consumer's thread unmapped a view whose pointer import
was still alive; the consumer dropped the import after the unmap. VK_EXT_external_memory_host
(VkImportMemoryHostPointerInfoEXT): "the application must ensure that the imported memory range
remains valid and accessible for the lifetime of the imported memory object". vkFreeMemory: a
bound buffer or image may hold the payload until it is destroyed. So the objects go first and the
pages after.

The runtime already keeps that order, and this commit changes no behaviour. A no-copy object's
keep-alive is dropped, and with none its deallocator runs, only after its import's vkFreeMemory
returned, on whichever thread freed it. That covers the releasing thread, a queue's thread at the
completion of the last command buffer that held it, a handler thread where a keep-alive alone
waits, and the import made again after the residency thread released it while idle. Imports never
go to the free thread. The one exception is a buffer lying in another live buffer's import, whose
own contract keeps the pages mapped.

The order was spread across private module docs. It now has one statement where consumers read:
- docs/HOWTO.md, "Unmapping host memory": the spec's rule, each object's signal, the threads that
  free imports or submit over them, and what an unmap made first did;
- the runtime README's host-memory bullet;
- the rustdoc of HostMemory::new (the spec's rule, and when a command buffer lets go: after its
  completed handlers, before wait_until_completed returns), Deallocator, KeepAlive and
  Device::host_range_remapped. That call's "they may be unmapped" read as a licence to unmap under
  a live buffer; it now says the call does not mend that.

New device test tests/unmap_order.rs (Linux, m2v_cpu_icd or m2v_gpu):
- 48 rounds. Each round covers a released buffer, a buffer released while a committed copy of it
  waits for an event, and (where pointer imports follow their address) a buffer whose import was
  released while idle and made again by a blit. Each case runs with a keep-alive and with a
  deallocator.
- Another thread submits copies between the device's own buffers throughout.
- Each signal reads WorkCounts::host_imports_live, which must already be back at its baseline,
  then unmaps the pages.
- It asserts that the held cases signalled on a runtime thread and not before the event, that the
  idle releases and imports again counted 96 each, and that every command buffer completed with no
  device loss or recovery.
2026-11-11 09:03:24 -08:00
..