Files
geramyloveless 2dd02645b6 AQL queues are mapped again after a device reset
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.
2026-10-06 17:18:27 -07:00

86 lines
4.2 KiB
C

/* A fixture amdgpu device for kernel-queue command submission tests
* (cs_fixture.c): the unmodified upstream DRM core, GEM, TTM, VM, rings,
* fences, drm_sched, contexts, CS and syncobjs over a software GPU that
* executes what the rings carry. */
#ifndef CS_FIXTURE_H
#define CS_FIXTURE_H
#include <stdint.h>
struct pci_dev;
struct cs_fixture_stats {
unsigned long compute_ibs, sdma_ibs; /* IBs executed */
unsigned long write_data; /* PM4 WRITE_DATA executed */
unsigned long fences, interrupts;
unsigned long pte_writes; /* SDMA page-table entries written */
unsigned long fills, copies; /* SDMA buffer operations */
unsigned long vm_flushes;
unsigned long faults; /* GPU accesses that did not translate */
unsigned long dart_faults; /* ... to system memory not DMA-mapped */
unsigned long dma_data; /* PM4 DMA_DATA (CP DMA) executed */
unsigned long release_mem; /* PM4 RELEASE_MEM in IBs executed */
unsigned long dispatches; /* dispatch packets seen (not run) */
unsigned long skipped; /* packets skipped (state, caches) */
unsigned long queue_resets; /* per-queue resets (fx_ring_reset) */
};
/* Before cs_fixture_init: two SDMA instances (each its own engine), and a
* display: the driver gets modesetting and dumb buffers, mode config is
* initialized and this function runs the display IP's init (after TTM,
* GART, VM and the rings, before drm_dev_register). */
struct amdgpu_device;
extern unsigned int cs_fixture_sdma_instances;
extern void (*cs_fixture_display)(struct amdgpu_device *adev);
/* Bring up the linked DRM/amdgpu modules and the fixture device, and
* register its DRM device (render node minor 128). Aborts on failure. */
struct pci_dev *cs_fixture_init(void);
/* Stop the software engines. */
void cs_fixture_stop(void);
void cs_fixture_stats(struct cs_fixture_stats *out);
/* Make the compute engine ignore its ring until resumed (a hung queue). A
* queue reset (a job timeout with GPU recovery) also ends it. */
void cs_fixture_hold_compute(int hold);
/* Make every queue reset fail (MES does not answer), as a GPU that needs
* a device reset. */
void cs_fixture_fail_queue_reset(int fail);
/* ASIC resets (mode1) upstream's recovery ran on the fixture. */
unsigned int cs_fixture_asic_resets(void);
/* IP blocks (GFX, SDMA) resumed after an ASIC reset: their rings restart at 0. */
unsigned int cs_fixture_ip_resumes(void);
/* Let the ASIC re-initialize after a reset (no VBIOS needed). */
void cs_fixture_asic_reinit_ok(int ok);
/* The same for the SDMA engine (TTM's moves, clears and PTE uploads). */
void cs_fixture_hold_sdma(int hold);
/* CPU-visible VRAM (the BAR), set before cs_fixture_init; 0: all VRAM. */
extern uint64_t cs_fixture_visible_vram;
struct amdgpu_device;
struct amdgpu_device *cs_fixture_adev(void);
/* The host memory behind VRAM MC address @mc, or NULL. */
uint8_t *cs_fixture_vram_host(uint64_t mc);
/* The fixture's read-write view of a driver pointer: one into VRAM (a kernel
* VRAM mapping, which the driver reaches only through the aperture, and the
* test would fault on) becomes the same bytes of the fixture's VRAM. */
void *cs_fixture_host_view(const void *driver_pointer);
/* TTM moves VRAM <-> GTT through the upstream code on this device
* (ttm_evict_check.c). */
void ttm_evict_check(void);
/* No kernel mapping of VRAM past the CPU-visible window
* (visible_kmap_check.c). */
void visible_kmap_check(void);
/* Surprise removal with work outstanding (removal_check.c); the device
* stays removed. */
void removal_check(struct pci_dev *pdev);
/* Let IBs carry what a full driver emits around its work: chained IBs are
* followed, packets the software GPU does not model (register state,
* cache and event packets, register writes) are skipped and counted, and
* dispatches are counted but not run (the software GPU executes no
* shaders); client SDMA IBs carry real SDMA packets (copy, write, fill,
* fence), which run. Off by default, so an unexpected packet aborts. */
void cs_fixture_model_driver_streams(int on);
/* The host memory behind @bytes at @offset of BAR @bar (BAR0: VRAM through
* its aperture), or NULL: lx_loopback_set_bar_memory's callback. */
void *cs_fixture_bar_memory(uint32_t bar, uint64_t offset, uint64_t bytes);
#endif