Skip to content

Commit 2d2ddb5

Browse files
drm/ttm: fix deref of bo->ttm without holding the lock v2
We need to grab the resv lock first before doing that check. v2 (chk): simplify the change for -fixes Signed-off-by: Christian König <[email protected]> Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Huang Rui <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 9bf3797 commit 2d2ddb5

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,10 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
11721172
if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked, NULL))
11731173
return -EBUSY;
11741174

1175-
if (!ttm_bo_get_unless_zero(bo)) {
1175+
if (!bo->ttm || !ttm_tt_is_populated(bo->ttm) ||
1176+
bo->ttm->page_flags & TTM_PAGE_FLAG_SG ||
1177+
bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED ||
1178+
!ttm_bo_get_unless_zero(bo)) {
11761179
if (locked)
11771180
dma_resv_unlock(bo->base.resv);
11781181
return -EBUSY;

drivers/gpu/drm/ttm/ttm_device.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,8 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
143143

144144
for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) {
145145
list_for_each_entry(bo, &man->lru[j], lru) {
146-
uint32_t num_pages;
146+
uint32_t num_pages = PFN_UP(bo->base.size);
147147

148-
if (!bo->ttm || !ttm_tt_is_populated(bo->ttm) ||
149-
bo->ttm->page_flags & TTM_PAGE_FLAG_SG ||
150-
bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)
151-
continue;
152-
153-
num_pages = bo->ttm->num_pages;
154148
ret = ttm_bo_swapout(bo, ctx, gfp_flags);
155149
/* ttm_bo_swapout has dropped the lru_lock */
156150
if (!ret)

0 commit comments

Comments
 (0)