Background
==========

When a GPU shader hits a hardware exception (s_trap 1), the first-level
CWSR trap handler reads TMA slots 0 and 1. If slot 0 contains a non-zero
address, the handler chains to the user-installed second-level TBA and
TMA. This is the mechanism used by RADV/Valve for GPU shader debugging.
KFD already provides this for compute workloads via kfd_process. Render-
node file descriptors had no equivalent.

Design
======
  - One global TBA BO (adev->trap_info->isa_bo) holds the shared ISA
    binary and is mapped into every GPUVM at AMDGPU_VA_RESERVED_TRAP_START.
    The ISA binary is identical across VMs for the same hardware generation,
    so one device-level allocation is sufficient.

  - One per-VM TMA BO is allocated at vm_init and mapped at
    AMDGPU_VA_RESERVED_TRAP_START + 0x1800. The 0x1800 offset matches
    KFD_CWSR_TMA_OFFSET so both KFD and render-node VMs share the same
    per-VM buffer layout.

  - SQ_SHADER_TBA/TMA registers are programmed for kernel-managed VMIDs
    from each gfxhub's setup_vmid_config() path. User-queue VMIDs receive
    their register state from MES/KIQ at queue creation.

  - SET_L2_TRAP is a per-VM operation exposed via the existing VM ioctl.
    All shader waves executing under that VMID — whether submitted through
    user queues or kernel queues — see the same second-level handler.

  - For user queues, SET/CLEAR evicts all queues and flushes the GPU TLB
    before writing the descriptor. For kernel queues, the VM is drained
    via amdgpu_vm_wait_idle() before eviction and the write.

  - Both TBA and TMA BOs must be allocated with VM_ALWAYS_VALID. The GPU
    jumps to TBA automatically on exception without any software job
    submission, so the kernel cannot add them to a job's used-buffer list.
        
Only compilation tested.

Srinivasan Shanmugam (4):
  drm/amdgpu: Add second-level trap handler infrastructure
  drm/amdgpu: Make first-level trap state GPUVM-owned
  drm/amdgpu: Program trap TBA/TMA for kernel-managed VMIDs
  drm/amdgpu/uapi: Add SET/CLEAR L2 TRAP to VM ioctl

 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c     |   1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |   8 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c    | 288 ++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h    |  73 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c   |  22 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h   |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      |  44 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h      |   3 +
 drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c |  35 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c   |  35 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c   |  39 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c    |  35 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c    |  35 +++
 include/uapi/drm/amdgpu_drm.h               | 114 ++++++--
 14 files changed, 613 insertions(+), 120 deletions(-)

-- 
2.34.1

Reply via email to