Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: Laura Abbott <lauraa-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	Yong Wu <yong.wu-NuS5LvNUpcJWk0Htik3J/w@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>,
	"thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org"
	<thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	Will Deacon <Will.Deacon-5wv7dgnIgG8@public.gmane.org>,
	"iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
	<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	"josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org"
	<josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	Yingjoe Chen
	<yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	Mitchel Humpherys
	<mitchelh-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	"linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [RFC PATCH v2 2/3] arm64: add IOMMU dma_ops
Date: Thu, 05 Mar 2015 11:16:28 +0000	[thread overview]
Message-ID: <54F83B0C.9020606@arm.com> (raw)
In-Reply-To: <54F7A121.3050103-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>

Hi Laura,

On 05/03/15 00:19, Laura Abbott wrote:
[...]
>> Consider that the IOMMU's page table walker is a DMA master in its own
> right, and that is the device you're mapping the page tables for.
> Therefore your IOMMU driver needs to have access to the struct device
> of the IOMMU itself to use for the page-table-related mappings. Also,
> be sure to set the IOMMU's DMA mask correctly to prevent SWIOTLB bounce
> buffers being created in the process (which as I've found generally ends
> in disaster).
>>
>>>           And normally, we always need do cache maintenance only for some
>>> bytes in the pagetable but not whole a page. Then is there a easy way to
>>> do the cache maintenance?
>>
>> For a noncoherent device, dma_map_single() will end up calling
> __dma_map_area() with the page offset and size of the original request, so
> the updated part gets flushed by VA, and the rest of the page isn't touched
> if it doesn't need to be. On the other hand if the page tables were
> allocated with dma_alloc_coherent() in the first place, then just calling
> dma_sync_single_for_device() for the updated region should suffice.
>>
>
> Where exactly would you call the dma_unmap? It seems a bit strange to
> be repeatedly calling dma_map and never calling dma_unmap. I don't see it
> explicitly forbidden in the docs anywhere to do this but it seems like
> it would be violating the implicit handoff of dma_map/dma_unmap.

I think ideally you'd call dma_map_page when you first create the page 
table, dma_sync_single_for_device on any update, and dma_unmap_page when 
you tear it down, and you'd also use the appropriate DMA addresses 
everywhere instead of physical addresses.

I wouldn't compare that with what we do in the ARM SMMU driver, because 
that's a lot more hacky; there we're actually _relying_ on the mapping 
aspect of dma_map_page being a no-op so we just get the implicit sync 
part of it, thus we know an unmap would do absolutely nothing (since the 
SMMU doesn't write to the page tables we've no need to sync them back to 
the CPU), so we can get away with skipping it. Of course, as both Mitch 
and I have apparently discovered recently, things end up going wrong 
when that no-op assumption isn't true and bounce buffers happen...

Robin.

  parent reply	other threads:[~2015-03-05 11:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-06 14:55 [RFC PATCH v2 0/3] arm64: IOMMU-backed DMA mapping Robin Murphy
     [not found] ` <cover.1423226542.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-02-06 14:55   ` [RFC PATCH v2 1/3] iommu: implement common IOMMU ops for " Robin Murphy
     [not found]     ` <da0e905ae94f2fca241a47b2a20e078255e45a81.1423226542.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-02-09  4:05       ` Will Deacon
     [not found]         ` <20150209040539.GE13969-5wv7dgnIgG8@public.gmane.org>
2015-02-10 15:11           ` Robin Murphy
2015-03-12 12:45       ` Marek Szyprowski
2015-02-06 14:55   ` [RFC PATCH v2 2/3] arm64: add IOMMU dma_ops Robin Murphy
     [not found]     ` <058e038009ac708a40197c80e07410914c2a162e.1423226542.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-02-09  6:02       ` Will Deacon
     [not found]         ` <20150209060224.GG13969-5wv7dgnIgG8@public.gmane.org>
2015-02-10 15:40           ` Robin Murphy
2015-02-10  4:39       ` Yingjoe Chen
2015-02-10 12:07         ` Robin Murphy
     [not found]           ` <54D9F486.10501-5wv7dgnIgG8@public.gmane.org>
2015-02-14  8:03             ` Yong Wu
2015-02-16 20:04               ` Robin Murphy
2015-03-03  3:38                 ` Yong Wu
2015-03-03 12:15                   ` Robin Murphy
     [not found]                     ` <54F5A5FE.3040506-5wv7dgnIgG8@public.gmane.org>
2015-03-05  0:19                       ` Laura Abbott
     [not found]                         ` <54F7A121.3050103-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-03-05 11:16                           ` Robin Murphy [this message]
2015-03-09 17:59                             ` Russell King - ARM Linux
     [not found]                               ` <20150309175904.GC8656-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-03-09 20:09                                 ` Robin Murphy
     [not found]                                   ` <54FDFE0D.8030807-5wv7dgnIgG8@public.gmane.org>
2015-03-10 10:16                                     ` Robin Murphy
2015-03-12 12:50       ` Marek Szyprowski
2015-02-06 14:55   ` [RFC PATCH v2 3/3] arm64: hook up " Robin Murphy
     [not found]     ` <482b3b109a3d4818b1b1e693f488a919cf1bb707.1423226542.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-03-03 11:05       ` leizhen
     [not found]         ` <54F59565.7000807-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-03-03 13:10           ` 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=54F83B0C.9020606@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=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=lauraa-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=mitchelh-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=stefano.stabellini-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org \
    --cc=thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=yong.wu-NuS5LvNUpcJWk0Htik3J/w@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