From: Catalin Marinas <catalin.marinas@arm.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
"Ian.Campbell@citrix.com" <Ian.Campbell@citrix.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>
Subject: Re: [PATCH v5 11/13] xen: introduce xen_alloc/free_coherent_pages
Date: Wed, 11 Sep 2013 10:36:46 +0100 [thread overview]
Message-ID: <20130911093646.GA26777@darko.cambridge.arm.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1309091732230.6397@kaball.uk.xensource.com>
On Mon, Sep 09, 2013 at 05:46:59PM +0100, Stefano Stabellini wrote:
> On Mon, 9 Sep 2013, Catalin Marinas wrote:
> > >>> They could also happen in a DomU if we assign a physical device to it
> > >>> (and an SMMU is not available).
> > >>
> > >> The problem is that you don't necessarily know one kind of coherency you
> > >> know for a physical device. As I said, we plan to do this DT-driven.
> > >
> > > OK, but if I call arm64_swiotlb_dma_ops.alloc passing the right
> > > arguments to it, I should be able to get the right coherency for the
> > > right device, correct?
> >
> > I think it needs a bit more work on the Xen part. Basically
> > dma_alloc_attrs() calls get_dma_ops() to obtain the best DMA operations
> > for a device. arm64_swiotlb_dma_ops is just the default implementation
> > and I'll add a _noncoherent variant as well. Default dma_ops will be
> > set to one of these during boot. But a device is also allowed to have
> > its own dev->archdata.dma_ops, set via set_dma_ops().
> >
> > So even if you set the default dma_ops to Xen ops, you may not get them
> > via dma_alloc_coherent(). I don't see any easier solution other than
> > patching the dma_alloc_attrs() function to issue a Hyp call after the
> > memory has been allocated with the get_dma_ops()->alloc(). But I don't
> > like this either.
>
> I see. This problem affects arch/arm as well.
> Either we add an if (!xen_domain()) in get_dma_ops, or we could make
> get_dma_ops a function pointer and let people overwrite it.
> See below the first option implemented for arch/arm on top of the
> swiotlb series:
>
>
> diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
> index 7d6e4f9..0b8b5e4 100644
> --- a/arch/arm/include/asm/dma-mapping.h
> +++ b/arch/arm/include/asm/dma-mapping.h
> @@ -12,6 +12,8 @@
> #include <asm/memory.h>
> #include <asm/cacheflush.h>
>
> +#include <xen/xen.h>
> +
> #define DMA_ERROR_CODE (~0)
> extern struct dma_map_ops *dma_ops;
> extern struct dma_map_ops arm_dma_ops;
> @@ -19,7 +21,7 @@ extern struct dma_map_ops arm_coherent_dma_ops;
>
> static inline struct dma_map_ops *get_dma_ops(struct device *dev)
> {
> - if (dev && dev->archdata.dma_ops)
> + if (!xen_domain() && dev && dev->archdata.dma_ops)
> return dev->archdata.dma_ops;
> return dma_ops;
> }
> diff --git a/arch/arm/include/asm/xen/page-coherent.h b/arch/arm/include/asm/xen/page-coherent.h
> index af2cf8d..c2232fe 100644
> --- a/arch/arm/include/asm/xen/page-coherent.h
> +++ b/arch/arm/include/asm/xen/page-coherent.h
> @@ -9,6 +9,8 @@ static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
> dma_addr_t *dma_handle, gfp_t flags,
> struct dma_attrs *attrs)
> {
> + if (hwdev && hwdev->archdata.dma_ops)
> + return hwdev->archdata.dma_ops->alloc(hwdev, size, dma_handle, flags, attrs);
> return arm_dma_ops.alloc(hwdev, size, dma_handle, flags, attrs);
I still don't like xen digging into the archdata internals. What about:
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 5b579b9..5fa472c 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -15,13 +15,20 @@
extern struct dma_map_ops arm_dma_ops;
extern struct dma_map_ops arm_coherent_dma_ops;
-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+static inline struct dma_map_ops *__get_dma_ops(struct device *dev)
{
if (dev && dev->archdata.dma_ops)
return dev->archdata.dma_ops;
return &arm_dma_ops;
}
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+ if (xen_domain())
+ return xen_dma_ops;
+ return __get_dma_ops(dev);
+}
+
static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
{
BUG_ON(!dev);
@@ -32,7 +39,7 @@ static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
static inline int dma_set_mask(struct device *dev, u64 mask)
{
- return get_dma_ops(dev)->set_dma_mask(dev, mask);
+ return __get_dma_ops(dev)->set_dma_mask(dev, mask);
}
#ifdef __arch_page_to_dma
And in xen_alloc_coherent_pages():
return __get_dma_ops(dev).alloc(...);
Alternatively, add the xen_domain() check in dma_alloc_attrs() instead
of get_dma_ops() (and other functions like map_sg etc.)
--
Catalin
next prev parent reply other threads:[~2013-09-11 9:37 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 18:31 [PATCH v5 0/13] enable swiotlb-xen on arm and arm64 Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 01/13] arm: make SWIOTLB available Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 02/13] arm: introduce a global dma_ops pointer Stefano Stabellini
2013-09-02 14:45 ` [Xen-devel] " Julien Grall
2013-09-05 16:39 ` Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 03/13] arm64: define DMA_ERROR_CODE Stefano Stabellini
2013-09-05 16:05 ` Catalin Marinas
2013-09-05 16:54 ` Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 04/13] arm64: do not initialize arm64_swiotlb if dma_ops is already set Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 05/13] xen/arm,arm64: move Xen initialization earlier Stefano Stabellini
2013-09-05 16:20 ` Catalin Marinas
2013-09-05 16:59 ` Stefano Stabellini
2013-09-06 8:58 ` Ian Campbell
2013-09-06 14:09 ` Catalin Marinas
2013-09-06 14:23 ` Konrad Rzeszutek Wilk
2013-09-06 14:53 ` Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 06/13] xen: introduce XENMEM_exchange_and_pin and XENMEM_unpin Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 07/13] xen: make xen_create_contiguous_region return the dma address Stefano Stabellini
2013-08-30 13:45 ` Konrad Rzeszutek Wilk
2013-08-29 18:32 ` [PATCH v5 08/13] swiotlb-xen: support autotranslate guests Stefano Stabellini
2013-08-30 13:46 ` Konrad Rzeszutek Wilk
2013-08-29 18:32 ` [PATCH v5 09/13] xen/arm,arm64: enable SWIOTLB_XEN Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 10/13] swiotlb-xen: introduce xen_swiotlb_set_dma_mask Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 11/13] xen: introduce xen_alloc/free_coherent_pages Stefano Stabellini
2013-09-05 16:09 ` Catalin Marinas
2013-09-05 16:43 ` Stefano Stabellini
2013-09-06 14:14 ` Catalin Marinas
2013-09-06 14:59 ` Stefano Stabellini
2013-09-06 15:59 ` Catalin Marinas
2013-09-06 16:09 ` Stefano Stabellini
2013-09-06 16:20 ` Catalin Marinas
2013-09-06 16:52 ` Stefano Stabellini
2013-09-09 15:51 ` Catalin Marinas
2013-09-09 16:46 ` Stefano Stabellini
2013-09-11 9:36 ` Catalin Marinas [this message]
2013-09-11 17:34 ` Stefano Stabellini
2013-09-12 13:53 ` Catalin Marinas
2013-09-12 14:44 ` Stefano Stabellini
2013-09-12 15:04 ` Catalin Marinas
2013-08-29 18:32 ` [PATCH v5 12/13] swiotlb-xen: use xen_alloc/free_coherent_pages Stefano Stabellini
2013-08-30 13:53 ` Konrad Rzeszutek Wilk
2013-09-05 16:50 ` Stefano Stabellini
2013-09-06 14:17 ` Konrad Rzeszutek Wilk
2013-09-06 15:04 ` Stefano Stabellini
2013-08-29 18:32 ` [PATCH v5 13/13] swiotlb: don't assume that io_tlb_start-io_tlb_end is coherent 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=20130911093646.GA26777@darko.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=Ian.Campbell@citrix.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stefano.stabellini@eu.citrix.com \
--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®