3 Commits
Author SHA1 Message Date
geramyloveless 4968adb4de VRAM only through the kernel: no CPU access through a BAR mapping
Unplugging the GPU with the display live panicked the Mac on 239 and 240
(LLC bus error, NC write, in the dext). On 240 the panicked thread was in
an atomic commit powering the display down after the agent's framebuffers
were removed: dmub_srv_fb_cmd_execute, with dmub_rb_push_front having
stored the command into DMUB's inbox in VRAM one byte at a time through
the dext's user-space mapping of BAR0. The removal was already under way
(Stop, removal_main, the aperture gate set); the error is reported only
after the store has retired, so no check before a store can prevent it.
Register accesses, through the kernel's IOPCIDevice MemoryRead/Write, ran
in the same commit after the link went down and never faulted.

So every access to the VRAM aperture goes through the kernel:
rt/aperture.h's read/write/copy/fill route through ops the dext installs
with the PCI device (BAR0 MemoryRead/MemoryWrite 8 to 64 bits, BAR0's
index and size read once). linux/io.h's readX/writeX, memcpy_toio,
memcpy_fromio and memset_io, the 64-bit MMIO atomics and the string
functions (memcpy, memset, memmove, memcmp) route aperture addresses
through them; the gate still skips writes and reads all ones once the
device is known gone. The GART page table in VRAM, written with writeq on
every GTT bind, now goes this way too.

dmub_cmd.h's inline dmub_rb_push_front (a byte loop) and
dmub_rb_flush_pending (READ_ONCE) reach the inbox with plain pointer
accesses no shim can route. A declared compile intervention for
dmub_srv.c (rt/dmub_inbox.h) includes dmub_cmd.h first and redirects its
two calls to the same operations written with dmub_memcpy, as upstream's
dmub_rb_out_push_front copies. Upstream sources stay unchanged.

Offline proof: the CS fixture gives the driver VRAM only as a no-access
alias of its pages, reached through the aperture's ops; the host
library's upstream objects alias the string functions as the dext's do.
Any direct load or store through a kernel VRAM pointer now crashes the
offline tests. With the two DMUB helpers redirected, every test passes:
the display pipeline (with its removal check now on the fixture's real
aperture), scanout, surface import, CS selftest, KFD and the rest.
2026-10-04 17:48:52 -07:00
geramyloveless bb6412357c Stop CPU access to the VRAM aperture once the GPU has left the bus
A Thunderbolt power-off of the R9700 with the display mirrored
panicked the Mac (panic-full-2026-10-03-200811: "LLC Bus error (Slave
error) ... NC Write ... uncorrectable", the panicked task the 235 dext).
The faulting thread, symbolized against the installed binary
(3C1A7727-6854-3A29-9D61-CD15EFA13081), was a DRM worker removing a
framebuffer (drm_mode_rmfb_work_fn, atomic_remove_fb): the output's
teardown deletes its scanout buffers, which commits the plane off, and
DC sent the DMUB its commands (set_pixel_clock_dmcub ->
dmub_srv_fb_cmd_execute) by copying them into the DMUB inbox in VRAM
with linuxu_device_memcpy, a CPU store through the dext's mapping of
BAR0. Registers and doorbells go through kernel IOPCIDevice calls,
which the kernel refuses for a vanished device (and the removal already
skips: no_hw_access); a store through a user mapping to a device that
is gone is an uncorrectable bus error on Apple silicon, not an error the
process can see.

Linux takes the aperture away on hot unplug (amdgpu_device_unmap_mmio).
Here it is gated: the device string functions (every memcpy, memset,
memmove and memcmp in the driver, which is how the DMUB inbox and
kmap'd VRAM are written) skip stores into the aperture and read all
ones from it once the device is known gone. It is known gone at the
first of: rt_removal_begin, the dext's removal notification, or a
register read of all ones after which the device no longer answers a
configuration read (checked at most every 10 ms, through the kernel),
which DC's own register reads (the DMUB inbox pointers) hit before it
writes the inbox. The display statistics now count the driver's CPU
accesses to the aperture.

test_display_pipeline: with the display live (flips writing registers,
copies on SDMA), the device leaves the bus with a frame queued; from
then on no register write, no SDMA copy and no store into the aperture
happen, aperture loads read all ones, and the output stops.
2026-10-03 20:27:48 -07:00
geramyloveless 953cf0149c mac_linuxgpu: upstream Linux amdgpu on macOS
Runs the unmodified upstream Linux amdgpu and amdkfd drivers on Apple
Silicon Macs inside a DriverKit system extension, for AMD GPUs attached
over Thunderbolt. The Linux sources come from a pinned submodule and are
compiled against linuxu, a userspace implementation of the Linux kernel
APIs they use. Includes the HSA runtime, the host installer app, the
setup and firmware fetch scripts, and the offline test suite.
2026-10-02 18:49:17 -07:00