Received: by 10.223.185.116 with SMTP id b49csp3556186wrg; Mon, 19 Feb 2018 01:57:29 -0800 (PST) X-Google-Smtp-Source: AH8x225HL7r0+N+1pgzCMu0lK9wWWH2dfvMXj7aLdlF6zLVVxxO9NRsQEcKL84Niz9HG4lcJkNbe X-Received: by 2002:a17:902:b403:: with SMTP id x3-v6mr2346959plr.359.1519034249690; Mon, 19 Feb 2018 01:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519034249; cv=none; d=google.com; s=arc-20160816; b=eae0XdQy/2DA8Vi/EU1dbhLmiIdqZHMST4zLVcxfKELGwPrnNFWi+QVwYvYI1t5m+q 2jXiTYDdpFNoThFhMIU1G6Qt+/OteXcd6knvvCq1S1E44OFC8XWmIPvjz4dhWJ5ew4LZ oS2O75Ytu+uphiPScu7Mm3oabx2jy12/8wrsvXMPnwqYulxBDQBcTy45RvgmPokQTB2/ x4IRiDIneph9jyS0rJPy1aN70a5lsFMEE6seLiNvx9jkSndaDdBxMNJcraRlPDji7ZML TxDeTqn1XDAHrkJZAh3L2CUd6gnzZ3Ql+tRbmF46Ii/td2FiP0lJDebBo22k2R/0LAzr 34RA== 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=TnSXCY6R5OplJdVbtcvlRypbMBxLffWu+33JYughEe6eU7w5eqb7+b77vnVq8cwKv9 KoR3Lo4YYkZQsayYZzB+UY7oh91z6mRj7E/c9aUh4m3NXRXb5aJ61ZI/aZWHBjyoWsZa TAbvBtL5GjW3rKOD9N2iZJEtcQeR8M9RE7ruCiAqQvH99/Si/0caDsoP0jkkFcS4GTZF r4bQT6fIAfgbtm7/yV6U5ffmWNqA5gsK5/OUaSijxJlp9jxWgiDk/Y3Gcvmh5ByLU1UN 6s7LAF2y2TZ6cbzWP1llyTOKlBL+azVPJ0VO9kszQBKhm+QeKgDgEcNfPl+WpFYVO2jT mEHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OCHQZut1; 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 q11si8068386pgc.165.2018.02.19.01.57.14; Mon, 19 Feb 2018 01:57:29 -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=OCHQZut1; 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 S1752526AbeBSJ42 (ORCPT + 99 others); Mon, 19 Feb 2018 04:56:28 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35935 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752487AbeBSJ4Z (ORCPT ); Mon, 19 Feb 2018 04:56:25 -0500 Received: by mail-wr0-f194.google.com with SMTP id u15so8969693wrg.3 for ; Mon, 19 Feb 2018 01:56:24 -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=OCHQZut170tJ9eIWKmNWS9UWtl++QwTYKRREKKtTaq2P209qjVfQLhzrizSP02j0Q0 Zs9oDv2M6mjFiaBhfHbSzQaTSXg3wx4pt/dZPrLbfv7z+GBLsHPPajzPz6vt/NdIN4vT c84Dv0PtRDB+uys9djUlTXLvKzZbMrxZQDrL4bxhvKvwB/XmO1nLFUotnbkoZS4kZ3vz E3tNjZmMKNgbpDA8hAh0h8GkR7vURR67bG2cBWIUc9dI26jkF1RHNKGeXiAXE7Rqhuaq V92Goff4wj0DZr8tHsnM2qjOy3BLkco/1eysZXfUm6ID+aRXwFASPRIoIAJRP5+Tsc0n MOFQ== 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=jZxZtH7xrwT/oTNCLWTvpwisud0qrfOoJcT6yHG5tFr0D0vLaA9XMCOKR7x2PHO0il +sRf6w8G++KkmsOKHW6Sd+5QVbbMSA9Y97zLMfc9STgJZiejse7kruJnPrdfGgz6xIan ZA5jCfKUuvD+Y9IvAQg7QLXrjwDdgPYe/dMTlGdnH21z1ldL6NGoNUaZ9oXVLNlTnubb x74Q0v3aMsHMvHZl+NvLmUxiOUIbbGhZUMu5Fsg3L7HtS960334ObCuEKhFvWZYyLNm+ Wrha91s5a90R7AHGorkYrc2IGq0+xkwJXuzG89WL9shDsBUotGvRhsOcsMnZHvOYfwwq wEtw== X-Gm-Message-State: APf1xPClNKrpoO3pVFT8hxNnqvJLL6BwgL3SOSV4pzz51TKdg0uogx6R J6vmWQLzwQ38DB9colQK3HepIQ== X-Received: by 10.223.136.236 with SMTP id g41mr12247296wrg.103.1519034184074; Mon, 19 Feb 2018 01:56:24 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:9533:206a:c0b5:3ad7]) by smtp.gmail.com with ESMTPSA id z74sm22309976wmz.21.2018.02.19.01.56.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 01:56:13 -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, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 4/4] drm/ttm: keep BOs reserved until end of eviction Date: Mon, 19 Feb 2018 10:56:10 +0100 Message-Id: <20180219095610.2747-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180219095610.2747-1-christian.koenig@amd.com> References: <20180219095610.2747-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