[PATCH 3.2 024/101] drm/ttm: Make sure BOs being swapped out are cacheable

From: Ben Hutchings
Date: Thu Jun 01 2017 - 13:05:31 EST


3.2.89-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Michel DÃnzer <michel.daenzer@xxxxxxx>

commit 239ac65fa5ffab71adf66e642750f940e7241d99 upstream.

The current caching state may not be tt_cached, even though the
placement contains TTM_PL_FLAG_CACHED, because placement can contain
multiple caching flags. Trying to swap out such a BO would trip up the

BUG_ON(ttm->caching_state != tt_cached);

in ttm_tt_swapout.

Signed-off-by: Michel DÃnzer <michel.daenzer@xxxxxxx>
Reviewed-by: Thomas Hellstrom <thellstrom@xxxxxxxxxx>
Reviewed-by: Christian KÃnig <christian.koenig@xxxxxxx>.
Reviewed-by: Sinclair Yeh <syeh@xxxxxxxxxx>
Signed-off-by: Christian KÃnig <christian.koenig@xxxxxxx>
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
drivers/gpu/drm/ttm/ttm_bo.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1807,7 +1807,6 @@ static int ttm_bo_swapout(struct ttm_mem
struct ttm_buffer_object *bo;
int ret = -EBUSY;
int put_count;
- uint32_t swap_placement = (TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM);

spin_lock(&glob->lru_lock);
while (ret == -EBUSY) {
@@ -1860,7 +1859,8 @@ static int ttm_bo_swapout(struct ttm_mem
if (unlikely(ret != 0))
goto out;

- if ((bo->mem.placement & swap_placement) != swap_placement) {
+ if (bo->mem.mem_type != TTM_PL_SYSTEM ||
+ bo->ttm->caching_state != tt_cached) {
struct ttm_mem_reg evict_mem;

evict_mem = bo->mem;