Skip to content

Commit 125a66a

Browse files
committed
drm/xe/display: fix ttm_bo_access() usage
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: b6308aa ("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 <[email protected]> Cc: Thomas Hellström <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Jani Nikula <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Reviewed-by: Nirmoy Das <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 20124c3 commit 125a66a

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

drivers/gpu/drm/xe/display/intel_bo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int intel_bo_read_from_page(struct drm_gem_object *obj, u64 offset, void *dst, i
4141
{
4242
struct xe_bo *bo = gem_to_xe_bo(obj);
4343

44-
return ttm_bo_access(&bo->ttm, offset, dst, size, 0);
44+
return xe_bo_read(bo, offset, dst, size);
4545
}
4646

4747
struct intel_frontbuffer *intel_bo_get_frontbuffer(struct drm_gem_object *obj)

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,30 @@ static int xe_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
13201320
return ret;
13211321
}
13221322

1323+
/**
1324+
* xe_bo_read() - Read from an xe_bo
1325+
* @bo: The buffer object to read from.
1326+
* @offset: The byte offset to start reading from.
1327+
* @dst: Location to store the read.
1328+
* @size: Size in bytes for the read.
1329+
*
1330+
* Read @size bytes from the @bo, starting from @offset, storing into @dst.
1331+
*
1332+
* Return: Zero on success, or negative error.
1333+
*/
1334+
int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size)
1335+
{
1336+
int ret;
1337+
1338+
ret = ttm_bo_access(&bo->ttm, offset, dst, size, 0);
1339+
if (ret >= 0 && ret != size)
1340+
ret = -EIO;
1341+
else if (ret == size)
1342+
ret = 0;
1343+
1344+
return ret;
1345+
}
1346+
13231347
static const struct vm_operations_struct xe_gem_vm_ops = {
13241348
.fault = xe_gem_fault,
13251349
.open = ttm_bo_vm_open,

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ xe_bo_ggtt_addr(struct xe_bo *bo)
228228

229229
int xe_bo_vmap(struct xe_bo *bo);
230230
void xe_bo_vunmap(struct xe_bo *bo);
231+
int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size);
231232

232233
bool mem_type_is_vram(u32 mem_type);
233234
bool xe_bo_is_vram(struct xe_bo *bo);

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,12 +3322,8 @@ void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap)
33223322
}
33233323

33243324
if (bo) {
3325-
err = ttm_bo_access(&bo->ttm, snap->snap[i].bo_ofs,
3326-
snap->snap[i].data, snap->snap[i].len, 0);
3327-
if (!(err < 0) && err != snap->snap[i].len)
3328-
err = -EIO;
3329-
else if (!(err < 0))
3330-
err = 0;
3325+
err = xe_bo_read(bo, snap->snap[i].bo_ofs,
3326+
snap->snap[i].data, snap->snap[i].len);
33313327
} else {
33323328
void __user *userptr = (void __user *)(size_t)snap->snap[i].bo_ofs;
33333329

0 commit comments

Comments
 (0)