Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp49851ybg; Mon, 8 Jun 2020 16:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNDpbCgZ1bXlc7EIeJa9RZoIgmT3xWHBDZAALohmC7U6vYu5xIppG4YHYNM9WoVAiqI/vl X-Received: by 2002:a17:906:c142:: with SMTP id dp2mr24122593ejc.541.1591657707625; Mon, 08 Jun 2020 16:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591657707; cv=none; d=google.com; s=arc-20160816; b=wS2XCd1908/3lM0iibNhIPz70W1Y4MGPYWZHEwtzZjRVC5xT9CypXFR+knWfTbZsHo OFd6Smnh6aEeA/q3xT6x3+0tCh6oa77qGMoz5mIbbvOv9r+HZ/GAK3kooF0pqOmKgr1C bmV3lG0C69q9YPv8UuK+kEA00zPOV3dM6sO+AXJi5iwv6YHy2cIeiaI1W0t6xWirbYyO b52FGP5hCxwwM8X9VeZhuw7UQ1wR949Ziv+8tM/ZeNxw7JP3/HDGOOOm2ezY9ZaJBXMC 2J82BLFVYHyTm2zTRfj5afk2YNVe0pJkubQSantKL6l8Ievkn9jS3zPoYPSatc43BdsT l2ig== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OC44lWBokKiwPrAyWPv/mbW1L9oR7lM+UXXgV6/39Zg=; b=DKv6UXcHHwVutFMiB40+PcLxAhT47je36H8iD/6iNVcGEYVjjPkhU9BSUg8mS/IO6H DUtpf+b4Bu4ZXimnzTtbATrh2GBaqDz9NQEl0AnGgkt8Y0XLRVIB9eM9HRqMzavGEAO8 u33nmwa0Fs2x9mSuCYXQQQGiKhEvgCnO19FpU4Wt4mKYUOv2CGE86uq6iYaqvvgl6ng/ e7wfQJ9UwELNmA5vPy8rUPK4v8/tsj7GBjP18O6+3aYYR6iPYcHsrDcg6nILsmAaIZ8Y b+V7k/zXf0KwpRqCjUE1yIEnzJ31p7rzYgf8W/dosT/xNImhwoZFZ4iA9Ic13Xs0nUJv jiDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nI2YdhB1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f24si9972583edr.137.2020.06.08.16.08.04; Mon, 08 Jun 2020 16:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nI2YdhB1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726848AbgFHXGK (ORCPT + 99 others); Mon, 8 Jun 2020 19:06:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:48944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726746AbgFHXGK (ORCPT ); Mon, 8 Jun 2020 19:06:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 899DA2076A; Mon, 8 Jun 2020 23:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657569; bh=CicGRjGSOTBsUj/Eqh9polVEPmrcjtOxTk5wOZR5tgE=; h=From:To:Cc:Subject:Date:From; b=nI2YdhB1zt9pJ919fxs1oyKtdENrnrLP24ylg86cC/kUoj9RYMFYPe0Ipv8Hn3GWu nZxfi5XehnjrGsJvLMtMlzOtIG5ZkVO4CuuenLWVF3RtdywZzfTkl4Mq+JN7GR6afq ynvWaLS+BIuCTUZ7fNshAQE/pc0Txda7UNMTR2OI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Christian=20K=C3=B6nig?= , xinhui pan , Alex Deucher , Sasha Levin , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH AUTOSEL 5.7 001/274] drm/amdgpu: fix and cleanup amdgpu_gem_object_close v4 Date: Mon, 8 Jun 2020 19:01:34 -0400 Message-Id: <20200608230607.3361041-1-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian König [ Upstream commit 82c416b13cb7d22b96ec0888b296a48dff8a09eb ] The problem is that we can't add the clear fence to the BO when there is an exclusive fence on it since we can't guarantee the the clear fence will complete after the exclusive one. To fix this refactor the function and also add the exclusive fence as shared to the resv object. v2: fix warning v3: add excl fence as shared instead v4: squash in fix for fence handling in amdgpu_gem_object_close Signed-off-by: Christian König Reviewed-by: xinhui pan Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 43 ++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 4277125a79ee..32f36c940abb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -161,16 +161,17 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj, struct amdgpu_bo_list_entry vm_pd; struct list_head list, duplicates; + struct dma_fence *fence = NULL; struct ttm_validate_buffer tv; struct ww_acquire_ctx ticket; struct amdgpu_bo_va *bo_va; - int r; + long r; INIT_LIST_HEAD(&list); INIT_LIST_HEAD(&duplicates); tv.bo = &bo->tbo; - tv.num_shared = 1; + tv.num_shared = 2; list_add(&tv.head, &list); amdgpu_vm_get_pd_bo(vm, &list, &vm_pd); @@ -178,28 +179,34 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj, r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates); if (r) { dev_err(adev->dev, "leaking bo va because " - "we fail to reserve bo (%d)\n", r); + "we fail to reserve bo (%ld)\n", r); return; } bo_va = amdgpu_vm_bo_find(vm, bo); - if (bo_va && --bo_va->ref_count == 0) { - amdgpu_vm_bo_rmv(adev, bo_va); - - if (amdgpu_vm_ready(vm)) { - struct dma_fence *fence = NULL; + if (!bo_va || --bo_va->ref_count) + goto out_unlock; - r = amdgpu_vm_clear_freed(adev, vm, &fence); - if (unlikely(r)) { - dev_err(adev->dev, "failed to clear page " - "tables on GEM object close (%d)\n", r); - } + amdgpu_vm_bo_rmv(adev, bo_va); + if (!amdgpu_vm_ready(vm)) + goto out_unlock; - if (fence) { - amdgpu_bo_fence(bo, fence, true); - dma_fence_put(fence); - } - } + fence = dma_resv_get_excl(bo->tbo.base.resv); + if (fence) { + amdgpu_bo_fence(bo, fence, true); + fence = NULL; } + + r = amdgpu_vm_clear_freed(adev, vm, &fence); + if (r || !fence) + goto out_unlock; + + amdgpu_bo_fence(bo, fence, true); + dma_fence_put(fence); + +out_unlock: + if (unlikely(r < 0)) + dev_err(adev->dev, "failed to clear page " + "tables on GEM object close (%ld)\n", r); ttm_eu_backoff_reservation(&ticket, &list); } -- 2.25.1