From: Mukul Joshi <[email protected]>

When two threads import the same UALINK handle concurrently, the first
xa_insert() succeeds and the second gets -EBUSY. Convert -EBUSY to
-EAGAIN so user-space retries instead of seeing a spurious error.

Signed-off-by: Mukul Joshi <[email protected]>
Reviewed-by: Felix Kuehling <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index a5dc6a13970f2..68c156c1d281b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3852,9 +3852,15 @@ int amdgpu_ualink_import_handle(struct drm_device *dev,
                              imp_xa_node, GFP_KERNEL);
                if (r) {
                        kfree(imp_xa_node);
-                       dev_err(adev->dev,
-                               "IMPORT: XA insert failed for handle:%llx:%llx 
err:%d\n",
-                               handle.handle_hi, handle.handle_lo, r);
+                       /* -EBUSY means another thread raced us and inserted a
+                        * node for the same handle. Ask user-space to retry.
+                        */
+                       if (r == -EBUSY)
+                               r = -EAGAIN;
+                       else
+                               dev_err(adev->dev,
+                                       "IMPORT: XA insert failed for 
handle:%llx:%llx err:%d\n",
+                                       handle.handle_hi, handle.handle_lo, r);
                        goto out;
                }
 
-- 
2.55.0

Reply via email to