Blocks whose wipe was queued before a GPU reset are freed as cleared, but the wipe may have been cancelled by the reset. Record the GPU reset counter when queueing the wipe and drop the cleared state on free if it changed. v2: - Split into multiple patches (Christian) - Use gpu_reset_counter, set before job cancel and on any reset (Christian) Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality") Cc: stable@vger.kernel.org Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index d4651f2d437c..01d18e46aa1b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1366,7 +1366,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); struct dma_fence *fence = NULL; struct amdgpu_bo *abo; - int r; + int reset_counter, r; if (!amdgpu_bo_is_amdgpu_bo(bo)) return; @@ -1398,13 +1398,14 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) if (r) goto out; + reset_counter = atomic_read(&adev->gpu_reset_counter); r = amdgpu_ttm_clear_buffer(amdgpu_ttm_next_clear_entity(adev), abo, &bo->base._resv, &fence, false, AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE); if (WARN_ON(r)) goto out; - amdgpu_vram_mgr_set_cleared(bo->resource); + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); dma_resv_add_fence(&bo->base._resv, fence, DMA_RESV_USAGE_KERNEL); dma_fence_put(fence); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 346e7be57fd8..fa21e2db545a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -435,13 +435,15 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, /* clear the space being freed */ if (old_mem->mem_type == TTM_PL_VRAM && (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) { + int reset_counter = atomic_read(&adev->gpu_reset_counter); struct dma_fence *wipe_fence = NULL; + r = amdgpu_ttm_clear_buffer(entity, abo, NULL, &wipe_fence, false, AMDGPU_KERNEL_JOB_ID_MOVE_BLIT); if (r) { goto error; } else if (wipe_fence) { - amdgpu_vram_mgr_set_cleared(bo->resource); + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); dma_fence_put(fence); fence = wipe_fence; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index d947e048952d..0706224583ce 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -666,6 +666,9 @@ static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, vis_usage += amdgpu_vram_mgr_vis_size(adev, block); amdgpu_vram_mgr_check_reset(adev, mgr); + if ((vres->flags & GPU_BUDDY_CLEARED) && + vres->clear_reset_counter != mgr->gpu_reset_counter) + vres->flags &= ~GPU_BUDDY_CLEARED; gpu_buddy_free_list(mm, &vres->blocks, vres->flags); amdgpu_vram_mgr_do_reserve(man); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h index da1efd0e26a1..abd7bc1811fc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h @@ -59,6 +59,7 @@ struct amdgpu_vram_mgr_resource { unsigned long flags; struct list_head vres_node; struct amdgpu_vres_task task; + int clear_reset_counter; }; static inline u64 amdgpu_vram_mgr_block_start(struct gpu_buddy_block *block) @@ -82,12 +83,14 @@ to_amdgpu_vram_mgr_resource(struct ttm_resource *res) return container_of(res, struct amdgpu_vram_mgr_resource, base); } -static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res) +static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res, + int reset_counter) { struct amdgpu_vram_mgr_resource *ares = to_amdgpu_vram_mgr_resource(res); WARN_ON(ares->flags & GPU_BUDDY_CLEARED); ares->flags |= GPU_BUDDY_CLEARED; + ares->clear_reset_counter = reset_counter; } int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr, -- 2.53.0