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.
32 lines
1.5 KiB
Bash
Executable File
32 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# The driver's AQL queues across a device reset (linuxu/tests/test_aql_reset.cpp):
|
|
# the real dext_aql.mm against a mock MES, under ASan/UBSan and under TSan.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
# DriverKit's IOLib, as much of it as dext_aql.mm uses.
|
|
mkdir -p "$test_dir/DriverKit"
|
|
cat > "$test_dir/DriverKit/IOLib.h" <<'HEADER'
|
|
#pragma once
|
|
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
typedef struct IOLock { pthread_mutex_t m; } IOLock;
|
|
static inline IOLock *IOLockAlloc(void)
|
|
{ IOLock *l = (IOLock *)calloc(1, sizeof(IOLock)); if (l) pthread_mutex_init(&l->m, NULL); return l; }
|
|
static inline void IOLockLock(IOLock *l) { pthread_mutex_lock(&l->m); }
|
|
static inline void IOLockUnlock(IOLock *l) { pthread_mutex_unlock(&l->m); }
|
|
static inline void *IOMallocZero(size_t size) { return calloc(1, size); }
|
|
static inline void IOFree(void *p, size_t size) { (void)size; free(p); }
|
|
static inline void IOSleep(unsigned ms) { usleep(ms * 1000); }
|
|
HEADER
|
|
common=(-std=c++17 -g -O1 -w -I"$test_dir" -Ilinuxu/headers -Idext/sources)
|
|
clang++ "${common[@]}" -fsanitize=address,undefined -fno-sanitize-recover=all \
|
|
linuxu/tests/test_aql_reset.cpp -o "$test_dir/test_aql_reset"
|
|
"$test_dir/test_aql_reset"
|
|
clang++ "${common[@]}" -fsanitize=thread linuxu/tests/test_aql_reset.cpp -o "$test_dir/test_aql_reset_tsan"
|
|
TSAN_OPTIONS=halt_on_error=1 "$test_dir/test_aql_reset_tsan" > /dev/null
|
|
echo "PASS AQL reset under TSan: no data race between the reset hooks and the owner's calls"
|