Skip to content

Commit dc023a2

Browse files
wegorz76gregkh
authored andcommitted
drm/xe/xe_sync: avoid race during ufence signaling
[ Upstream commit 04e1f68 ] Marking ufence as signalled after copy_to_user() is too late. Worker thread which signals ufence by memory write might be raced with another userspace vm-bind call. In map/unmap scenario unmap may still see ufence is not signalled causing -EBUSY. Change the order of marking / write to user-fence fixes this issue. Fixes: 977e5b8 ("drm/xe: Expose user fence from xe_sync_entry") Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/5536 Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> Cc: Matthew Brost <matthew.brost@intel.com> Cc: Matthew Auld <matthew.auld@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://lore.kernel.org/r/20250820083903.2109891-2-zbigniew.kempczynski@intel.com (cherry picked from commit 8ae04fe) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 630c0e6 commit dc023a2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/gpu/drm/xe/xe_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void user_fence_worker(struct work_struct *w)
7777
{
7878
struct xe_user_fence *ufence = container_of(w, struct xe_user_fence, worker);
7979

80+
WRITE_ONCE(ufence->signalled, 1);
8081
if (mmget_not_zero(ufence->mm)) {
8182
kthread_use_mm(ufence->mm);
8283
if (copy_to_user(ufence->addr, &ufence->value, sizeof(ufence->value)))
@@ -91,7 +92,6 @@ static void user_fence_worker(struct work_struct *w)
9192
* Wake up waiters only after updating the ufence state, allowing the UMD
9293
* to safely reuse the same ufence without encountering -EBUSY errors.
9394
*/
94-
WRITE_ONCE(ufence->signalled, 1);
9595
wake_up_all(&ufence->xe->ufence_wq);
9696
user_fence_put(ufence);
9797
}

0 commit comments

Comments
 (0)