diff mbox series

[v3,4/4] drm/xe: Use get_user / put_user with memory barriers for ufence

Message ID 20240301224919.271153-5-matthew.brost@intel.com (mailing list archive)
State New, archived
Headers show
Series xe_sync and ufence rework | expand

Commit Message

Matthew Brost March 1, 2024, 10:49 p.m. UTC
Better aligns with atomic semantics than copy to/from user.

Suggested-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_sync.c            | 6 +++---
 drivers/gpu/drm/xe/xe_wait_user_fence.c | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/xe/xe_sync.c b/drivers/gpu/drm/xe/xe_sync.c
index bf348d50a0b6..d6d2c8c19f71 100644
--- a/drivers/gpu/drm/xe/xe_sync.c
+++ b/drivers/gpu/drm/xe/xe_sync.c
@@ -116,9 +116,9 @@  static void user_fence_worker(struct work_struct *w)
 			}
 		}
 		if (!ufence->use_page) {
-			if (copy_to_user(ufence->addr, &ufence->value,
-					 sizeof(ufence->value)))
-				drm_warn(&ufence->xe->drm, "copy_to_user failed\n");
+			if (put_user(ufence->value, ufence->addr))
+				drm_warn(&ufence->xe->drm, "put_user failed\n");
+			smp_mb();
 		}
 		kthread_unuse_mm(mm);
 		mmput(mm);
diff --git a/drivers/gpu/drm/xe/xe_wait_user_fence.c b/drivers/gpu/drm/xe/xe_wait_user_fence.c
index f69721339201..af5b9a634c21 100644
--- a/drivers/gpu/drm/xe/xe_wait_user_fence.c
+++ b/drivers/gpu/drm/xe/xe_wait_user_fence.c
@@ -17,11 +17,13 @@ 
 
 static int do_compare(u64 addr, u64 value, u64 mask, u16 op)
 {
+	u64 __user *ptr = u64_to_user_ptr(addr);
 	u64 rvalue;
 	int err;
 	bool passed;
 
-	err = copy_from_user(&rvalue, u64_to_user_ptr(addr), sizeof(rvalue));
+	smp_mb();
+	err = get_user(rvalue, ptr);
 	if (err)
 		return -EFAULT;