From: acourbot@nvidia.com (Alexandre Courbot)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 8/8] arm: dma-mapping: plumb our iommu mapping ops into arch_setup_dma_ops
Date: Thu, 15 Jan 2015 11:57:04 +0900 [thread overview]
Message-ID: <54B72C80.5010400@nvidia.com> (raw)
In-Reply-To: <20150114104610.GC4050@arm.com>
On 01/14/2015 07:46 PM, Will Deacon wrote:
> Hi Alex,
>
> On Wed, Jan 14, 2015 at 09:00:24AM +0000, Alexandre Courbot wrote:
>> On 12/02/2014 01:57 AM, Will Deacon wrote:
>>> This patch plumbs the existing ARM IOMMU DMA infrastructure (which isn't
>>> actually called outside of a few drivers) into arch_setup_dma_ops, so
>>> that we can use IOMMUs for DMA transfers in a more generic fashion.
>>>
>>> Since this significantly complicates the arch_setup_dma_ops function,
>>> it is moved out of line into dma-mapping.c. If CONFIG_ARM_DMA_USE_IOMMU
>>> is not set, the iommu parameter is ignored and the normal ops are used
>>> instead.
>>
>> A series for IOMMU support with Tegra/Nouveau ceased to work after this
>> patch.
>
> Which series? This code shouldn't even be executed unless you start using
> of_xlate and the generic bindings.
>
>> The Tegra IOMMU is not registered by the time the DT is parsed,
>> and thus all devices end up without the proper DMA ops set up because
>> the phandle to the IOMMU cannot be resolved.
>
> You might want to look at the patches posted for the exynos, renesas and ARM
> SMMUs for some hints in how to use the new API.
>
>> Subsequently calling arm_iommu_create_mapping() and
>> arm_iommu_attach_device() from the driver (as I used to do until 3.18)
>> does not help since the call to set_dma_ops() has been moved out of
>> arm_iommu_attach_device(). Therefore there seems to be no way for a device
>> to gets its correct DMA ops unless the IOMMU is ready by the time the DT
>> is parsed.
>>
>> Also potentially affected by this are the Rockchip DRM and OMAP3 ISP
>> drivers, which follow the same pattern.
>
> I don't understand why any code currently in mainline should be affected.
> Please can you elaborate on the failure case?
Here is the sequence of events:
1) DT is populated and of_dma_configure() is called for every device.
Here is the stack trace:
of_dma_configure
of_platform_device_create_pdata
of_platform_bus_create
of_platform_bus_create
of_platform_populate
customize_machine
do_one_initcall
of_dma_configure() is supposed to set the iommu_ops for every device
(and this is currently the only place in the kernel where this can
happen), but since the IOMMU is not ready yet it falls back to the
default arm_dma_ops.
2) Driver calls arm_iommu_create_mapping() and arm_iommu_attach_device()
(which were already called during step 1 btw). Both calls succeed, but
since arm_iommu_attach_device() does not change the ops anymore we are
still left with arm_dma_ops.
3) Things don't go well. :)
There are several problems with the way things are currently setup IMHO:
1) CONFIG_ARM_DMA_USE_IOMMU forcibly makes the DMA API go through the
IOMMU. This effectively forbids the simultaneous use of the IOMMU API
and DMA API because of address-space collisions issue. Being a kernel
config option, there is no way to turn this behavior off which will
likely become a problem for multi-configs where some platforms might
want this and some other not.
2) IIUC arm_iommu_*() are now not supposed to be called directly by
drivers anymore. At least that's what their current behavior makes me
think, as well as the fact that they are not defined if
CONFIG_ARM_DMA_USE_IOMMU is not set. Yet they are still public and
drivers that use them have not been updated consequently.
3) This is a longer-standing issue, but IIUC the fact that the IOMMU VM
used by the DMA API is not available effectively prevents anyone from
using the DMA API behind a IOMMU and the IOMMU API simultaneously (which
you now have to assume is always the case because of 1)).
These are huge issues - under the current conditions the only safe path
for me is to eschew the DMA API completely and port my work to the IOMMU
API, and I suspect this will affect other people as well.
>
>> This raises the following questions:
>>
>> 1) Why are arm_iommu_create_mapping() and arm_iommu_attach_device()
>> still public since they cannot set the DMA ops and thus seem to be
>> useless outside of arch_setup_dma_ops()?
>
> It has callers outside of the file. I'd like to make it static, but that
> means doing some non-trivial porting of all the callers, which I'm also
> unable to test.
Yeah, but all the callers of these functions are broken anyway as of
3.18-rc4...
>
>> 2) Say you want to use the IOMMU API in your driver, and have an iommu
>> property in your device's DT node. If by chance your IOMMU is registered
>> early, you will already have a mapping automatically created even before
>> your probe function is called. Can this be avoided? Is it even safe?
>
> Currently, I think you have to either teardown the ops manually or return
> an error from of_xlate. Thierry was also looking at this sort of thing,
> so it might be worth talking to him.
Tearing down the ops manually does not sound like something drivers
should do - how can they even be aware of the private dma_ops anyway?
Thanks,
Alex.
next prev parent reply other threads:[~2015-01-15 2:57 UTC|newest]
Thread overview: 110+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-01 16:57 [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Will Deacon
2014-12-01 16:57 ` [PATCH v6 1/8] iommu: provide early initialisation hook for IOMMU drivers Will Deacon
2014-12-01 23:54 ` Rob Herring
2014-12-02 9:23 ` Marek Szyprowski
2014-12-02 9:36 ` Arnd Bergmann
2014-12-02 9:43 ` Will Deacon
2014-12-02 12:05 ` Thierry Reding
2014-12-02 10:30 ` Pantelis Antoniou
2014-12-02 14:16 ` Grant Likely
2014-12-03 19:57 ` Arnd Bergmann
2014-12-04 9:49 ` Will Deacon
2014-12-04 10:10 ` Arnd Bergmann
2014-12-04 10:21 ` Will Deacon
2014-12-04 11:19 ` Arnd Bergmann
2014-12-04 11:25 ` Grant Likely
2014-12-04 11:52 ` Will Deacon
2014-12-04 12:43 ` Grant Likely
2014-12-04 12:26 ` Robin Murphy
2014-12-04 12:42 ` Grant Likely
2014-12-04 13:43 ` Robin Murphy
2014-12-04 13:58 ` Grant Likely
2014-12-04 14:49 ` Thierry Reding
2014-12-04 17:42 ` Robin Murphy
2014-12-04 17:58 ` Grant Likely
2014-12-04 19:42 ` Robin Murphy
2014-12-05 12:10 ` Will Deacon
2014-12-05 12:21 ` Arnd Bergmann
2014-12-05 12:35 ` Robin Murphy
2014-12-05 13:06 ` Grant Likely
2014-12-05 13:18 ` Thierry Reding
2014-12-05 13:21 ` Grant Likely
2014-12-05 13:31 ` Thierry Reding
2014-12-05 13:49 ` Marek Szyprowski
2014-12-04 12:51 ` Arnd Bergmann
2014-12-01 16:57 ` [PATCH v6 2/8] dma-mapping: replace set_arch_dma_coherent_ops with arch_setup_dma_ops Will Deacon
2014-12-01 22:58 ` Rob Herring
2014-12-02 9:16 ` Arnd Bergmann
2014-12-01 16:57 ` [PATCH v6 3/8] iommu: add new iommu_ops callback for adding an OF device Will Deacon
2014-12-01 16:57 ` [PATCH v6 4/8] iommu: provide helper function to configure an IOMMU for an of master Will Deacon
2014-12-01 16:57 ` [PATCH v6 5/8] iommu: fix initialization without 'add_device' callback Will Deacon
2014-12-01 16:57 ` [PATCH v6 6/8] dma-mapping: detect and configure IOMMU in of_dma_configure Will Deacon
2014-12-01 23:06 ` Rob Herring
2014-12-10 14:52 ` Rob Clark
2014-12-10 15:08 ` Will Deacon
2014-12-10 15:54 ` Robin Murphy
2014-12-10 15:56 ` Laurent Pinchart
2014-12-14 15:49 ` Laurent Pinchart
2014-12-14 15:59 ` Laurent Pinchart
2014-12-15 17:10 ` Will Deacon
2014-12-15 16:40 ` Will Deacon
2014-12-15 17:16 ` Laurent Pinchart
2014-12-15 18:09 ` Will Deacon
2014-12-16 12:08 ` Arnd Bergmann
2014-12-17 12:09 ` Will Deacon
2014-12-17 14:15 ` Arnd Bergmann
2014-12-17 14:45 ` Will Deacon
2014-12-17 15:35 ` Arnd Bergmann
2014-12-17 17:17 ` Will Deacon
2014-12-17 19:48 ` Arnd Bergmann
2014-12-21 10:04 ` Will Deacon
2014-12-22 13:36 ` Arnd Bergmann
2015-01-07 18:57 ` Will Deacon
2015-01-07 19:29 ` Arnd Bergmann
2015-01-08 10:53 ` Will Deacon
2014-12-17 14:27 ` Robin Murphy
2014-12-17 15:01 ` Will Deacon
2014-12-17 15:38 ` Arnd Bergmann
2014-12-17 17:20 ` Will Deacon
2014-12-17 0:05 ` Laurent Pinchart
2014-12-14 15:51 ` Laurent Pinchart
2014-12-15 11:32 ` Will Deacon
2014-12-17 0:19 ` Laurent Pinchart
2014-12-17 11:14 ` Will Deacon
2014-12-01 16:57 ` [PATCH v6 7/8] arm: call iommu_init before of_platform_populate Will Deacon
2014-12-01 16:57 ` [PATCH v6 8/8] arm: dma-mapping: plumb our iommu mapping ops into arch_setup_dma_ops Will Deacon
2015-01-14 9:00 ` Alexandre Courbot
2015-01-14 10:46 ` Will Deacon
2015-01-14 13:51 ` Heiko Stübner
2015-01-14 19:17 ` Will Deacon
2015-01-15 8:30 ` Thierry Reding
2015-01-15 11:13 ` Will Deacon
2015-01-15 2:57 ` Alexandre Courbot [this message]
2015-01-15 8:28 ` Thierry Reding
2015-01-15 11:12 ` Will Deacon
2015-01-15 23:18 ` Laurent Pinchart
2015-01-18 6:54 ` Alexandre Courbot
2015-01-18 11:18 ` Laurent Pinchart
2015-01-19 11:12 ` Will Deacon
2015-01-19 11:34 ` Laurent Pinchart
2015-01-19 12:31 ` Thierry Reding
2015-01-20 15:14 ` Laurent Pinchart
2015-01-20 15:19 ` Will Deacon
2015-01-20 15:21 ` Will Deacon
2015-01-20 15:35 ` Laurent Pinchart
2015-01-19 12:43 ` Thierry Reding
2015-01-19 12:50 ` Will Deacon
2015-01-19 13:36 ` Thierry Reding
2015-01-20 13:50 ` Laurent Pinchart
2015-01-19 16:13 ` Arnd Bergmann
2015-01-20 16:41 ` Laurent Pinchart
2015-01-19 12:36 ` Thierry Reding
2015-01-19 15:52 ` Arnd Bergmann
2015-01-19 16:21 ` Thierry Reding
2015-01-19 17:02 ` Arnd Bergmann
2015-01-20 13:47 ` Laurent Pinchart
2015-01-19 12:49 ` Thierry Reding
2015-01-20 14:05 ` Laurent Pinchart
2014-12-05 7:12 ` [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Olof Johansson
2014-12-05 12:11 ` Will Deacon
2014-12-15 0:24 ` [PATCH/RFC] iommu/ipmmu-vmsa: Use DT-based instantiation Laurent Pinchart
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=54B72C80.5010400@nvidia.com \
--to=acourbot@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.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).