linux/drivers/gpu/drm/amd
Sunil Khatri 65b5c326ce drm/amdgpu/userq: refcount userqueues to avoid any race conditions
To avoid race condition and avoid UAF cases, implement kref
based queues and protect the below operations using xa lock
a. Getting a queue from xarray
b. Increment/Decrement it's refcount

Every time some one want to access a queue, always get via
amdgpu_userq_get to make sure we have locks in place and get
the object if active.

A userqueue is destroyed on the last refcount is dropped which
typically would be via IOCTL or during fini.

v2: Add the missing drop in one the condition in the signal ioclt [Alex]

v3: remove the queue from the xarray first in the free queue ioctl path
    [Christian]

- Pass queue to the amdgpu_userq_put directly.
- make amdgpu_userq_put xa_lock free since we are doing put for each get
  only and final put is done via destroy and we remove the queue from xa
  with lock.
- use userq_put in fini too so cleanup is done fully.

v4: Use xa_erase directly rather than doing load and erase in free
    ioctl. Also remove some of the error logs which could be exploited
    by the user to flood the logs [Christian]

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 4952189b284d4d847f92636bb42dd747747129c0)
Cc: <stable@vger.kernel.org> # 048c1c4e51: drm/amdgpu/userq: Consolidate wait ioctl exit path
Cc: <stable@vger.kernel.org>
2026-03-04 13:15:00 -05:00
..
acp
amdgpu drm/amdgpu/userq: refcount userqueues to avoid any race conditions 2026-03-04 13:15:00 -05:00
amdkfd Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
amdxcp drm/amd/amdgpu: Release xcp drm memory after unplug 2025-08-04 14:35:48 -04:00
display drm/amd/display: Fallback to boot snapshot for dispclk 2026-03-02 17:13:52 -05:00
include drm/amdgpu/psp: Use Indirect access address for GFX to PSP mailbox 2026-03-04 13:15:00 -05:00
pm drm/amd/pm: remove invalid gpu_metrics.energy_accumulator on smu v13.0.x 2026-03-04 13:14:59 -05:00
ras Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00