mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Will Deacon <Will.Deacon@arm.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>,
	"Ian.Campbell@citrix.com" <Ian.Campbell@citrix.com>,
	"david.vrabel@citrix.com" <david.vrabel@citrix.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v7 3/8] arm64: introduce is_device_dma_coherent
Date: Mon, 10 Nov 2014 12:35:06 +0000	[thread overview]
Message-ID: <alpine.DEB.2.02.1411101200080.22875@kaball.uk.xensource.com> (raw)
In-Reply-To: <20141110101645.GA21366@e104818-lin.cambridge.arm.com>

On Mon, 10 Nov 2014, Catalin Marinas wrote:
> On Fri, Nov 07, 2014 at 06:45:22PM +0000, Stefano Stabellini wrote:
> > On Fri, 7 Nov 2014, Catalin Marinas wrote:
> > > On Fri, Nov 07, 2014 at 05:35:41PM +0000, Stefano Stabellini wrote:
> > > > On Fri, 7 Nov 2014, Stefano Stabellini wrote:
> > > > > On Fri, 7 Nov 2014, Catalin Marinas wrote:
> > > > > > What I would like to see is xen_dma_map_page() also using hyp calls for
> > > > > > cache maintenance when !pfn_valid(), for symmetry with unmap. You would
> > > > > > need another argument to xen_dma_map_page() though to pass the real
> > > > > > device address or mfn (and on the map side you could simply check for
> > > > > > page_to_pfn(page) != mfn). For such cases, Xen swiotlb already handles
> > > > > > bouncing so you don't need dom0 swiotlb involved as well.
> > > > > 
> > > > > I can see that it would be nice to have map_page and unmap_page be
> > > > > symmetrical. However actually doing the map_page flush with an hypercall
> > > > > would slow things down. Hypercalls are slower than function calls. It is
> > > > > faster to do the cache flushing in dom0 if possible. In the map_page
> > > > > case we have the struct page so we can easily do it by calling the
> > > > > native dma_ops function.
> > > > > 
> > > > > Maybe I could just add a comment to explain the reason for the asymmetry?
> > > > 
> > > > Ah, but the problem is that map_page could allocate a swiotlb buffer
> > > > (actually it does on arm64) that without a corresponding unmap_page
> > > > call, would end up being leaked, right?
> > > 
> > > Yes. You could hack dma_capable() to always return true for dom0
> > > (because the pfn/dma address here doesn't have anything to do with the
> > > real mfn) but that's more of a hack assuming a lot about the swiotlb
> > > implementation.
> > 
> > Another idea would be to avoid calling the native map_page for foreign
> > pages, but in the xen specific implementation instead of making the
> > hypercall, we could call __dma_map_area on arm64 and map_page on arm.
> 
> The problem here is that you assume that for an SoC that is not fully
> coherent all it needs is __dma_map_area. If you look at mach-mvebu, the
> DMA is nearly cache coherent but it needs some specific synchronisation
> barrier at the interconnect level. If we get something like this on a
> platform with virtualisation, it would be implemented at the dom0 level
> by SoC-specific DMA ops. Xen hypervisor I assume has its own BSP, hence
> it could implement SoC specific cache flushing there. But with the mix
> of cache flushing in dom0 on map and hypervisor on unmap such thing is
> no longer be possible in a nice way.

Yes, Xen has its own little platform files.

I think you convinced me that having map in Linux and unmap in Xen is
not a long term solid solution.


> > In arch/arm/include/asm/xen/page-coherent.h:
> > 
> > static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
> > 	     dma_addr_t dev_addr, unsigned long offset, size_t size,
> > 	     enum dma_data_direction dir, struct dma_attrs *attrs)
> > {
> > 	if (pfn_valid(PFN_DOWN(dev_addr))) {
> 
> BTW, pfn_valid() is more expensive than simply comparing the mfn with
> pfn for dom0. The calling code knows this already and it may be quicker
> to simply pass a "bool foreign" argument.

Good point, I can compare mfn and pfn here.
I cannot do the same in unmap_page and the various sync operations,
because there is no pfn available, but maybe I could use
set_page_private to set a flag. I'll think about it.


> > It wouldn't be as nice as using the hypercall but it would be faster and
> > wouldn't depend on the inner workings of the arm64 implementation of
> > map_page, except for __dma_map_area.
> 
> This "except" is big as we may at some point get some SoC like mvebu (I
> would say less likely for arm64 than arm32).
> 
> BTW, does the Xen hypervisor already have a mapping of the mfn?

On arm64, it does.
On arm32, we have a pool of mappings, when we run out we start
overwriting old mappings.


> If not
> and it has to create one temporarily for the flush, you may not lose
> much by using the dom0 ops for unmap with a hyper call for temporarily
> mapping the foreign page in dom0's IPA space (you could do the unmapping
> lazily).

That's true. Fortunately on arm64 we are OK.

  reply	other threads:[~2014-11-10 12:35 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27 15:08 [PATCH v7 0/8] introduce GNTTABOP_cache_flush Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 1/8] xen/arm: remove handling of XENFEAT_grant_map_identity Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 2/8] xen/arm: remove outer_*_range call Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 3/8] arm64: introduce is_device_dma_coherent Stefano Stabellini
2014-11-03 10:46   ` Stefano Stabellini
2014-11-03 10:57     ` Will Deacon
2014-11-03 11:10       ` Stefano Stabellini
2014-11-04 11:35         ` Grygorii Strashko
2014-11-04 15:00           ` Stefano Stabellini
2014-11-05 16:56         ` Catalin Marinas
2014-11-05 18:15           ` Stefano Stabellini
2014-11-06 10:33             ` Catalin Marinas
2014-11-06 12:22               ` Stefano Stabellini
2014-11-06 13:40                 ` Catalin Marinas
2014-11-07 11:05                 ` Catalin Marinas
2014-11-07 11:11                   ` Catalin Marinas
2014-11-07 14:10                     ` Stefano Stabellini
2014-11-07 14:10                   ` Stefano Stabellini
2014-11-07 16:00                     ` Catalin Marinas
2014-11-07 17:24                       ` Stefano Stabellini
2014-11-07 17:35                         ` Stefano Stabellini
2014-11-07 18:14                           ` Catalin Marinas
2014-11-07 18:45                             ` Stefano Stabellini
2014-11-10 10:16                               ` Catalin Marinas
2014-11-10 12:35                                 ` Stefano Stabellini [this message]
2014-11-10 12:41                                   ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 4/8] arm: " Stefano Stabellini
2014-11-03 10:55   ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 5/8] xen/arm: use is_device_dma_coherent Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 6/8] xen/arm/arm64: merge xen/mm32.c into xen/mm.c Stefano Stabellini
2014-11-07 14:22   ` Catalin Marinas
2014-11-07 15:28     ` Stefano Stabellini
2014-11-07 16:03       ` Catalin Marinas
2014-11-07 16:46         ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 7/8] xen/arm/arm64: introduce xen_arch_need_swiotlb Stefano Stabellini
2014-11-03 10:45   ` Stefano Stabellini
2014-11-03 11:01     ` [Xen-devel] " David Vrabel
2014-11-03 16:04     ` Konrad Rzeszutek Wilk
2014-10-27 15:09 ` [PATCH v7 8/8] xen/arm: introduce GNTTABOP_cache_flush Stefano Stabellini

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=alpine.DEB.2.02.1411101200080.22875@kaball.uk.xensource.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Will.Deacon@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=david.vrabel@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xensource.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

all inboxes | Powered by JetHome®