Skip to content

drm/amdgpu: secure userq lifecycle by its kref

Zhu Lingshan amd-gfx 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v1 Latest posting 2/210 patches 4 repliesIn review
  2. v1 posting 1/210 patches 18 repliesSuperseded

Patches in v1 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10drm/amdgpu: introduce amdgpu_lookup_queue_by_doorbelldrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h+32 -00 replies
2/10drm/amdgpu: keep the userq manager alive as long as its queuesdrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h+39 -00 replies
3/10drm/amdgpu/gfx11: hold userq refs in private fault workerdrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c+5 -20 replies
4/10drm/amdgpu/gfx12: hold userq refs in private fault workerdrivers/gpu/drm/amd/amdgpu/gfx_v12_0.c+5 -20 replies
5/10drm/amdgpu: implement asynchronous userq destruction routinedrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h+19 -30 replies
6/10drm/amdgpu: hold userq kref in MES resetdrivers/gpu/drm/amd/amdgpu/mes_userqueue.c+23 -230 replies
7/10drm/amdgpu: hold userq kref during isolation schedulingdrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c+68 -40 replies
8/10drm/amdgpu: hold userq kref during suspend and resumedrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c+29 -60 replies
9/10drm/amdgpu: free userq by kref_put when fails to createdrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c+15 -50 replies
10/10drm/amdgpu: take queue kref in userq_create to avoid UAFdrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c+11 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RESEND 00/10] drm/amdgpu: secure userq lifecycle by its kref

A struct kref is embedded in user queue, which manages the lifecycle of a user queue. However, several code paths access user queues without hoding the kref of a user queue, especially from the doorbell XArray.

These accesses can race with the queue destruction process and result in use-after-free bugs.

To fix this issue, this commit:
1) Introduces a new helper amdgpu_lookup_queue_by_doorbell, which looks up a user queue with locking and hold its kref during access.

2) Implement asynchronous userq destruction routine, because the last put of a queue kref may be placed in a code path where can not sleep or conflict locking with the destruction process.

3) Hold kref during access the user queues

4) Keep the userq manager alive as long as its queues, to avoid UAF issues.

This seires passed amd_basic tests in igt tests

Link to previus discussions: https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.html

Please help review

Thanks
Lingshan

Zhu Lingshan (10):
drm/amdgpu: introduce amdgpu_lookup_queue_by_doorbell drm/amdgpu: keep the userq manager alive as long as its queues drm/amdgpu/gfx11: hold userq refs in private fault worker drm/amdgpu/gfx12: hold userq refs in private fault worker drm/amdgpu: implement asynchronous userq destruction routine drm/amdgpu: hold userq kref in MES reset
drm/amdgpu: hold userq kref during isolation scheduling drm/amdgpu: hold userq kref during suspend and resume drm/amdgpu: free userq by kref_put when fails to create drm/amdgpu: take queue kref in userq_create to avoid UAF

 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 214 +++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |  18 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |   7 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c     |   7 +-
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c |  46 ++---
 5 files changed, 246 insertions(+), 46 deletions(-)
Signature · 1 line
2.53.0