linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-direct: Export dma_direct_alloc() and dma_direct_free()
Date: Tue, 5 Feb 2019 17:20:57 +0100	[thread overview]
Message-ID: <20190205162057.GA29974@ulmo> (raw)
In-Reply-To: <20190205161036.GA782@lst.de>

[-- Attachment #1: Type: text/plain, Size: 1580 bytes --]

On Tue, Feb 05, 2019 at 05:10:36PM +0100, Christoph Hellwig wrote:
> On Tue, Feb 05, 2019 at 12:06:02PM +0100, Thierry Reding wrote:
> > From: Thierry Reding <treding@nvidia.com>
> > 
> > Drivers that are built as modules may want to use these functions, so
> > make them available like the rest of the functions.
> > 
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> How do they want to use these functions?  The proper way is to
> call dma_alloc_coherent / dma_alloc_free and let the DMA API
> handle the rest.

This is again for the host1x driver and Tegra DRM where we had a similar
situation a little while ago where we needed to explicitly detach from a
DMA/IOMMU mapping.

I ran into a similar situation on Tegra186 (which has an ARM SMMU). The
host1x driver needs to allocate memory for a push buffer that commands
are written to. This push buffer is mapped translated through the SMMU
using direct IOMMU API usage. We use the same domain to also map command
buffers that userspace can pass in.

The problem is that if I use dma_alloc_coherent(), then the memory will
already be mapped via the SMMU at that point and then the driver, not
knowing that memory has already been mapped, will attempt to map an IOVA
which will cause an SMMU fault when the host1x tries to access the
memory.

I didn't find an equivalent to arm_iommu_detach_device() for non-ARM,
but then stumbled across this and thought it was rather convenient for
these cases. If there's a better way to deal with this situation, I'd be
happy to do so.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-02-05 16:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 11:06 [PATCH] dma-direct: Export dma_direct_alloc() and dma_direct_free() Thierry Reding
2019-02-05 16:10 ` Christoph Hellwig
2019-02-05 16:20   ` Thierry Reding [this message]
2019-02-05 16:38     ` Christoph Hellwig
2019-02-05 17:56       ` Thierry Reding
2019-02-05 18:02         ` Christoph Hellwig
2019-02-05 22:29           ` Thierry Reding
2019-02-06  6:57             ` Christoph Hellwig
2019-02-06  7:37             ` Marek Szyprowski

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=20190205162057.GA29974@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.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).