drm/xe/display: fix ttm_bo_access() usage
authorMatthew Auld <matthew.auld@intel.com>
Mon, 2 Dec 2024 17:01:03 +0000 (17:01 +0000)
committerMatthew Auld <matthew.auld@intel.com>
Wed, 4 Dec 2024 10:28:33 +0000 (10:28 +0000)
ttm_bo_access() returns the size on success, account for that otherwise
the caller incorrectly thinks this is an error in
intel_atomic_prepare_plane_clear_colors().

v2 (Thomas)
 - Make sure we check for the partial copy case. Also since this api is
   easy to get wrong, wrap the whole thing in a new helper to hide the
   details and then convert the existing users over.

Fixes: b6308aaa24a7 ("drm/xe/display: Update intel_bo_read_from_page to use ttm_bo_access")
Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/3661
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241202170102.88893-2-matthew.auld@intel.com
drivers/gpu/drm/xe/display/intel_bo.c
drivers/gpu/drm/xe/xe_bo.c
drivers/gpu/drm/xe/xe_bo.h
drivers/gpu/drm/xe/xe_vm.c

index 43141964f6f23f171a925994e683957cb84c3354..b463f5bd4eed11e1f93671bb8d42bc5d58d5b9d2 100644 (file)
@@ -41,7 +41,7 @@ int intel_bo_read_from_page(struct drm_gem_object *obj, u64 offset, void *dst, i
 {
        struct xe_bo *bo = gem_to_xe_bo(obj);
 
-       return ttm_bo_access(&bo->ttm, offset, dst, size, 0);
+       return xe_bo_read(bo, offset, dst, size);
 }
 
 struct intel_frontbuffer *intel_bo_get_frontbuffer(struct drm_gem_object *obj)
index f51d86511cb9e6f74b9c599244e162377cfc09ea..73689dd7d672a02a9649e05ea10eed1605cae8eb 100644 (file)
@@ -1320,6 +1320,30 @@ static int xe_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
        return ret;
 }
 
+/**
+ * xe_bo_read() - Read from an xe_bo
+ * @bo: The buffer object to read from.
+ * @offset: The byte offset to start reading from.
+ * @dst: Location to store the read.
+ * @size: Size in bytes for the read.
+ *
+ * Read @size bytes from the @bo, starting from @offset, storing into @dst.
+ *
+ * Return: Zero on success, or negative error.
+ */
+int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size)
+{
+       int ret;
+
+       ret = ttm_bo_access(&bo->ttm, offset, dst, size, 0);
+       if (ret >= 0 && ret != size)
+               ret = -EIO;
+       else if (ret == size)
+               ret = 0;
+
+       return ret;
+}
+
 static const struct vm_operations_struct xe_gem_vm_ops = {
        .fault = xe_gem_fault,
        .open = ttm_bo_vm_open,
index d0dce44317c74dc03bf10d5cf901953f4c72d095..d9386ab031404d1de21d81c1c8b545f0be25d8dd 100644 (file)
@@ -228,6 +228,7 @@ xe_bo_ggtt_addr(struct xe_bo *bo)
 
 int xe_bo_vmap(struct xe_bo *bo);
 void xe_bo_vunmap(struct xe_bo *bo);
+int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size);
 
 bool mem_type_is_vram(u32 mem_type);
 bool xe_bo_is_vram(struct xe_bo *bo);
index 610226c7c1cef78fd74a869d8b351094c4594ce8..183ec8f7698a0832df530297decdea6673545a20 100644 (file)
@@ -3322,12 +3322,8 @@ void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap)
                }
 
                if (bo) {
-                       err = ttm_bo_access(&bo->ttm, snap->snap[i].bo_ofs,
-                                           snap->snap[i].data, snap->snap[i].len, 0);
-                       if (!(err < 0) && err != snap->snap[i].len)
-                               err = -EIO;
-                       else if (!(err < 0))
-                               err = 0;
+                       err = xe_bo_read(bo, snap->snap[i].bo_ofs,
+                                        snap->snap[i].data, snap->snap[i].len);
                } else {
                        void __user *userptr = (void __user *)(size_t)snap->snap[i].bo_ofs;