linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Robert Jennings <rcj@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	paulus@samba.org, linuxppc-dev@ozlabs.org,
	Brian King <brking@linux.vnet.ibm.com>,
	Nathan Fontenot <nfont@austin.ibm.com>,
	David Darrington <ddarring@linux.vnet.ibm.com>
Subject: [PATCH] powerpc: Correct CMO entitlement accounting for map_sg
Date: Mon, 21 Jul 2008 19:24:21 -0500	[thread overview]
Message-ID: <20080722002420.GA26633@linux.vnet.ibm.com> (raw)

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.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>

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

---
 arch/powerpc/kernel/vio.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Index: b/arch/powerpc/kernel/vio.c
===================================================================
--- a/arch/powerpc/kernel/vio.c
+++ 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);
 

                 reply	other threads:[~2008-07-22  0:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080722002420.GA26633@linux.vnet.ibm.com \
    --to=rcj@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=brking@linux.vnet.ibm.com \
    --cc=ddarring@linux.vnet.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=nfont@austin.ibm.com \
    --cc=paulus@samba.org \
    /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;
as well as URLs for NNTP newsgroup(s).