From: Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>
To: "Christian König"
<ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: nouveau
<nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
Ilia Mirkin <imirkin-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org>,
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [Nouveau] [PATCH 4/5] drm/ttm: add ttm_sg_tt_init
Date: Tue, 6 Mar 2018 10:19:07 +0100 [thread overview]
Message-ID: <20180306091907.GL22212@phenom.ffwll.local> (raw)
In-Reply-To: <b5cb1980-7865-f45a-bc9d-9569f860fb50-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On Tue, Feb 27, 2018 at 01:07:06PM +0100, Christian König wrote:
> Hi guys,
>
> at least on amdgpu and radeon the page array allocated by ttm_dma_tt_init is
> completely unused in the case of DMA-buf sharing. So I'm trying to get rid
> of that by only allocating the DMA address array.
>
> Now the only other user of DMA-buf together with ttm_dma_tt_init is Nouveau.
> So my question is are you guys using the page array anywhere in your kernel
> driver in case of a DMA-buf sharing?
>
> If no then I could just make this the default behavior for all drivers and
> save quite a bit of memory for everybody.
+1 on teaching ttm to no longer look at the struct page * in the dma-buf
sgt, but only the dma_buf address.
If there's still some need for in-kernel cpu or userspace mmap access then
imo ttm needs to be fixed to delegate all that to the right dma-buf
interfaces. The ttm abstraction is already there, it's just not passed
through.
I don't pretend to now enough of the details to review this stuff :-)
-Daniel
>
> Thanks,
> Christian.
>
> Am 27.02.2018 um 12:49 schrieb Christian König:
> > This allows drivers to only allocate dma addresses, but not a page
> > array.
> >
> > Signed-off-by: Christian König <christian.koenig@amd.com>
> > ---
> > drivers/gpu/drm/ttm/ttm_tt.c | 54 ++++++++++++++++++++++++++++++++++++--------
> > include/drm/ttm/ttm_tt.h | 2 ++
> > 2 files changed, 47 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> > index 8e0b525cda00..971133106ec2 100644
> > --- a/drivers/gpu/drm/ttm/ttm_tt.c
> > +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> > @@ -108,6 +108,16 @@ static int ttm_dma_tt_alloc_page_directory(struct ttm_dma_tt *ttm)
> > return 0;
> > }
> > +static int ttm_sg_tt_alloc_page_directory(struct ttm_dma_tt *ttm)
> > +{
> > + ttm->dma_address = kvmalloc_array(ttm->ttm.num_pages,
> > + sizeof(*ttm->dma_address),
> > + GFP_KERNEL | __GFP_ZERO);
> > + if (!ttm->dma_address)
> > + return -ENOMEM;
> > + return 0;
> > +}
> > +
> > #ifdef CONFIG_X86
> > static inline int ttm_tt_set_page_caching(struct page *p,
> > enum ttm_caching_state c_old,
> > @@ -227,8 +237,8 @@ void ttm_tt_destroy(struct ttm_tt *ttm)
> > ttm->func->destroy(ttm);
> > }
> > -int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
> > - unsigned long size, uint32_t page_flags)
> > +void ttm_tt_init_fields(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
> > + unsigned long size, uint32_t page_flags)
> > {
> > ttm->bdev = bdev;
> > ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > @@ -236,6 +246,12 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
> > ttm->page_flags = page_flags;
> > ttm->state = tt_unpopulated;
> > ttm->swap_storage = NULL;
> > +}
> > +
> > +int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
> > + unsigned long size, uint32_t page_flags)
> > +{
> > + ttm_tt_init_fields(ttm, bdev, size, page_flags);
> > if (ttm_tt_alloc_page_directory(ttm)) {
> > ttm_tt_destroy(ttm);
> > @@ -258,12 +274,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
> > {
> > struct ttm_tt *ttm = &ttm_dma->ttm;
> > - ttm->bdev = bdev;
> > - ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > - ttm->caching_state = tt_cached;
> > - ttm->page_flags = page_flags;
> > - ttm->state = tt_unpopulated;
> > - ttm->swap_storage = NULL;
> > + ttm_tt_init_fields(ttm, bdev, size, page_flags);
> > INIT_LIST_HEAD(&ttm_dma->pages_list);
> > if (ttm_dma_tt_alloc_page_directory(ttm_dma)) {
> > @@ -275,11 +286,36 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
> > }
> > EXPORT_SYMBOL(ttm_dma_tt_init);
> > +int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
> > + unsigned long size, uint32_t page_flags)
> > +{
> > + struct ttm_tt *ttm = &ttm_dma->ttm;
> > + int ret;
> > +
> > + ttm_tt_init_fields(ttm, bdev, size, page_flags);
> > +
> > + INIT_LIST_HEAD(&ttm_dma->pages_list);
> > + if (page_flags & TTM_PAGE_FLAG_SG)
> > + ret = ttm_sg_tt_alloc_page_directory(ttm_dma);
> > + else
> > + ret = ttm_dma_tt_alloc_page_directory(ttm_dma);
> > + if (ret) {
> > + ttm_tt_destroy(ttm);
> > + pr_err("Failed allocating page table\n");
> > + return -ENOMEM;
> > + }
> > + return 0;
> > +}
> > +EXPORT_SYMBOL(ttm_sg_tt_init);
> > +
> > void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
> > {
> > struct ttm_tt *ttm = &ttm_dma->ttm;
> > - kvfree(ttm->pages);
> > + if (ttm->pages)
> > + kvfree(ttm->pages);
> > + else
> > + kvfree(ttm_dma->dma_address);
> > ttm->pages = NULL;
> > ttm_dma->dma_address = NULL;
> > }
> > diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
> > index 9c78556b488e..1cf316a4257c 100644
> > --- a/include/drm/ttm/ttm_tt.h
> > +++ b/include/drm/ttm/ttm_tt.h
> > @@ -163,6 +163,8 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
> > unsigned long size, uint32_t page_flags);
> > int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
> > unsigned long size, uint32_t page_flags);
> > +int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
> > + unsigned long size, uint32_t page_flags);
> > /**
> > * ttm_tt_fini
>
> _______________________________________________
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
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-06 9:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 11:49 [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach Christian König
[not found] ` <20180227115000.4105-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-02-27 11:49 ` [PATCH 2/5] drm/prime: make the pages array optional for drm_prime_sg_to_page_addr_arrays Christian König
2018-03-06 9:21 ` Daniel Vetter
[not found] ` <20180306092102.GM22212-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-06 9:25 ` Christian König
2018-03-06 9:37 ` Daniel Vetter
2018-02-27 11:49 ` [PATCH 3/5] drm/ttm: move ttm_tt defines into ttm_tt.h Christian König
[not found] ` <20180227115000.4105-3-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-03-06 9:13 ` Christian König
2018-03-06 9:56 ` Michel Dänzer
2018-03-06 10:00 ` Thomas Hellstrom
2018-02-27 11:49 ` [PATCH 4/5] drm/ttm: add ttm_sg_tt_init Christian König
[not found] ` <20180227115000.4105-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-02-27 12:07 ` Christian König
[not found] ` <b5cb1980-7865-f45a-bc9d-9569f860fb50-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-05 12:06 ` Christian König
2018-03-05 20:55 ` Ben Skeggs
[not found] ` <1592dc9f-d76e-7174-1785-624cbd69d744-5C7GfCeVMHo@public.gmane.org>
2018-03-06 1:52 ` He, Roger
2018-03-06 9:19 ` Daniel Vetter [this message]
2018-02-27 11:50 ` [PATCH 5/5] drm/amdgpu: stop allocating a page array for prime shared BOs Christian König
2018-03-05 12:05 ` [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach Christian König
2018-02-28 9:48 ` Lucas Stach
[not found] ` <1519811307.6253.5.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2018-02-28 10:25 ` Christian König
[not found] ` <3a4f9020-235d-ef05-a246-1ba920070f09-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-06 9:15 ` Daniel Vetter
2018-03-06 9:30 ` Christian König
2018-03-06 9:39 ` Daniel Vetter
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=20180306091907.GL22212@phenom.ffwll.local \
--to=daniel-/w4ywyx8dfk@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=imirkin-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org \
--cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@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