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.
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.
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.
read-sysfs.py read a file until its reported length; a bin attribute of
size 0, such as a DRM connector's edid, reports none, so it stopped after
the first chunk. It now ends such a read at a short chunk. The usage text
shows the connector directories.
read-driver-log.py --display prints only the lines of display bring-up
and the display test: the display opt-in, DMCUB/DMUB, Display Core and
its clock manager, SMU, HPD, EDID, link training, commits and their
waits, connectors and the display test's own lines.
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.
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.