mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@canonical.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ming Lei <ming.lei@canonical.com>, Shuah Khan <shuah.khan@hp.com>,
	Joerg Roedel <joro@8bytes.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Duyck <alexander.h.duyck@intel.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [RFC PATCH 1/2] dma-debug: allow size to become smaller in dma_unmap
Date: Tue, 28 May 2013 00:13:06 +0800	[thread overview]
Message-ID: <1369671187-24430-2-git-send-email-ming.lei@canonical.com> (raw)
In-Reply-To: <1369671187-24430-1-git-send-email-ming.lei@canonical.com>

This patch looses the check on DMA buffer size for streaming
DMA unmap, based on the below fact:

- it is common to see only part of DMA transfer is completed,
especially in case of DMA_FROM_DEVICE

So it isn't necessary to unmap the whole DMA buffer inside DMA
unmapping, and unmapping the actual completed buffer should be more
efficient. Considered that unmapping is often called in hard irq
context, time of irq handling can be saved.

Cc: Shuah Khan <shuah.khan@hp.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Duyck <alexander.h.duyck@intel.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 lib/dma-debug.c |   39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index d87a17a..202c522 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -857,6 +857,7 @@ static void check_unmap(struct dma_debug_entry *ref)
 	struct dma_debug_entry *entry;
 	struct hash_bucket *bucket;
 	unsigned long flags;
+	unsigned int  size_invalid = 0;
 
 	bucket = get_hash_bucket(ref, &flags);
 	entry = bucket_find_exact(bucket, ref);
@@ -879,13 +880,8 @@ static void check_unmap(struct dma_debug_entry *ref)
 		return;
 	}
 
-	if (ref->size != entry->size) {
-		err_printk(ref->dev, entry, "DMA-API: device driver frees "
-			   "DMA memory with different size "
-			   "[device address=0x%016llx] [map size=%llu bytes] "
-			   "[unmap size=%llu bytes]\n",
-			   ref->dev_addr, entry->size, ref->size);
-	}
+	if (ref->size > entry->size)
+		size_invalid = 1;
 
 	if (ref->type != entry->type) {
 		err_printk(ref->dev, entry, "DMA-API: device driver frees "
@@ -894,18 +890,27 @@ static void check_unmap(struct dma_debug_entry *ref)
 			   "[mapped as %s] [unmapped as %s]\n",
 			   ref->dev_addr, ref->size,
 			   type2name[entry->type], type2name[ref->type]);
-	} else if ((entry->type == dma_debug_coherent) &&
-		   (ref->paddr != entry->paddr)) {
-		err_printk(ref->dev, entry, "DMA-API: device driver frees "
-			   "DMA memory with different CPU address "
-			   "[device address=0x%016llx] [size=%llu bytes] "
-			   "[cpu alloc address=0x%016llx] "
-			   "[cpu free address=0x%016llx]",
-			   ref->dev_addr, ref->size,
-			   (unsigned long long)entry->paddr,
-			   (unsigned long long)ref->paddr);
+	} else if (entry->type == dma_debug_coherent) {
+		if (ref->paddr != entry->paddr)
+			err_printk(ref->dev, entry, "DMA-API: device driver frees "
+				   "DMA memory with different CPU address "
+				   "[device address=0x%016llx] [size=%llu bytes] "
+				   "[cpu alloc address=0x%016llx] "
+				   "[cpu free address=0x%016llx]",
+				   ref->dev_addr, ref->size,
+				   (unsigned long long)entry->paddr,
+				   (unsigned long long)ref->paddr);
+		if (ref->size != entry->size)
+			size_invalid = 1;
 	}
 
+	if (size_invalid)
+		err_printk(ref->dev, entry, "DMA-API: device driver frees "
+			   "DMA memory with different size "
+			   "[device address=0x%016llx] [map size=%llu bytes] "
+			   "[unmap size=%llu bytes]\n",
+			   ref->dev_addr, entry->size, ref->size);
+
 	if (ref->sg_call_ents && ref->type == dma_debug_sg &&
 	    ref->sg_call_ents != entry->sg_call_ents) {
 		err_printk(ref->dev, entry, "DMA-API: device driver frees "
-- 
1.7.9.5


  reply	other threads:[~2013-05-27 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 16:13 [RFC PATCH 0/2] dma-unmap: allow to only unmap completed DMA buffer Ming Lei
2013-05-27 16:13 ` Ming Lei [this message]
2013-05-27 20:37   ` [RFC PATCH 1/2] dma-debug: allow size to become smaller in dma_unmap Alexander Duyck
2013-05-27 16:13 ` [PATCH 2/2] USB: hcd: only unmap the actual completed DMA buffer Ming Lei
2013-05-27 17:13   ` Sergei Shtylyov
2013-05-27 20:18 ` [RFC PATCH 0/2] dma-unmap: allow to only unmap " Alan Stern

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=1369671187-24430-2-git-send-email-ming.lei@canonical.com \
    --to=ming.lei@canonical.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.h.duyck@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joro@8bytes.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah.khan@hp.com \
    /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

all inboxes | Powered by JetHome®