Received: by 10.223.185.116 with SMTP id b49csp2083266wrg; Thu, 15 Feb 2018 06:20:45 -0800 (PST) X-Google-Smtp-Source: AH8x225J/eTfWZtfGB1nGiPrKluzGrFYx2EvDh0I+RUjLEevzcslbNCw7wZPrbZC+/Q4yKxmlO/z X-Received: by 2002:a17:902:901:: with SMTP id 1-v6mr2726285plm.404.1518704445344; Thu, 15 Feb 2018 06:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518704445; cv=none; d=google.com; s=arc-20160816; b=eg+40tzrnRZVbmz0nIpuThvRinTqrS0KDH9YG9zhxK3gjW9EMjILZrbTDpCsj88wgm HonXy9/P9ioVrjqR33gy52kMVPPD4aLS+Ec5bf0QHWN0ck8NQialmgvd76sIZhCe2XhT DTRIQEUIgUUvmRS8En/ggPyAy7WuOCXmjI7drN5kmA5w7bEClhgZ7uWzV0dz24qPxc17 09SgjyQplURh/YoU3nuzfGzyN6Ycs1i9RG+xj2JAw8bRoiqBQWYwPK9n/e5Jb0YmBB0v EPbAUDvIjAFMp09ecn8vj80q2xPazwjws/tOvIRLmfQfSZipQYpj75zIn5rI98F2pd3v 3cBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=l48005zLFSJn9dmUob3oqnwgeiv3h5ET+9/UgJ7nrg4=; b=w6mENUHYKQ0wPuFH1AVFp6PMiqZW/Hf1oMHiYXWmE4OSg9/JVYo0Dro8yOVGv2TeVy tleuCianHHHlAGVkMMIt99ULdHiWJE/4FD5YjykzJtmjTakEc39Cpcv80kVLOURfUdyF ZHr7wgAgYVFNBKNpR+BjhWTFQ59cqrO6+ijoFn2unUGO/mQxs5r+LX0PVCELNWZPGfdj hCyfk1clce2cFAVBxX7QnB5y20mj6TY2JD/e88WJrtpNsjhXU2d0ZO4+2TdX/kUU+jsp GawbBTbqC90eEg1uVEMkDJMYxQkud/MZVqdwY8FhaEmurNAA8gzsWMKRubUChfnQrC4w 1rRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Mmf9ZOqa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e192si4753038pfc.292.2018.02.15.06.20.30; Thu, 15 Feb 2018 06:20:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Mmf9ZOqa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033180AbeBOOTv (ORCPT + 99 others); Thu, 15 Feb 2018 09:19:51 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:45655 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033101AbeBOOTt (ORCPT ); Thu, 15 Feb 2018 09:19:49 -0500 Received: by mail-wr0-f196.google.com with SMTP id q16so1721315wrf.12 for ; Thu, 15 Feb 2018 06:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=l48005zLFSJn9dmUob3oqnwgeiv3h5ET+9/UgJ7nrg4=; b=Mmf9ZOqajyQEb33HUClJX/G6MWAD1vSJNtyzqGYgglyGpY4HxrQPLepxRMbk7CIe+v 0EpShw8vLisYP90n+/tuYqS2zcKyT08gnDkD9mDtPaMeRWrGvKwZ9l7yw46m9VfYLMgA 3KSEvSi59kJD8dKDwIzvE0u2V2X0/H6Pc8bk798KgfBlRBx/y2pIHTpiqh3Ccod9Qzbg IvlsIwEoE7Grx+1EOKjMopzbuXuucQVQTWt9dlbq4UTUfTL4j36ulJn49VnpZ1YZCkG3 vMbg3oOtUKOA1khx1vR3GKCx/cbB91M5/j8G82cp0+evi57Hl54AVwwvIUfya9uWCxUy KnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l48005zLFSJn9dmUob3oqnwgeiv3h5ET+9/UgJ7nrg4=; b=sOJBExkoqXuxYE5Y4H5U2XEg5pamxUxj7Y+fxvdYtmFTuJJNSkvFlu2uVlbfldtzRd E7dBn8aY7K4hTOKhPr5/+ecGNlkWQqAkyvdqZfeh8AgO0TrGRr+9rhG9313nSQI43y8m KPKOVYeIk0n9PLn8QYturb3ff/gPSWcZhn5bPOcQxGStzTrDbVgp8+Y5Q+zvB2vMt6kh C53OtRyAXfc3s5JlsF6IK5MLoju+rndSMUjuAHnOgdazYN0YySsgXfAO9vrc5b2BcwE1 NGyG1Yf9TKva81kg5FXDzGPNiTs6lBvVcWqdyccE/t7nKQzVjJiL7Zozx1Imv4j8J8wW EGQg== X-Gm-Message-State: APf1xPCgT33eCyjxCXW/MnwiCv4JTIDhQfPeK2v/igkNrkByIqFu6//1 DwvaGeOQaNlTnA6BQDHouIY= X-Received: by 10.223.163.93 with SMTP id d29mr2816812wrb.187.1518704387831; Thu, 15 Feb 2018 06:19:47 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:3595:2adb:15ea:f8af]) by smtp.gmail.com with ESMTPSA id 19sm27382433wrv.0.2018.02.15.06.19.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 06:19:47 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] drm/ttm: keep BOs reserved until end of eviction Date: Thu, 15 Feb 2018 15:19:44 +0100 Message-Id: <20180215141944.4332-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180215141944.4332-1-christian.koenig@amd.com> References: <20180215141944.4332-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This avoids problems when BOs are evicted but directly moved back into the domain from other threads. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index fba40e22d088..568cf216b374 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -742,7 +742,8 @@ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, static int ttm_mem_evict_first(struct ttm_bo_device *bdev, uint32_t mem_type, const struct ttm_place *place, - struct ttm_operation_ctx *ctx) + struct ttm_operation_ctx *ctx, + struct list_head *evicted) { struct ttm_bo_global *glob = bdev->glob; struct ttm_mem_type_manager *man = &bdev->man[mem_type]; @@ -792,17 +793,28 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ret = ttm_bo_evict(bo, ctx); if (locked) { - ttm_bo_unreserve(bo); + list_add_tail(&bo->lru, evicted); } else { spin_lock(&glob->lru_lock); ttm_bo_add_to_lru(bo); spin_unlock(&glob->lru_lock); + kref_put(&bo->list_kref, ttm_bo_release_list); } - kref_put(&bo->list_kref, ttm_bo_release_list); return ret; } +static void ttm_mem_evict_cleanup(struct list_head *evicted) +{ + struct ttm_buffer_object *bo, *tmp; + + list_for_each_entry_safe(bo, tmp, evicted, lru) { + list_del_init(&bo->lru); + ttm_bo_unreserve(bo); + kref_put(&bo->list_kref, ttm_bo_release_list); + } +} + void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem) { struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type]; @@ -852,20 +864,26 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, { struct ttm_bo_device *bdev = bo->bdev; struct ttm_mem_type_manager *man = &bdev->man[mem_type]; + struct list_head evicted; int ret; + INIT_LIST_HEAD(&evicted); do { ret = (*man->func->get_node)(man, bo, place, mem); if (unlikely(ret != 0)) return ret; if (mem->mm_node) break; - ret = ttm_mem_evict_first(bdev, mem_type, place, ctx); + ret = ttm_mem_evict_first(bdev, mem_type, place, ctx, &evicted); if (unlikely(ret != 0)) - return ret; + goto error; } while (1); mem->mem_type = mem_type; - return ttm_bo_add_move_fence(bo, man, mem); + ret = ttm_bo_add_move_fence(bo, man, mem); + +error: + ttm_mem_evict_cleanup(&evicted); + return ret; } static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man, @@ -1345,6 +1363,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, struct ttm_operation_ctx ctx = { false, false }; struct ttm_mem_type_manager *man = &bdev->man[mem_type]; struct ttm_bo_global *glob = bdev->glob; + struct list_head evicted; struct dma_fence *fence; int ret; unsigned i; @@ -1352,18 +1371,20 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, /* * Can't use standard list traversal since we're unlocking. */ - + INIT_LIST_HEAD(&evicted); spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { while (!list_empty(&man->lru[i])) { spin_unlock(&glob->lru_lock); - ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx); + ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx, + &evicted); if (ret) return ret; spin_lock(&glob->lru_lock); } } spin_unlock(&glob->lru_lock); + ttm_mem_evict_cleanup(&evicted); spin_lock(&man->move_lock); fence = dma_fence_get(man->move); -- 2.14.1