Skip to content

Commit c537fb4

Browse files
author
Thomas Zimmermann
committed
drm/qxl: Pin buffer objects for internal mappings
Add qxl_bo_pin_and_vmap() that pins and vmaps a buffer object in one step. Update callers of the regular qxl_bo_vmap(). Fixes a bug where qxl accesses an unpinned buffer object while it is being moved; such as with the monitor-description BO. An typical error is shown below. [ 4.303586] [drm:drm_atomic_helper_commit_planes] *ERROR* head 1 wrong: 65376256x16777216+0+0 [ 4.586883] [drm:drm_atomic_helper_commit_planes] *ERROR* head 1 wrong: 65376256x16777216+0+0 [ 4.904036] [drm:drm_atomic_helper_commit_planes] *ERROR* head 1 wrong: 65335296x16777216+0+0 [ 5.374347] [drm:qxl_release_from_id_locked] *ERROR* failed to find id in release_idr Commit b33651a ("drm/qxl: Do not pin buffer objects for vmap") removed the implicit pin operation from qxl's vmap code. This is the correct behavior for GEM and PRIME interfaces, but the pin is still needed for qxl internal operation. Also add a corresponding function qxl_bo_vunmap_and_unpin() and remove the old qxl_bo_vmap() helpers. Future directions: BOs should not be pinned or vmapped unnecessarily. The pin-and-vmap operation should be removed from the driver and a temporary mapping should be established with a vmap_local-like helper. See the client helper drm_client_buffer_vmap_local() for semantics. v2: - unreserve BO on errors in qxl_bo_pin_and_vmap() (Dmitry) Signed-off-by: Thomas Zimmermann <[email protected]> Fixes: b33651a ("drm/qxl: Do not pin buffer objects for vmap") Reported-by: David Kaplan <[email protected]> Closes: https://lore.kernel.org/dri-devel/[email protected]/ Tested-by: David Kaplan <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Cc: Thomas Zimmermann <[email protected]> Cc: Dmitry Osipenko <[email protected]> Cc: Christian König <[email protected]> Cc: Zack Rusin <[email protected]> Cc: Dave Airlie <[email protected]> Cc: Gerd Hoffmann <[email protected]> Cc: [email protected] Cc: [email protected] Reviewed-by: Dmitry Osipenko <[email protected]> Reviewed-by: Zack Rusin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ec85147 commit c537fb4

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

drivers/gpu/drm/qxl/qxl_display.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,11 @@ static struct qxl_bo *qxl_create_cursor(struct qxl_device *qdev,
584584
if (ret)
585585
goto err;
586586

587-
ret = qxl_bo_vmap(cursor_bo, &cursor_map);
587+
ret = qxl_bo_pin_and_vmap(cursor_bo, &cursor_map);
588588
if (ret)
589589
goto err_unref;
590590

591-
ret = qxl_bo_vmap(user_bo, &user_map);
591+
ret = qxl_bo_pin_and_vmap(user_bo, &user_map);
592592
if (ret)
593593
goto err_unmap;
594594

@@ -614,12 +614,12 @@ static struct qxl_bo *qxl_create_cursor(struct qxl_device *qdev,
614614
user_map.vaddr, size);
615615
}
616616

617-
qxl_bo_vunmap(user_bo);
618-
qxl_bo_vunmap(cursor_bo);
617+
qxl_bo_vunmap_and_unpin(user_bo);
618+
qxl_bo_vunmap_and_unpin(cursor_bo);
619619
return cursor_bo;
620620

621621
err_unmap:
622-
qxl_bo_vunmap(cursor_bo);
622+
qxl_bo_vunmap_and_unpin(cursor_bo);
623623
err_unref:
624624
qxl_bo_unpin(cursor_bo);
625625
qxl_bo_unref(&cursor_bo);
@@ -1205,7 +1205,7 @@ int qxl_create_monitors_object(struct qxl_device *qdev)
12051205
}
12061206
qdev->monitors_config_bo = gem_to_qxl_bo(gobj);
12071207

1208-
ret = qxl_bo_vmap(qdev->monitors_config_bo, &map);
1208+
ret = qxl_bo_pin_and_vmap(qdev->monitors_config_bo, &map);
12091209
if (ret)
12101210
return ret;
12111211

@@ -1236,7 +1236,7 @@ int qxl_destroy_monitors_object(struct qxl_device *qdev)
12361236
qdev->monitors_config = NULL;
12371237
qdev->ram_header->monitors_config = 0;
12381238

1239-
ret = qxl_bo_vunmap(qdev->monitors_config_bo);
1239+
ret = qxl_bo_vunmap_and_unpin(qdev->monitors_config_bo);
12401240
if (ret)
12411241
return ret;
12421242

drivers/gpu/drm/qxl/qxl_object.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,23 @@ int qxl_bo_vmap_locked(struct qxl_bo *bo, struct iosys_map *map)
182182
return 0;
183183
}
184184

185-
int qxl_bo_vmap(struct qxl_bo *bo, struct iosys_map *map)
185+
int qxl_bo_pin_and_vmap(struct qxl_bo *bo, struct iosys_map *map)
186186
{
187187
int r;
188188

189189
r = qxl_bo_reserve(bo);
190190
if (r)
191191
return r;
192192

193+
r = qxl_bo_pin_locked(bo);
194+
if (r) {
195+
qxl_bo_unreserve(bo);
196+
return r;
197+
}
198+
193199
r = qxl_bo_vmap_locked(bo, map);
200+
if (r)
201+
qxl_bo_unpin_locked(bo);
194202
qxl_bo_unreserve(bo);
195203
return r;
196204
}
@@ -241,7 +249,7 @@ void qxl_bo_vunmap_locked(struct qxl_bo *bo)
241249
ttm_bo_vunmap(&bo->tbo, &bo->map);
242250
}
243251

244-
int qxl_bo_vunmap(struct qxl_bo *bo)
252+
int qxl_bo_vunmap_and_unpin(struct qxl_bo *bo)
245253
{
246254
int r;
247255

@@ -250,6 +258,7 @@ int qxl_bo_vunmap(struct qxl_bo *bo)
250258
return r;
251259

252260
qxl_bo_vunmap_locked(bo);
261+
qxl_bo_unpin_locked(bo);
253262
qxl_bo_unreserve(bo);
254263
return 0;
255264
}

drivers/gpu/drm/qxl/qxl_object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ extern int qxl_bo_create(struct qxl_device *qdev,
5959
u32 priority,
6060
struct qxl_surface *surf,
6161
struct qxl_bo **bo_ptr);
62-
int qxl_bo_vmap(struct qxl_bo *bo, struct iosys_map *map);
62+
int qxl_bo_pin_and_vmap(struct qxl_bo *bo, struct iosys_map *map);
6363
int qxl_bo_vmap_locked(struct qxl_bo *bo, struct iosys_map *map);
64-
int qxl_bo_vunmap(struct qxl_bo *bo);
64+
int qxl_bo_vunmap_and_unpin(struct qxl_bo *bo);
6565
void qxl_bo_vunmap_locked(struct qxl_bo *bo);
6666
void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, int page_offset);
6767
void qxl_bo_kunmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, void *map);

0 commit comments

Comments
 (0)