Skip to contentSkip to conversation

drm/amdgpu: reject IB addresses with reserved byte-swap bits

PATCH In review John B. Moore 2 participants 2 messages Apr 27 – Apr 28

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

PATCH v3 1/1 drm/amdgpu: reject IB addresses with reserved byte-swap bits

Reject IB GPU addresses with bits [1:0] set early in the CS parser, before they reach ring emission callbacks. On legacy AMD hardware (pre-amdgpu era), these two bits encoded byte-swap mode for IB memory fetches. That feature was dropped on all hardware that amdgpu supports, but the ring emission paths still contain BUG_ON(addr & 0x3) assertions that crash the kernel if userspace submits a misaligned IB address.

Add an early check in amdgpu_cs_p2_ib() to reject such submissions with -EINVAL before the IB is allocated.

Fixes b0635e808290 ("drm/amdgpu: implement GFX 9.0 support (v2)")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +8 -0
index f3b5bcdbf..c44692a2a 100644
@@ -386,6 +386,14 @@ static int amdgpu_cs_p2_ib(struct amdgpu_cs_parser *p,
 	if (chunk_ib->flags & AMDGPU_IB_FLAG_PREAMBLE)
 		job->preamble_status |= AMDGPU_PREAMBLE_IB_PRESENT;
 
+	/* Reject IB addresses with reserved byte-swap bits set.
+	 * On legacy HW (pre-amdgpu), bits [1:0] encoded byte-swap mode
+	 * for IB fetches. That feature is deprecated on all HW that
+	 * amdgpu supports, so these bits must be zero.
+	 */
+	if (chunk_ib->va_start & 0x3)
+		return -EINVAL;
+
 	r =  amdgpu_ib_get(p->adev, vm, ring->funcs->parse_cs ?
 			   chunk_ib->ib_bytes : 0,
 			   AMDGPU_IB_POOL_DELAYED, ib);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 7 lines · John B. Moore

Reject IB GPU addresses with bits [1:0] set early in the CS parser, before they reach ring emission callbacks. On legacy AMD hardware (pre-amdgpu era), these two bits encoded byte-swap mode for IB memory fetches. That feature was dropped on all hardware that amdgpu supports, but the ring emission paths still contain BUG_ON(addr & 0x3) assertions that crash the kernel if userspace submits a misaligned IB address.

Quoted 5 lines

Add an early check in amdgpu_cs_p2_ib() to reject such submissions with -EINVAL before the IB is allocated.

Fixes b0635e808290 ("drm/amdgpu: implement GFX 9.0 support (v2)")

That should probably be dropped. The issue was there much earlier than that.

Quoted 2 lines

@Alex do you want to pick that up or should I do that?

Thanks,
Christian

Quoted 23 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +8 -0
index f3b5bcdbf..c44692a2a 100644
@@ -386,6 +386,14 @@ static int amdgpu_cs_p2_ib(struct amdgpu_cs_parser *p,
 	if (chunk_ib->flags & AMDGPU_IB_FLAG_PREAMBLE)
 		job->preamble_status |= AMDGPU_PREAMBLE_IB_PRESENT;
 
+	/* Reject IB addresses with reserved byte-swap bits set.
+	 * On legacy HW (pre-amdgpu), bits [1:0] encoded byte-swap mode
+	 * for IB fetches. That feature is deprecated on all HW that
+	 * amdgpu supports, so these bits must be zero.
+	 */
+	if (chunk_ib->va_start & 0x3)
+		return -EINVAL;
+
 	r =  amdgpu_ib_get(p->adev, vm, ring->funcs->parse_cs ?
 			   chunk_ib->ib_bytes : 0,
 			   AMDGPU_IB_POOL_DELAYED, ib);