dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Nicolai Hähnle" <nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: "Nicolai Hähnle" <nicolai.haehnle-5C7GfCeVMHo@public.gmane.org>,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 3/3] drm/amdgpu: fix lock cleanup during buffer creation
Date: Tue, 14 Feb 2017 11:37:44 +0100	[thread overview]
Message-ID: <20170214103744.4133-3-nhaehnle@gmail.com> (raw)
In-Reply-To: <20170214103744.4133-1-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Nicolai Hähnle <nicolai.haehnle@amd.com>

Open-code the initial ttm_bo_validate call, so that we can properly
unlock the reservation lock when it fails. Also, properly destruct
the reservation object when the first part of TTM BO initialization
fails.

Actual deadlocks caused by the missing unlock should have been fixed
by "drm/ttm: never add BO that failed to validate to the LRU list",
superseding the flawed fix in commit 38fc4856ad98 ("drm/amdgpu: fix
a potential deadlock in amdgpu_bo_create_restricted()").

This change fixes remaining recursive locking errors that can be seen
with lock debugging enabled, and avoids the error of freeing a locked
mutex.

Fixes: 12a852219583 ("drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)")
Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 +++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d1ef1d0..bea845f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -399,12 +399,34 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 		locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock);
 		WARN_ON(!locked);
 	}
-	r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type,
-			&bo->placement, page_align, !kernel, NULL,
-			acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
-			&amdgpu_ttm_bo_destroy);
-	if (unlikely(r != 0))
+	r = ttm_bo_init_top(&adev->mman.bdev, &bo->tbo, size, type,
+			    page_align, NULL,
+			    acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
+			    &amdgpu_ttm_bo_destroy);
+	if (unlikely(r != 0)) {
+		if (!resv) {
+			ww_mutex_unlock(&bo->tbo.ttm_resv.lock);
+			reservation_object_fini(&bo->tbo.ttm_resv);
+		}
+		amdgpu_ttm_bo_destroy(&bo->tbo);
+		return r;
+	}
+
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, !kernel, false);
+	if (unlikely(r != 0)) {
+		struct ttm_buffer_object *tbo = &bo->tbo;
+
+		if (!resv)
+			ww_mutex_unlock(&bo->tbo.ttm_resv.lock);
+		ttm_bo_unref(&tbo);
 		return r;
+	}
+
+	if (!(bo->tbo.mem.placement & TTM_PL_FLAG_NO_EVICT)) {
+		spin_lock(&bo->tbo.glob->lru_lock);
+		ttm_bo_add_to_lru(&bo->tbo);
+		spin_unlock(&bo->tbo.glob->lru_lock);
+	}
 
 	bo->tbo.priority = ilog2(bo->tbo.num_pages);
 	if (kernel)
-- 
2.9.3

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-02-14 10:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 10:37 [PATCH 1/3] drm/ttm: split BO structure initialization into a separate function Nicolai Hähnle
     [not found] ` <20170214103744.4133-1-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-14 10:37   ` [PATCH 2/3] drm/ttm: fix the documentation of ttm_bo_init Nicolai Hähnle
2017-02-14 10:37   ` Nicolai Hähnle [this message]
2017-02-15  3:16   ` [PATCH 1/3] drm/ttm: split BO structure initialization into a separate function zhoucm1
     [not found]     ` <58A3C7FE.2080308-5C7GfCeVMHo@public.gmane.org>
2017-02-15 10:43       ` Nicolai Hähnle
     [not found]         ` <403a8be3-7f55-085c-b9ad-19551be33332-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-15 10:47           ` zhoucm1
2017-02-15 14:05       ` Nicolai Hähnle
2017-02-14 10:49 ` Christian König
     [not found]   ` <b9c665fe-4e9a-7163-aa8a-0c9ce73a78a0-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-02-14 12:00     ` Nicolai Hähnle
     [not found]       ` <9229e0d9-4e9d-0233-4ba2-c54c7192acfa-5C7GfCeVMHo@public.gmane.org>
2017-02-14 12:51         ` Christian König
     [not found]           ` <f43631b3-2527-54c1-d0bc-98460772b77b-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-02-15 13:35             ` Nicolai Hähnle
     [not found]               ` <06a90674-9f46-e646-9893-8b2748ddd9e4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-15 13:54                 ` Nicolai Hähnle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170214103744.4133-3-nhaehnle@gmail.com \
    --to=nhaehnle-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=nicolai.haehnle-5C7GfCeVMHo@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).