Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: Joseph Lo <josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	"linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
	"iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
	<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Cc: "linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org"
	<linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
	"arnd-r2nGTMty4D4@public.gmane.org"
	<arnd-r2nGTMty4D4@public.gmane.org>,
	"stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org"
	<stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>,
	Catalin Marinas <Catalin.Marinas-5wv7dgnIgG8@public.gmane.org>,
	Will Deacon <Will.Deacon-5wv7dgnIgG8@public.gmane.org>,
	"thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org"
	<thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	"dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org"
	<dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Subject: Re: [RFC PATCH 4/5] arm64: add IOMMU dma_ops
Date: Tue, 27 Jan 2015 17:30:45 +0000	[thread overview]
Message-ID: <54C7CB45.7030907@arm.com> (raw)
In-Reply-To: <54C5B3B9.1040300-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

Hi Joseph,

Thanks for giving it a spin,

On 26/01/15 03:25, Joseph Lo wrote:
> On 01/13/2015 04:48 AM, Robin Murphy wrote:
>> Taking some inspiration from the arch/arm code, implement the
>> arch-specific side of the DMA mapping ops using the new IOMMU-DMA layer.
>>
>> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
>> ---
>>    arch/arm64/include/asm/device.h      |   3 +
>>    arch/arm64/include/asm/dma-mapping.h |  12 ++
>>    arch/arm64/mm/dma-mapping.c          | 297 +++++++++++++++++++++++++++++++++++
>>    3 files changed, 312 insertions(+)
>>
> [snip]
>> +static struct dma_map_ops iommu_dma_ops = {
>> +	.alloc = __iommu_alloc_attrs,
>> +	.free = __iommu_free_attrs,
>> +	.mmap = __swiotlb_mmap,
>
> Hi Robin,
>
> Thanks for posting this series. I spent some time to re-write Tegra-smmu
> driver to work with the new DT-based iommu initialization procedure and
> do some modification in Tegra/DRM driver to make it work with
> IOMMU-backed DMA mapping API.
>
> Found two issues, one is the mmap function here.
> The mmap function is not reliable, the userspace application and kernel
> easily leads to crash after calling this. Can we mmap the CPU VA to the
> IOVA?
> This issue was gone after replacing it with the same function
> (arm_iommu_mmap_attrs) in the ARM32 kernel. And everything just works fine.
>

Hmm, it looks like __dma_common_mmap might rely on pages being 
contiguous, which would be a big problem I hadn't noticed. I'll have a 
dig into it and see if it's feasible to extend the existing 
implementation, otherwise we'll have to just pull in the arm_iommu 
version and have two.

>> +	.map_page = __iommu_map_page,
>> +	.unmap_page = __iommu_unmap_page,
>> +	.map_sg = __iommu_map_sg_attrs,
>> +	.unmap_sg = __iommu_unmap_sg_attrs,
>> +	.sync_single_for_cpu = __iommu_sync_single_for_cpu,
>> +	.sync_single_for_device = __iommu_sync_single_for_device,
>> +	.sync_sg_for_cpu = __iommu_sync_sg_for_cpu,
>> +	.sync_sg_for_device = __iommu_sync_sg_for_device,
>> +	.dma_supported = iommu_dma_supported,
>> +	.mapping_error = iommu_dma_mapping_error,
>> +};
>> +
>> +static void __iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
>> +				  struct iommu_ops *ops)
>> +{
>> +	struct iommu_dma_mapping *mapping;
>> +
>> +	if (!ops)
>> +		return;
>> +
>> +	mapping = iommu_dma_create_mapping(ops, dma_base, size);
>
> The other issue is here. We create a DMA range here, but the
> __iova_alloc not really working with that, if the end of the range was
> under 4G limitation. The allocation address always starts from
> 0xfffxxxxx, because we set the .dma_mask to DMA_BIT_MASK(32) by default.
> If we don't expect that, we need one more function call like
> dma_coerce_mask_and_coherent(dev, 0x80000000) for the range of 0 to 2G
> for example.
>
> Does this the expectation when we use this framework?
>
> (Except the issue of __alloc_iova, I am ok with this. We could set up a
> default range from 0 to 4G for every device by default, and then isolate
> the virtual range by reset the .dma_mask of the device later.)
>

Yes, I failed to consider dma-ranges in this initial version, so it 
allocates based on the DMA mask alone. I hacked up an unsatisfactory 
workaround in preparation for v2, but it turns out the fix as per your 
suggestion is already in progress elsewhere[1], so I'll rework based on 
that idea.

Robin.

[1]:https://lkml.org/lkml/2015/1/23/694

> Thanks,
> -Joseph
>
>> +	if (!mapping) {
>> +		pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n",
>> +				size, dev_name(dev));
>> +		return;
>> +	}
>> +
>> +	if (iommu_dma_attach_device(dev, mapping))
>> +		pr_warn("Failed to attach device %s to IOMMU mapping\n",
>> +				dev_name(dev));
>> +	else
>> +		dev->archdata.dma_ops = &iommu_dma_ops;
>> +
>> +	/* drop the initial mapping refcount */
>> +	iommu_dma_release_mapping(mapping);
>> +}
>> +
>> +#else
>> +
>> +static void __iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
>> +				  struct iommu_ops *iommu)
>> +{ }
>> +
>> +#endif  /* CONFIG_IOMMU_DMA */
>>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

  parent reply	other threads:[~2015-01-27 17:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-12 20:48 [RFC PATCH 0/5] arm64: IOMMU-backed DMA mapping Robin Murphy
     [not found] ` <cover.1421086706.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-01-12 20:48   ` [RFC PATCH 1/5] arm64: Combine coherent and non-coherent swiotlb dma_ops Robin Murphy
2015-01-12 20:48   ` [RFC PATCH 2/5] arm64: implement generic IOMMU configuration Robin Murphy
2015-01-12 20:48   ` [RFC PATCH 3/5] iommu: implement common IOMMU ops for DMA mapping Robin Murphy
     [not found]     ` <09e5515a9afcb3235f4c425520cd18a6032d31b4.1421086706.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-01-23 17:42       ` Laura Abbott
     [not found]         ` <54C287F7.3060603-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-01-23 18:14           ` Robin Murphy
2015-01-27  0:21       ` Joerg Roedel
     [not found]         ` <20150127002116.GI30345-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-01-27 12:27           ` Robin Murphy
     [not found]             ` <54C7843B.3000605-5wv7dgnIgG8@public.gmane.org>
2015-01-27 12:38               ` Joerg Roedel
     [not found]                 ` <20150127123809.GJ30345-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-01-28 13:53                   ` Will Deacon
2015-01-12 20:48   ` [RFC PATCH 4/5] arm64: add IOMMU dma_ops Robin Murphy
     [not found]     ` <aa7de3b1dd189c31eb8b14d0c0eea699183f8a2c.1421086706.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-01-23 15:26       ` Will Deacon
     [not found]         ` <20150123152605.GA31460-5wv7dgnIgG8@public.gmane.org>
2015-01-23 17:33           ` Robin Murphy
2015-01-26  3:25       ` Joseph Lo
     [not found]         ` <54C5B3B9.1040300-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-01-27 17:30           ` Robin Murphy [this message]
2015-01-26  9:10       ` Joseph Lo
2015-01-28  2:22       ` Joseph Lo
2015-03-05 14:31       ` Marek Szyprowski
2015-01-12 20:48   ` [RFC PATCH 5/5] arm64: hook up " Robin Murphy
2015-01-13 11:08   ` [RFC PATCH 0/5] arm64: IOMMU-backed DMA mapping Stefano Stabellini
     [not found]     ` <alpine.DEB.2.02.1501131102540.3058-7Z66fg9igcxYtxbxJUhB2Dgeux46jI+i@public.gmane.org>
2015-01-13 11:45       ` Robin Murphy
2015-01-23 16:47   ` Catalin Marinas
     [not found]     ` <20150123164759.GF9557-M2fw3Uu6cmfZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2015-01-23 17:41       ` Robin Murphy
2015-03-05 14:31   ` Marek Szyprowski
     [not found]     ` <54F868A8.7070103-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-03-05 16:42       ` Robin Murphy
2015-01-13  8:02 ` Yingjoe Chen
2015-01-13 12:07   ` Robin Murphy
2015-01-15 18:35   ` Robin Murphy
2015-01-16  7:21     ` Yong Wu
2015-01-16 20:12       ` Robin Murphy

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=54C7CB45.7030907@arm.com \
    --to=robin.murphy-5wv7dgnigg8@public.gmane.org \
    --cc=Catalin.Marinas-5wv7dgnIgG8@public.gmane.org \
    --cc=Will.Deacon-5wv7dgnIgG8@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org \
    --cc=thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@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