xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] XEN SWIOTLB dma operations extension
@ 2017-02-07 17:58 Andrii Anisov
  2017-02-07 17:58 ` [PATCH v4 1/2] swiotlb-xen: implement xen_swiotlb_dma_mmap callback Andrii Anisov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andrii Anisov @ 2017-02-07 17:58 UTC (permalink / raw)
  To: xen-devel; +Cc: julien.grall, sstabellini, andrii_anisov, oleksandr.dmytryshyn

From: Andrii Anisov <andrii_anisov@epam.com>

Some drivers need additional dma ops to be provided by xen swiotlb. Because
common operations implementation came from x86 world and does not suite ARM
needs we have to provide needed XEN SWIOTLB for ARM callbacks.

dma_mmap patch is a port of an antique and lost patch discussed here:
http://marc.info/?l=xen-devel&m=139695901430667&w=4

Changes in V4:
 - No functional changes
 - '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad
   insisted
 - Added more comments for the functions added and for the debug code
 - fixed code alignment.

Changes in V3:
 - dma ops are moved from ARM specific to generic code
 - runtime operation verified for arm64 with LK 4.9
 - compilation verified for arm, arm64, x86 with the current LK master HEAD
   566cf877a1fcb6d6dc0126b076aad062054c2637

Changes in V2:
 - patches are rebased and checked for compilation for x86, arm, arm64 with
   the current LK master HEAD 83346fbc07d267de777e2597552f785174ad0373

Andrii Anisov (1):
  swiotlb-xen: implement xen_swiotlb_get_sgtable callback

Stefano Stabellini (1):
  swiotlb-xen: implement xen_swiotlb_dma_mmap callback

 arch/arm/xen/mm.c         |  2 ++
 drivers/xen/swiotlb-xen.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/xen/swiotlb-xen.h | 11 +++++++++++
 3 files changed, 60 insertions(+)

-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/2] swiotlb-xen: implement xen_swiotlb_dma_mmap callback
  2017-02-07 17:58 [PATCH v4 0/2] XEN SWIOTLB dma operations extension Andrii Anisov
@ 2017-02-07 17:58 ` Andrii Anisov
  2017-02-07 17:58 ` [PATCH v4 2/2] swiotlb-xen: implement xen_swiotlb_get_sgtable callback Andrii Anisov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrii Anisov @ 2017-02-07 17:58 UTC (permalink / raw)
  To: xen-devel; +Cc: julien.grall, sstabellini, andrii_anisov, oleksandr.dmytryshyn

From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

This function creates userspace mapping for the DMA-coherent memory.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@globallogic.com>
Signed-off-by: Andrii Anisov <andrii_anisov@epam.com>
---
 arch/arm/xen/mm.c         |  1 +
 drivers/xen/swiotlb-xen.c | 19 +++++++++++++++++++
 include/xen/swiotlb-xen.h |  5 +++++
 3 files changed, 25 insertions(+)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index bd62d94..cd1684e 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -198,6 +198,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = {
 	.unmap_page = xen_swiotlb_unmap_page,
 	.dma_supported = xen_swiotlb_dma_supported,
 	.set_dma_mask = xen_swiotlb_set_dma_mask,
+	.mmap = xen_swiotlb_dma_mmap,
 };
 
 int __init xen_mm_init(void)
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index f8afc6d..728d4e0 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -681,3 +681,22 @@ xen_swiotlb_set_dma_mask(struct device *dev, u64 dma_mask)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(xen_swiotlb_set_dma_mask);
+
+/*
+ * Create userspace mapping for the DMA-coherent memory.
+ * This function should be called with the pages from the current domain only,
+ * passing pages mapped from other domains would lead to memory corruption.
+ */
+int
+xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
+		     void *cpu_addr, dma_addr_t dma_addr, size_t size,
+		     unsigned long attrs)
+{
+#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
+	if (__generic_dma_ops(dev)->mmap)
+		return __generic_dma_ops(dev)->mmap(dev, vma, cpu_addr,
+						    dma_addr, size, attrs);
+#endif
+	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap);
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index a0083be..a315c87 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -55,4 +55,9 @@ xen_swiotlb_dma_supported(struct device *hwdev, u64 mask);
 
 extern int
 xen_swiotlb_set_dma_mask(struct device *dev, u64 dma_mask);
+
+extern int
+xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
+		     void *cpu_addr, dma_addr_t dma_addr, size_t size,
+		     unsigned long attrs);
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] swiotlb-xen: implement xen_swiotlb_get_sgtable callback
  2017-02-07 17:58 [PATCH v4 0/2] XEN SWIOTLB dma operations extension Andrii Anisov
  2017-02-07 17:58 ` [PATCH v4 1/2] swiotlb-xen: implement xen_swiotlb_dma_mmap callback Andrii Anisov
@ 2017-02-07 17:58 ` Andrii Anisov
  2017-02-07 18:26 ` [PATCH v4 0/2] XEN SWIOTLB dma operations extension Stefano Stabellini
  2017-02-13 11:29 ` Andrii Anisov
  3 siblings, 0 replies; 5+ messages in thread
From: Andrii Anisov @ 2017-02-07 17:58 UTC (permalink / raw)
  To: xen-devel; +Cc: julien.grall, sstabellini, andrii_anisov, oleksandr.dmytryshyn

From: Andrii Anisov <andrii_anisov@epam.com>

Signed-off-by: Andrii Anisov <andrii_anisov@epam.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c         |  1 +
 drivers/xen/swiotlb-xen.c | 28 ++++++++++++++++++++++++++++
 include/xen/swiotlb-xen.h |  6 ++++++
 3 files changed, 35 insertions(+)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index cd1684e..76ea48a 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -199,6 +199,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = {
 	.dma_supported = xen_swiotlb_dma_supported,
 	.set_dma_mask = xen_swiotlb_set_dma_mask,
 	.mmap = xen_swiotlb_dma_mmap,
+	.get_sgtable = xen_swiotlb_get_sgtable,
 };
 
 int __init xen_mm_init(void)
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 728d4e0..e8cef1a 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -700,3 +700,31 @@ xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
 	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
 }
 EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap);
+
+/*
+ * This function should be called with the pages from the current domain only,
+ * passing pages mapped from other domains would lead to memory corruption.
+ */
+int
+xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
+			void *cpu_addr, dma_addr_t handle, size_t size,
+			unsigned long attrs)
+{
+#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
+	if (__generic_dma_ops(dev)->get_sgtable) {
+#if 0
+	/*
+	 * This check verifies that the page belongs to the current domain and
+	 * is not one mapped from another domain.
+	 * This check is for debug only, and should not go to production build
+	 */
+		unsigned long bfn = PHYS_PFN(dma_to_phys(dev, handle));
+		BUG_ON (!page_is_ram(bfn));
+#endif
+		return __generic_dma_ops(dev)->get_sgtable(dev, sgt, cpu_addr,
+							   handle, size, attrs);
+	}
+#endif
+	return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size);
+}
+EXPORT_SYMBOL_GPL(xen_swiotlb_get_sgtable);
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index a315c87..1f6d78f 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -2,6 +2,7 @@
 #define __LINUX_SWIOTLB_XEN_H
 
 #include <linux/dma-direction.h>
+#include <linux/scatterlist.h>
 #include <linux/swiotlb.h>
 
 extern int xen_swiotlb_init(int verbose, bool early);
@@ -60,4 +61,9 @@ extern int
 xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
 		     void *cpu_addr, dma_addr_t dma_addr, size_t size,
 		     unsigned long attrs);
+
+extern int
+xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
+			void *cpu_addr, dma_addr_t handle, size_t size,
+			unsigned long attrs);
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 0/2] XEN SWIOTLB dma operations extension
  2017-02-07 17:58 [PATCH v4 0/2] XEN SWIOTLB dma operations extension Andrii Anisov
  2017-02-07 17:58 ` [PATCH v4 1/2] swiotlb-xen: implement xen_swiotlb_dma_mmap callback Andrii Anisov
  2017-02-07 17:58 ` [PATCH v4 2/2] swiotlb-xen: implement xen_swiotlb_get_sgtable callback Andrii Anisov
@ 2017-02-07 18:26 ` Stefano Stabellini
  2017-02-13 11:29 ` Andrii Anisov
  3 siblings, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2017-02-07 18:26 UTC (permalink / raw)
  To: Andrii Anisov
  Cc: sstabellini, andrii_anisov, oleksandr.dmytryshyn, julien.grall,
	xen-devel

Both patches are fine by me.

On Tue, 7 Feb 2017, Andrii Anisov wrote:
> From: Andrii Anisov <andrii_anisov@epam.com>
> 
> Some drivers need additional dma ops to be provided by xen swiotlb. Because
> common operations implementation came from x86 world and does not suite ARM
> needs we have to provide needed XEN SWIOTLB for ARM callbacks.
> 
> dma_mmap patch is a port of an antique and lost patch discussed here:
> http://marc.info/?l=xen-devel&m=139695901430667&w=4
> 
> Changes in V4:
>  - No functional changes
>  - '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad
>    insisted
>  - Added more comments for the functions added and for the debug code
>  - fixed code alignment.
> 
> Changes in V3:
>  - dma ops are moved from ARM specific to generic code
>  - runtime operation verified for arm64 with LK 4.9
>  - compilation verified for arm, arm64, x86 with the current LK master HEAD
>    566cf877a1fcb6d6dc0126b076aad062054c2637
> 
> Changes in V2:
>  - patches are rebased and checked for compilation for x86, arm, arm64 with
>    the current LK master HEAD 83346fbc07d267de777e2597552f785174ad0373
> 
> Andrii Anisov (1):
>   swiotlb-xen: implement xen_swiotlb_get_sgtable callback
> 
> Stefano Stabellini (1):
>   swiotlb-xen: implement xen_swiotlb_dma_mmap callback
> 
>  arch/arm/xen/mm.c         |  2 ++
>  drivers/xen/swiotlb-xen.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/xen/swiotlb-xen.h | 11 +++++++++++
>  3 files changed, 60 insertions(+)
> 
> -- 
> 2.7.4
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 0/2] XEN SWIOTLB dma operations extension
  2017-02-07 17:58 [PATCH v4 0/2] XEN SWIOTLB dma operations extension Andrii Anisov
                   ` (2 preceding siblings ...)
  2017-02-07 18:26 ` [PATCH v4 0/2] XEN SWIOTLB dma operations extension Stefano Stabellini
@ 2017-02-13 11:29 ` Andrii Anisov
  3 siblings, 0 replies; 5+ messages in thread
From: Andrii Anisov @ 2017-02-13 11:29 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: xen-devel, Julien Grall, Stefano Stabellini, Andrii Anisov,
	Oleksandr Dmytryshyn


[-- Attachment #1.1: Type: text/plain, Size: 1583 bytes --]

Konrad,

Any comments?

Sincerely,
Andrii Anisov.

On Tue, Feb 7, 2017 at 7:58 PM, Andrii Anisov <andrii.anisov@gmail.com>
wrote:

> From: Andrii Anisov <andrii_anisov@epam.com>
>
> Some drivers need additional dma ops to be provided by xen swiotlb. Because
> common operations implementation came from x86 world and does not suite ARM
> needs we have to provide needed XEN SWIOTLB for ARM callbacks.
>
> dma_mmap patch is a port of an antique and lost patch discussed here:
> http://marc.info/?l=xen-devel&m=139695901430667&w=4
>
> Changes in V4:
>  - No functional changes
>  - '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad
>    insisted
>  - Added more comments for the functions added and for the debug code
>  - fixed code alignment.
>
> Changes in V3:
>  - dma ops are moved from ARM specific to generic code
>  - runtime operation verified for arm64 with LK 4.9
>  - compilation verified for arm, arm64, x86 with the current LK master HEAD
>    566cf877a1fcb6d6dc0126b076aad062054c2637
>
> Changes in V2:
>  - patches are rebased and checked for compilation for x86, arm, arm64 with
>    the current LK master HEAD 83346fbc07d267de777e2597552f785174ad0373
>
> Andrii Anisov (1):
>   swiotlb-xen: implement xen_swiotlb_get_sgtable callback
>
> Stefano Stabellini (1):
>   swiotlb-xen: implement xen_swiotlb_dma_mmap callback
>
>  arch/arm/xen/mm.c         |  2 ++
>  drivers/xen/swiotlb-xen.c | 47 ++++++++++++++++++++++++++++++
> +++++++++++++++++
>  include/xen/swiotlb-xen.h | 11 +++++++++++
>  3 files changed, 60 insertions(+)
>
> --
> 2.7.4
>
>

[-- Attachment #1.2: Type: text/html, Size: 2419 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-13 11:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-07 17:58 [PATCH v4 0/2] XEN SWIOTLB dma operations extension Andrii Anisov
2017-02-07 17:58 ` [PATCH v4 1/2] swiotlb-xen: implement xen_swiotlb_dma_mmap callback Andrii Anisov
2017-02-07 17:58 ` [PATCH v4 2/2] swiotlb-xen: implement xen_swiotlb_get_sgtable callback Andrii Anisov
2017-02-07 18:26 ` [PATCH v4 0/2] XEN SWIOTLB dma operations extension Stefano Stabellini
2017-02-13 11:29 ` Andrii Anisov

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).