USERQ_WAIT adds the driver to fence_drv_xa before taking its
reference. Once the lock is dropped, USERQ_SIGNAL can remove the
entry and put the driver before WAIT gets its reference. This can
free the driver while WAIT is still using it.

Take the reference before dropping fence_drv_lock.

Fixes: a292fdecd728 ("drm/amdgpu: Implement userqueue signal/wait IOCTL")
Signed-off-by: Erhan Bilgili <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
index dd976a50e053..13a339918ee3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
@@ -912,12 +912,12 @@ amdgpu_userq_wait_return_fence_info(struct drm_device 
*dev, struct drm_file *fil
                mutex_lock(&waitq->fence_drv_lock);
                r = xa_alloc(&waitq->fence_drv_xa, &index, fence_drv,
                             xa_limit_32b, GFP_KERNEL);
+               if (!r)
+                       amdgpu_userq_fence_driver_get(fence_drv);
                mutex_unlock(&waitq->fence_drv_lock);
                if (r)
                        goto put_waitq;
 
-               amdgpu_userq_fence_driver_get(fence_drv);
-
                trace_amdgpu_userq_wait_deps(dev->dev, waitq, userq_fence);
 
                /* Store drm syncobj's gpu va address and value */
-- 
2.56.1

Reply via email to