The device's thread for a guest RAM (import_ahead, listed_chunks) upgraded the
RAM and faulted a chunk in by reading its pages (read_volatile, since
259be5d3c5) with no hold the use's end waited for. A consumer that dropped
the use and its RAM and then unmapped the pages, as a VMM's teardown does,
had the thread read an unmapped page: SIGSEGV in a consumer's test on an RTX
5080, and in our contended bench on a Radeon 780M (12 of 12 runs before the
bench's keep-alive fix).
Now HostRamUse keeps the thread's JoinHandle. Its drop sets the use's end
(Wake::ended), wakes the thread and joins it. fault_in checks the flag before
each 2 MiB step, and both threads check it at each look and between the
fault-in and the import. So the drop waits at most one step of reads or one
import under way, and once it returns the runtime reads, faults in and imports
no page of the RAM. An import a buffer or a pending command buffer holds still
keeps its pages until the keep-alive goes, as before. The fault_in SAFETY
comment now names what keeps the pages mapped.
Test: a_use_s_drop_waits_out_the_thread_so_its_pages_may_be_unmapped_at_once
makes 32 rounds over a fresh 64 MiB memfd mapped shared, with a keep-alive
that does not unmap. Each round uses the RAM, drops the use 0 to 4.8 ms
later, drops the RAM and unmaps at once. It checks that each round's
keep-alive went before the unmap and that every chunk was freed.
(cherry picked from commit 0c18e1898fc5a9ce50eb5bd7508dd171c01e3093)