From: Jonathan Lemon <jonathan.lemon@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
iommu@lists.linux-foundation.org, bpf@vger.kernel.org,
"Björn Töpel" <bjorn.topel@intel.com>,
"Magnus Karlsson" <magnus.karlsson@intel.com>
Subject: Re: [PATCH 1/4] dma-mapping: add a new dma_need_sync API
Date: Tue, 7 Jul 2020 08:11:09 -0700 [thread overview]
Message-ID: <20200707151109.qui5uzzzq4dihfie@bsd-mbp> (raw)
In-Reply-To: <20200707064730.GA23602@lst.de>
On Tue, Jul 07, 2020 at 08:47:30AM +0200, Christoph Hellwig wrote:
> On Mon, Jul 06, 2020 at 12:42:27PM -0700, Jonathan Lemon wrote:
> > On Mon, Jun 29, 2020 at 03:03:56PM +0200, Christoph Hellwig wrote:
> > > Add a new API to check if calls to dma_sync_single_for_{device,cpu} are
> > > required for a given DMA streaming mapping.
> > >
> > > +::
> > > +
> > > + bool
> > > + dma_need_sync(struct device *dev, dma_addr_t dma_addr);
> > > +
> > > +Returns %true if dma_sync_single_for_{device,cpu} calls are required to
> > > +transfer memory ownership. Returns %false if those calls can be skipped.
> >
> > Hi Christoph -
> >
> > Thie call above is for a specific dma_addr. For correctness, would I
> > need to check every addr, or can I assume that for a specific memory
> > type (pages returned from malloc), that the answer would be identical?
>
> You need to check every mapping. E.g. this API pairs with a
> dma_map_single/page call. For S/G mappings you'd need to call it for
> each entry, although if you have a use case for that we really should
> add a dma_sg_need_sync helper instea of open coding the scatterlist walk.
My use case is setting up a pinned memory area, and caching the dma
mappings. I'd like to bypass storing the DMA addresses if they aren't
needed. For example:
setup()
{
if (dma_need_sync(dev, addr, len)) {
kvmalloc_array(...)
cache_dma_mappings(...)
}
dev_get_dma(page)
{
if (!cache)
return page_to_phys(page)
return dma_cache_lookup(...)
The reason for doing it this way is that the page in question may be
backed by either system memory, or device memory such as a GPU. For the
latter, the GPU provides a table of DMA addresses where data may be
accessed, so I'm unable to use the dma_map_page() API.
--
Jonathan
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-07-07 15:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-29 13:03 add an API to check if a streamming mapping needs sync calls Christoph Hellwig
2020-06-29 13:03 ` [PATCH 1/4] dma-mapping: add a new dma_need_sync API Christoph Hellwig
2020-07-06 19:42 ` Jonathan Lemon
2020-07-07 6:47 ` Christoph Hellwig
2020-07-07 15:11 ` Jonathan Lemon [this message]
2020-07-07 15:14 ` Christoph Hellwig
2020-06-29 13:03 ` [PATCH 2/4] xsk: replace the cheap_dma flag with a dma_need_sync flag Christoph Hellwig
2020-06-29 13:03 ` [PATCH 3/4] xsk: remove a double pool->dev assignment in xp_dma_map Christoph Hellwig
2020-06-29 13:03 ` [PATCH 4/4] xsk: use dma_need_sync instead of reimplenting it Christoph Hellwig
2020-06-29 13:39 ` add an API to check if a streamming mapping needs sync calls Björn Töpel
2020-06-29 14:22 ` Christoph Hellwig
2020-07-08 7:44 ` Christoph Hellwig
2020-07-08 9:01 ` Daniel Borkmann
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=20200707151109.qui5uzzzq4dihfie@bsd-mbp \
--to=jonathan.lemon@gmail.com \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.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).