Skip to content

Commit 9a9a8fe

Browse files
author
Thomas Hellström
committed
drm/ttm: Fix a NULL pointer dereference
The LRU mechanism may look up a resource in the process of being removed from an object. The locking rules here are a bit unclear but it looks currently like res->bo assignment is protected by the LRU lock, whereas bo->resource is protected by the object lock, while *clearing* of bo->resource is also protected by the LRU lock. This means that if we check that bo->resource points to the LRU resource under the LRU lock we should be safe. So perform that check before deciding to swap out a bo. That avoids dereferencing a NULL bo->resource in ttm_bo_swapout(). Fixes: 6a9b028 ("drm/ttm: move the LRU into resource handling v4") Cc: Christian König <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Christian Koenig <[email protected]> Cc: Huang Rui <[email protected]> Cc: Alex Deucher <[email protected]> Cc: Felix Kuehling <[email protected]> Cc: Philip Yang <[email protected]> Cc: Qiang Yu <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Nirmoy Das <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: "Thomas Hellström" <[email protected]> Cc: Anshuman Gupta <[email protected]> Cc: Arunpravin Paneer Selvam <[email protected]> Cc: [email protected] Cc: <[email protected]> # v5.19+ Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c22f2ff commit 9a9a8fe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/gpu/drm/ttm/ttm_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
158158
struct ttm_buffer_object *bo = res->bo;
159159
uint32_t num_pages;
160160

161-
if (!bo)
161+
if (!bo || bo->resource != res)
162162
continue;
163163

164164
num_pages = PFN_UP(bo->base.size);

0 commit comments

Comments
 (0)