From patchwork Tue Feb 20 12:58:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10230003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF77A602A7 for ; Tue, 20 Feb 2018 12:58:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D01E028464 for ; Tue, 20 Feb 2018 12:58:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4B8828657; Tue, 20 Feb 2018 12:58:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 721F728464 for ; Tue, 20 Feb 2018 12:58:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 723526E3F8; Tue, 20 Feb 2018 12:58:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 473BB6E3F6; Tue, 20 Feb 2018 12:58:35 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id v65so14074941wrc.11; Tue, 20 Feb 2018 04:58:35 -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=xe53kV3WymTgNP1awpregwrcrM2545QLq3kBx7RSZYo=; b=RRz6r/MB6s1Mz2THkijl25iClRnaxzf8aNOsNo17R7ub23/Es+xo0FgXQ8N/4cUgah Y4Hye+7Xqm59ky9v5UGxdyzqNMOzKmfDkLNr7RzwyznLbocdlC9ngZkgFTTMvhX+MaE4 D8BMl3kUk/Mzn0r+e7NTiYUIjxlCeN2G0E4tc8j2OCuiRV9tq4IfTCQeGmZsI2EuqT/P FcKOfC5/B+0QsEVs/Dd0RM1Jk2xrQGCv88jJD964wz+hY5zBoxIhYZ7BgSXLaHW/pzaU EDerRKHmjt8PzzhN0egelnjUjPAO8Vea6NyG3fV2YSrDzFRJdmqak9yEndEKvzWsBoIm +jiA== 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=xe53kV3WymTgNP1awpregwrcrM2545QLq3kBx7RSZYo=; b=Pt8zhYgfiowEfMMH6dCWsrq4gsHEgzrXtxQT524yKlyWY6+ghmad2Kv0wecD2i9G1W MvSgi1bhgDPfShpGpYoHBrPMc4DCaQUF/NQzX6gvsJ/6Fi5kRb/KshlEiaS7qggG4cuT vH1pheE/na1V692GftmhtraHKHKqfXEHGHEQXsvgCiBsocB4N92mtvLG0PZ9ZvdfiG0c ds0bmfIxPoaROYhrJamslAa4zaZ0OVa/a4193L3MRdKpO3r3tpcvvVeRpcCor0LVd59A izSuZPOpXK7Ds7WkmESRtfUlv9hLsoWJXfyAKID/8nCJIC5Es40TNhwgJIvAdsWykxJg alBw== X-Gm-Message-State: APf1xPAzN9ekxPCZcxD1dAxJfKmj7enyX+koRKwRETZQJDj2Lu70Y7yC 5V7/0HellpsdTAq0mB8g3xwFCg== X-Google-Smtp-Source: AH8x227J5ejuTGhqpjdAYGfqJN3m2Lwnz1PsLGO8lIYJryoHZ7iftJB8XnC6KpZYwscXfEMFt2v8dg== X-Received: by 10.223.178.206 with SMTP id g72mr15153472wrd.135.1519131513555; Tue, 20 Feb 2018 04:58:33 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:7008:2819:5c1a:982d]) by smtp.gmail.com with ESMTPSA id 32sm24179502wrm.14.2018.02.20.04.58.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 04:58:33 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] drm/ttm: keep BOs reserved until end of eviction Date: Tue, 20 Feb 2018 13:58:29 +0100 Message-Id: <20180220125829.27060-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180220125829.27060-1-christian.koenig@amd.com> References: <20180220125829.27060-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 3a44c2ee4155..593a0216faff 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);