public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: laurent.pinchart@ideasonboard.com (Laurent Pinchart)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 6/8] dma-mapping: detect and configure IOMMU in of_dma_configure
Date: Wed, 17 Dec 2014 02:05:05 +0200	[thread overview]
Message-ID: <3351702.svo5za0hNC@avalon> (raw)
In-Reply-To: <20141215180933.GW20738@arm.com>

Hi Will,

On Monday 15 December 2014 18:09:33 Will Deacon wrote:
> On Mon, Dec 15, 2014 at 05:16:50PM +0000, Laurent Pinchart wrote:
> > On Monday 15 December 2014 16:40:41 Will Deacon wrote:
> >> On Sun, Dec 14, 2014 at 03:49:34PM +0000, Laurent Pinchart wrote:
> >>> On Wednesday 10 December 2014 15:08:53 Will Deacon wrote:
> >>>> On Wed, Dec 10, 2014 at 02:52:56PM +0000, Rob Clark wrote:
> >>>>> so, what is the way for a driver that explicitly wants to manage
> >>>>> it's own device virtual address space to opt out of this?  I
> >>>>> suspect that won't be the common case, but for a gpu, if dma layer
> >>>>> all of a sudden thinks it is in control of the gpu's virtual
> >>>>> address space, things are going to end in tears..
> >>>> 
> >>>> I think you'll need to detach from the DMA domain, then have the
> >>>> driver manage everything itself. As you say, it's not the common
> >>>> case, so you may need to add some hooks for detaching from the
> >>>> default domain and swizzling your DMA ops.
> >>> 
> >>> I'm wondering if it's such an exotic case after all. I can see two
> >>> reasons not to use the default domain. In addition to special
> >>> requirements coming from the bus master side, the IOMMU itself might
> >>> not support one domain per bus master (I'm of course raising the issue
> >>> from a very selfish Renesas IPMMU point of view).
> >> 
> >> Do you mean that certain masters must be grouped into the same domain,
> >> or that the IOMMU can fail with -ENOSPC?
> > 
> > My IOMMU has hardware supports for 4 domains, and serves N masters (where
> > N is dependent on the SoC but is > 4). In its current form the driver
> > supports a single domain and thus detaches devices from the default
> > domain in the add_device callback:
>
> Hmm, ok. Ideally, you wouldn't need to do any of that in the driver, but I
> can understand why you decided to go down that route.

I'm of course open to alternative suggestions :-)

> > 	/*
> > 	 * Detach the device from the default ARM VA mapping and attach it to
> > 	 * our private mapping.
> > 	 */
> > 	arm_iommu_detach_device(dev);
> > 	ret = arm_iommu_attach_device(dev, mmu->mapping);
> > 	if (ret < 0) {
> > 	
> > 		dev_err(dev, "Failed to attach device to VA mapping\n");
> > 		return ret;
> > 	
> > 	}
> > 
> > I would have implemented that in the of_xlate callback, but that's too
> > early as the ARM default domain isn't created yet at that point.
> 
> Yup, the mythical ->get_default_domain might be the right place instead.
> 
> > Using a single domain is a bit of a waste of resources in my case, so an
> > evolution would be to create four domains and assign devices to them based
> > on a policy. The policy could be fixed (round-robin for instance), or
> > configurable (possibly through DT, although it's really a policy, not a
> > hardware description).
> 
> I think having one default domain, which is home to all of the masters that
> don't have any DMA restrictions is a good use of the hardware. That then
> leaves you with three domains to cover VFIO, devices with DMA limitations
> and potentially device isolation (if we had a way to describe that).
> 
> >> For the former, we need a way to represent IOMMU groups for the platform
> >> bus.
> > 
> > To be honest I'm not entirely sure how IOMMU groups are supposed to be
> > used. I understand they can be used by VFIO to group several masters that
> > will be able to see each other's memory through the same page table, and
> > also that a page table could be shared between multiple groups. When it
> > comes to group creation, though, things get fuzzy. I started with
> > creating one group per master in my driver, which is probably not the
> > thing to do. The Exynos IOMMU driver used to do the same, until Marek's
> > patch series converting it to DT- based instantiation (on top of your
> > patch set) has removed groups altogether. Groups seem to be more or less
> > optional, except in a couple of places (for instance the remove_device
> > callback will not be called by the BUS_NOTIFY_DEL_DEVICE notifier if the
> > device isn't part of an iommu group).
> > 
> > I'd appreciate if someone could clarify this to help me make an informed
> > opinion on the topic.
> 
> Ok, an iommu_group is the minimum granularity for which a specific IOMMU
> can offer address translation. So, if your IPMMU can isolate an arbitrary
> device (assuming there is a domain available), then each device is in its
> own iommu_group. This isn't always the case, for example if two masters are
> behind some sort of bridge that makes them indistinguishable to the IOMMU
> (perhaps they appear to have the same master ID), then they would have to
> be in the same iommu_group. Essentially, iommu_groups are a property of
> the hardware and should be instantiated by the bus. PCI does this, but
> we don't yet have anything for the platform bus.
> 
> VFIO puts multiple groups (now called vfio_groups) into a container. The
> container is synoymous to an iommu_domain (i.e. a shared address space).

Thank you for the explanation, that was very informative. It would be nice to 
capture that somewhere in Documentation/ ;-)

I'll thus create one group per bus master in the of_xlate function, as my 
platforms don't have masters indistinguishable to the IOMMUs (at least not to 
my knowledge).

-- 
Regards,

Laurent Pinchart

  parent reply	other threads:[~2014-12-17  0:05 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 [this message]
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
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=3351702.svo5za0hNC@avalon \
    --to=laurent.pinchart@ideasonboard.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