From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>,
christian.koenig-5C7GfCeVMHo@public.gmane.org
Cc: "moderated list:DMA BUFFER SHARING FRAMEWORK"
<linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw@public.gmane.org>,
Daniel Vetter <daniel.vetter-/w4YWyX8dFk@public.gmane.org>,
amd-gfx list
<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
dri-devel
<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
"open list:DMA BUFFER SHARING FRAMEWORK"
<linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [Linaro-mm-sig] [PATCH 1/5] dma-buf: add optional invalidate_mappings callback v2
Date: Thu, 22 Mar 2018 10:58:55 +0100 [thread overview]
Message-ID: <ef9fa9a2-c368-1fca-a8ac-8ee8d522b6ab@gmail.com> (raw)
In-Reply-To: <20180322071804.GH14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
Am 22.03.2018 um 08:18 schrieb Daniel Vetter:
> On Wed, Mar 21, 2018 at 12:54:20PM +0100, Christian König wrote:
>> Am 21.03.2018 um 09:28 schrieb Daniel Vetter:
>>> On Tue, Mar 20, 2018 at 06:47:57PM +0100, Christian König wrote:
>>>> Am 20.03.2018 um 15:08 schrieb Daniel Vetter:
>>>>> [SNIP]
>>>>> For the in-driver reservation path (CS) having a slow-path that grabs a
>>>>> temporary reference, drops the vram lock and then locks the reservation
>>>>> normally (using the acquire context used already for the entire CS) is a
>>>>> bit tricky, but totally feasible. Ttm doesn't do that though.
>>>> That is exactly what we do in amdgpu as well, it's just not very efficient
>>>> nor reliable to retry getting the right pages for a submission over and over
>>>> again.
>>> Out of curiosity, where's that code? I did read the ttm eviction code way
>>> back, and that one definitely didn't do that. Would be interesting to
>>> update my understanding.
>> That is in amdgpu_cs.c. amdgpu_cs_parser_bos() does a horrible dance with
>> grabbing, releasing and regrabbing locks in a loop.
>>
>> Then in amdgpu_cs_submit() we grab an lock preventing page table updates and
>> check if all pages are still the one we want to have:
>>> amdgpu_mn_lock(p->mn);
>>> if (p->bo_list) {
>>> for (i = p->bo_list->first_userptr;
>>> i < p->bo_list->num_entries; ++i) {
>>> struct amdgpu_bo *bo = p->bo_list->array[i].robj;
>>>
>>> if
>>> (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>> amdgpu_mn_unlock(p->mn);
>>> return -ERESTARTSYS;
>>> }
>>> }
>>> }
>> If anything changed on the page tables we restart the whole IOCTL using
>> -ERESTARTSYS and try again.
> I'm not talking about userptr here, but general bo eviction. Sorry for the
> confusion.
>
> The reason I'm dragging all the general bo management into this
> discussions is because we do seem to have fairly fundamental difference in
> how that's done, with resulting consequences for the locking hierarchy.
>
> And if this invalidate_mapping stuff should work, together with userptr
> and everything else, I think we're required to agree on how this is all
> supposed to nest, and how exactly we should back off for the other side
> that needs to break the locking circle.
>
> That aside, I don't entirely understand why you need to restart so much. I
> figured that get_user_pages is ordered correctly against mmu
> invalidations, but I get the impression you think that's not the case. How
> does that happen?
Correct. I've had the same assumption, but both Jerome as well as our
internal tests proved me wrong on that.
Key take away from that was that you can't take any locks from neither
the MMU notifier nor the shrinker you also take while calling kmalloc
(or simpler speaking get_user_pages()).
Additional to that in the MMU or shrinker callback all different kinds
of locks might be held, so you basically can't assume that you do thinks
like recursive page table walks or call dma_unmap_anything.
Thinking a moment about that it actually seems to make perfect sense.
So it doesn't matter what order you got between the mmap_sem and your
buffer or allocation lock, it will simply be incorrect with other locks
in the system anyway.
The only solution to that problem we have found is the dance we have in
amdgpu now:
1. Inside invalidate_range_start you grab a recursive read side lock.
2. Wait for all GPU operation on that pages to finish.
3. Then mark all pages as dirty and accessed.
4. Inside invalidate_range_end you release your recursive read side lock
again.
Then during command submission you do the following:
1. Take the locks Figure out all the userptr BOs which needs new pages.
2. Drop the locks again call get_user_pages().
3. Install the new page arrays and reiterate with #1
4. As soon as everybody has pages update your page tables and prepare
all command submission.
5. Take the write side of our recursive lock.
6. Check if all pages are still valid, if not restart the whole IOCTL.
7. Submit the job to the hardware.
8. Drop the write side of our recursive lock.
Regards,
Christian.
> -Daniel
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2018-03-22 9:58 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-16 13:20 RFC: unpinned DMA-buf exporting v2 Christian König
2018-03-16 13:20 ` [PATCH 1/5] dma-buf: add optional invalidate_mappings callback v2 Christian König
2018-03-16 13:51 ` Chris Wilson
[not found] ` <152120831102.25315.4326885184264378830-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
2018-03-16 14:22 ` Christian König
2018-03-19 15:53 ` Chris Wilson
2018-03-19 16:23 ` Christian König
[not found] ` <0bd85f69-c64c-70d1-a4a0-10ae0ed8b4e8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-20 7:44 ` [Linaro-mm-sig] " Daniel Vetter
2018-03-20 10:54 ` Christian König
[not found] ` <19ed21a5-805d-271f-9120-49e0c00f510f-5C7GfCeVMHo@public.gmane.org>
2018-03-20 14:08 ` Daniel Vetter
[not found] ` <20180320140810.GU14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-20 17:47 ` Christian König
[not found] ` <37ba7394-2a5c-a0bc-cc51-c8a0edc2991d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-21 8:18 ` Daniel Vetter
[not found] ` <20180321081800.GW14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-21 9:34 ` Christian König
[not found] ` <c9070eb2-9b4e-9ac2-ecbc-74dcf5069858-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-22 7:14 ` Daniel Vetter
[not found] ` <20180322071425.GG14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-22 9:37 ` Christian König
2018-03-26 7:51 ` Daniel Vetter
2018-03-21 8:28 ` Daniel Vetter
[not found] ` <20180321082839.GA14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-21 11:54 ` Christian König
2018-03-22 7:18 ` Daniel Vetter
[not found] ` <20180322071804.GH14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-22 9:58 ` Christian König [this message]
[not found] ` <ef9fa9a2-c368-1fca-a8ac-8ee8d522b6ab-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-26 8:01 ` Daniel Vetter
[not found] ` <20180326080121.GO14155-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-26 15:42 ` Jerome Glisse
2018-03-27 7:35 ` Christian König
2018-03-27 7:53 ` Daniel Vetter
2018-03-27 8:06 ` Christian König
[not found] ` <71f3f0cc-263d-bf60-aff8-6f2277884aaf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-27 8:27 ` Daniel Vetter
2018-03-19 14:04 ` Daniel Vetter
[not found] ` <20180316132049.1748-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-03-16 13:20 ` [PATCH 2/5] drm/ttm: keep a reference to transfer pipelined BOs Christian König
[not found] ` <20180316132049.1748-3-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-03-27 3:32 ` He, Roger
2018-03-16 13:20 ` [PATCH 3/5] drm/ttm: remove the backing store if no placement is given Christian König
2018-03-16 13:20 ` [PATCH 4/5] drm/amdgpu: add independent DMA-buf export v2 Christian König
2018-03-19 14:09 ` RFC: unpinned DMA-buf exporting v2 Daniel Vetter
2018-03-16 13:20 ` [PATCH 5/5] drm/amdgpu: add independent DMA-buf import v2 Christian König
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=ef9fa9a2-c368-1fca-a8ac-8ee8d522b6ab@gmail.com \
--to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
--cc=daniel-/w4YWyX8dFk@public.gmane.org \
--cc=daniel.vetter-/w4YWyX8dFk@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw@public.gmane.org \
--cc=linux-media-u79uwXL29TY76Z2rM5mHXA@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