src/nx/memory/own.c, over a plat_trap_* layer per host:
| Call | What |
|---|---|
own_begin(cpu, size, producer, key) | the range is the producer's from now on: its trap is made, older owners of the bytes split |
own_lookup(cpu, size, cb) | GPU consumers (texture and buffer uploads, the vi present, VIC inputs) find the GPU copy to copy from |
own_acquire(cpu, size, mode) | the runtime's own C code before it touches guest memory: read, write, or discard (bytes it overwrites whole skip the readback) |
own_drop(range) | unmapped or freed memory: no writeback |
gmem_*.vk_lock, then the renderer's pend_lock, then mem.c's lock, then the trap lock, then the map's lock.
Every mapping change holds pend_lock while it changes memory, and so does the renderer when it adds a pending
result or an owner. A change of guest memory alone (GPU_MAPPING_GUEST_ONLY: map, unmap, MapPhysicalMemory,
UnmapPhysicalMemory) where the renderer has no pending result, no owner on its host pages and no GPU mapping of it
takes no vk_lock. A landing first waits for the GPU's work on its entries with no lock held. Then it takes
vk_lock before it marks its entries, lands them, lets their pages go and releases their resources, then lets
vk_lock go. Every
thread that waits for a mark (publishing, dropping or landing the same bytes) holds vk_lock too, so the mark it
waits for is never another thread's that waits for vk_lock in turn.vk_lock waits for the kernel's lock: the guest thread faults, the handler waits for
vk_lock, and its holder waits for the kernel's lock. A syncpoint a release performs under vk_lock signals the
kernel events waiting for it once vk_lock is let go (syncpt_add_quiet, syncpt_events). Leaf locks such as
nvdrv's sync_lk and the GPU queue's lock are taken under vk_lock, and no holder of one faults. A thread holding
mem.c's lock may not fault, since vk_lock holders wait for it (publishing, every mapping change): mem.c lands what
it touches first (own_acquire).vk_lock on an owned range is a bug in the runtime (the GPU thread touching it
without own_acquire): fatal, with the range, when that thread is waiting in the fault. A late fault message, from a
thread that has taken vk_lock since, lands as any other. Its fault on a page no entry is on any more (landed, not
let go yet) goes on.ownership-fault: lines record the read/write direction, guest page and host page, whether
the wait was confirmed, and up to sixteen overlapping owners (guest ranges, pool offsets, resource identities,
resource offsets and landing state). The address is page-granular, not the exact byte accessed.
On Linux the report reads the blocked thread's PC and SP from /proc/self/task/TID/syscall, then records its
executable mapping and file offset. It scans at most 128 native stack words for executable addresses, explicitly
labeled stack-candidate: these may be saved callers or unrelated values, not an unwound backtrace. It never
reads shared guest pool pages for this scan or resumes the thread. Missing procfs/register/stack access is logged.
Use the build revision printed at startup and that build's unstripped binary/debug symbols to resolve addresses;
a file offset must be translated through the ELF load segments before using it as an addr2line address.
See https://man7.org/linux/man-pages/man5/proc_pid_syscall.5.html for the blocked-thread register format.
With traps by protection (no userfaultfd minor faults, as on the Android phones reported so far, or
memory_traps=1) the thread waits in its handler's futex, so /proc shows only that wait. There the handler keeps
the access's context instead: the report gives its PC, SP and exact address (access-address=), on aarch64 the link
register too (lr[0], the caller of a leaf such as memcpy), and scans the stack from that SP, bionic's named thread
stacks included.gmem_read (copy_runs) reads a run none of whose bytes are
owned through own_stage, which reads a trapped page through the mirror (on Windows its shadow), so an owner beside
the run on its pages stays on the GPU. A shader's code window (gmem_read_code_cpu) stops at the first owned byte, and lands only when
the program reaches that byte (gmem_code_cut). Before, each of these landed GPU results in one game several times
a frame.Made from docs/layers/gpu/ownership.md at 69237645142c. GPL-3.0-or-later.