lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 28 May 2013 00:13:06 +0800
From:	Ming Lei <ming.lei@...onical.com>
To:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:	linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
	Ming Lei <ming.lei@...onical.com>,
	Shuah Khan <shuah.khan@...com>, Joerg Roedel <joro@...tes.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Alexander Duyck <alexander.h.duyck@...el.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>
Subject: [RFC PATCH 1/2] dma-debug: allow size to become smaller in dma_unmap

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@...com>
Cc: Joerg Roedel <joro@...tes.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Alexander Duyck <alexander.h.duyck@...el.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>
Signed-off-by: Ming Lei <ming.lei@...onical.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ