2 Commits
Author SHA1 Message Date
geramyloveless ec8198541d lx: no request that can sleep runs on the driver's incoming-call thread
On 241 a request that waited on a GPU ring that had stopped ran on the
one thread DriverKit delivers every client's calls on: every client froze,
and the driver could not take its own Stop after the GPU was powered off.

Every Linux-file request that can sleep now runs on a worker of the
client's process and completes through AsyncCompletion:
- mlg_lx_cmd_sleeps (lx_describe.c, shared by the client library and the
  driver) names the few requests that provably do not sleep: VERSION,
  GET_CAP, SET_CLIENT_CAP, the syncobj create, destroy, export, import,
  reset, signal, timeline signal, query and eventfd requests, a syncobj
  wait that only polls, and KFD GET_VERSION. Everything else is async,
  AMDGPU_CS, INFO, GEM and context requests included.
- LX_IOCTL runs only those, through rt_lx_ioctl_nosleep; any other is
  refused without running (kIOReturnNotPermitted) and logged with the
  request and the process.
- LX_CALL_ASYNC (selector 105) runs open, close, mmap and munmap on a
  worker; the synchronous selectors 96, 97, 101 and 103 are retired.
- A Linux-file client's Stop hands its process's exit to a thread of its
  own (rt_lx_client_retire) instead of waiting for its calls on the
  incoming-call thread; a session close waits for those exits
  (rt_lx_retire_drain) before the driver goes. On an unplug the Stop has
  already begun removal, which completes the GPU's fences, so the exits
  finish.
- An async call holds one of MLG_LX_MAX_ASYNC slots until its result is
  delivered: with the completion (the slot frees before it is sent) or by
  LX_RESULT, whose result is in place before the completion goes out. The
  client library keeps its calls within the limit, waiting on its own
  thread. A worker still sending a completion holds no slot, so a call
  queues for it instead of failing.
- The transport revision is MLG_LX_ABI 2: libmlg_drm's dylib
  compatibility version, and the text MLG_LX_ABI_TAG in the library for
  launchers to check. A client library older than this driver fails at
  its first sleeping request or open, with the reason in the driver log.

Events reach the unified log; routine lines stay in the retained ring.
The dext logged every line through os_log, and nothing from it reached
the unified log in the boot where 241 hung (probably quarantined for
volume), so the hang's cause was lost with the dext. Now only events go
there, prefixed "mac.linuxgpu: EVENT ": driver start, probe outcome,
removal, quarantine and release, session close, DMA mapping failures,
printk at error level and above (ring timeouts among them), and the head
of a device coredump, which dev_coredumpm now logs before freeing it.
Read them with
  log show --predicate 'eventMessage BEGINSWITH "mac.linuxgpu: EVENT"'

Tests: test_lx_files covers the table, the synchronous refusal, the
operations on workers, inline and fetched results and the new slot rules.
blocked_call_check (test-cs-selftest) blocks a client's AMDGPU_CS behind
amdgpu_sched_jobs submissions on a held compute engine and checks that
every call returns at once, the blocked client's non-sleeping request
runs and its sleeping one is refused synchronously, another client opens,
allocates and completes SDMA work, the blocked client's Stop returns at
once and its exit finishes when the engine runs, and, during the surprise
removal check, that removal ends a blocked submission and the client's
exit completes.
2026-10-04 20:27:43 -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