amd-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Felix Kuehling <felix.kuehling@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 9/9] drm/amdgpu: Lock the attached dmabuf in unpopulate
Date: Thu, 15 Apr 2021 09:41:44 +0200	[thread overview]
Message-ID: <01c6a6ab-1301-dac5-70d4-74d5dbbcb67a@amd.com> (raw)
In-Reply-To: <bf7a332a-b696-dc49-efa8-2fec477e3bbd@amd.com>



Am 14.04.21 um 17:15 schrieb Felix Kuehling:
> Am 2021-04-14 um 3:33 a.m. schrieb Christian König:
>> Am 14.04.21 um 08:46 schrieb Felix Kuehling:
>>> amdgpu_ttm_tt_unpopulate can be called during bo_destroy. The
>>> dmabuf->resv
>>> must not be held by the caller or dma_buf_detach will deadlock. This is
>>> probably not the right fix. I get a recursive lock warning with the
>>> reservation held in ttm_bo_release. Should unmap_attachment move to
>>> backend_unbind instead?
>> Yes probably, but I'm really wondering if we should call unpopulate
>> without holding the reservation lock.
> There is an error handling code path in ttm_tt_populate that calls
> unpopulate.

That should be harmless. For populating the page array we need the same 
lock as for unpopulating it.

> I believe that has to be holding the reservation lock.

Correct, yes.

> The other cases (destroy and swapout) do not hold the lock, AIUI.

That's not correct. See ttm_bo_release() for example:

...
         if (!dma_resv_test_signaled_rcu(bo->base.resv, true) ||
             !dma_resv_trylock(bo->base.resv)) {
...

We intentionally lock the reservation object here or put it on the 
delayed delete list because dropping the tt object without holding the 
lock is illegal for multiple reasons.

If you run into an unpopulate which doesn't hold the lock then I really 
need that backtrace because we are running into a much larger bug here.

Thanks,
Christian.


>
> Regards,
>    Felix
>
>
>> Christian.
>>
>>> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
>>> ---
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 13 +++++++++++++
>>>    1 file changed, 13 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> index 936b3cfdde55..257750921eed 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> @@ -1216,9 +1216,22 @@ static void amdgpu_ttm_tt_unpopulate(struct
>>> ttm_device *bdev,
>>>          if (ttm->sg && gtt->gobj->import_attach) {
>>>            struct dma_buf_attachment *attach;
>>> +        bool locked;
>>>              attach = gtt->gobj->import_attach;
>>> +        /* FIXME: unpopulate can be called during bo_destroy.
>>> +         * The dmabuf->resv must not be held by the caller or
>>> +         * dma_buf_detach will deadlock. This is probably not
>>> +         * the right fix. I get a recursive lock warning with the
>>> +         * reservation held in ttm_bo_releas.. Should
>>> +         * unmap_attachment move to backend_unbind instead?
>>> +         */
>>> +        locked = dma_resv_is_locked(attach->dmabuf->resv);
>>> +        if (!locked)
>>> +            dma_resv_lock(attach->dmabuf->resv, NULL);
>>>            dma_buf_unmap_attachment(attach, ttm->sg, DMA_BIDIRECTIONAL);
>>> +        if (!locked)
>>> +            dma_resv_unlock(attach->dmabuf->resv);
>>>            ttm->sg = NULL;
>>>            return;
>>>        }

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

  reply	other threads:[~2021-04-15  7:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210414064621.29273-1-Felix.Kuehling@amd.com>
     [not found] ` <20210414064621.29273-10-Felix.Kuehling@amd.com>
     [not found]   ` <517032d9-1a37-ed7b-1443-9f5148e2f457@amd.com>
2021-04-14 15:15     ` [PATCH 9/9] drm/amdgpu: Lock the attached dmabuf in unpopulate Felix Kuehling
2021-04-15  7:41       ` Christian König [this message]
2021-04-15 14:29         ` Felix Kuehling
2021-04-14  6:47 [PATCH 0/9] Implement multi-GPU DMA mappings for KFD Felix Kuehling
2021-04-14  6:48 ` [PATCH 9/9] drm/amdgpu: Lock the attached dmabuf in unpopulate Felix Kuehling

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=01c6a6ab-1301-dac5-70d4-74d5dbbcb67a@amd.com \
    --to=christian.koenig@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=felix.kuehling@amd.com \
    /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).