Skip to contentSkip to conversation

powerpc: node-away dma allocations

PATCH New Christoph Hellwig 2 participants 2 messages Jun 6, 2006 – Jun 10, 2006 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 powerpc: node-away dma allocations

Make sure dma_alloc_coherent allocates memory from the local node. This is important on Cell where we avoid going through the slow cpu interconnect.

Note: I could only test this patch on Cell, it should be verified on some pseries machine by thos that have the hardware.

arch/powerpc/kernel/iommu.c +8 -6
Index: linux-2.6/arch/powerpc/kernel/iommu.c
===================================================================
@@ -536,11 +536,12 @@
  * to the dma address (mapping) of the first page.
  */
 void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
-		dma_addr_t *dma_handle, unsigned long mask, gfp_t flag)
+		dma_addr_t *dma_handle, unsigned long mask, gfp_t flag, int node)
 {
 	void *ret = NULL;
 	dma_addr_t mapping;
 	unsigned int npages, order;
+	struct page *page;
 
 	size = PAGE_ALIGN(size);
 	npages = size >> PAGE_SHIFT;
@@ -560,9 +561,10 @@
 		return NULL;
 
 	/* Alloc enough pages (and possibly more) */
-	ret = (void *)__get_free_pages(flag, order);
-	if (!ret)
+	page = alloc_pages_node(flag, order, node);
+	if (!page)
 		return NULL;
+	ret = page_address(page);
 	memset(ret, 0, size);
 
 	/* Set up tces to cover the allocated range */
@@ -570,9 +572,9 @@
 			      mask >> PAGE_SHIFT, order);
 	if (mapping == DMA_ERROR_CODE) {
 		free_pages((unsigned long)ret, order);
-		ret = NULL;
-	} else
-		*dma_handle = mapping;
+		return NULL;
+	}
+	*dma_handle = mapping;
 	return ret;
 }
 
arch/powerpc/kernel/pci_iommu.c +2 -1
Index: linux-2.6/arch/powerpc/kernel/pci_iommu.c
===================================================================
@@ -86,7 +86,8 @@
 			   dma_addr_t *dma_handle, gfp_t flag)
 {
 	return iommu_alloc_coherent(devnode_table(hwdev), size, dma_handle,
-			device_to_mask(hwdev), flag);
+			device_to_mask(hwdev), flag,
+			pcibus_to_node(to_pci_dev(hwdev)->bus));
 }
 
 static void pci_iommu_free_coherent(struct device *hwdev, size_t size,
arch/powerpc/kernel/vio.c +1 -1
Index: linux-2.6/arch/powerpc/kernel/vio.c
===================================================================
@@ -229,7 +229,7 @@
 			   dma_addr_t *dma_handle, gfp_t flag)
 {
 	return iommu_alloc_coherent(to_vio_dev(dev)->iommu_table, size,
-			dma_handle, ~0ul, flag);
+			dma_handle, ~0ul, flag, -1);
 }
 
 static void vio_free_coherent(struct device *dev, size_t size,
include/asm-powerpc/iommu.h +2 -1
Index: linux-2.6/include/asm-powerpc/iommu.h
===================================================================
@@ -76,7 +76,8 @@
 		int nelems, enum dma_data_direction direction);
 
 extern void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
-		dma_addr_t *dma_handle, unsigned long mask, gfp_t flag);
+		dma_addr_t *dma_handle, unsigned long mask,
+		gfp_t flag, int node);
 extern void iommu_free_coherent(struct iommu_table *tbl, size_t size,
 		void *vaddr, dma_addr_t dma_handle);
 extern dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
#1 lore raw

PATCH 1/1 powerpc: Fix pseries IOMMU allocations

Quoted 7 lines

Make sure dma_alloc_coherent allocates memory from the local node. This is important on Cell where we avoid going through the slow cpu interconnect.

Note: I could only test this patch on Cell, it should be verified on some pseries machine by thos that have the hardware.

Looks like this patch is merged in Pauls tree and breaking pseries boot. The patch below should fix it.

--

The arguments to alloc_pages_node were reversed, resulting in IOMMU allocation failures. Fix it.

---

arch/powerpc/kernel/iommu.c +1 -1
Index: build/arch/powerpc/kernel/iommu.c
===================================================================
@@ -561,7 +561,7 @@ void *iommu_alloc_coherent(struct iommu_
 		return NULL;
 
 	/* Alloc enough pages (and possibly more) */
-	page = alloc_pages_node(flag, order, node);
+	page = alloc_pages_node(node, flag, order);
 	if (!page)
 		return NULL;
 	ret = page_address(page);