Linux: userfaultfd, minor faults, the alias pool

Guest memory is a private anonymous reservation (plat_vm_reserve), and memory mapped at two guest addresses comes from a memfd mapped shared (the alias pool, plat_posix.c). An owned span is moved into the pool when its trap is made (mem.c's promote_nl), so it has a mirror (plat_alias_host) and its edge pages keep the CPU's bytes in the page cache. The move is no write: plat_alias_map keeps what write tracking says of each page of the range mem_own_prepare froze, as plat_vm_share does for a dma-buf region (below). The pool's mapping is registered with the write watch before the trap takes it out of the scans, and a scan on another thread between the two would report every moved page: marked after the result published there took its baseline, they would read as the CPU's writes, and the image stored there again would keep memory's bytes on them.

A Linux host without minor faults (older kernels, Android's 5.10 kernels, or any Linux with memory_traps=1) uses Skyline's own shape: plat_trap_arm makes the span's views inaccessible with mprotect, and the SIGSEGV handler, checked before the crash handler, posts the page to the trap's own thread through a lock-free ring and waits on a futex. That thread lands it as the userfaultfd's would, and plat_trap_continue opens the pages and wakes the waiters, whose accesses then go again. Nothing but atomics, mprotect and futexes runs in the handler. FreeBSD and macOS have no alias pool yet, so no mirror and no traps.


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