All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>
Cc: <amd-gfx@lists.freedesktop.org>,
	Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Subject: [RFC PATCH 1/2] drm/amdgpu: Add kernel VMID trap handler infrastructure
Date: Wed, 2 Sep 2026 20:36:55 +0530	[thread overview]
Message-ID: <20260902150656.183333-2-srinivasan.shanmugam@amd.com> (raw)
In-Reply-To: <20260902150656.183333-1-srinivasan.shanmugam@amd.com>

MES owns kernel queue VMIDs (1..first_kfd_vmid-1) but does not program
SQ_SHADER_TBA/TMA registers for them. Add infrastructure to let the
driver program the first-level CWSR trap handler for these VMIDs directly
via SRBM select.

Add kq_tma_bo — a pinned GTT BO used as device-level TMA scratch for
kernel queue VMIDs. Unlike per-process TMA (created in amdgpu_trap_alloc),
this is device-level and lives for the lifetime of the device. It is
zero-initialized by the OS: the second-level handler address is 0 until
userspace calls SET_L2_TRAP.

Add amdgpu_trap_program_kernel_vmids() which dispatches to a per-HW
vmhub callback, and a new program_kernel_trap_vmids hook in
amdgpu_vmhub_funcs for per-GFX-generation register writes.

Required for:
  - RADV graphics debugging on Vega/Navi/Steam Deck (Valve request)
  - Consistent trap handler behavior when switching between kernel
    queues and user queues

Suggested-by: Christian König <christian.koenig@amd.com>
Cc: Alexander Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Change-Id: I0709e788835b69d3d492864de8d5c2d36d0f08c8
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 37 ++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h |  2 ++
 3 files changed, 40 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 3ca187f5ade8..5624a5ab5c62 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -115,6 +115,7 @@ struct amdgpu_vmhub_funcs {
 	void (*print_l2_protection_fault_status)(struct amdgpu_device *adev,
 						 uint32_t status);
 	uint32_t (*get_invalidate_req)(unsigned int vmid, uint32_t flush_type);
+	void (*program_kernel_trap_vmids)(struct amdgpu_device *adev);
 };
 
 struct amdgpu_vmhub {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
index 31f653ec3fb1..0e0aeea0aa2d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
@@ -256,8 +256,23 @@ int amdgpu_trap_init(struct amdgpu_device *adev)
 
 	memcpy(ptr, trap_info->isa_buf, trap_info->isa_sz);
 
+	/*
+	 * Device-level TMA for kernel queue VMIDs. Pinned GTT — not subject
+	 * to eviction. Zero-initialized by OS: second-level handler address
+	 * is 0 until userspace calls SET_L2_TRAP.
+	 */
+	r = amdgpu_bo_create_kernel(adev, AMDGPU_TRAP_TMA_MAX_SIZE, PAGE_SIZE,
+				    AMDGPU_GEM_DOMAIN_GTT,
+				    &trap_info->kq_tma_bo, NULL, NULL);
+	if (r) {
+		/* isa_bo freed explicitly; trap_info struct freed by __free */
+		amdgpu_bo_free_kernel(&trap_info->isa_bo, NULL, NULL);
+		return r;
+	}
+
 	amdgpu_trap_cwsr_init_save_area_info(adev, trap_info);
 	adev->trap_info = no_free_ptr(trap_info);
+	amdgpu_trap_program_kernel_vmids(adev);
 
 	return 0;
 }
@@ -267,11 +282,33 @@ void amdgpu_trap_fini(struct amdgpu_device *adev)
 	if (!amdgpu_trap_is_enabled(adev))
 		return;
 
+	amdgpu_bo_free_kernel(&adev->trap_info->kq_tma_bo, NULL, NULL);
 	amdgpu_bo_free_kernel(&adev->trap_info->isa_bo, NULL, NULL);
 	kfree(adev->trap_info);
 	adev->trap_info = NULL;
 }
 
+/**
+ * amdgpu_trap_program_kernel_vmids - program first-level trap handler for
+ *                                    kernel queue VMIDs
+ * @adev: amdgpu device pointer
+ *
+ * Programs SQ_SHADER_TBA/TMA for kernel queue VMIDs (1..first_kfd_vmid-1)
+ * via SRBM select. MES owns these VMIDs but does not program trap handler
+ * state. Called after trap init and on GPU resume via setup_vmid_config.
+ */
+void amdgpu_trap_program_kernel_vmids(struct amdgpu_device *adev)
+{
+	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
+
+	if (!amdgpu_trap_is_enabled(adev))
+		return;
+	if (!hub->vmhub_funcs || !hub->vmhub_funcs->program_kernel_trap_vmids)
+		return;
+
+	hub->vmhub_funcs->program_kernel_trap_vmids(adev);
+}
+
 /*
  * amdgpu_map_cwsr_trap_handler should be called during amdgpu_vm_init
  * it maps virtual address amdgpu_trap_tba_vaddr() to this VM, and each
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
index 6d4664469bad..326910f1d94d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
@@ -48,6 +48,7 @@ struct amdgpu_trap_obj {
 struct amdgpu_trap_info {
 	/* cwsr isa */
 	struct amdgpu_bo *isa_bo;
+	struct amdgpu_bo *kq_tma_bo;	/* pinned GTT, device-level TMA for kernel queue VMIDs */
 	const void *isa_buf;
 	uint32_t isa_sz;
 	/* cwsr size info per XCC*/
@@ -70,6 +71,7 @@ struct amdgpu_trap_usr_addr {
 };
 
 int amdgpu_trap_init(struct amdgpu_device *adev);
+void amdgpu_trap_program_kernel_vmids(struct amdgpu_device *adev);
 void amdgpu_trap_fini(struct amdgpu_device *adev);
 
 int amdgpu_trap_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-- 
2.34.1


  reply	other threads:[~2026-09-02 15:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 15:06 [RFC PATCH 0/2] drm/amdgpu: First-level trap handler for kernel queue VMIDs Srinivasan Shanmugam
2026-09-02 15:06 ` Srinivasan Shanmugam [this message]
2026-09-02 15:28   ` [RFC PATCH 1/2] drm/amdgpu: Add kernel VMID trap handler infrastructure Lazar, Lijo
2026-09-02 15:59     ` SHANMUGAM, SRINIVASAN
2026-09-02 16:11       ` Lazar, Lijo
2026-09-02 16:55         ` Deucher, Alexander
2026-09-03  4:02           ` Lazar, Lijo
2026-09-03  4:03             ` Lazar, Lijo
2026-09-03  7:09               ` Christian König
2026-09-03  9:34                 ` SHANMUGAM, SRINIVASAN
2026-09-02 15:45   ` Deucher, Alexander
2026-09-02 15:06 ` [RFC PATCH 2/2] drm/amdgpu: Implement kernel VMID trap handler for GFX10/11/12 Srinivasan Shanmugam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902150656.183333-2-srinivasan.shanmugam@amd.com \
    --to=srinivasan.shanmugam@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.