mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
The driver's persistent AQL queues are legacy kernel queues MES maps; a device reset takes them with MES's state. Upstream's device recovery now carries them across: - As upstream halts the device, a DRM client of the device (the hook upstream gives everything outside amdgpu that must stop before its IPs suspend) marks every mapped queue unmapped. Kicks are refused until it is mapped again. - Once the reset has succeeded and the schedulers run again (where KFD restores its queues), before the new reset generation is published, each queue's storage block is written again with an MQD upstream builds afresh, positioned at the producer's write_dispatch_id, the reader is moved there, and the queue is mapped. Packets not finished were lost with the GPU's state; the generation tells clients. The restore writes the storage through SDMA, so it cannot run from the DRM client's resume, which precedes the schedulers' restart. - A queue that cannot be mapped again is retained, and its owner's next call freezes the session. A queue destroyed after a reset that was not followed by a restore (the device wedged) is freed without an MES unmap. The hooks run on the reset domain's thread while the owner queue serves calls, so dext_aql keeps its own list of mapped queues under a lock held only across bounded steps (MES map/unmap, storage writes), never across a wait the reset must finish. Without it a restore could write a queue a destroy had just freed. The fixture's device-reset-recovers check failed intermittently: the fixture's ASIC reset zeroed its engines' read pointers while the driver's rings kept their write pointers (the fixture's IP blocks had no resume), and an engine could also carry on mid-batch from the cleared position. The SDMA engine then executed its stale ring from the start, old fence values included; amdgpu_fence_process took the lower sequence for a wrap and signalled every pending fence, so a new client's IB ran before its page-table update and faulted. The ASIC reset now stops each engine at a packet boundary, and the fixture's GFX and SDMA blocks resume their rings at 0 as gfx_v12_0 and sdma_v7_0 do. The check now also asserts both resumes ran. Tests: test-aql-reset builds the real dext_aql.mm against a mock MES and checks restore at the producer's position, kicks refused in between, the wedged destroy, a failed restore, and the hooks on their own thread against 300 rounds of create/kick/destroy under ASan and TSan (without the lock it reports a use-after-free). The production-backend scenarios cover the hooks' installation and the freeze on a failed restore; the fixture's device-reset-recovers covers upstream's recovery running the hooks around a real reset.
52 lines
2.4 KiB
Bash
Executable File
52 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Kernel-queue command submission offline: the CS self-test through the
|
|
# Linux-file transport against the unmodified upstream DRM core, GEM, TTM,
|
|
# VM, rings, fences, drm_sched, CS and syncobjs of a fixture device whose
|
|
# software GPU executes the rings (linuxu/tests/cs_fixture.c). Links the
|
|
# host library (make lib).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
make -s lib >/dev/null
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
cat > "$work/flags.mk" <<'MAKE'
|
|
.PHONY: print-includes
|
|
print-includes:
|
|
@printf '%s\n' $(INCPATHS)
|
|
.PHONY: print-hostcflags
|
|
print-hostcflags:
|
|
@printf '%s\n' $(filter-out -MMD -MP -DLINUXU_RT_HOST_SHADOW=1,$(HOSTCFLAGS))
|
|
MAKE
|
|
include_string=$(make -s -f Makefile -f "$work/flags.mk" print-includes | tr '\n' ' ')
|
|
read -r -a includes <<< "$include_string"
|
|
host_string=$(make -s -f Makefile -f "$work/flags.mk" print-hostcflags | tr '\n' ' ')
|
|
read -r -a hostcflags <<< "$host_string"
|
|
cflags=("${hostcflags[@]}" -g -O1 "${includes[@]}")
|
|
# The fixture's GART table and VRAM are host memory. The library's host
|
|
# build routes readX/writeX through synthetic MMIO tokens, which would drop
|
|
# the GART PTE writes (amdgpu_gmc_set_pte_pde uses writeq); these two
|
|
# upstream files are rebuilt with plain-memory accessors, as the KFD session
|
|
# test builds its doorbell code, and take the archive members' place.
|
|
plain=()
|
|
for source in third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c \
|
|
third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c; do
|
|
object="$work/$(basename "$source" .c).o"
|
|
clang "${cflags[@]}" -c "$source" -o "$object"
|
|
plain+=("$object")
|
|
done
|
|
clang "${cflags[@]}" -fsanitize=address \
|
|
linuxu/tests/test_cs_selftest.c linuxu/tests/cs_fixture.c linuxu/tests/ttm_evict_check.c linuxu/tests/visible_kmap_check.c \
|
|
linuxu/tests/removal_check.c linuxu/tests/blocked_call_check.c \
|
|
"${plain[@]}" build/libmacamgdu.a \
|
|
-lpthread -o "$work/test_cs_selftest"
|
|
"$work/test_cs_selftest" wedge
|
|
"$work/test_cs_selftest" device-reset
|
|
"$work/test_cs_selftest" device-reset-recovers
|
|
# CS_SELFTEST_KEEP=<path> keeps the binary for a debugger; CS_FIXTURE_TRACE=1
|
|
# traces what the software engines execute.
|
|
if [ -n "${CS_SELFTEST_KEEP:-}" ]; then cp "$work/test_cs_selftest" "$CS_SELFTEST_KEEP"; fi
|
|
"$work/test_cs_selftest"
|
|
"$work/test_cs_selftest" wedge
|
|
"$work/test_cs_selftest" device-reset
|
|
"$work/test_cs_selftest" device-reset-recovers
|