Skip to contentSkip to conversation

powerpc: Correct CMO entitlement accounting for map_sg

PATCH New Robert Jennings 1 participant 1 message Jul 22, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Correct CMO entitlement accounting for map_sg

The ibmvscsi driver maps pages via map_sg and frees the sg list by calling unmap_single. This exposes a problem where the code had been using the length field in the scatterlist to account for the allocation when the mapping was created but the dma_length would be used when the mapping was destroyed. The iommu code does coalesce the pages so the dma_length can be smaller and would result in an entitlement accounting leak. This patch frees up the entitlement after calling the iommu map_sg code when pages have been coalesced so that freeing entitlement based on dma_length is correct.

---
This applies on top of the existing CMO patchset.

---
 arch/powerpc/kernel/vio.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kernel/vio.c +6 -1
Index: b/arch/powerpc/kernel/vio.c
===================================================================
@@ -571,6 +571,11 @@ static int vio_dma_iommu_map_sg(struct d
 		atomic_inc(&viodev->cmo.allocs_failed);
 	}
 
+	for (sgl = sglist, count = 0; count < ret; count++, sgl++)
+		alloc_size -= roundup(sgl->dma_length, PAGE_SIZE);
+	if (alloc_size)
+		vio_cmo_dealloc(viodev, alloc_size);
+
 	return ret;
 }
 
@@ -584,7 +589,7 @@ static void vio_dma_iommu_unmap_sg(struc
 	int count = 0;
 
 	for (sgl = sglist; count < nelems; count++, sgl++)
-		alloc_size += roundup(sgl->length, PAGE_SIZE);
+		alloc_size += roundup(sgl->dma_length, PAGE_SIZE);
 
 	dma_iommu_ops.unmap_sg(dev, sglist, nelems, direction);