@@ -399,12 +399,34 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock);
WARN_ON(!locked);
}
- r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type,
- &bo->placement, page_align, !kernel, NULL,
- acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
- &amdgpu_ttm_bo_destroy);
- if (unlikely(r != 0))
+ r = ttm_bo_init_top(&adev->mman.bdev, &bo->tbo, size, type,
+ page_align, NULL,
+ acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
+ &amdgpu_ttm_bo_destroy);
+ if (unlikely(r != 0)) {
+ if (!resv) {
+ ww_mutex_unlock(&bo->tbo.ttm_resv.lock);
+ reservation_object_fini(&bo->tbo.ttm_resv);
+ }
+ amdgpu_ttm_bo_destroy(&bo->tbo);
+ return r;
+ }
+
+ r = ttm_bo_validate(&bo->tbo, &bo->placement, !kernel, false);
+ if (unlikely(r != 0)) {
+ struct ttm_buffer_object *tbo = &bo->tbo;
+
+ if (!resv)
+ ww_mutex_unlock(&bo->tbo.ttm_resv.lock);
+ ttm_bo_unref(&tbo);
return r;
+ }
+
+ if (!(bo->tbo.mem.placement & TTM_PL_FLAG_NO_EVICT)) {
+ spin_lock(&bo->tbo.glob->lru_lock);
+ ttm_bo_add_to_lru(&bo->tbo);
+ spin_unlock(&bo->tbo.glob->lru_lock);
+ }
bo->tbo.priority = ilog2(bo->tbo.num_pages);
if (kernel)