Files
mac_linuxgpu/linuxu/tests
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
..
2026-10-03 17:50:21 -07:00
2026-10-03 17:50:21 -07:00
2026-10-03 17:50:21 -07:00

linuxu tests

Standalone unit tests for the linuxu shim layer. Each test is a plain main() program using a local EXPECT() macro (no test framework — the dext cannot link gtest/libc-test deps).

Build & run

cd <repo>/linuxu
# host build (no DriverKit): -fsyntax-only first, then real link
clang -std=gnu11 -D__KERNEL__ -I<repo>/linuxu/headers \
  <test>.c <required shim .c files> -lpthread -o <test>
./<test>

The make test target (top-level Makefile) builds and runs all of them. Per-test required shim files:

test links with (shim sources)
test_kmemcheck kmem/kmemcheck.c kmem/kmemalloc.c kmem/string.c shims/printk.c
test_fake_mmio pci/pdev_mmio.c
test_vram amdgpu-rt/vram.c
test_irq amdgpu-rt/device.c pci/pci_stub.c shims/printk.c
test_workqueue work.c sync.c shims/printk.c
test_timer timer.c sync.c shims/printk.c
test_xarray xarray.c
test_rcu rcu.c shims/printk.c

What is REAL vs STUB

  • REAL (assertions exercise the actual algorithm): kmemcheck canaries, fake-MMIO token table + 16KB slots + readl/writel dispatch, vram bump allocator + pfn mapping, irq register/inject/unregister, workqueue (pthread worker + jiffy-delayed promotion + cancel_delayed_work_sync), timer_list (4ms reaper), xarray (node tree + xa_alloc), rcu (per-thread defer list + synchronize barrier).
  • STUB (documented, no assertions beyond "does not crash"): i2c (xfer → -ENOENT), acpi, mmu_notifier, dev_coredump, module, firmware (loader is REAL for the host build; the dext build swaps in the embedded-table path), debugfs/sysfs (table no-ops — could be extended with a test_debugfs later).

Running without a GPU

All tests run in-process on the host with no GPU, no IOKit, and no root. The fake-MMIO and vram backends use host shadow buffers; the LINUXU_DEXT compile flag switches them to the IOPCIDevice backends (compiled only for the dext bundle, not for these tests).