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

Matthew Brost matthew.brost at intel.com
Fri Mar 1 22:49:19 UTC 2024


Better aligns with atomic semantics than copy to/from user.

Suggested-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost at 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 --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;
 
-- 
2.34.1



More information about the Intel-xe mailing list