What keeps it correct

Android: guest memory moved into AHardwareBuffers

Every Android driver takes AHardwareBuffers (VK_ANDROID_external_memory_android_hardware_buffer), and Qualcomm's has no VK_EXT_external_memory_host. Where a device has the first and not the second, vk_memory=2 moves guest memory into AHardwareBuffers instead of importing it where it is (vk_uma_way; the migrate way in uma.c), and auto copies, as no phone has measured the moves yet (check_uma_way); uma_memory=2 moves it on any driver that takes them. The windows a range touches become a region, a buffer of its own that Vulkan imports once, and their pages then move into it with their bytes, mapped where they were (mem_migrate: a copy, then the buffer's dma-buf mapped over the range, writers held off by plat_freeze). A region that a range reaches moves on into one region of their union, once the writes in place pending in it have landed, as the move copies what its pages hold (check_uma_region_merge). A region is 256 MiB at most: on an Adreno 830 (Snapdragon 8 Elite) Android's allocator gave 256 MiB, and 512 MiB aborted its service. The memory of an AHardwareBuffer is taken whole when it is made and never swapped, so only what the GPU reads moves, and a region that goes for idleness or room first moves its pages back into the reservation's own (mem_unmigrate).

A probe on that phone (Android 16) found the buffer's mapping to be the memory AHardwareBuffer_lock gives, the GPU reading what the CPU wrote and the CPU what the GPU wrote with no sync, the CPU's bandwidth there that of malloc's memory (31.5 against 31.2 GB/s), mprotect trapping there, and a submission costing the same with 16 or 256 MiB imported (7 to 30 us), where amdgpu's user pointers cost 6.4 us more per MiB.

A region's buffer is memory of its own, which no change of the guest's pages touches. Pages of a region unmapped, decommitted or moved into the alias pool (a view, a trap) get other pages there (give_back_nl maps fresh ones, as decommitting shared pages keeps their bytes); the region goes then with no wait, the commands recorded before read the bytes it had, and it is destroyed once the last of them is done. Write tracking leaves a region's pages alone as it leaves an import's: that phone's kernel (6.6) has no PAGEMAP_SCAN, and userfaultfd can't protect a dma-buf mapping. Off Android plat_gpu_buffer makes a memfd, which the driver imports as host memory: vulkan_headless's check_uma_migrate runs the migrate way where the driver takes a memfd's pages (lavapipe) and skips where it doesn't (amdgpu's user pointers take anonymous memory only), and memory_alias moves guest memory into memfds and back.


Made from docs/layers/gpu/ownership.md at 69237645142c. GPL-3.0-or-later.