drm/amdgpu: Fix UserQ fence driver reference race
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix UserQ fence driver reference race
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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2 -2
@@ -912,12 +912,12 @@ amdgpu_userq_wait_return_fence_info(struct drm_device *dev, struct drm_file *filmutex_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 */
Signature · 1 line
2.56.1
Christian König
maintainerQuoted 4 lines · Erhan Bilgili
USERQ_WAITadds the driver tofence_drv_xabefore taking its reference. Once the lock is dropped,USERQ_SIGNALcan remove the entry and put the driver before WAIT gets its reference. This can free the driver while WAIT is still using it.
The fence is holding the reference to the fence driver so that is completely unnecessary.
Quoted 3 lines
Take the reference before dropping
fence_drv_lock.
That just unnecessarily complicates the code.
It could be that we change the userq fence so that it doesn't hold the fence driver reference in the future, but that would require a completely different approach here.
Regards,
Christian.
Quoted 25 lines
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(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -912,12 +912,12 @@ amdgpu_userq_wait_return_fence_info(struct drm_device *dev, struct drm_file *filmutex_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 */