All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] drm/amdgpu: Second-level trap handler for kernel queues
@ 2026-09-05  8:19 Srinivasan Shanmugam
  2026-09-05  8:19 ` [PATCH 1/3] drm/amdgpu: Add per-VM kernel queue first-level trap handler infrastructure Srinivasan Shanmugam
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Srinivasan Shanmugam @ 2026-09-05  8:19 UTC (permalink / raw)
  To: Christian König, Alex Deucher; +Cc: amd-gfx, Srinivasan Shanmugam

Background
----------
When a GPU shader crashes or hits an exception, the hardware
automatically jumps to a trap handler. There are two levels:

  First-level  — always active, managed by the kernel (CWSR)
  Second-level — optional, installed by userspace (RADV, ROCm)

The second-level handler lets userspace debuggers catch GPU crashes
and inspect what went wrong.

Problem
-------
The existing second-level trap handler support (merged earlier) only
works for user queues. RADV on GFX9 and GFX10 hardware (Vega, Navi,
Steam Deck) uses kernel queues — not user queues — because user queues
are not supported on those GPUs. This means RADV has no way to install
a second-level trap handler for shader debugging on those platforms.

Root cause: the SQ_SHADER_TMA register for kernel queue VMIDs was
never programmed by the driver, so there was nowhere to store the
second-level handler address.

Solution
--------
This series fixes the problem in three steps:

Patch 1 — Infrastructure
  - Allocate a small per-VM TMA buffer (kq_tma_bo) at VM creation time,
    the same way page tables are allocated.
  - Map it read-only into the GPU VM at a fixed address
    (AMDGPU_VA_RESERVED_TRAP_START).
  - Program SQ_SHADER_TMA for all kernel queue VMIDs to point to this
    fixed address. Because each VM has its own buffer at the same
    address, per-process isolation comes from the page tables — not
    from reprogramming the register per job.

Patch 2 — Hardware register programming (GFX10/11/12)
  - Implement the actual register writes (SQ_SHADER_TBA/TMA) for all
    supported GPU generations via SRBM select.
  - GFX10 uses mm-prefixed registers, GFX11/12 use reg-prefixed.
  - GFX12.1 has multiple XCC instances and iterates over all of them.
  - Called at boot and on GPU resume.

Patch 3 — Wire up SET_L2_TRAP and CLEAR_L2_TRAP
  - When userspace calls SET_L2_TRAP, write the second-level handler
    address into both the user queue TMA and the new kernel queue TMA.
  - When userspace calls CLEAR_L2_TRAP, zero both.
  - No new ioctl needed — RADV uses the same SET_L2_TRAP ioctl that
    user queues already use.

Design decisions
----------------
  - kq_tma_bo is per-VM, not device-level. One BO per process,
    same model as page tables.
  - Fixed VA (AMDGPU_VA_RESERVED_TRAP_START) in every VM's address
    space. Same register value for all VMIDs — isolation via page tables.
  - GPU sees it as read-only. Kernel CPU updates it via CPU mapping
    when SET_L2_TRAP is called.
  - Lifecycle matches page tables: allocated at VM init, freed at
    VM fini.
	
Only compilation tested.

Srinivasan Shanmugam (3):
  drm/amdgpu: Add per-VM kernel queue first-level trap handler
    infrastructure
  drm/amdgpu: Implement kernel VMID SQ_SHADER_TBA/TMA programming for
    GFX10/11/12
  drm/amdgpu: Extend second-level trap handler to kernel queues

 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h     |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c    | 107 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h    |   7 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      |   9 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h      |  13 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c |  38 +++++++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c   |  38 +++++++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c   |  36 +++++++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c    |  38 +++++++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c    |  33 ++++++
 10 files changed, 320 insertions(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-09-11 15:18 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-05  8:19 [PATCH 0/3] drm/amdgpu: Second-level trap handler for kernel queues Srinivasan Shanmugam
2026-09-05  8:19 ` [PATCH 1/3] drm/amdgpu: Add per-VM kernel queue first-level trap handler infrastructure Srinivasan Shanmugam
2026-09-09  7:45   ` Lazar, Lijo
2026-09-09 13:02     ` SRINIVASAN SHANMUGAM
2026-09-09 17:58       ` Lazar, Lijo
2026-09-09 18:54         ` Alex Deucher
2026-09-10  2:06           ` Lazar, Lijo
2026-09-10  5:23             ` Lazar, Lijo
2026-09-11 14:07               ` Alex Deucher
2026-09-11 14:09                 ` Alex Deucher
2026-09-11 15:17                   ` Lazar, Lijo
2026-09-09 19:23   ` Alex Deucher
2026-09-09 20:39     ` Alex Deucher
2026-09-09 20:42   ` Alex Deucher
2026-09-09 20:50     ` Alex Deucher
2026-09-10  6:13       ` SRINIVASAN SHANMUGAM
2026-09-10  6:57         ` Lazar, Lijo
2026-09-10  8:25           ` SRINIVASAN SHANMUGAM
2026-09-10  9:43             ` Lazar, Lijo
2026-09-10  9:43             ` Lazar, Lijo
2026-09-11 14:41             ` Alex Deucher
2026-09-05  8:19 ` [PATCH 2/3] drm/amdgpu: Implement kernel VMID SQ_SHADER_TBA/TMA programming for GFX10/11/12 Srinivasan Shanmugam
2026-09-09 20:38   ` Alex Deucher
2026-09-05  8:19 ` [PATCH 3/3] drm/amdgpu: Extend second-level trap handler to kernel queues Srinivasan Shanmugam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.