public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb
  2009-03-31 22:52 [PATCH] swiotlb updates " Jeremy Fitzhardinge
@ 2009-03-31 22:52 ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-03-31 22:52 UTC (permalink / raw)
  To: FUJITA Tomonori
  Cc: the arch/x86 maintainers, Ingo Molnar, Linux Kernel Mailing List,
	Ian Campbell, Jeremy Fitzhardinge

From: Ian Campbell <ian.campbell@citrix.com>

Impact: Xen support for DMA

Add hooks to allow Xen to do translation between pfn and mfns for the swiotlb
layer, so that dma actually ends up going to the proper machine pages.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/kernel/pci-swiotlb_64.c |    6 ++++++
 drivers/pci/xen-iommu.c          |   10 ++++++++++
 include/xen/swiotlb.h            |   12 ++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb_64.c b/arch/x86/kernel/pci-swiotlb_64.c
index be379af..7f87ce2 100644
--- a/arch/x86/kernel/pci-swiotlb_64.c
+++ b/arch/x86/kernel/pci-swiotlb_64.c
@@ -38,11 +38,17 @@ void *swiotlb_alloc(unsigned order, unsigned long nslabs)
 
 dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
 {
+	if (xen_pv_domain())
+		return xen_phys_to_bus(paddr);
+
 	return paddr;
 }
 
 phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
 {
+	if (xen_pv_domain())
+		return xen_bus_to_phys(baddr);
+
 	return baddr;
 }
 
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index b9b4620..47d87a7 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -59,6 +59,16 @@ void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 			panic(KERN_ERR "xen_create_contiguous_region failed\n");
 	}
 }
+dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
+{
+	return phys_to_machine(XPADDR(paddr)).maddr;
+}
+
+phys_addr_t xen_bus_to_phys(dma_addr_t daddr)
+{
+	return machine_to_phys(XMADDR(daddr)).paddr;
+}
+
 static inline int address_needs_mapping(struct device *hwdev,
 						dma_addr_t addr)
 {
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
index 8d59439..3d96b07 100644
--- a/include/xen/swiotlb.h
+++ b/include/xen/swiotlb.h
@@ -3,10 +3,22 @@
 
 #ifdef CONFIG_PCI_XEN
 extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
+extern phys_addr_t xen_bus_to_phys(dma_addr_t daddr);
+extern dma_addr_t xen_phys_to_bus(phys_addr_t paddr);
 #else
 static inline void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 {
 }
+
+static inline phys_addr_t xen_bus_to_phys(dma_addr_t daddr)
+{
+	return daddr;
+}
+
+static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
+{
+	return paddr;
+}
 #endif
 
 #endif /* _XEN_SWIOTLB_H */
-- 
1.6.0.6


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

* [GIT PULL] xen: swiotlb support for Xen dom0
@ 2009-05-08  0:17 Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
                   ` (11 more replies)
  0 siblings, 12 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel

Hi Ingo,

This branch adds the swiotlb hooks for Xen dom0.  We use swiotlb to handle
various device drivers which assume that multipage DMA transfers which are
contigious in kernel memory are also contigious in machine memory (mostly
lower-performance devices, as high-performance ones already do a good job
of scatter-gather).

Following Fujita's suggestion, these changes remove a lot of the
placeholder stubs in arch/x86/kernel/pci-swiotlb.c and moves them into
the Xen-specific arch/x86/xen/pci-swiotlb.c.  (It still relies on
overriding the weak functions defined in lib/swiotlb.c.)

The following changes since commit 2af252ab26150b4411889c9eaf1af4c5bf03de78:
  Jeremy Fitzhardinge (1):
        xen: checkpatch cleanups

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git xen-tip/for-ingo/dom0/swiotlb

Ian Campbell (4):
      xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER
      xen: add hooks for mapping phys<->bus addresses in swiotlb
      xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen
      xen: enable swiotlb for xen domain 0.

Jeremy Fitzhardinge (5):
      xen: make sure swiotlb allocation is physically contigious
      swiotlb: use swiotlb_alloc_boot to allocate emergency pool
      xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent()
      xen/swiotlb: add sync functions
      xen/swiotlb: update to new new dma_ops

 arch/x86/kernel/pci-swiotlb.c |   30 ++--------
 arch/x86/xen/Kconfig          |    1 +
 arch/x86/xen/Makefile         |    1 +
 arch/x86/xen/pci-swiotlb.c    |   53 ++++++++++++++++++
 drivers/pci/xen-iommu.c       |  123 +++++++++++++++++++++++++++++------------
 include/xen/swiotlb.h         |   18 ++++++
 lib/swiotlb.c                 |    3 +-
 7 files changed, 168 insertions(+), 61 deletions(-)
 create mode 100644 arch/x86/xen/pci-swiotlb.c
 create mode 100644 include/xen/swiotlb.h

Thanks,
	J

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

* [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08  7:47   ` [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious Jan Beulich
                     ` (2 more replies)
  2009-05-08  0:17 ` [PATCH 2/9] xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER Jeremy Fitzhardinge
                   ` (10 subsequent siblings)
  11 siblings, 3 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge,
	Jeremy Fitzhardinge

Impact: make swiotlb allocation suitable for Xen

When allocating the swiotlb buffer under Xen, make sure the memory is
physically contiguous so that its really suitable for DMA.

Do this by allocating the memory as usual, but then call a Xen
function to rearrange the underlying pages to be physically
contiguous.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 arch/x86/kernel/pci-swiotlb.c |   10 ----------
 arch/x86/xen/Makefile         |    1 +
 arch/x86/xen/pci-swiotlb.c    |   27 +++++++++++++++++++++++++++
 drivers/pci/xen-iommu.c       |   16 ++++++++++++++++
 include/xen/swiotlb.h         |    6 ++++++
 5 files changed, 50 insertions(+), 10 deletions(-)
 create mode 100644 arch/x86/xen/pci-swiotlb.c
 create mode 100644 include/xen/swiotlb.h

diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 34f12e9..bc09da7 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -13,16 +13,6 @@
 
 int swiotlb __read_mostly;
 
-void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
-{
-	return alloc_bootmem_low_pages(size);
-}
-
-void *swiotlb_alloc(unsigned order, unsigned long nslabs)
-{
-	return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order);
-}
-
 dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
 {
 	return paddr;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index c4cda96..caede49 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -12,3 +12,4 @@ obj-y		:= enlighten.o setup.o multicalls.o mmu.o irq.o \
 obj-$(CONFIG_SMP)		+= smp.o spinlock.o
 obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 obj-$(CONFIG_XEN_DOM0)		+= vga.o
+obj-$(CONFIG_PCI_XEN)		+= pci-swiotlb.o
\ No newline at end of file
diff --git a/arch/x86/xen/pci-swiotlb.c b/arch/x86/xen/pci-swiotlb.c
new file mode 100644
index 0000000..25f0365
--- /dev/null
+++ b/arch/x86/xen/pci-swiotlb.c
@@ -0,0 +1,27 @@
+#include <linux/bootmem.h>
+#include <linux/gfp.h>
+
+#include <xen/swiotlb.h>
+#include <asm/xen/hypervisor.h>
+
+/* 
+ * This file defines overrides for weak functions with default
+ * implementations in lib/swiotlb.c.
+ */
+
+void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
+{
+	void *ret = alloc_bootmem_low_pages(size);
+
+	if (ret && xen_pv_domain())
+		xen_swiotlb_fixup(ret, size, nslabs);
+
+	return ret;
+}
+
+void *swiotlb_alloc(unsigned order, unsigned long nslabs)
+{
+	/* Never called on x86.  Warn, just in case. */
+	WARN_ON(1);
+	return NULL;
+}
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 32a8b49..c593058 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -12,6 +12,7 @@
 #include <xen/grant_table.h>
 #include <xen/page.h>
 #include <xen/xen-ops.h>
+#include <xen/swiotlb.h>
 
 #include <asm/iommu.h>
 #include <asm/swiotlb.h>
@@ -34,6 +35,21 @@ do {							\
 	(unsigned long long)addr + size);		\
 } while (0)
 
+
+void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
+{
+	unsigned order = get_order(size);
+
+	printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu order=%u\n",
+		buf, size, order);
+
+	if (WARN_ON(size != (PAGE_SIZE << order)))
+		return;
+
+	if (xen_create_contiguous_region((unsigned long)buf,
+					 order, 0xffffffff))
+		printk(KERN_ERR "xen_create_contiguous_region failed\n");
+}
 static inline int address_needs_mapping(struct device *hwdev,
 						dma_addr_t addr)
 {
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
new file mode 100644
index 0000000..67b7b42
--- /dev/null
+++ b/include/xen/swiotlb.h
@@ -0,0 +1,6 @@
+#ifndef _XEN_SWIOTLB_H
+#define _XEN_SWIOTLB_H
+
+extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
+
+#endif /* _XEN_SWIOTLB_H */
-- 
1.6.0.6


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

* [PATCH 2/9] xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

From: Ian Campbell <ian.campbell@citrix.com>

Impact: bugfix

Don't attempt to make larger memory ranges than Xen can cope with
contiguous.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 drivers/pci/xen-iommu.c |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index c593058..b9b4620 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -5,6 +5,7 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/scatterlist.h>
+#include <linux/swiotlb.h>
 #include <linux/io.h>
 #include <linux/bug.h>
 
@@ -36,19 +37,27 @@ do {							\
 } while (0)
 
 
+static int max_dma_bits = 32;
+
 void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 {
-	unsigned order = get_order(size);
-
-	printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu order=%u\n",
-		buf, size, order);
-
-	if (WARN_ON(size != (PAGE_SIZE << order)))
-		return;
-
-	if (xen_create_contiguous_region((unsigned long)buf,
-					 order, 0xffffffff))
-		printk(KERN_ERR "xen_create_contiguous_region failed\n");
+	int i, rc;
+	int dma_bits;
+
+	printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu\n",
+		buf, size);
+
+	dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
+	for (i = 0; i < nslabs; i += IO_TLB_SEGSIZE) {
+		do {
+			rc = xen_create_contiguous_region(
+				(unsigned long)buf + (i << IO_TLB_SHIFT),
+				get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
+				dma_bits);
+		} while (rc && dma_bits++ < max_dma_bits);
+		if (rc)
+			panic(KERN_ERR "xen_create_contiguous_region failed\n");
+	}
 }
 static inline int address_needs_mapping(struct device *hwdev,
 						dma_addr_t addr)
-- 
1.6.0.6


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

* [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 2/9] xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:11   ` Joerg Roedel
  2009-05-08  0:17 ` [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen Jeremy Fitzhardinge
                   ` (8 subsequent siblings)
  11 siblings, 2 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

From: Ian Campbell <ian.campbell@citrix.com>

Impact: Xen support for DMA

Add hooks to allow Xen to do translation between pfn and mfns for the swiotlb
layer, so that dma actually ends up going to the proper machine pages.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 arch/x86/kernel/pci-swiotlb.c |   10 ----------
 arch/x86/xen/pci-swiotlb.c    |   18 ++++++++++++++++++
 drivers/pci/xen-iommu.c       |   11 +++++++++++
 include/xen/swiotlb.h         |    2 ++
 4 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index bc09da7..3216674 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -13,16 +13,6 @@
 
 int swiotlb __read_mostly;
 
-dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
-{
-	return paddr;
-}
-
-phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
-{
-	return baddr;
-}
-
 int __weak swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
 {
 	return 0;
diff --git a/arch/x86/xen/pci-swiotlb.c b/arch/x86/xen/pci-swiotlb.c
index 25f0365..1d43fde 100644
--- a/arch/x86/xen/pci-swiotlb.c
+++ b/arch/x86/xen/pci-swiotlb.c
@@ -1,5 +1,7 @@
 #include <linux/bootmem.h>
 #include <linux/gfp.h>
+#include <linux/dma-mapping.h>
+#include <linux/swiotlb.h>
 
 #include <xen/swiotlb.h>
 #include <asm/xen/hypervisor.h>
@@ -25,3 +27,19 @@ void *swiotlb_alloc(unsigned order, unsigned long nslabs)
 	WARN_ON(1);
 	return NULL;
 }
+
+dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
+{
+	if (xen_pv_domain())
+		return xen_phys_to_bus(paddr);
+
+	return paddr;
+}
+
+phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
+{
+	if (xen_pv_domain())
+		return xen_bus_to_phys(baddr);
+
+	return baddr;
+}
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index b9b4620..e3d6ddb 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -59,6 +59,17 @@ void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 			panic(KERN_ERR "xen_create_contiguous_region failed\n");
 	}
 }
+
+dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
+{
+	return phys_to_machine(XPADDR(paddr)).maddr;
+}
+
+phys_addr_t xen_bus_to_phys(dma_addr_t daddr)
+{
+	return machine_to_phys(XMADDR(daddr)).paddr;
+}
+
 static inline int address_needs_mapping(struct device *hwdev,
 						dma_addr_t addr)
 {
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
index 67b7b42..4229f27 100644
--- a/include/xen/swiotlb.h
+++ b/include/xen/swiotlb.h
@@ -2,5 +2,7 @@
 #define _XEN_SWIOTLB_H
 
 extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
+extern phys_addr_t xen_bus_to_phys(dma_addr_t daddr);
+extern dma_addr_t xen_phys_to_bus(phys_addr_t paddr);
 
 #endif /* _XEN_SWIOTLB_H */
-- 
1.6.0.6


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

* [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (2 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:16   ` Joerg Roedel
  2009-05-08  0:17 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
                   ` (7 subsequent siblings)
  11 siblings, 2 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

From: Ian Campbell <ian.campbell@citrix.com>

Impact: Xen support for DMA

Add hook so that Xen can determine whether a particular address range needs
pfn<->mfn mapping.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 arch/x86/kernel/pci-swiotlb.c |    5 -----
 arch/x86/xen/pci-swiotlb.c    |    8 ++++++++
 drivers/pci/xen-iommu.c       |    5 +++++
 include/xen/swiotlb.h         |    1 +
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 3216674..861c869 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -13,11 +13,6 @@
 
 int swiotlb __read_mostly;
 
-int __weak swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
-{
-	return 0;
-}
-
 static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 					dma_addr_t *dma_handle, gfp_t flags)
 {
diff --git a/arch/x86/xen/pci-swiotlb.c b/arch/x86/xen/pci-swiotlb.c
index 1d43fde..6f248a5 100644
--- a/arch/x86/xen/pci-swiotlb.c
+++ b/arch/x86/xen/pci-swiotlb.c
@@ -43,3 +43,11 @@ phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
 
 	return baddr;
 }
+
+int swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
+{
+	if (xen_pv_domain())
+		return xen_range_needs_mapping(paddr, size);
+
+	return 0;
+}
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index e3d6ddb..994671c 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -119,6 +119,11 @@ static int range_straddles_page_boundary(phys_addr_t p, size_t size)
 	return 1;
 }
 
+int xen_range_needs_mapping(phys_addr_t paddr, size_t size)
+{
+	return range_straddles_page_boundary(paddr, size);
+}
+
 static inline void xen_dma_unmap_page(struct page *page)
 {
 	/* Xen TODO: 2.6.18 xen calls __gnttab_dma_unmap_page here
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
index 4229f27..8b51ff7 100644
--- a/include/xen/swiotlb.h
+++ b/include/xen/swiotlb.h
@@ -4,5 +4,6 @@
 extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
 extern phys_addr_t xen_bus_to_phys(dma_addr_t daddr);
 extern dma_addr_t xen_phys_to_bus(phys_addr_t paddr);
+extern int xen_range_needs_mapping(phys_addr_t phys, size_t size);
 
 #endif /* _XEN_SWIOTLB_H */
-- 
1.6.0.6


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

* [PATCH 5/9] xen: enable swiotlb for xen domain 0.
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (3 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:21   ` Joerg Roedel
  2009-05-08  0:17 ` [PATCH 6/9] swiotlb: use swiotlb_alloc_boot to allocate emergency pool Jeremy Fitzhardinge
                   ` (6 subsequent siblings)
  11 siblings, 2 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

From: Ian Campbell <ian.campbell@citrix.com>

Impact: Xen DMA support

Enable swiotlb when running as a Xen dom0 domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 arch/x86/kernel/pci-swiotlb.c |    5 +++++
 arch/x86/xen/Kconfig          |    1 +
 drivers/pci/xen-iommu.c       |    5 +++++
 include/xen/swiotlb.h         |    9 +++++++++
 4 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 861c869..2d8dd35 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -11,6 +11,8 @@
 #include <asm/swiotlb.h>
 #include <asm/dma.h>
 
+#include <xen/swiotlb.h>
+
 int swiotlb __read_mostly;
 
 static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
@@ -49,6 +51,9 @@ void __init pci_swiotlb_init(void)
 	if (!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN)
 	       swiotlb = 1;
 #endif
+	if (xen_wants_swiotlb())
+		swiotlb = 1;
+
 	if (swiotlb_force)
 		swiotlb = 1;
 	if (swiotlb) {
diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
index 87c13db..2c85967 100644
--- a/arch/x86/xen/Kconfig
+++ b/arch/x86/xen/Kconfig
@@ -6,6 +6,7 @@ config XEN
 	bool "Xen guest support"
 	select PARAVIRT
 	select PARAVIRT_CLOCK
+	select SWIOTLB
 	depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
 	depends on X86_CMPXCHG && X86_TSC
 	help
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 994671c..4625143 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -60,6 +60,11 @@ void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 	}
 }
 
+int xen_wants_swiotlb(void)
+{
+	return xen_initial_domain();
+}
+
 dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 {
 	return phys_to_machine(XPADDR(paddr)).maddr;
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
index 8b51ff7..75d1da1 100644
--- a/include/xen/swiotlb.h
+++ b/include/xen/swiotlb.h
@@ -6,4 +6,13 @@ extern phys_addr_t xen_bus_to_phys(dma_addr_t daddr);
 extern dma_addr_t xen_phys_to_bus(phys_addr_t paddr);
 extern int xen_range_needs_mapping(phys_addr_t phys, size_t size);
 
+#ifdef CONFIG_PCI_XEN
+extern int xen_wants_swiotlb(void);
+#else
+static inline int xen_wants_swiotlb(void)
+{
+	return 0;
+}
+#endif
+
 #endif /* _XEN_SWIOTLB_H */
-- 
1.6.0.6


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

* [PATCH 6/9] swiotlb: use swiotlb_alloc_boot to allocate emergency pool
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (4 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 7/9] xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent() Jeremy Fitzhardinge
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge,
	Jeremy Fitzhardinge

Impact: bugfix

Also fix xen_swiotlb_fixup() to deal with sub-slab-sized allocations.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 drivers/pci/xen-iommu.c |   12 +++++++++---
 lib/swiotlb.c           |    3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 4625143..9d01be6 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -48,16 +48,22 @@ void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
 		buf, size);
 
 	dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
-	for (i = 0; i < nslabs; i += IO_TLB_SEGSIZE) {
+
+	i = 0;
+	do {
+		int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+
 		do {
 			rc = xen_create_contiguous_region(
 				(unsigned long)buf + (i << IO_TLB_SHIFT),
-				get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
+				get_order(slabs << IO_TLB_SHIFT),
 				dma_bits);
 		} while (rc && dma_bits++ < max_dma_bits);
 		if (rc)
 			panic(KERN_ERR "xen_create_contiguous_region failed\n");
-	}
+
+		i += slabs;
+	} while(i < nslabs);
 }
 
 int xen_wants_swiotlb(void)
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 2b0b5a7..a69834c 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -202,7 +202,8 @@ swiotlb_init_with_default_size(size_t default_size)
 	/*
 	 * Get the overflow emergency buffer
 	 */
-	io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
+	io_tlb_overflow_buffer = swiotlb_alloc_boot(io_tlb_overflow,
+						    io_tlb_overflow >> IO_TLB_SHIFT);
 	if (!io_tlb_overflow_buffer)
 		panic("Cannot allocate SWIOTLB overflow buffer!\n");
 
-- 
1.6.0.6


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

* [PATCH 7/9] xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent()
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (5 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 6/9] swiotlb: use swiotlb_alloc_boot to allocate emergency pool Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 8/9] xen/swiotlb: add sync functions Jeremy Fitzhardinge
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

Impact: cleanup

Clarify why we don't care about the kernel's pseudo-phys restrictions,
so long as the underlying pages are in the right place.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 drivers/pci/xen-iommu.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 9d01be6..492ef42 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -199,15 +199,17 @@ static void *xen_alloc_coherent(struct device *dev, size_t size,
 	unsigned long vstart;
 	u64 mask;
 
-	/* ignore region specifiers */
+	/*
+	 * Ignore region specifiers - the kernel's ideas of
+	 * pseudo-phys memory layout has nothing to do with the
+	 * machine physical layout.  We can't allocate highmem
+	 * because we can't return a pointer to it.
+	 */
 	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
 
 	if (dma_alloc_from_coherent(dev, size, dma_handle, &ret))
 		return ret;
 
-	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
-		gfp |= GFP_DMA;
-
 	vstart = __get_free_pages(gfp, order);
 	ret = (void *)vstart;
 
-- 
1.6.0.6


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

* [PATCH 8/9] xen/swiotlb: add sync functions
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (6 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 7/9] xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent() Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08  0:17 ` [PATCH 9/9] xen/swiotlb: update to new new dma_ops Jeremy Fitzhardinge
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

Impact: bugfix

Add all the missing sync functions.  This fixes iwlagn.
(Need to think about what to do with non-swiotlb mode.)

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 drivers/pci/xen-iommu.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 492ef42..81338b2 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -312,6 +312,13 @@ static struct dma_mapping_ops xen_swiotlb_dma_ops = {
 
 	.mapping_error = swiotlb_dma_mapping_error,
 
+	.sync_single_for_cpu = swiotlb_sync_single_for_cpu,
+	.sync_single_for_device = swiotlb_sync_single_for_device,
+	.sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
+	.sync_single_range_for_device = swiotlb_sync_single_range_for_device,
+	.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
+	.sync_sg_for_device = swiotlb_sync_sg_for_device,
+
 	.is_phys = 0,
 };
 
-- 
1.6.0.6


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

* [PATCH 9/9] xen/swiotlb: update to new new dma_ops
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (7 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 8/9] xen/swiotlb: add sync functions Jeremy Fitzhardinge
@ 2009-05-08  0:17 ` Jeremy Fitzhardinge
  2009-05-08 11:19 ` [GIT PULL] xen: swiotlb support for Xen dom0 Ingo Molnar
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08  0:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

Convert to use map_page/unmap_page rather than map_single, use enum
dma_data_direction.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 drivers/pci/xen-iommu.c |   54 ++++++++++++++++++++---------------------------
 1 files changed, 23 insertions(+), 31 deletions(-)

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 81338b2..41c276f 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -154,7 +154,9 @@ static inline dma_addr_t xen_dma_map_page(struct page *page)
 }
 
 static int xen_map_sg(struct device *hwdev, struct scatterlist *sg,
-			int nents, int direction)
+		      int nents,
+		      enum dma_data_direction direction,
+		      struct dma_attrs *attrs)
 {
 	struct scatterlist *s;
 	struct page *page;
@@ -179,7 +181,9 @@ static int xen_map_sg(struct device *hwdev, struct scatterlist *sg,
 }
 
 static void xen_unmap_sg(struct device *hwdev, struct scatterlist *sg,
-			 int nents, int direction)
+			 int nents,
+			 enum dma_data_direction direction,
+			 struct dma_attrs *attrs)
 {
 	struct scatterlist *s;
 	struct page *page;
@@ -242,53 +246,41 @@ static void xen_free_coherent(struct device *dev, size_t size,
 	free_pages((unsigned long)vaddr, order);
 }
 
-static dma_addr_t xen_swiotlb_map_single(struct device *dev, phys_addr_t paddr,
-					 size_t size, int direction)
+static dma_addr_t xen_map_page(struct device *dev, struct page *page,
+			       unsigned long offset, size_t size,
+			       enum dma_data_direction direction,
+			       struct dma_attrs *attrs)
 {
 	dma_addr_t dma;
-	BUG_ON(direction == DMA_NONE);
-
-	WARN_ON(size == 0);
-	dma = swiotlb_map_single(dev, phys_to_virt(paddr), size, direction);
-
-	flush_write_buffers();
-	return dma;
-}
-
-static dma_addr_t xen_map_single(struct device *dev, phys_addr_t paddr,
-					size_t size, int direction)
-{
-	struct page *page;
-	dma_addr_t dma;
 
 	BUG_ON(direction == DMA_NONE);
 
 	WARN_ON(size == 0);
-	page = pfn_to_page(PFN_DOWN(paddr));
 
-	dma = xen_dma_map_page(page) + offset_in_page(paddr);
+	dma = xen_dma_map_page(page) + offset;
 
 	IOMMU_BUG_ON(address_needs_mapping(dev, dma));
-	IOMMU_BUG_ON(range_straddles_page_boundary(paddr, size));
 	flush_write_buffers();
 	return dma;
 }
 
-static void xen_unmap_single(struct device *dev, dma_addr_t dma_addr,
-				size_t size, int direction)
+static void xen_unmap_page(struct device *dev, dma_addr_t dma_addr,
+			   size_t size,
+			   enum dma_data_direction direction,
+			   struct dma_attrs *attrs)
 {
 	BUG_ON(direction == DMA_NONE);
 	xen_dma_unmap_page(pfn_to_page(mfn_to_pfn(PFN_DOWN(dma_addr))));
 }
 
-static struct dma_mapping_ops xen_dma_ops = {
+static struct dma_map_ops xen_dma_ops = {
 	.dma_supported = NULL,
 
 	.alloc_coherent = xen_alloc_coherent,
 	.free_coherent = xen_free_coherent,
 
-	.map_single = xen_map_single,
-	.unmap_single = xen_unmap_single,
+	.map_page = xen_map_page,
+	.unmap_page = xen_unmap_page,
 
 	.map_sg = xen_map_sg,
 	.unmap_sg = xen_unmap_sg,
@@ -298,17 +290,17 @@ static struct dma_mapping_ops xen_dma_ops = {
 	.is_phys = 0,
 };
 
-static struct dma_mapping_ops xen_swiotlb_dma_ops = {
+static struct dma_map_ops xen_swiotlb_dma_ops = {
 	.dma_supported = swiotlb_dma_supported,
 
 	.alloc_coherent = xen_alloc_coherent,
 	.free_coherent = xen_free_coherent,
 
-	.map_single = xen_swiotlb_map_single,	/* swiotlb_map_single has a different prototype */
-	.unmap_single = swiotlb_unmap_single,
+	.map_page = swiotlb_map_page,
+	.unmap_page = swiotlb_unmap_page,
 
-	.map_sg = swiotlb_map_sg,
-	.unmap_sg = swiotlb_unmap_sg,
+	.map_sg = swiotlb_map_sg_attrs,
+	.unmap_sg = swiotlb_unmap_sg_attrs,
 
 	.mapping_error = swiotlb_dma_mapping_error,
 
-- 
1.6.0.6


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

* Re: [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
@ 2009-05-08  7:47   ` Jan Beulich
  2009-05-08 15:51     ` Jeremy Fitzhardinge
  2009-05-11  3:40   ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious FUJITA Tomonori
  2009-05-11 13:55   ` Joerg Roedel
  2 siblings, 1 reply; 28+ messages in thread
From: Jan Beulich @ 2009-05-08  7:47 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Jeremy Fitzhardinge, Ingo Molnar, the arch/x86 maintainers,
	FUJITA Tomonori, Xen-devel, Linux Kernel Mailing List

>>> Jeremy Fitzhardinge <jeremy@goop.org> 08.05.09 02:17 >>>
>Impact: make swiotlb allocation suitable for Xen
>
>When allocating the swiotlb buffer under Xen, make sure the memory is
>physically contiguous so that its really suitable for DMA.
>
>Do this by allocating the memory as usual, but then call a Xen
>function to rearrange the underlying pages to be physically
>contiguous.

As pointed out before, you must not use alloc_bootmem_low...() here,
as on large systems you may otherwise get an allocation failure (i.e. a
panic - checking the return value is pointless). The alternative is to fix
the bootmem allocator to no longer allocate from bottom up.

Jan


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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (8 preceding siblings ...)
  2009-05-08  0:17 ` [PATCH 9/9] xen/swiotlb: update to new new dma_ops Jeremy Fitzhardinge
@ 2009-05-08 11:19 ` Ingo Molnar
  2009-05-11  3:40 ` FUJITA Tomonori
  2009-05-11 13:04 ` Ingo Molnar
  11 siblings, 0 replies; 28+ messages in thread
From: Ingo Molnar @ 2009-05-08 11:19 UTC (permalink / raw)
  To: Jeremy Fitzhardinge, FUJITA Tomonori, Joerg Roedel
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel


* Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> Hi Ingo,
> 
> This branch adds the swiotlb hooks for Xen dom0.  We use swiotlb to handle
> various device drivers which assume that multipage DMA transfers which are
> contigious in kernel memory are also contigious in machine memory (mostly
> lower-performance devices, as high-performance ones already do a good job
> of scatter-gather).
> 
> Following Fujita's suggestion, these changes remove a lot of the
> placeholder stubs in arch/x86/kernel/pci-swiotlb.c and moves them into
> the Xen-specific arch/x86/xen/pci-swiotlb.c.  (It still relies on
> overriding the weak functions defined in lib/swiotlb.c.)
> 
> The following changes since commit 2af252ab26150b4411889c9eaf1af4c5bf03de78:
>   Jeremy Fitzhardinge (1):
>         xen: checkpatch cleanups
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git xen-tip/for-ingo/dom0/swiotlb
> 
> Ian Campbell (4):
>       xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER
>       xen: add hooks for mapping phys<->bus addresses in swiotlb
>       xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen
>       xen: enable swiotlb for xen domain 0.
> 
> Jeremy Fitzhardinge (5):
>       xen: make sure swiotlb allocation is physically contigious
>       swiotlb: use swiotlb_alloc_boot to allocate emergency pool
>       xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent()
>       xen/swiotlb: add sync functions
>       xen/swiotlb: update to new new dma_ops
> 
>  arch/x86/kernel/pci-swiotlb.c |   30 ++--------
>  arch/x86/xen/Kconfig          |    1 +
>  arch/x86/xen/Makefile         |    1 +
>  arch/x86/xen/pci-swiotlb.c    |   53 ++++++++++++++++++
>  drivers/pci/xen-iommu.c       |  123 +++++++++++++++++++++++++++++------------
>  include/xen/swiotlb.h         |   18 ++++++
>  lib/swiotlb.c                 |    3 +-
>  7 files changed, 168 insertions(+), 61 deletions(-)
>  create mode 100644 arch/x86/xen/pci-swiotlb.c
>  create mode 100644 include/xen/swiotlb.h

Ok, this looks good to me at a quick glance and it makes quite a bit 
of sense - but it would be nice to get the acks (or reviewed-by 
tags) of Fujita-san and Joerg, and address any review feedback and 
if everything is resolved, propagate those tags into the series.

Thanks,

	Ingo

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

* Re: [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation  isphysically contigious
  2009-05-08  7:47   ` [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious Jan Beulich
@ 2009-05-08 15:51     ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-08 15:51 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Jeremy Fitzhardinge, Ingo Molnar, the arch/x86 maintainers,
	FUJITA Tomonori, Xen-devel, Linux Kernel Mailing List

Jan Beulich wrote:
> As pointed out before, you must not use alloc_bootmem_low...() here,
> as on large systems you may otherwise get an allocation failure (i.e. a
> panic - checking the return value is pointless). The alternative is to fix
> the bootmem allocator to no longer allocate from bottom up.

I was going to do that as a separate change so it can be argued on its 
own merits (though now that the allocation is happening in purely Xen 
code, that's less of an issue).

    J

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

* Re: [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
  2009-05-08  7:47   ` [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious Jan Beulich
@ 2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 13:55   ` Joerg Roedel
  2 siblings, 0 replies; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11  3:40 UTC (permalink / raw)
  To: jeremy
  Cc: mingo, fujita.tomonori, x86, linux-kernel, xen-devel,
	jeremy.fitzhardinge

On Thu,  7 May 2009 17:17:14 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> Impact: make swiotlb allocation suitable for Xen
> 
> When allocating the swiotlb buffer under Xen, make sure the memory is
> physically contiguous so that its really suitable for DMA.
> 
> Do this by allocating the memory as usual, but then call a Xen
> function to rearrange the underlying pages to be physically
> contiguous.
> 
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  arch/x86/kernel/pci-swiotlb.c |   10 ----------
>  arch/x86/xen/Makefile         |    1 +
>  arch/x86/xen/pci-swiotlb.c    |   27 +++++++++++++++++++++++++++
>  drivers/pci/xen-iommu.c       |   16 ++++++++++++++++
>  include/xen/swiotlb.h         |    6 ++++++
>  5 files changed, 50 insertions(+), 10 deletions(-)
>  create mode 100644 arch/x86/xen/pci-swiotlb.c
>  create mode 100644 include/xen/swiotlb.h

Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

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

* Re: [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb
  2009-05-08  0:17 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
@ 2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:11   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11  3:40 UTC (permalink / raw)
  To: jeremy
  Cc: mingo, fujita.tomonori, x86, linux-kernel, xen-devel,
	ian.campbell, jeremy.fitzhardinge

On Thu,  7 May 2009 17:17:16 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen support for DMA
> 
> Add hooks to allow Xen to do translation between pfn and mfns for the swiotlb
> layer, so that dma actually ends up going to the proper machine pages.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  arch/x86/kernel/pci-swiotlb.c |   10 ----------
>  arch/x86/xen/pci-swiotlb.c    |   18 ++++++++++++++++++
>  drivers/pci/xen-iommu.c       |   11 +++++++++++
>  include/xen/swiotlb.h         |    2 ++
>  4 files changed, 31 insertions(+), 10 deletions(-)

Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

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

* Re: [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen
  2009-05-08  0:17 ` [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen Jeremy Fitzhardinge
@ 2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:16   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11  3:40 UTC (permalink / raw)
  To: jeremy
  Cc: mingo, fujita.tomonori, x86, linux-kernel, xen-devel,
	ian.campbell, jeremy.fitzhardinge

On Thu,  7 May 2009 17:17:17 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen support for DMA
> 
> Add hook so that Xen can determine whether a particular address range needs
> pfn<->mfn mapping.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  arch/x86/kernel/pci-swiotlb.c |    5 -----
>  arch/x86/xen/pci-swiotlb.c    |    8 ++++++++
>  drivers/pci/xen-iommu.c       |    5 +++++
>  include/xen/swiotlb.h         |    1 +
>  4 files changed, 14 insertions(+), 5 deletions(-)
> 

Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

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

* Re: [PATCH 5/9] xen: enable swiotlb for xen domain 0.
  2009-05-08  0:17 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
@ 2009-05-11  3:40   ` FUJITA Tomonori
  2009-05-11 14:21   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11  3:40 UTC (permalink / raw)
  To: jeremy
  Cc: mingo, fujita.tomonori, x86, linux-kernel, xen-devel,
	ian.campbell, jeremy.fitzhardinge

On Thu,  7 May 2009 17:17:18 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen DMA support
> 
> Enable swiotlb when running as a Xen dom0 domain.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  arch/x86/kernel/pci-swiotlb.c |    5 +++++
>  arch/x86/xen/Kconfig          |    1 +
>  drivers/pci/xen-iommu.c       |    5 +++++
>  include/xen/swiotlb.h         |    9 +++++++++
>  4 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> index 861c869..2d8dd35 100644
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ b/arch/x86/kernel/pci-swiotlb.c
> @@ -11,6 +11,8 @@
>  #include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  
> +#include <xen/swiotlb.h>
> +
>  int swiotlb __read_mostly;
>  
>  static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
> @@ -49,6 +51,9 @@ void __init pci_swiotlb_init(void)
>  	if (!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN)
>  	       swiotlb = 1;
>  #endif
> +	if (xen_wants_swiotlb())
> +		swiotlb = 1;
> +
>  	if (swiotlb_force)
>  		swiotlb = 1;
>  	if (swiotlb) {

Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

I don't like the patch much though.

The x86 dma startup code is complicated and adding another hook makes
it more complicated.

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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (9 preceding siblings ...)
  2009-05-08 11:19 ` [GIT PULL] xen: swiotlb support for Xen dom0 Ingo Molnar
@ 2009-05-11  3:40 ` FUJITA Tomonori
  2009-05-11 16:59   ` Jeremy Fitzhardinge
  2009-05-11 13:04 ` Ingo Molnar
  11 siblings, 1 reply; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11  3:40 UTC (permalink / raw)
  To: jeremy; +Cc: mingo, fujita.tomonori, x86, linux-kernel, xen-devel

On Thu,  7 May 2009 17:17:13 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> Hi Ingo,
> 
> This branch adds the swiotlb hooks for Xen dom0.  We use swiotlb to handle
> various device drivers which assume that multipage DMA transfers which are
> contigious in kernel memory are also contigious in machine memory (mostly
> lower-performance devices, as high-performance ones already do a good job
> of scatter-gather).
> 
> Following Fujita's suggestion, these changes remove a lot of the
> placeholder stubs in arch/x86/kernel/pci-swiotlb.c and moves them into
> the Xen-specific arch/x86/xen/pci-swiotlb.c.

Yeah, all Xen-specific stuff should live in the Xen land. The changes
to non-Xen code (like arch/x86/kernel/pci-swiotlb.c) look fine to me.


>  (It still relies on
> overriding the weak functions defined in lib/swiotlb.c.)

As I said before, I don't like such weak hacks added for dom0. We will
merge dom0 support?

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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
                   ` (10 preceding siblings ...)
  2009-05-11  3:40 ` FUJITA Tomonori
@ 2009-05-11 13:04 ` Ingo Molnar
  2009-05-11 16:57   ` Jeremy Fitzhardinge
  11 siblings, 1 reply; 28+ messages in thread
From: Ingo Molnar @ 2009-05-11 13:04 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel


* Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> Hi Ingo,
> 
> This branch adds the swiotlb hooks for Xen dom0.  We use swiotlb 
> to handle various device drivers which assume that multipage DMA 
> transfers which are contigious in kernel memory are also 
> contigious in machine memory (mostly lower-performance devices, as 
> high-performance ones already do a good job of scatter-gather).
> 
> Following Fujita's suggestion, these changes remove a lot of the 
> placeholder stubs in arch/x86/kernel/pci-swiotlb.c and moves them 
> into the Xen-specific arch/x86/xen/pci-swiotlb.c.  (It still 
> relies on overriding the weak functions defined in lib/swiotlb.c.)
> 
> The following changes since commit 2af252ab26150b4411889c9eaf1af4c5bf03de78:
>   Jeremy Fitzhardinge (1):
>         xen: checkpatch cleanups

Would be nice to have a pull request for this with Fujita-san's acks 
embedded in the commits, and with a tree based against tip:x86/xen.

	Ingo

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

* Re: [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious
  2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
  2009-05-08  7:47   ` [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious Jan Beulich
  2009-05-11  3:40   ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious FUJITA Tomonori
@ 2009-05-11 13:55   ` Joerg Roedel
  2009-05-11 18:42     ` Jeremy Fitzhardinge
  2 siblings, 1 reply; 28+ messages in thread
From: Joerg Roedel @ 2009-05-11 13:55 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Ingo Molnar, FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge

On Thu, May 07, 2009 at 05:17:14PM -0700, Jeremy Fitzhardinge wrote:
> Impact: make swiotlb allocation suitable for Xen
> 
> When allocating the swiotlb buffer under Xen, make sure the memory is
> physically contiguous so that its really suitable for DMA.
> 
> Do this by allocating the memory as usual, but then call a Xen
> function to rearrange the underlying pages to be physically
> contiguous.
> 
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  arch/x86/kernel/pci-swiotlb.c |   10 ----------
>  arch/x86/xen/Makefile         |    1 +
>  arch/x86/xen/pci-swiotlb.c    |   27 +++++++++++++++++++++++++++
>  drivers/pci/xen-iommu.c       |   16 ++++++++++++++++
>  include/xen/swiotlb.h         |    6 ++++++
>  5 files changed, 50 insertions(+), 10 deletions(-)
>  create mode 100644 arch/x86/xen/pci-swiotlb.c
>  create mode 100644 include/xen/swiotlb.h
> 
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> index 34f12e9..bc09da7 100644
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ b/arch/x86/kernel/pci-swiotlb.c
> @@ -13,16 +13,6 @@
>  
>  int swiotlb __read_mostly;
>  
> -void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
> -{
> -	return alloc_bootmem_low_pages(size);
> -}
> -
> -void *swiotlb_alloc(unsigned order, unsigned long nslabs)
> -{
> -	return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order);
> -}
> -
>  dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
>  {
>  	return paddr;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index c4cda96..caede49 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -12,3 +12,4 @@ obj-y		:= enlighten.o setup.o multicalls.o mmu.o irq.o \
>  obj-$(CONFIG_SMP)		+= smp.o spinlock.o
>  obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  obj-$(CONFIG_XEN_DOM0)		+= vga.o
> +obj-$(CONFIG_PCI_XEN)		+= pci-swiotlb.o
> \ No newline at end of file
> diff --git a/arch/x86/xen/pci-swiotlb.c b/arch/x86/xen/pci-swiotlb.c
> new file mode 100644
> index 0000000..25f0365
> --- /dev/null
> +++ b/arch/x86/xen/pci-swiotlb.c
> @@ -0,0 +1,27 @@
> +#include <linux/bootmem.h>
> +#include <linux/gfp.h>
> +
> +#include <xen/swiotlb.h>
> +#include <asm/xen/hypervisor.h>
> +
> +/* 
> + * This file defines overrides for weak functions with default
> + * implementations in lib/swiotlb.c.
> + */
> +
> +void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
> +{
> +	void *ret = alloc_bootmem_low_pages(size);
> +
> +	if (ret && xen_pv_domain())
> +		xen_swiotlb_fixup(ret, size, nslabs);
> +
> +	return ret;
> +}
> +
> +void *swiotlb_alloc(unsigned order, unsigned long nslabs)
> +{
> +	/* Never called on x86.  Warn, just in case. */

Can't this function be removed completly then?

> +	WARN_ON(1);
> +	return NULL;
> +}
> diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
> index 32a8b49..c593058 100644
> --- a/drivers/pci/xen-iommu.c
> +++ b/drivers/pci/xen-iommu.c
> @@ -12,6 +12,7 @@
>  #include <xen/grant_table.h>
>  #include <xen/page.h>
>  #include <xen/xen-ops.h>
> +#include <xen/swiotlb.h>
>  
>  #include <asm/iommu.h>
>  #include <asm/swiotlb.h>
> @@ -34,6 +35,21 @@ do {							\
>  	(unsigned long long)addr + size);		\
>  } while (0)
>  
> +
> +void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
> +{
> +	unsigned order = get_order(size);
> +
> +	printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu order=%u\n",
> +		buf, size, order);
> +
> +	if (WARN_ON(size != (PAGE_SIZE << order)))
> +		return;
> +
> +	if (xen_create_contiguous_region((unsigned long)buf,
> +					 order, 0xffffffff))
                                                DMA_32BIT_MASK?

> +		printk(KERN_ERR "xen_create_contiguous_region failed\n");
> +}
>  static inline int address_needs_mapping(struct device *hwdev,
>  						dma_addr_t addr)
>  {
> diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
> new file mode 100644
> index 0000000..67b7b42
> --- /dev/null
> +++ b/include/xen/swiotlb.h
> @@ -0,0 +1,6 @@
> +#ifndef _XEN_SWIOTLB_H
> +#define _XEN_SWIOTLB_H
> +
> +extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
> +
> +#endif /* _XEN_SWIOTLB_H */
> -- 
> 1.6.0.6
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb
  2009-05-08  0:17 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
@ 2009-05-11 14:11   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: Joerg Roedel @ 2009-05-11 14:11 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Ingo Molnar, FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

On Thu, May 07, 2009 at 05:17:16PM -0700, Jeremy Fitzhardinge wrote:
> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen support for DMA
> 
> Add hooks to allow Xen to do translation between pfn and mfns for the swiotlb
> layer, so that dma actually ends up going to the proper machine pages.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

Acked-by: Joerg Roedel <joerg.roedel@amd.com>

> ---
>  arch/x86/kernel/pci-swiotlb.c |   10 ----------
>  arch/x86/xen/pci-swiotlb.c    |   18 ++++++++++++++++++
>  drivers/pci/xen-iommu.c       |   11 +++++++++++
>  include/xen/swiotlb.h         |    2 ++
>  4 files changed, 31 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> index bc09da7..3216674 100644
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ b/arch/x86/kernel/pci-swiotlb.c
> @@ -13,16 +13,6 @@
>  
>  int swiotlb __read_mostly;
>  
> -dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
> -{
> -	return paddr;
> -}
> -
> -phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
> -{
> -	return baddr;
> -}
> -
>  int __weak swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
>  {
>  	return 0;
> diff --git a/arch/x86/xen/pci-swiotlb.c b/arch/x86/xen/pci-swiotlb.c
> index 25f0365..1d43fde 100644
> --- a/arch/x86/xen/pci-swiotlb.c
> +++ b/arch/x86/xen/pci-swiotlb.c
> @@ -1,5 +1,7 @@
>  #include <linux/bootmem.h>
>  #include <linux/gfp.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/swiotlb.h>
>  
>  #include <xen/swiotlb.h>
>  #include <asm/xen/hypervisor.h>
> @@ -25,3 +27,19 @@ void *swiotlb_alloc(unsigned order, unsigned long nslabs)
>  	WARN_ON(1);
>  	return NULL;
>  }
> +
> +dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
> +{
> +	if (xen_pv_domain())
> +		return xen_phys_to_bus(paddr);
> +
> +	return paddr;
> +}
> +
> +phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr)
> +{
> +	if (xen_pv_domain())
> +		return xen_bus_to_phys(baddr);
> +
> +	return baddr;
> +}
> diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
> index b9b4620..e3d6ddb 100644
> --- a/drivers/pci/xen-iommu.c
> +++ b/drivers/pci/xen-iommu.c
> @@ -59,6 +59,17 @@ void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
>  			panic(KERN_ERR "xen_create_contiguous_region failed\n");
>  	}
>  }
> +
> +dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
> +{
> +	return phys_to_machine(XPADDR(paddr)).maddr;
> +}
> +
> +phys_addr_t xen_bus_to_phys(dma_addr_t daddr)
> +{
> +	return machine_to_phys(XMADDR(daddr)).paddr;
> +}
> +
>  static inline int address_needs_mapping(struct device *hwdev,
>  						dma_addr_t addr)
>  {
> diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
> index 67b7b42..4229f27 100644
> --- a/include/xen/swiotlb.h
> +++ b/include/xen/swiotlb.h
> @@ -2,5 +2,7 @@
>  #define _XEN_SWIOTLB_H
>  
>  extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
> +extern phys_addr_t xen_bus_to_phys(dma_addr_t daddr);
> +extern dma_addr_t xen_phys_to_bus(phys_addr_t paddr);
>  
>  #endif /* _XEN_SWIOTLB_H */
> -- 
> 1.6.0.6
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen
  2009-05-08  0:17 ` [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
@ 2009-05-11 14:16   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: Joerg Roedel @ 2009-05-11 14:16 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Ingo Molnar, FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

On Thu, May 07, 2009 at 05:17:17PM -0700, Jeremy Fitzhardinge wrote:
> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen support for DMA
> 
> Add hook so that Xen can determine whether a particular address range needs
> pfn<->mfn mapping.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

Acked-by: Joerg Roedel <joerg.roedel@amd.com>

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

* Re: [PATCH 5/9] xen: enable swiotlb for xen domain 0.
  2009-05-08  0:17 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
  2009-05-11  3:40   ` FUJITA Tomonori
@ 2009-05-11 14:21   ` Joerg Roedel
  1 sibling, 0 replies; 28+ messages in thread
From: Joerg Roedel @ 2009-05-11 14:21 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Ingo Molnar, FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Ian Campbell,
	Jeremy Fitzhardinge

On Thu, May 07, 2009 at 05:17:18PM -0700, Jeremy Fitzhardinge wrote:
> From: Ian Campbell <ian.campbell@citrix.com>
> 
> Impact: Xen DMA support
> 
> Enable swiotlb when running as a Xen dom0 domain.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

Acked-by: Joerg Roedel <joerg.roedel@amd.com>

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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-11 13:04 ` Ingo Molnar
@ 2009-05-11 16:57   ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-11 16:57 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel

Ingo Molnar wrote:
> * Jeremy Fitzhardinge <jeremy@goop.org> wrote:
>
>   
>> Hi Ingo,
>>
>> This branch adds the swiotlb hooks for Xen dom0.  We use swiotlb 
>> to handle various device drivers which assume that multipage DMA 
>> transfers which are contigious in kernel memory are also 
>> contigious in machine memory (mostly lower-performance devices, as 
>> high-performance ones already do a good job of scatter-gather).
>>
>> Following Fujita's suggestion, these changes remove a lot of the 
>> placeholder stubs in arch/x86/kernel/pci-swiotlb.c and moves them 
>> into the Xen-specific arch/x86/xen/pci-swiotlb.c.  (It still 
>> relies on overriding the weak functions defined in lib/swiotlb.c.)
>>
>> The following changes since commit 2af252ab26150b4411889c9eaf1af4c5bf03de78:
>>   Jeremy Fitzhardinge (1):
>>         xen: checkpatch cleanups
>>     
>
> Would be nice to have a pull request for this with Fujita-san's acks 
> embedded in the commits, and with a tree based against tip:x86/xen.
>   

I will regenerate the branch with the acks (and Joerg made some comments 
which I'll address too).

    J

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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-11  3:40 ` FUJITA Tomonori
@ 2009-05-11 16:59   ` Jeremy Fitzhardinge
  2009-05-11 22:45     ` FUJITA Tomonori
  0 siblings, 1 reply; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-11 16:59 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: mingo, x86, linux-kernel, xen-devel

FUJITA Tomonori wrote:
> As I said before, I don't like such weak hacks added for dom0. We will
> merge dom0 support?
>   

That's in progress.  But they're largely the same hooks that ppc is 
using as well.

    J


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

* Re: [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious
  2009-05-11 13:55   ` Joerg Roedel
@ 2009-05-11 18:42     ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 28+ messages in thread
From: Jeremy Fitzhardinge @ 2009-05-11 18:42 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Ingo Molnar, FUJITA Tomonori, the arch/x86 maintainers,
	Linux Kernel Mailing List, Xen-devel, Jeremy Fitzhardinge

Joerg Roedel wrote:
>> +}
>> +
>> +void *swiotlb_alloc(unsigned order, unsigned long nslabs)
>> +{
>> +	/* Never called on x86.  Warn, just in case. */
>>     
>
> Can't this function be removed completly then?
>   

The swiotlb code contains a static call, which never ends up being 
executed, so there has to be something to be called.  But you're right 
that there's no particular reason for this warning unless someone starts 
to call swiotlb_alloc in the future.

I'd briefly discussed the idea of eliminating the distinction between 
boot and post-boot swiotlb allocation, but it looks tricky to implement.

>> +
>> +	if (xen_create_contiguous_region((unsigned long)buf,
>> +					 order, 0xffffffff))
>>     
>                                                 DMA_32BIT_MASK?
>   

OK (ditto other mentions).

    J

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

* Re: [GIT PULL] xen: swiotlb support for Xen dom0
  2009-05-11 16:59   ` Jeremy Fitzhardinge
@ 2009-05-11 22:45     ` FUJITA Tomonori
  0 siblings, 0 replies; 28+ messages in thread
From: FUJITA Tomonori @ 2009-05-11 22:45 UTC (permalink / raw)
  To: jeremy; +Cc: fujita.tomonori, mingo, x86, linux-kernel, xen-devel

On Mon, 11 May 2009 09:59:38 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> FUJITA Tomonori wrote:
> > As I said before, I don't like such weak hacks added for dom0. We will
> > merge dom0 support?
> >   
> 
> That's in progress.  But they're largely the same hooks that ppc is 
> using as well.

As I explained before, if we have only ppc here, I can remove all the
hacks by using arch/include/asm cleanly. These hacks are just due to
dom0.

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

end of thread, other threads:[~2009-05-11 22:47 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-08  0:17 [GIT PULL] xen: swiotlb support for Xen dom0 Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
2009-05-08  7:47   ` [Xen-devel] [PATCH 1/9] xen: make sure swiotlb allocation isphysically contigious Jan Beulich
2009-05-08 15:51     ` Jeremy Fitzhardinge
2009-05-11  3:40   ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious FUJITA Tomonori
2009-05-11 13:55   ` Joerg Roedel
2009-05-11 18:42     ` Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 2/9] xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
2009-05-11  3:40   ` FUJITA Tomonori
2009-05-11 14:11   ` Joerg Roedel
2009-05-08  0:17 ` [PATCH 4/9] xen/swiotlb: add swiotlb_arch_range_needs_mapping hook for xen Jeremy Fitzhardinge
2009-05-11  3:40   ` FUJITA Tomonori
2009-05-11 14:16   ` Joerg Roedel
2009-05-08  0:17 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
2009-05-11  3:40   ` FUJITA Tomonori
2009-05-11 14:21   ` Joerg Roedel
2009-05-08  0:17 ` [PATCH 6/9] swiotlb: use swiotlb_alloc_boot to allocate emergency pool Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 7/9] xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent() Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 8/9] xen/swiotlb: add sync functions Jeremy Fitzhardinge
2009-05-08  0:17 ` [PATCH 9/9] xen/swiotlb: update to new new dma_ops Jeremy Fitzhardinge
2009-05-08 11:19 ` [GIT PULL] xen: swiotlb support for Xen dom0 Ingo Molnar
2009-05-11  3:40 ` FUJITA Tomonori
2009-05-11 16:59   ` Jeremy Fitzhardinge
2009-05-11 22:45     ` FUJITA Tomonori
2009-05-11 13:04 ` Ingo Molnar
2009-05-11 16:57   ` Jeremy Fitzhardinge
  -- strict thread matches above, loose matches on Subject: below --
2009-03-31 22:52 [PATCH] swiotlb updates " Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox