Message ID | 56BB02C2.7090004@daenzer.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 10.02.2016 18:28, Michel Dänzer wrote: > > I recently came to realize that nothing seems to be ensuring that BOs > which are unpinned in the amdgpu/radeon drivers get added to the TTM > LRU list. I thought that should be easy enough to fix, but I ran into > an issue that has me scratching my head. > > See the attached patch for the current debugging state, and the > corresponding dmesg output below. The BO's lru member is considered > empty (i.e. it's not hooked up to the LRU list) in radeon_bo_unpin, > as expected. However, calling ttm_bo_add_to_lru in that case, the lru > member is suddenly not considered empty (i.e. it seems to be hooked up > to the LRU list, which would normally trigger the BUG_ON). And indeed, > the prev/next pointers are different between the two functions. But I > have no idea how they could be modified between those two points, or > why else they would be seeing different values... > > *Any* ideas for what might be going on here would be much appreciated. Okay, so it was just me being stupid and missing that ttm_bo_unreserve already calls ttm_bo_add_to_lru. Thanks to olesalscheider for enlightening me on IRC.
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c index 84d4563..7f09ebf 100644 --- a/drivers/gpu/drm/radeon/radeon_object.c +++ b/drivers/gpu/drm/radeon/radeon_object.c @@ -396,6 +396,16 @@ int radeon_bo_unpin(struct radeon_bo *bo) } r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); if (likely(r == 0)) { + struct ttm_bo_global *glob = bo->rdev->mman.bdev.glob; + + spin_lock(&glob->lru_lock); + if (!WARN_ON_ONCE(!list_empty(&bo->tbo.lru))) { + pr_info_once("&bo->tbo.lru=%p, bo->tbo.lru.prev=%p, bo->tbo.lru.next=%p\n", + &bo->tbo.lru, bo->tbo.lru.prev, bo->tbo.lru.next); + ttm_bo_add_to_lru(&bo->tbo); + } + spin_unlock(&glob->lru_lock); + if (bo->tbo.mem.mem_type == TTM_PL_VRAM) bo->rdev->vram_pin_size -= radeon_bo_size(bo); else diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 923079c..31353a9 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -170,7 +170,11 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) { - BUG_ON(!list_empty(&bo->lru)); + if (WARN_ON_ONCE(!list_empty(&bo->lru))) { + pr_info_once("&bo->lru=%p, bo->lru.prev=%p, bo->lru.next=%p\n", + &bo->lru, bo->lru.prev, bo->lru.next); + return; + } man = &bdev->man[bo->mem.mem_type]; list_add_tail(&bo->lru, &man->lru);