dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Christian König" <christian.koenig@amd.com>
Cc: Logan Gunthorpe <logang@deltatee.com>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Christoph Hellwig <hch@infradead.org>,
	linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org
Subject: Re: [PATCH 1/6] lib/scatterlist: add sg_set_dma_addr() function
Date: Thu, 12 Mar 2020 13:19:31 -0300	[thread overview]
Message-ID: <20200312161931.GQ31668@ziepe.ca> (raw)
In-Reply-To: <5383c8de-4e2c-dc8c-363d-a35d671abfc3@amd.com>

On Thu, Mar 12, 2020 at 04:39:02PM +0100, Christian König wrote:
> > > The structure for holding dma addresses doesn't really exist
> > > in a generic form, but would be an array of these structures:
> > > 
> > > struct dma_sg {
> > > 	dma_addr_t	addr;
> > > 	u32		len;
> > > };
> > Same question, RDMA needs to represent gigabytes of pages in a DMA
> > list, we will need some generic way to handle that. I suspect GPU has
> > a similar need? Can it be accomidated in some generic dma_sg?
> 
> Yes, we easily have ranges of >1GB. So I would certainly say u64 for the len
> here.

To be clear, I mean specifically 1GB of dma map composed of 262k
pages, mapped into 262k dma_sg's that take around some 4M of memory to
represent as struct dma_dg.

Really prefer some scheme that doesn't rely on vmalloc..

Some approach to have a single dma_sg > 4G seems less commonly needed?
I don't think any RDMA HW today can handle a single SGL that large at
least.

> >   - Add some generic dma_sg data structure and helper
> >   - Add dma mapping code to go from pages to dma_sg
> >   - Rework RDMA to use dma_sg and the new dma mapping code
> >   - Rework dmabuf to support dma mapping to a dma_sg
> >   - Rework GPU drivers to use dma_sg
> >   - Teach p2pdma to generate a dma_sg from a BAR page list
> >   - This series
> > 
> > ?
> 
> Sounds pretty much like a plan to me, but unfortunately like a rather huge
> one.

I know parts of this have been advancing.. CH has been working on
fixing up the DMA layer enough to do #1 and #2, I think.

> Because of this and cause I don't know if all drivers can live with dma_sg
> I'm not sure if we shouldn't have the switch from scatterlist to dma_sg
> separately to this peer2peer work.

So far any attempts to make sgls without struct page have failed for
various reasons. Too often obscure stuff does actually want the struct
page.

Stuffing BAR memory pages into the SGL is bad enough already. :(

One pragmatic path might be to define this new 'dma_sg' in a way where
it would have the same memory layout as a 'struct scatterlist'

Something like

struct dma_scatterlist {
        unsigned long   link;
        unsigned int    reserved1;
#ifndef CONFIG_NEED_SG_DMA_LENGTH
        unsigned int    dma_length;
#else
        unsigned int    reserved2;
#endif
        dma_addr_t      dma_address;
#ifdef CONFIG_NEED_SG_DMA_LENGTH
        unsigned int    dma_length;
#endif
};

struct dma_sg_table {
     union {
         struct dma_scatterlist *dma_sgl;
         struct future_more_efficient_structure *future;
     }
     unsigned int nents;
};

Then a dma_map_sg could be 

struct dma_sg_table *dma_map_sg_attrs_to_dma(
       struct device *dev, struct scatterlist *sg,
       int nents, enum dma_data_direction dir,
       unsigned long attrs)
{
   ret = dma_map_sg_attrs(dev, sg, nents, dir, attrs);
   res = kmalloc(sizeof(dma_sg_table));
   res->dma_sgl = sg;
   return res;
}

Then at least the work can get gets split up, I can switch RDMA
drivers to use dma_sg_table, then I can switch the subsystem to call
dma_map_sg_attrs_to_dma, then when we get dma_map_biovec_attrs() I can
work on switching the input sgl to a biovec without changing the
drivers.

After enough conversions are done we can optimize the memory layout
inside dma_sg_table, after everything is done we can drop support for
'dma_scatterlist'

It doesn't feel objectionable to build a 'dma_sg_table' without a
struct page.

Jason
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-03-13  8:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 13:51 P2P for DMA-buf Christian König
2020-03-11 13:51 ` [PATCH 1/6] lib/scatterlist: add sg_set_dma_addr() function Christian König
     [not found]   ` <20200311152838.GA24280@infradead.org>
2020-03-12 10:14     ` Christian König
     [not found]       ` <20200312101943.GA14618@infradead.org>
2020-03-12 10:31         ` Christian König
     [not found]           ` <20200312104729.GA26031@infradead.org>
2020-03-12 11:02             ` Christian König
2020-03-12 14:19             ` Jason Gunthorpe
2020-03-12 15:39               ` Christian König
2020-03-12 16:19                 ` Jason Gunthorpe [this message]
2020-03-12 16:13               ` Logan Gunthorpe
     [not found]               ` <20200313112139.GA4913@infradead.org>
2020-03-13 12:17                 ` Jason Gunthorpe
     [not found]                   ` <20200316085642.GC1831@infradead.org>
2020-03-16  9:41                     ` Christian König
     [not found]                       ` <20200316095213.GA29212@infradead.org>
2020-03-16 12:37                         ` Jason Gunthorpe
2020-03-13 13:33                 ` Christian König
2020-03-11 13:51 ` [PATCH 2/6] dma-buf: add peer2peer flag Christian König
2020-03-11 13:51 ` [PATCH 3/6] drm/amdgpu: note that we can handle peer2peer DMA-buf Christian König
2020-03-11 13:51 ` [PATCH 4/6] drm/amdgpu: add checks if DMA-buf P2P is supported Christian König
2020-03-11 14:04   ` Jason Gunthorpe
2020-03-11 14:33     ` Christian König
2020-03-11 14:38       ` Jason Gunthorpe
2020-03-11 14:43         ` Christian König
2020-03-11 14:48           ` Jason Gunthorpe
2020-03-11 13:51 ` [PATCH 5/6] drm/amdgpu: add support for exporting VRAM using DMA-buf v2 Christian König
2020-03-11 14:33   ` Jason Gunthorpe
2020-03-11 14:39   ` Jason Gunthorpe
2020-03-11 15:08   ` Alex Deucher
2020-03-11 13:51 ` [PATCH 6/6] drm/amdgpu: improve amdgpu_gem_info debugfs file 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=20200312161931.GQ31668@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@infradead.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=logang@deltatee.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).