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.
A process that renders on the GPU can now show its frames on the monitor
the display output drives with no copy: its framebuffers go into the
output worker's own commits, which stays the only committer.
- Linux-file clients open the primary node (MLG_LX_DEV_PRIMARY). drm_open
makes the first opener DRM master; the display hooks drop that before
the file is installed, under the display lock, so the driver's own
modesets keep working. The node carries the KMS queries and ADDFB2,
RMFB and CLOSEFB (lx_describe.c), nothing that changes the display.
- LX_SCANOUT (selector 104): ATTACH (one client per output, which gets a
free overlay plane of the CRTC), TEST, PRESENT, DETACH, STATE. A frame
goes on the primary plane in place of the desktop, whose frames then
wait in the mailbox and are counted as held, or on the overlay plane at
a rectangle over the desktop. The client's syncobj gets the flip's
fence at the commit; the commit waits for the rendering through the
framebuffer's implicit fences. DETACH, and a client going away, put the
desktop back before its framebuffers can go.
- The worker builds each commit from the desktop buffer and the client's
frame; client flips do not count as desktop frames in the statistics
the agent reads.
- libmlg_drm: /dev/dri/cardN, mlg_scanout and the IOKit transport's
LX_SCANOUT; the loopback transport sets the display hooks as the dext
does.
What a libdrm on top of the library needs:
- mlg_pci_identity: the GPU's PCI function for libdrm's device list. The
IOKit transport reads vendor, device, subsystem, revision and location
from the IOPCIDevice the driver matched; a transport without an identity
callback gets vendor, device and revision from AMDGPU_INFO_DEV_INFO.
- Render-node requests encoded with more directions than the driver's
table declares are sent in the table's encoding. The DRM core matches
driver requests by number and copies only the directions both encodings
have; Mesa issues DRM_AMDGPU_GEM_VA read-write against a write-only table
entry, which the transport refused as unknown.
- mlg_mmap maps whole pages, as mmap(2) does: the driver process takes
page-multiple lengths only, and Mesa maps 4 KiB buffers on a 16 KiB page
system. munmap still takes the caller's length.
- mlg_is_mapping tells a libmlg_drm mapping from any other, for wrappers
that must route munmap.
test_mlg_drm covers each, and checks that a KFD request with altered
direction bits is still refused.
linuxu's drm/display/drm_dp_helper.h defines reply as a macro, so a
translation unit that also reaches it would rewrite a parameter or field
named reply. The transport's headers and the loopback test name their
reply buffers rbuf.
The client side of the Linux-file RPC for a macOS process: mlg_open,
mlg_close, mlg_ioctl, mlg_mmap and mlg_munmap on /dev/dri/renderD128 and
/dev/kfd, mirroring the system calls, for a Mesa winsys or libdrm shim.
Requests are Linux ones: the Linux uapi headers are built through
libmlg_drm/compat with Linux ioctl encodings on any host, and
mlg_ioctl_from_bsd converts what a macOS build of the same headers
produces. Each request is described with the shared tables
(lx_describe.c), framed (lx_frame.c), and its reply copied back; waits
with a deadline go through LX_IOCTL_ASYNC and complete on a per-thread
notification port, deadlines travel as time left, mmaps go through
IOConnectMapMemory64 with the cache mode the driver reports, and errors
come back as this platform's errno (mlg_last_linux_errno keeps the
Linux one).
The default transport is the dext's Linux-file user client (type 2);
tests install their own. make libmlg_drm builds a static and a shared
library. Tests: the library alone against a recording transport, and a
RADV-like client end to end through the core into upstream DRM/amdgpu on
the CS fixture: INFO, contexts, GEM, a BO list, AMDGPU_CS, WAIT_CS,
WAIT_FENCES and SYNCOBJ_WAIT on async workers, syncobj and fence export
as descriptors of the driver process.