4 Commits
Author SHA1 Message Date
geramyloveless c282a82741 MMIO tokens live in their own address range; process memory is memory
The display's rejoin with LSE loaded knocked the GPU "off the bus" on 248
and 249. The new framebuffers' pin evicted LSE's VRAM, and the eviction's
SDMA copy maps its window through amdgpu_ttm_map_buffer. That calls
amdgpu_gart_map, and amdgpu_gmc_set_pte_pde writes the PTEs into the copy
job's IB, which is ordinary process memory, with writeq(). Linux allows
this. The DriverKit accessors decoded every address outside the BAR0
aperture as a synthetic token (address / 256 GB), so the IB at
0x127849020 became token 0, "a lost mapping". The first such write
recorded a definite MMIO transport fault, which closes PCI admission and
quarantines DMA. Upstream then reported "device lost from bus" with the
GPU still on it, and every client's work hung. The fault's call chain
(next commit) named the site.

The encoding also overlapped real memory in the other direction. A
process mapping above 256 GB decoded as a live token, and a store to it
went to that token's BAR.

Tokens now start at 2^48, above the arm64 user VA ceiling, where no
process memory can be. Token 0's range is never minted. Decoding means
"inside that range", nothing else. readX/writeX, memcpy_toio/fromio and
memset_io go to:
- the BAR0 aperture: the kernel, as before;
- the token range: MMIO for a live token, a loud fault for a stale or
  never-minted one;
- below 4 GB (__PAGEZERO, a null-based bug): a fault, as before;
- anything else: a plain load or store, ordered as Linux orders readX
  and writeX.

test_mmio_dk_accessors checks:
- a live register token goes to MMIO;
- PTE writes into an IB through amdgpu_gmc_set_pte_pde's own expression
  are plain stores, as are memset_io and memcpy_to/fromio on heap memory;
- a process mapping that the old scheme decoded as the live register
  token is plain memory;
- a stale token, token 0's range and a null-based address still fault
  and touch nothing.
2026-10-05 16:30:21 -07:00
geramyloveless 0ee07c4401 MMIO token numbers are renewed between sessions
Every DriverKit MMIO mapping takes a token number (1..511) that doubles
as its synthetic pointer. To keep a stale pointer from reaching a
different mapping, an unmapped number was never issued again, so each
session consumed about four for good: the register token, upstream's
register ioremap and the kernel doorbell kmap among them. After roughly
120 session open/close cycles none were left; the doorbell kmap failed
and the probe returned -ENOMEM (242: "kernel bo map failed",
quarantine, restart required).

The numbers are now renewed when the last mapping is unmapped. The
session's register token lives from dext_open to dext_close, so an empty
table means no session, no upstream module and no synthetic pointer
remain. Within a session an unmapped number is still never reissued.

test-session-cycles runs 300 session open/probe/close cycles through the
real upstream probe and the production PCI, MMIO-token and heap code
against a mock IOPCIDevice, and checks after every close that no MMIO
mapping survives and that heap, DART-mapped bytes and mappings, page
descriptors and threads are at their baseline. Before this change it
fails at cycle 255 with the probe returning -ENOMEM. The DriverKit token
bounds test also covers renewal and in-session non-reuse.
2026-10-05 00:25:22 -07:00
geramyloveless c969e84507 dart: no fixed DMA budget; the platform's refusal is the limit, logged
The DART layer refused any mapping past a hard-coded 1.5 GiB of live
DMA bytes. Every dext page is DMA-backed, so GTT objects failed with
ENOMEM at 1439 MiB (97 MiB already mapped at start) although amdgpu
reports 64 GiB of GTT; llama.cpp's 1 GiB staging buffer and pinned host
buffers could not be allocated.

The limits that exist are the platform's: memory and wiring (the user
wire limit here is 108.8 GiB of 128 GiB, with 19.2 GiB kept for the
kernel), and the DART's IOVA window for the device, which the device
tree gives a Thunderbolt port's dart-apciec as 2047 MiB (IOVAs from
2 GiB). DriverKit enforces both: IOBufferMemoryDescriptor::Create or
PrepareForDMA fails. So:

- dart.c only accounts live-mapped bytes (used/peak); a mapping fails
  when the seam fails it. linuxu_dart_budget and rt_dart_ceiling are
  gone (rt_dart_peak reports the high-water mark).
- The seam logs each refusal with its size, the refusing call, its
  IOReturn and what is already mapped (a run of identical refusals
  logs its first and every 256th).
- The shutdown and probe holds take no ceiling. They count the bytes
  mapped at their start and those mapped during them; retired mappings
  keep their DART IOVA until the endpoint reset, so the DART refuses a
  teardown mapping that would not fit beside them. A ceiling at the
  live total would refuse every probe allocation (nothing is mapped
  when the probe hold starts).
- The dext's mapping table and dart.c's streaming slots were fixed at
  4096 entries, another wall: both grow in chunks that never move.

test_iokit_dma models the DART window and adds large mappings: a
1.5 GiB + 16 KiB mapping, a refused 512 MiB one (logged), 4500 live
mappings, and a teardown mapping refused beside retired ones under
the shutdown hold. test_session_shutdown closes a session with 6 GiB
mapped. test_dma_dart maps 3 GiB and 6000 live mappings.
2026-10-04 09:29:20 -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