Skip to content

Commit 6305418

Browse files
committed
ttm: don't destroy old mm_node on memcpy failure
When we are using memcpy to move objects around, and we fail to memcpy due to lack of memory to populate or failure to finish the copy, we don't want to destroy the mm_node that has been copied into old_copy. While working on a new kms driver that uses memcpy, if I overallocated bo's up to the memory limits, and eviction failed, then machine would oops soon after due to having an active bo with an already freed drm_mm embedded in it, freeing it a second time didn't end well. Reviewed-by: Jerome Glisse <jglisse@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent ffb5fd5 commit 6305418

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,12 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
344344

345345
if (ttm->state == tt_unpopulated) {
346346
ret = ttm->bdev->driver->ttm_tt_populate(ttm);
347-
if (ret)
347+
if (ret) {
348+
/* if we fail here don't nuke the mm node
349+
* as the bo still owns it */
350+
old_copy.mm_node = NULL;
348351
goto out1;
352+
}
349353
}
350354

351355
add = 0;
@@ -371,8 +375,11 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
371375
prot);
372376
} else
373377
ret = ttm_copy_io_page(new_iomap, old_iomap, page);
374-
if (ret)
378+
if (ret) {
379+
/* failing here, means keep old copy as-is */
380+
old_copy.mm_node = NULL;
375381
goto out1;
382+
}
376383
}
377384
mb();
378385
out2:

0 commit comments

Comments
 (0)