Skip to contentSkip to conversation

drm/amdgpu: look up the L2 trap handler mappings by GPU page

PATCH In review Jesse Zhang 2 participants 3 messages Nov 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: look up the L2 trap handler mappings by GPU page

amdgpu_trap_validate_user_addr() passes the byte address of the second level TBA and TMA to amdgpu_vm_bo_lookup_mapping(), but the VM mappings are indexed by GPU page number, like every other caller of it does and like the range check right after it assumes. The lookup never finds the mapping, so SET_L2_TRAP fails with -EINVAL for any valid TBA/TMA.

On navi48 with the VM ioctl SET_L2_TRAP added, the IGT slth-* tests map the TBA at 0x100000000 and the lookup of 0x100000000 returns NULL, while the mapping is at page 0x100000. With the page number the lookup finds the mapping and slth-{gfx,comp}-kq-vgpr-proof, slth-gfx-umq-vgpr-proof and slth-comp-kq-returnproof pass.

Look the mapping up by page number.

CC Christian Koenig <[email protected]>
CC Lijo Lazar <[email protected]>
CC Srinivasan Shanmugam <[email protected]>
Fixes 1a6f95d4a5d7 ("drm/amdgpu: Add second-level trap handler infrastructure")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +5 -8
index 3660f94a0929..52e4d30e63fa 100644
@@ -622,17 +622,14 @@ static int amdgpu_trap_validate_user_addr(struct amdgpu_device *adev,
 	if (check_add_overflow(start, (u64)usr_addr->size - 1, &end))
 		return -EINVAL;
 
-	/*
-	 * amdgpu_vm_bo_lookup_mapping() expects a GPU VA,
-	 * not a page-shifted address.
-	 */
-	va_map = amdgpu_vm_bo_lookup_mapping(vm, start);
-	if (!va_map)
-		return -EINVAL;
-
 	addr = start >> AMDGPU_GPU_PAGE_SHIFT;
 	last = end >> AMDGPU_GPU_PAGE_SHIFT;
 
+	/* The VM mappings are indexed by GPU page number */
+	va_map = amdgpu_vm_bo_lookup_mapping(vm, addr);
+	if (!va_map)
+		return -EINVAL;
+
 	if (addr < va_map->start || last > va_map->last)
 		return -EINVAL;
 
Signature · 1 line
2.50.1
#1 lore raw

AMD General

drop this patch. It is only needed on the amd-unified-interface branch, which is missing a prerequisite change; the latest amd-staging-drm-next does not need it.

Quoted 68 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Monday, November 16, 2026 11:23 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; SHANMUGAM, SRINIVASAN <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH] drm/amdgpu: look up the L2 trap handler mappings by GPU page

amdgpu_trap_validate_user_addr() passes the byte address of the second level TBA and TMA to amdgpu_vm_bo_lookup_mapping(), but the VM mappings are indexed by GPU page number, like every other caller of it does and like the range check right after it assumes. The lookup never finds the mapping, so SET_L2_TRAP fails with -EINVAL for any valid TBA/TMA.

On navi48 with the VM ioctl SET_L2_TRAP added, the IGT slth-* tests map the TBA at 0x100000000 and the lookup of 0x100000000 returns NULL, while the mapping is at page 0x100000. With the page number the lookup finds the mapping and slth-{gfx,comp}-kq-vgpr-proof, slth-gfx-umq-vgpr-proof and slth-comp-kq-returnproof pass.

Look the mapping up by page number.

CC:[email protected]
CC:Christian Koenig <[email protected]> CC:Lijo Lazar <[email protected]> CC:Srinivasan Shanmugam <[email protected]>

Fixes 1a6f95d4a5d7 ("drm/amdgpu: Add second-level trap handler

infrastructure")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +5 -9
index 3660f94a0929..52e4d30e63fa 100644
@@ -622,17 +622,14 @@ static int amdgpu_trap_validate_user_addr(struct
 amdgpu_device *adev,
      if (check_add_overflow(start, (u64)usr_addr->size - 1, &end))
              return -EINVAL;
 
-     /*
-      * amdgpu_vm_bo_lookup_mapping() expects a GPU VA,
-      * not a page-shifted address.
-      */
-     va_map = amdgpu_vm_bo_lookup_mapping(vm, start);
-     if (!va_map)
-             return -EINVAL;
-
      addr = start >> AMDGPU_GPU_PAGE_SHIFT;
      last = end >> AMDGPU_GPU_PAGE_SHIFT;
 
+     /* The VM mappings are indexed by GPU page number */
+     va_map = amdgpu_vm_bo_lookup_mapping(vm, addr);
+     if (!va_map)
+             return -EINVAL;
+
      if (addr < va_map->start || last > va_map->last)
              return -EINVAL;
 
--

2.50.1

maintainer
#2 lore raw
In reply to Jesse Zhang
Quoted 40 lines · Jesse Zhang

amdgpu_trap_validate_user_addr() passes the byte address of the second level TBA and TMA to amdgpu_vm_bo_lookup_mapping(), but the VM mappings are indexed by GPU page number, like every other caller of it does and like the range check right after it assumes. The lookup never finds the mapping, so SET_L2_TRAP fails with -EINVAL for any valid TBA/TMA.

On navi48 with the VM ioctl SET_L2_TRAP added, the IGT slth-* tests map the TBA at 0x100000000 and the lookup of 0x100000000 returns NULL, while the mapping is at page 0x100000. With the page number the lookup finds the mapping and slth-{gfx,comp}-kq-vgpr-proof, slth-gfx-umq-vgpr-proof and slth-comp-kq-returnproof pass.

Look the mapping up by page number.

CC Christian Koenig <[email protected]>
CC Lijo Lazar <[email protected]>
CC Srinivasan Shanmugam <[email protected]>
Fixes 1a6f95d4a5d7 ("drm/amdgpu: Add second-level trap handler infrastructure")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +0 -7
index 3660f94a0929..52e4d30e63fa 100644
@@ -622,17 +622,14 @@ static int amdgpu_trap_validate_user_addr(struct amdgpu_device *adev,
 	if (check_add_overflow(start, (u64)usr_addr->size - 1, &end))
 		return -EINVAL;
 
-	/*
-	 * amdgpu_vm_bo_lookup_mapping() expects a GPU VA,
-	 * not a page-shifted address.
-	 */
-	va_map = amdgpu_vm_bo_lookup_mapping(vm, start);
-	if (!va_map)
-		return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c static int amdgpu_trap_validate_user_addr(struct amdgpu_device *adev, · line 633

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +5 -1
-
 	addr = start >> AMDGPU_GPU_PAGE_SHIFT;
 	last = end >> AMDGPU_GPU_PAGE_SHIFT;
 
+	/* The VM mappings are indexed by GPU page number */
+	va_map = amdgpu_vm_bo_lookup_mapping(vm, addr);
+	if (!va_map)
+		return -EINVAL;
+
 	if (addr < va_map->start || last > va_map->last)

Only a nit but the addr < va_map->start check here doesn't make sense, only the last > va_map->last does.

With that fixed Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +0 -0
 		return -EINVAL;