35 Commits
Author SHA1 Message Date
geramyloveless b190c105a8 Kernel arguments in CPU-visible VRAM, published with the HDP flush
HRX on Linux keeps a queue's kernel arguments in CPU-visible VRAM and
publishes them with the HDP flush register when the HSA runtime reports
HSA_AMD_AGENT_INFO_HDP_FLUSH and lets the CPU at the device coarse pool.
This brings that path to the Mac, where a CPU store to a GPU that stopped
answering can panic the machine, so every such store is bracketed under
the client's gate.

patches/linux/amdgpu-mmio-remap-4k-hole.patch: the NBIO/NBIF HDP flush
remap stays in the 4 KiB register hole the hardware leaves unused,
whatever the host page size (upstream moved it with PAGE_SIZE and turned
it off for pages over 4 KiB). KFD's own MMIO paths still refuse large
pages; nothing upstream maps the page into a process.

linuxu (kfd_session.c): rt_kfd_session_hdp_flush gives the host page of
the register BAR holding the remap page, after checking that no register
block of the device starts in the rest of it. VRAM can take a window VA,
and rt_kfd_bo_make_cpu_visible pins such a buffer in the CPU-visible
window: unmapped from the GPU, off the eviction fence, pinned with
CPU_ACCESS_REQUIRED, the move waited for, mapped again at the same VA.
rt_kfd_bo_bar_ranges reports its BAR ranges; a free unpins it first.

dext (hdp_flush.h): QueryInfo MLG_QUERY_BAR_WRITES lets a KFD client
opt in. It gets its gate (published, so every power transition, reset,
quarantine, fault, removal and close closes it and drains), the HDP
flush page as client memory, and CPU access to hostable VRAM: BOAlloc
flag DEXT_COMPUTE_BO_FLAG_HOSTABLE, then BOMap pins it and hands out its
BAR ranges. A client that never asks gets none of it. A retired gate is
marked so the client knows it never reopens. Closes that stop the device
answering (the session's close, quarantine, reset) wait up to 1 s for
an open bracket. Build 265.

HSA runtime: mac_hsa_bar_writes_enable, mac_hsa_bar_write_begin and
mac_hsa_bar_write_end. After enable the agent reports HDP_FLUSH, the CPU
agent's access to the VRAM pool is DISALLOWED_BY_DEFAULT, VRAM is
allocated hostable, and hsa_amd_agents_allow_access with a CPU agent maps
an allocation write combined at its own address, as ROCr does on a
large-BAR device; nothing else is CPU-mapped. begin waits while the gate
is held and fails once the device is gone, after replacing every BAR
mapping of the process with host memory (bar_mapping_retire.h); kicks
that find the GPU disconnected do the same.

libmlg_drm: a transport that says the device is gone has every mapping
retired the same way, so Vulkan clients' stores through mapped VRAM and
doorbells land in host memory too.

Tests: the session test pins hostable VRAM, checks its BAR ranges, a
full window and the HDP page with and without a register block beside
it; the production test enables BAR writes, maps hostable VRAM and
ranges it; hsa-bar-writes checks what is reported before and after
enable, the CPU grant, nested brackets, a held gate and a lost device;
the gate and libmlg_drm tests check retired gates and mappings.
2026-10-06 19:29:29 -07:00
geramyloveless 4fe23bc535 A client rings its KFD queues' doorbells itself
A doorbell cost the submitting thread a trip through the driver: 14.7 us
for the synchronous AQLQueueKick of build 263 (20 us async before it), on
the one delivery thread every client's calls share. On Linux a process
writes the doorbell page it mmaps from /dev/kfd: one store. From build 264
the runtime does the same.

- The client maps its KFD process's doorbell slice (MLG_DOORBELL_MEMORY_TYPE,
  uncached): the page of the doorbell BAR KFD gave that process
  (rt_kfd_session_doorbells), holding only its own doorbells, as libhsakmt
  maps it. AQLQueueCreate asked for three outputs answers the queue's
  doorbell in it (out[2]), or MLG_DOORBELL_NONE for a queue rung through
  AQLQueueKick (a legacy queue). A KFD queue whose doorbell cannot be
  mapped is destroyed again and the call fails.
- A store to the GPU's BARs once it stops answering can panic the Mac, so
  every doorbell write goes through a gate (doorbell_gate.h): a page the
  driver and the client share (MLG_DOORBELL_GATE_MEMORY_TYPE). The client
  counts itself busy, writes only while the gate is open, and counts itself
  out; the driver closes the gate and waits until busy is zero (Dekker's
  protocol, sequentially consistent both sides), so once a close returns
  the client writes nothing. A closed gate writes nothing: the runtime
  then sends the doorbell as AQLQueueKick, which answers what the device
  can take (Offline while it suspends: the doorbell waits for resume, as
  before; NoDevice once it is gone).
- The driver closes every gate for a power transition (power_set), and for
  a device reset's whole window (the recovery hooks, before upstream halts
  the device until the PCI restore put the BARs back; a failed reset
  wedges and keeps them closed). Both doorbell paths, the clients' and the
  delivery thread's kick table, now hold a set of reasons instead of one
  flag, so a power change inside a reset opens nothing. A client's gate
  is retired (closed, drained, forgotten) at its close, its KFD process's
  release (whose doorbell slice may go to another process), the session's
  close or quarantine, a transport fault and a removal. The wait is a
  bounded spin (it may run on the delivery thread): a client stopped
  inside a write for 20 ms is named in the log.
- Runtime: the queue keeps its doorbell and gate from creation until
  inactivate; a write never lowers the doorbell (as the driver's paths).

Measured on the R9700 over Thunderbolt 5 (lat.cpp, display mirroring):
doorbell store 14.7 -> 0.38 us median; empty dispatch round trip 43.9 ->
32.4 us (Linux on the same card: 31.3); back-to-back wall per dispatch with
a doorbell each 16.8 -> 12.7 us. LemonSeed Engine decode is GPU-bound:
plain 28.2 -> 28.7 tok/s, DFlash2 51.3 -> 51.4.

Tests: test-doorbell-gate races client threads ringing through their gates
against power holds, device-reset holds inside them, client closes and
session closes, under ThreadSanitizer and AddressSanitizer; a doorbell
written after a close returns fails it (dropping the drain does). It also
names a client stopped mid-write. test-kfd-session checks the slice (a
page of BAR 2, the process's own) and that the client's offset is the word
the driver's kicks write; test-dext-compute-production the doorbell
lookup, gate publish, power and reset holds and retire at the client's
release; test-kick-table holds and releases both reasons;
test-hsa-power-transport the runtime's maps, its direct store, a closed
gate, and the failures that destroy the queue again.
2026-10-06 17:18:27 -07:00
geramyloveless b856a93f95 GPU recovery: device resets behind a gate, bounded; RESET_WAIT
A hang the queue reset cannot end now runs upstream's device reset
(amdgpu_device_gpu_recover, mode1 on gfx12) when the platform allows it
(rt_recovery_set_full_reset_gate), and wedges the GPU otherwise. The
driver's gate allows it only when the personality enables device resets
(MacLinuxGPUDeviceReset, absent = off until a reset is validated over
Thunderbolt) and no client maps one of the GPU's BARs: neither a raw BAR
lease nor any Linux-file mapping through a BAR (rt_lx_bar_mappings),
since a client store into a BAR that stops decoding can take the Mac
down. Every refusal is logged with its reason as the wedge's.

Upstream's own recovery runs unchanged, with three bounds around it:
the ASIC reset is wrapped so one recovery makes at most two attempts
(upstream retries a reset whose IB tests fail without limit on bare
metal); a device reset that fails (reset_domain->reset_res) wedges the
GPU, where upstream would leave its schedulers stopped with no event;
and one that succeeds advances the reset generation, with
RT_RECOVERY_LAST_VRAM_LOST when the VRAM-lost counter moved. The KFD
and user-queue reset works go through the same path.

RESET_WAIT (selector 91, observers and session clients, registration on
the delivery thread) completes when the reset generation differs from
the one the caller knows, with the generation and MLG_RESET_FLAG_*; a
client's waits end with it. The host's daemon re-arms it to post its
notification.

Tests: device_reset_check (the CS fixture, which now has soc24's reset
method and an ASIC reset that restarts its engines) allows device
resets and hangs a queue whose reset fails: upstream's
amdgpu_device_gpu_recover runs, the GPU does not come back (no VBIOS),
the device wedges after one ASIC reset and nothing retries. test-owner-
call covers RESET_WAIT (new generation, stale generation, cancel) and
the gate (personality, raw lease, client BAR mappings);
test_lx_files counts a client's BAR mapping.
2026-10-06 17:18:27 -07:00
geramyloveless 2122b9b1c1 The CP write-pointer polling experiment, off by default
KFD's GFX 12 MQD already points CP_HQD_PQ_WPTR_POLL_ADDR at each queue's
write index (amd_queue_t.write_dispatch_id). Upstream leaves the global
CP_PQ_WPTR_POLL_CNTL.EN off (gfx_v12_0_kiq_init_register writes it for
the KIQ only), and MES takes each queue's write-pointer address in
ADD_QUEUE and handles unmapped queues through CP_UNMAPPED_DOORBELL. Nothing
upstream says whether MES firmware writes the polling register. With EN
set, the CP would read the write indexes itself every PERIOD, and a
client's own store to its write index would start its work with no
doorbell and no CPU store to the BAR at all.

rt/wptr_poll.h:
- Observation, always on: the register is read once after each KFD queue
  is created, when MES has mapped it and compute is active (KFD keeps
  GFXOFF off then), and logged whenever its value changed. The first runs
  show whether MES writes it.
- The experiment, off unless the dext's personality sets
  MacLinuxGPUWptrPollPeriod (1-255, the field's raw value, whose unit is
  undocumented): EN and PERIOD are written, re-written if MES clears them,
  and reported in session state (WPTR_POLL).
- The runtime skips doorbells only with MAC_HSA_DOORBELL=poll and only
  while the driver reports polling; otherwise it says why and the queue
  fails.

GFX 12.0 only (the gc_12_0_0 register headers); nothing else changes.
2026-10-06 15:39:53 -07:00
geramyloveless 3b10f769bb An upgrade hands over without Retire: ShutdownGPU, remembered until idle
Since the device stays up across clients (248), a previous instance whose
last client left keeps its session, and with it the GPU, open. It can
leave only once that session is closed, and Retire, the installer's way to
close it, needs the session-release authorization the signed app does not
have (kIOReturnNotPrivileged). So every upgrade stayed "terminating for
upgrade via delegate" until someone killed the old driver, which panics the
Mac, or power-cycled the GPU.

The installer now hands over without Retire when Retire is refused. It
opens a session client of its own on each previous instance and asks
ShutdownGPU, which any session client may ask and which closes the session
when no other client uses it. The display agents are already stopped for
the upgrade. The installer keeps asking until the instance is gone, and
says which programs still hold it.

When other clients still use the GPU, the driver now remembers the request
(s_closeWhenIdle, session state flag CLOSE_WHEN_IDLE): the last client's
leaving closes the session, even after the installer has given up. The
request goes with the session. Nothing about Retire's authorization
changes. Disconnect GPU uses the same path when its Retire DISCONNECT is
refused.

Tests: test-session-shutdown runs the production code for the upgrade with
no client left (ShutdownGPU closes the session at once, IOKit's Stop then
finishes) and with a client that leaves afterwards (refused, remembered,
closed by that client's leaving, then Stop). test-display-agent covers
reading ShutdownGPU's answers. A previous instance from before build 263
does not remember the request: the installer then asks again after the
clients leave.
2026-10-06 15:39:53 -07:00
geramyloveless 04ee55a519 SysfsWrite takes any observer client; every write is logged
The session-release entitlement is in Host.entitlements, but the signed
host app does not carry it: local signing with the approved profiles
leaves it out, in both the installed build and this one. Gating SysfsWrite
on it would refuse the menu's every write. Any process can already run
GPU work through a session client, so an observer client may make these
writes too. The allowlist bounds what can be set (four levels, a profile
index), and the driver logs each write with the client that made it.
2026-10-06 09:30:59 -07:00
geramyloveless 79036bbc8f SysfsWrite: the performance level and power profile, through upstream's store()
On Linux, root writes power_dpm_force_performance_level and
pp_power_profile_mode, and amdgpu_pm.c's store() applies them. This
driver had no sysfs write path: its observer client only reads.

Selector 89 (SysfsWrite) takes an attribute id and a value and runs that
attribute's own store(), through linuxu_sysfs_write (as kernfs, one
store() of a NUL-terminated page). It is limited to:
- An allowlist in session_state.h: power_dpm_force_performance_level
  with auto, low, high or profile_peak, and pp_power_profile_mode with a
  bare profile index, 0-99. Manual, the other profile_* levels and custom
  profile parameters are not offered.
- Observer clients that carry the session-release entitlement, which is
  the host app's, as for Retire and the quarantine release.
- Synchronous and bounded on the observer reads' driver thread, never the
  delivery thread, with admission as for SysfsRead.
store()'s result comes back as the bytes taken or a negative Linux errno.
A value outside the allowlist is NotPermitted, a missing entitlement is
NotPrivileged, and a store() still running at 250 ms is Timeout.

Tests: test-sysfs-read writes through a device attribute's store(), and
checks the NUL-terminated buffer, store()'s own errno, and the read-only,
missing and empty cases. test-session-shutdown checks the observer
policy, that the call is synchronous but not on the delivery thread, the
paths, and the value allowlist (every offered level and index, with and
without a newline, and the levels, spellings and parameters it refuses).
2026-10-06 09:27:35 -07:00
geramyloveless a6f59666d5 The driver's Stop and Retire never wait forever behind a session call
Stop and Retire run on the session queue, behind whatever session call
runs there. On 250 a CPU-access pin that had to evict a compute client's
buffers waited forever. The session queue stayed blocked, and the
instance lingered in "terminating for upgrade via delegate" until the
user killed it; it could neither stop nor hand over to the next version.

owner_job_main now records the running session call's selector and
start. When a Stop or Retire is asked for, a watchdog on a queue of its
own (one watch at a time) checks once a second until it runs. If a
session call has held the queue for MLG_SESSION_BLOCK_BOUND_MS (30 s),
it makes GPU work complete at once, as a removal does (rt_device_lost):
fences complete with -ECANCELED, the call returns, and the Stop or
Retire runs. The device is unusable for this instance from then on. The
session closes with it and the event names the selector that blocked.

session shutdown watchdog-never-returning:
- nothing is forced with no call running, or before the bound;
- past the bound the GPU work is forced once, even when asked twice, and
  the log names the call;
- a freed queue clears it;
- the driver's Stop starts a watch.
2026-10-05 16:46:33 -07:00
geramyloveless d9df9a3a17 Disconnect GPU closes the device for the programs on it
With the device kept up across programs (248), Disconnect GPU could no
longer bring the GPU down. Once the display daemon let go, the session
stayed up with or without programs. The menu bar said "still in use" for
any program with the driver open, even an observer such as mtopg, and
had no way to close the GPU for programs still using it.

- Retire gets a DISCONNECT op (session_state.h). It closes the session
  now through the normal close, as QUIESCE with FORCE does, whatever
  clients it has. Unlike QUIESCE it keeps admitting sessions, so the next
  program to start brings the GPU up again. A raw BAR mapping still
  refuses, since a close would quarantine. A quarantine is released only
  when provably quiescent, as for Retire. out[2] counts the clients that
  lose the GPU.
- The closed session's clients get kIOReturnNoDevice on every further
  call (session and Linux-file clients alike), and the driver log says
  once per client that the GPU was disconnected. They are never silently
  rejoined to a new session with stale state. HSA maps NoDevice to device
  lost and now says the GPU was disconnected and the program must
  restart.
- The menu bar and `disconnect-gpu` wait for the displays to stop. If the
  driver's session is still up, they close it with DISCONNECT. The GPU is
  safe to unplug once the session is closed, whatever programs still have
  the driver open. Those programs are named: they are told the GPU was
  disconnected if they use it.

Tests:
- session shutdown retire-disconnect: the session closes the normal way
  for every program with nothing refused, the old clients' generation is
  the disconnected one, the call reports IDLE once closed, and the next
  program opens a new session.
- retire-disconnect-raw-bar: refused, nothing changes.
- The observer policy admits the op.
- The display agent's readiness: safe with clients named, an open
  session means apps connected (even none), closing, and the messages.
2026-10-05 16:30:21 -07:00
geramyloveless fbc26b2b12 A transport fault names its caller and ends the session's waits
When a definite PCI transport fault is recorded, admission closes. From
then on nothing this driver waits for on the GPU completes. Fences,
eviction copies and MES requests all wait forever, and they hold the
session queue, which is also where the driver's Stop runs. The three 248
instances from today's hangs never exited after the GPU was power-cycled,
and the upgrade to 249 waited on them until the user killed them.

- The first fault logs where it came from: the frame-pointer return
  addresses above it and record_fault's own address, so atos places them
  in the dext binary. This is what named amdgpu_gmc_set_pte_pde. It runs
  only on that fault.
- dext_pci_set_fault_hook: the session layer reacts once, on the faulting
  thread. transport_lost calls rt_device_lost. That does what a removal
  does: the DRM device counts as unplugged, there is no hardware access,
  and every ring's fences are force-completed with -ECANCELED, now and
  from a thread every 5 ms. So no wait outlives the fault.
  Unlike a removal, the PCI device is not marked disconnected
  (rt_removal_active stays false), so what the GPU may still reach stays
  retained by the fault's DMA quarantine.
- With the GPU unreachable, the last client's leaving closes the session.
  The close quarantines, naming the PCI fault. When the device then
  leaves the bus, the removal releases the session and the driver stops.
  rt_removal_end also stops the lost device's thread, and a new session
  starts with s_deviceLost clear.

session shutdown transport-fault-removal: a fault while a program and the
display run, with one hook reaction even when it fires twice. The program
leaves, the close quarantines on the fault, the power cycle removes the
device, and the instance finishes and stops.
2026-10-05 16:30:21 -07:00
geramyloveless cda0670cd9 Client records go with every client, and a missing session is an error
The compute backend keeps one record per runtime client in a fixed table
of 64, and client IDs are never reused. Records were cleared only when a
participant that was not the last one left. The last leaver's session
close, Linux-file clients, session clients that never joined, and the
records of a stopped session all kept theirs. After 64 clients over the
dext's lifetime, a new client got no record: its identity failed
silently, QueryInfo tag 12 said "not ready", HSA went on with the session
unreported on the legacy path, and queue creation failed with
OUT_OF_RESOURCES.

- Every Stop path forgets the client's record: session clients
  (participant or not, including the last leaver whose leaving closes
  the session), Linux-file clients and observers. A client outside the
  session that still owns a KFD process (opened by its QueryInfo)
  releases it. dext_compute_stop forgets every record with no KFD process
  left. A record whose KFD process could not be closed stays, and the log
  says so along with the record count.
- No record for a client is loud. Its identity failure is logged, its
  InitDevice fails with kIOReturnNoResources, and tag 12 fails with
  kIOReturnNoResources.
- A KFD process that cannot be opened on a device that supports KFD is
  that client's error on every compute call (tag 12, tag 10, BO alloc,
  import, queue create, host window). It no longer falls back to the
  legacy path, which may have no HQD at all. The open is not retried, and
  the log carries its errno.
- HSA: a driver that has tag 12 and gives no session fails hsa_init at
  that query, with a message naming it, instead of continuing on the
  legacy path into a queue OOM.

Tests:
- dext_compute production: client-churn runs 256 rounds of every client
  kind through join and leave, plus a kept KFD record; client-churn-close
  runs 256 last-leaver close-and-restart cycles; client-records-full
  checks the loud full-table path; kfd-open-failure now expects the error.
- session shutdown: client-churn drives every Stop path 256 times
  against a 64-record model; last-leaver-churn runs 256 closing last
  clients.
- HSA shim init: a refused or modeless tag 12 fails initialization.

client-churn-close fails on the 7c6afe9 backend at the 65th client, and
both session churn scenarios fail on the 7c6afe9 driver source.
2026-10-05 16:30:21 -07:00
geramyloveless b7370ef645 The GPU stays up across clients
The upstream driver was brought up per session and removed when its last
client left: every program started cold (a probe, about 2-3 s), and
while a session closed, new session clients were refused (the closing
window). Linux keeps amdgpu probed while programs open and close their
files.

Now the device is brought up on first use and stays up. A leaving client
releases only what it owned (dext_compute_release_client: its KFD
process, queues and BOs; a Linux-file client's process exits with its
files), and the next client joins the running device without opening PCI
or probing. The session closes only:
- at the driver's Stop, a device removal, Retire, or ShutdownGPU;
- when it is tainted (a client's release failed, or the GPU's state is
  uncertain), as before;
- when the last client leaves a session that must end with it: the device
  left the bus, a raw BAR mapping's revocation is not proved, the GPU was
  never brought up (what was set before the probe was that client's), or
  the client used the legacy (non-KFD) path, whose host window is the GART
  window placed in its own address space. On the iPad, Studio is that
  path's only client, and each launch places its window and probes again,
  as before. Concurrent legacy clients share the window as they did.

Tests (test-session-shutdown):
- client-exit-reopen: the only client leaves and finishes, nothing
  closes, and the next client joins without a PCI open or a probe.
- client-exit-unprobed, -release-failure, -raw-mapped, -legacy: the last
  client's leaving still closes the session in each case above.
- concurrent-clients: two HSA and two Linux-file programs join and leave
  in overlapping orders, one leaving while another joins, and a program
  starts after all left, with an observer attached; then 1000 rounds of
  two programs at a time. Nothing closes or blocks; the driver's Stop
  closes the device once.
- upgrade stops and surprise removals follow the new order: the clients
  finish, the driver's Stop or the removal closes.
The probe/remove cycles of test-session-cycles keep covering the close.
2026-10-05 16:30:21 -07:00
geramyloveless 121b63ba35 GPU recovery: hung queues reset as on Linux; a device reset wedges for now
With amdgpu_gpu_recovery off, a job on a hung ring never completed and
every wait on it lasted forever (build 241). Recovery is now upstream's
default: a job that times out resets its queue (amdgpu_job_timedout ->
ring->funcs->reset: a MES queue reset for compute and gfx, an SDMA queue
reset), the guilty job's fence gets -ETIME, its context reports the reset
(AMDGPU_CTX_QUERY2_FLAGS_RESET) and refuses further work, and the work
queued behind it from other contexts runs.

A device reset (mode1 on gfx12, after a failed queue reset, on a ring
without one, or requested by KFD or a user queue) needs platform work not
done yet over Thunderbolt: the PCI configuration's restore with its BARs,
MSI-X, client BAR mappings in the reset window. Until then
(rt_recovery_full_reset_available), rt/recovery.h turns every request for
one into what Linux ends in when a reset fails: the device wedges. The DRM
device is unplugged (new requests fail with -ENODEV), hardware access and
bus mastering stop, every ring's fences complete with -ECANCELED and keep
completing, and KFD's waiters get its reset event. Nothing waits forever
and nothing loops on resets.

rt_recovery_attach hooks this in after the probe without changing
upstream: each scheduler's timeout handler and each queue reset are
wrapped (upstream's run unchanged inside; every recovery handler runs on
the reset domain's one ordered queue), and the KFD and user-queue reset
works are redirected to the wedge. Each queue reset that succeeds, and
the wedge, advance a reset generation. The driver publishes it as
QueryInfo "LRST" (generation, wedged and VRAM-lost flags, queue resets,
VRAM-lost counter, last result), sets MLG_SESSION_FLAG_GPU_WEDGED in the
session state, logs both as unified-log events, and the host app and
read-driver-log.py say to power-cycle the GPU when it is wedged.

The CS fixture resets queues as MES does (fx_ring_reset, with a ring test
that runs on the engine). queue_reset_check hangs a compute job: the
timeout fires, the queue resets without a device reset, another
process's job behind it runs, the guilty context reports the reset and
refuses work, a new context works and the generation advances.
wedge_check (a process of its own) makes the queue reset fail: the device
wedges, blocked work and a wait with no deadline end, new requests fail
with -ENODEV, and no device reset is tried. ttm_evict_check's stalled
move now ends with an SDMA queue reset.
2026-10-04 21:55:02 -07:00
geramyloveless f40f5f45f4 The driver's own calls arrive on a queue of their own
The driver's Stop, its power changes and NewUserClient were delivered on
the session queue (the driver's default queue), and DriverKit runs a
delivery on the thread every client's calls share, under its target
queue: behind a session call that slept there, the driver's Stop could
not be delivered, and neither could anything else.

The driver's default queue is now a queue of its own. Stop and
SetPowerState hand their session work to the session queue and return at
once: Stop finishes later through FinishStop, as it already did after a
session close, and a power change is acknowledged from the session queue
(at once, or after its work, as before). Clients take the session queue
itself as their owner's queue.
2026-10-04 21:26:02 -07:00
geramyloveless 9d10aa0e33 Session calls never run on the driver's incoming-call thread
DriverKit delivers every client's calls, and the driver's own Stop, on
one thread, and runs each under its target queue with a synchronous
dispatch. Session clients shared the owner's queue, and observers and
Linux-file clients hopped to it synchronously, so a session call that
slept there (a probe, an allocation that evicts, a fence wait, a session
close), or anything queued behind one, held every client; on a GPU that
stopped, forever (build 241).

Every client now has a queue of its own, and nothing on the delivery
thread waits for the owner's queue:
- Selectors that never sleep answer there: Ping, RuntimeBuild (from flags
  the session queue publishes; the context is never touched), the cached
  QueryInfo tags, the power query and the power wait's registration, and
  OWNER_RESULT (88).
- Every other selector must be called with IOConnectCallAsync*: the call
  returns at once with a token and runs on the owner's queue, in arrival
  order, exactly as it ran there before; it completes with its IOReturn,
  scalar outputs and structure output length, and OWNER_RESULT fetches the
  structure output once. EVENT_WAIT keeps its own completion; a wait that
  does not start completes at once with the reason. A synchronous call of
  such a selector is refused (kIOReturnNotPermitted, logged once per
  client).
- SysfsRead and DrmInfo stay synchronous but bounded: the read runs on a
  wait-pool thread (rt_bounded_run, new) and the call waits at most
  250 ms (kIOReturnTimeout; while one overruns, the next is kIOReturnBusy).
  The observer's self-test, Retire and ReleaseQuarantine are async calls.
- A session client's Stop, and an observer's FinishStop, run on the owner's
  queue after the client's queued calls. Linux-file clients join the
  session on the owner's queue with their first open (LX_CALL_ASYNC),
  and the first open's InitDevice and HostWindow are async calls.
- CopyClientMemoryForType no longer touches the session: BOMap makes the
  BO's descriptor on the owner's queue and the mapping looks it up; the
  raw BAR lease takes its own spinlock.

Clients: host/owner_call.h and host/selector_call.h (header-only) call a
selector as the driver serves it, synchronously or as an awaited async
call; the HSA runtime, the host app (callScalar, callStruct, callMethod)
and libmlg_drm use them, and scripts/mlg_owner_call.py does the same for
drm-selftest.py and display-test.py's initialization. A client older
than this driver fails at its first session call that can sleep, with
the reason in the driver log.

Tests: test-owner-call runs the production owner_call machinery
(extracted, DriverKit mocked) against a session call that sleeps: calls
return at once, cached queries and the power wait answer while it
sleeps, later calls queue in order, completions carry the right layout,
OWNER_RESULT once, BO memory is found without the session, and a hung
bounded read times out within its bound. test-bounded covers
rt_bounded_run on the real wait pool; test-session-shutdown checks the
selector rules and runs the Stop paths through the owner's queue.
2026-10-04 21:22:42 -07:00
geramyloveless 0c8ffc27d5 Merge feature/async-lx (3e4651d) into display-c
b4d1555: an ALLOC1 xarray never hands out index 0 (the first syncobj got
handle 0). ec81985: no Linux-file request that can sleep runs on the
driver's incoming-call thread (per-client workers, LX_CALL_ASYNC 105, the
teardown thread), with its test in test-cs-selftest.

Conflicts: MacLinuxGPUXcode.mm keeps both the display gate's lock at Start
and the driver-start event. The installer files (MacLinuxGPUHostApp.swift,
activate.sh, build-installer-dmg.sh) stay as 56165a8 has them, which
already installs libmlg_drm and libdrm_mlg to /usr/local/lib; from
3e4651d only build-radv.sh, which adds /usr/local/lib as RADV's second
rpath after @loader_path.
2026-10-04 20:30:15 -07:00
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 347a44ec16 display: no op that can sleep runs on a client's call
On 241 a GPU ring hung (no recovery), and the display agent's OUTPUT then
pinned a framebuffer: TTM evicted, the blit waited for an IB from a pool
whose fences never signal, with no timeout, on the call itself. That was
the driver's incoming-call thread, so every client froze with it, the
observer's reads and Linux-file calls included, and the driver could not
even take its own Stop after the GPU was powered off.

Every display op that can sleep (PROBE, SHOW, OFF, STATUS, MODES, IMPORT,
VERIFY, RELEASE, OUTPUT) now needs an async completion: the call takes the
display gate, queues the op on a wait-pool thread (rt_wait_pool, the
threads that already sleep for event waits) and returns at once with a
token. The thread runs the op, keeps its structure output for RESULT
(op 10, once) in a slot the op shares with the client (an op may end after
the client stopped), and completes the call with the token, the op's
IOReturn, its two scalars and its output length. A synchronous call of
one is refused; one while another runs is kIOReturnBusy.

PRESENT stays synchronous and never sleeps: it takes no display gate, and
rt_display_present and rt_display_stats take the display lock with
trylock, -EBUSY while an op holds it. The agent then carries that frame's
damage (moves as rectangles) to the next PRESENT and forgets its tile
hashes, so no later frame moves or skips rows the driver never drew.
A stopped client's imports and output are released on a pool thread once
the display gate is free (after any op of its own that is finishing).
The daemon skips a STATUS poll that finds the display busy instead of
closing its clients.

The host app's display calls are async: IOConnectCallAsyncMethod with a
notification port, the completion received on the calling thread (up to
60 s, then kIOReturnTimeout), and RESULT for the output.

test-display-async runs the production display_call machinery, extracted
from the dext source, with DriverKit mocked and an OUTPUT that never
finishes: the call returns at once, the op does not run on it, PRESENT
and another client are answered meanwhile, a second op is busy, a stop
waits for the op, the completion and RESULT (once) carry its result, and
a refused thread leaves the display free. With the op run on the call
(the 241 behaviour) it fails within 20 s instead of hanging.
2026-10-04 19:12:11 -07:00
geramyloveless 4b142d018e Merge feature/radv-apple-vram (d132e25) into display-c
The DART has no fixed DMA budget (the platform's refusal is the limit,
logged), page descriptors grow with RAM, and kmemcheck is compiled only
in debug builds.

Conflicts, both sides kept: the shutdown hold still waits up to
DEXT_DMA_HOLD_DRAIN_MS for operations in flight, now without a budget
argument; test_iokit_dma keeps the in-flight hold, aperture gate and
large-mapping tests; the fence wait-any test keeps one 2 s bound.
2026-10-04 10:08:00 -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 994a5e516f display-agent: read the driver's statistics through an imported surface
The agent read the output worker's statistics with PRESENT, handle 0
and no rectangle, but the observer gate admits PRESENT only with a
nonzero handle, so on build 235 the read failed and the agent ended
the mirroring two seconds in (at the end of --warmup), reporting
FAILED. The agent now passes one of its imported surfaces' handles for
the read (the driver ignores it when there is no rectangle), opens the
measured window only once a surface exists, and never stops mirroring
because a statistics read failed: it says so and continues unmeasured.

The gate now admits handle 0 for PRESENT, as session_state.h
documents, and the gate test checks it. iokit_bridge.mm includes
time.h for the hold's clock.
2026-10-03 19:37:27 -07:00
geramyloveless 2a512ea890 dext: a quarantined instance whose device left the bus exits
When the provider stopped and found the device gone under a
quarantined session, Stop released the session and the provider
(release_removed, which ends in FinishStop), then called close_session
again. That started a new close of a session that no longer existed:
its final cleanup found the DMA backing the removal had kept, saw no
removed device (the flag was cleared for the next probe), and
quarantined it again. The instance stayed alive with no device, and a
replug could not attach a fresh one without a restart (seen on build
235 after the R9700 was powered off).

Stop now returns once the removal has released the session. The
surprise-removal test drives the real Stop for the quarantined case
and checks that nothing closes again and the instance stops.
2026-10-03 19:34:38 -07:00
geramyloveless 0a67e495c2 Merge feature/sysinfo: the R9700's identity in System Report
The display OUTPUT op republishes MacLinuxGPUDisplays with the lit
mode, as STATUS and the pattern ops do.
2026-10-03 17:14:14 -07:00
geramyloveless a56c499f91 Publish the GPU's identity and monitors for System Information
System Information builds a PCI GPU's entry from the IOPCIDevice merged
with the properties of its direct children, and properties a dext sets
with SetProperties() reach user space as top-level keys. The dext now
sets the keys it reads on its own service:

  model             the product name, from libdrm's table (Start)
  VRAM,totalMB      gmc.real_vram_size (after the probe)
  ATY,EFIVersionB   the VBIOS part number ("VBIOS Version")
  rom-revision      the VBIOS version string

so "Display" becomes "AMD Radeon AI Pro R9700" with its VRAM and VBIOS.
A device the table does not list gets no name; Metal and core-count keys
are not published because they would be false.

MacLinuxGPUDevice carries the rest of the identity (IDs, PCIe link, VRAM
type, CUs, ISA target, VBIOS details) and MacLinuxGPUDisplays the DRM
connectors with their monitors' EDID names and modes, updated by the
display operations and removed when the session closes. System
Information cannot list those monitors under this GPU (it only lists
IOFramebuffer kernel objects there), so MacLinuxGPUHost shows the GPU
with its monitors: "MacLinuxGPUHost device", and a GPU panel in its
window, both read from the IORegistry without a user client.

test-device-properties builds the property set with DriverKit container
substitutes, including every allocation failure; test-device-info checks
the host view.
2026-10-03 17:12:22 -07:00
geramyloveless 2ea5d08b16 dext: hand the GPU to a replacement driver (Retire), stop at once when idle
macOS does not stop a running driver extension when an activation request
replaces it. kernelmanagerd declines to terminate the old version ("being
replaced and cannot be terminated"), sysextd leaves it "terminating for
upgrade via delegate", and the kernel attaches the new version only once
every instance of the old one is gone. Until then a GPU that appears still
matches the old version. Nothing in the driver ever let an instance go
except its GPU leaving the bus, so an upgrade with the GPU attached left the
old process holding it until someone killed it, which can panic the Mac.

Retire (selector 85, entitled, observers may call it) is how the installer
makes an instance go:

- QUIESCE admits no new session and closes an open one through the normal
  close: upstream removal, interrupt drain, endpoint reset, provider close.
- TERMINATE also asks IOKit to terminate this driver instance once nothing
  of the session is left (IOService::Terminate). IOKit stops the clients,
  then the driver, and the process exits.
- RESUME undoes QUIESCE when the replacement failed or was deferred.

Nothing is forced into quarantine. A client's raw BAR mapping refuses the
close, as do other session clients unless FORCE is given. A quarantined
session is released only when it is provably quiescent; otherwise Retire
reports the blocker and the instance stays (restart, never kill). Session
state gains a RETIRING flag.

Stop of a driver with no session (an upgrade, a deactivation, an unplug of
an idle GPU) now releases the provider at once instead of going through an
interrupt drain and a queue hop.

The session-shutdown fixture runs the production MacLinuxGPU::Stop and
Retire. It covers Stop during an upgrade with an idle observer, with an open
session, with a quiescent quarantine and with an uncertain one. It covers
Retire when idle, quiesce and resume, terminate with a session, a raw BAR
mapping, and a releasable and a held quarantine. Each finishes every Stop
and releases the service and provider, or keeps everything and reports a
restart.
2026-10-03 16:43:29 -07:00
geramyloveless 331692b9ca display: a GPU that left the bus has no display to drive
With the device removed (rt/removal.h), every display op returns
-ENODEV, and turning a pattern or output off commits nothing: the
recorded configuration is dropped and the buffers and client go as on a
Linux unplug. Surface imports, copies and checks return -ENODEV;
releasing still works and the client's mapping is returned once the
removal has completed the BO's fences.

The dext releases what the display ops hold in one place
(release_display_owners): at a session close unless a quarantine keeps
every owner, or the device is gone; and when a removal releases a
session that was quarantined, before compute stop and upstream removal.

Tests: test-session-shutdown removes the device under a display agent
with an output on screen and two imports, in a plain session, one that
quarantines during the close, and one quarantined before it (released
only by the removal); test-surface-import removes the device with an
import held; test-dm-offline removes it with the pattern on screen and
turns it off without a register write.
2026-10-03 15:57:17 -07:00
geramyloveless eea40d37ac Merge feature/hotplug into feature/display-c
The surprise-removal path of the DMA seam completes retired table entries, which now hold an IOMemoryDescriptor (imports share the table).
2026-10-03 15:57:17 -07:00
geramyloveless 457a75876b dext: survive the GPU leaving the bus
Unplugging the eGPU with a session open took the whole iPad down. When
its PCI provider and clients are terminated the device is already gone,
but the close treated it as a GPU that might still run: every teardown
step waited on hardware that never answered, the session quarantined
(retaining the provider, the DMA backing and the upstream driver), and a
dext that dies while it holds the device panics the kernel in
IOPCIFamily's client crash recovery, as on the Mac.

Detect the removal when a client or the driver stops: configuration
space no longer answers (asked on the provider directly, since a fault
may have closed admission). From then on nothing touches the device:
admission closes for good, nothing resets or isolates it, BAR0 CPU
accesses through the io accessors read ~0 and drop writes, and the
runtime's removal begins (GPU work completes with -ECANCELED). A device
off the bus can reach no memory, so DMA safety holds: the DMA seam lifts
a quarantine and its holds and completes retired descriptors at once,
compute stop and client release stop refusing on account of uncertain
GPU work, and no step quarantines. The close runs to the end, removes
the upstream driver after the removal thread stops, releases the BAR0
aperture and closes the provider once nothing is admitted and no
interrupt source is left, then reopens admission so the replugged GPU
probes afresh. A session already quarantined when the removal is seen is
released the same way. New session opens fail with kIOReturnNotAttached
meanwhile.

The power state goes to lost with the new cause "device removed" and
the link-down flag, so clients learn what happened; the session state
has a device-removed flag and read-driver-log.py names both.

Tests: the session shutdown fixture removes the device under a client's
open session whose compute stop fails, and under a session already
quarantined; neither resets, isolates or quarantines, every Stop
finishes, and a new client opens a new session. The production backend
stops a device whose legacy queue could not be removed once it is
removed.
2026-10-03 15:44:38 -07:00
geramyloveless 52d053efce dext: IMPORT, VERIFY, RELEASE, OUTPUT and PRESENT on selector 84
A display agent's frame path, for observer clients, admitted and
serialized like the other display ops:

- IMPORT maps the client's memory (the structure-input descriptor) for
  the GPU with dext_dma_import, keeps a read-only CPU view of it, and
  imports it as a GPU buffer; the handle comes back in scalar out [1].
  The mapping and view are released once the GPU can no longer reach
  them (the surface's provider release after its BO is destroyed).
- VERIFY checks the surface with the GPU and the CPU view against the
  client's pattern.
- RELEASE drops one import.
- OUTPUT lights a connector at a mode for the client; PRESENT copies a
  frame's dirty rectangles and flips.

A client's Stop releases its imports and turns off the output it
started; a session close releases every import right after the display
pattern or output goes off. Statuses are Linux errnos; nothing falls
back to another mechanism. The observer policy checks each op's scalar
shape; test-session-shutdown covers the policy and the close order.
2026-10-03 15:37:19 -07:00
geramyloveless ce35d2c1cf display: connector status with a hotplug epoch, and per-connector modes
For a display agent that mirrors the GPU's monitors as macOS displays:

- rt_display_status() (selector 84 op STATUS) returns the cached
  connector state, with no detection and no AUX or DDC traffic, and a
  hotplug epoch. The first call registers a monitor DRM client whose
  hotplug callback counts events; DM's HPD handling reaches it through
  drm_kms_helper_connector_hotplug_event(). Upstream unregisters and
  frees the client with the DRM device; its callbacks take no lock of
  ours. The report's reserved word is now hotplug_epoch.
- rt_display_modes() (op MODES, connector name required) lists one
  connector's probed modes: size, refresh in mHz, pixel clock, the
  preferred and interlace flags, and the physical size.

test-dm-offline checks epoch 1 at registration and +1 on a hotplug event,
the [email protected] preferred mode and 600x340 mm of a forced sink, an
empty list for an empty connector and -ENOENT for an unknown one;
test-session-shutdown checks the selector shapes.
2026-10-03 14:35:21 -07:00
geramyloveless 74fb0a661f Merge main into feature/display-b
# Conflicts:
#	Makefile
#	dext/sources/session_state.h
#	linuxu/tests/test_read_driver_log.py
#	linuxu/tests/test_session_shutdown.cpp
#	scripts/read-driver-log.py
2026-10-03 14:15:00 -07:00
geramyloveless 9718e8d8cf dext: Display selector 84 for the in-driver display test
MLG_SELECTOR_DISPLAY (84, after DrmSelfTest 82 and PowerControl 83 on
feature/power; 96-103 stay the Linux-file selectors) runs the display
test client (rt/display.h) for observer clients, admitted like the other
observer reads, one op at a time (Busy otherwise):

  scalar in   [0] op: probe, show or off  [1] pattern (show only)
              [2] MLG_DISPLAY_CONFIRM ("DISP")
  struct in   show only, optional connector name; none means every
              connected output
  struct out  struct rt_display_report
  scalar out  [0] 0 or the op's negative Linux errno

The observer policy accepts only that shape. Each op is logged with its
probe, commit and restore status, the connected and lit outputs, the
framebuffer and the fill and commit times.

close_session turns a showing pattern off right after observer
admission drains and before anything else is torn down, so the
configuration it replaced is committed again while the driver still
runs; a quarantined session keeps the client with every other upstream
owner. test-session-shutdown covers both orders and the selector policy.
2026-10-03 14:08:22 -07:00
geramyloveless f1557dd66c dext: sleep, device low power and client low-power requests
The driver now handles DriverKit's power changes and gives clients a
power state, a way to ask for low power, and a way to wait for changes.

SetPowerState(Low), the device in a reduced power state while the
system runs, and a client's PowerControl PREPARE quiesce the compute
session through upstream KFD suspend (rt/power.h): every user queue off
MES with its work saved, VRAM untouched. RESUME by the last holder, or
SetPowerState(On), resumes it through upstream KFD resume and the saved
work continues.

SetPowerState(Off), system sleep, takes the Thunderbolt link and with
it the endpoint's state; VRAM cannot survive it on these hosts, and
upstream's only dGPU path evicts all of VRAM to system memory through
SDMA, which neither fits on the iPad nor is safe over the link. The
driver closes the compute session through its ordinary close path
before acknowledging the change; the acknowledgement waits for the close
on the default queue, with a watcher that acknowledges at a deadline so
a stuck close never stalls the sleep. On wake the state is lost if a
session was closed, and the next InitDevice probes afresh and makes it
active again. A quiesced session closes as it is, its queues already
off MES; the KFD suspend is handed back before upstream removal takes
its own, so upstream's suspend count stays balanced across sessions.

A failed quiesce or resume hands the suspend back, so MES maps the
queues again and the close removes them through MES; a GPU that cannot
prove itself idle leaves the session to the existing quarantine rather
than freeing memory it may use.

Clients see state, generation, flags (VRAM preserved among them),
cause, error and counters through QueryInfo tag "LPWR" (observers too)
and the PowerControl selector 83: QUERY, PREPARE, RESUME and an async
WAIT completing at the next generation change. While suspending,
suspended or resuming, selectors that would put work on the GPU are
refused with kIOReturnOffline, which a client retries after resume;
frees, queue destruction and cached queries stay available. A closing
client's waits end and its hold is dropped. Observers may request
transitions only with the session-release entitlement.

power_state.h holds the state machine, the snapshot, the admission
policy and the plan each event leads to, with a host test that also
checks the runtime's copy of the protocol. The session shutdown test
covers the removal hook and the observer policy for the new tag and
selector, and read-driver-log.py prints the power state.
2026-10-03 10:03:32 -07:00
geramyloveless 65bf0fbb13 dext: Linux-file user clients and the CS self-test selector
User-client type 2 (MLG_USER_CLIENT_LINUX_FILE) is a Linux process of
its own: LX_OPEN, LX_CLOSE, LX_IOCTL, LX_IOCTL_ASYNC, LX_RESULT, LX_MMAP,
LX_MMAP_COMMIT and LX_MUNMAP (selectors 96-103, rt/lx_abi.h) run its
system calls through lx_files on the client's own dispatch queue, so no
call waits behind another client's. Request frames arrive as structure
input or, above 4096 bytes, as a descriptor; replies go back the same
way. Waits run on workers of the process and complete through
AsyncCompletion with the reply inline when it fits. LX_MMAP memory types
resolve in CopyClientMemoryForType to the buffer's page runs or to BAR
sub-ranges (CPU-visible VRAM, doorbells). Ping, RuntimeBuild, QueryInfo
and InitDevice hop to the owner's queue as observers' calls do; nothing
else of the MacAMDGPU ABI is offered to this type, and types 0 and 1
are unchanged.

The client joins the session at its first call, as a session client
does. Its calls are admitted only while the upstream driver runs; a
session close or quarantine closes the admission, waits for calls in
flight, and makes every client process exit (waits return, files close
through upstream postclose) before anything is removed. A client's Stop
does the same for its own process on its queue, then leaves the session
on the owner's queue.

Observer selector 82 (DrmSelfTest, confirmed with "CSST") runs the CS
self-test and returns its result; one test at a time. A test whose GPU
work never completed keeps its process; a session close reaps it once
idle or quarantines with compute uncertain. scripts/drm-selftest.py runs
it on hardware.
2026-10-02 21:52:07 -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