Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)

Drop this whole reserve/unreserve dance, just lock the
reservation object manually when creating the BO.

v2: rebase on dma_fence renaming

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
f45dc74c c3af1258

+14 -15
+14 -15
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
··· 371 371 372 372 amdgpu_fill_placement_to_bo(bo, placement); 373 373 /* Kernel allocation are uninterruptible */ 374 + 375 + if (!resv) { 376 + bool locked; 377 + 378 + reservation_object_init(&bo->tbo.ttm_resv); 379 + locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock); 380 + WARN_ON(!locked); 381 + } 374 382 r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type, 375 383 &bo->placement, page_align, !kernel, NULL, 376 - acc_size, sg, resv, &amdgpu_ttm_bo_destroy); 377 - if (unlikely(r != 0)) { 384 + acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, 385 + &amdgpu_ttm_bo_destroy); 386 + if (unlikely(r != 0)) 378 387 return r; 379 - } 380 388 381 389 if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED && 382 390 bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) { 383 391 struct dma_fence *fence; 384 - 385 - r = amdgpu_bo_reserve(bo, false); 386 - if (unlikely(r != 0)) 387 - goto fail_free; 388 - 389 - amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM); 390 - r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 391 - if (unlikely(r != 0)) 392 - goto fail_unreserve; 393 392 394 393 r = amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence); 395 394 if (unlikely(r)) 396 395 goto fail_unreserve; 397 396 398 397 amdgpu_bo_fence(bo, fence, false); 399 - amdgpu_bo_unreserve(bo); 400 398 dma_fence_put(bo->tbo.moving); 401 399 bo->tbo.moving = dma_fence_get(fence); 402 400 dma_fence_put(fence); 403 401 } 402 + if (!resv) 403 + ww_mutex_unlock(&bo->tbo.resv->lock); 404 404 *bo_ptr = bo; 405 405 406 406 trace_amdgpu_bo_create(bo); ··· 408 408 return 0; 409 409 410 410 fail_unreserve: 411 - amdgpu_bo_unreserve(bo); 412 - fail_free: 411 + ww_mutex_unlock(&bo->tbo.resv->lock); 413 412 amdgpu_bo_unref(&bo); 414 413 return r; 415 414 }