linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -tip 0/3] dma-debug fixes
@ 2009-05-27  0:43 FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 1/3] dma-debug: use sg_dma_address accessor instead of using dma_address directly FUJITA Tomonori
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: FUJITA Tomonori @ 2009-05-27  0:43 UTC (permalink / raw)
  To: mingo; +Cc: joerg.roedel, fujita.tomonori, linux-kernel

None of them is critical (we get bogus warnings due to the bugs but
the bugs are in unpopular DMA mapping functions).

This patchset is against to tip/master.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH -tip 1/3] dma-debug: use sg_dma_address accessor instead of using dma_address directly
  2009-05-27  0:43 [PATCH -tip 0/3] dma-debug fixes FUJITA Tomonori
@ 2009-05-27  0:43 ` FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 2/3] dma-debug: use sg_dma_len accessor FUJITA Tomonori
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: FUJITA Tomonori @ 2009-05-27  0:43 UTC (permalink / raw)
  To: mingo; +Cc: joerg.roedel, fujita.tomonori, linux-kernel

Architectures might not have dma_address in struct scatterlist (PARISC
doesn't). Directly accessing to dma_address in struct scatterlist is
wrong; we need to use sg_dma_address() accesssor instead.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 lib/dma-debug.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index cdd205d..64aaa96 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -784,7 +784,7 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
 		entry->dev            = dev;
 		entry->paddr          = sg_phys(s);
 		entry->size           = s->length;
-		entry->dev_addr       = s->dma_address;
+		entry->dev_addr       = sg_dma_address(s);
 		entry->direction      = direction;
 		entry->sg_call_ents   = nents;
 		entry->sg_mapped_ents = mapped_ents;
@@ -816,7 +816,7 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
 			.type           = dma_debug_sg,
 			.dev            = dev,
 			.paddr          = sg_phys(s),
-			.dev_addr       = s->dma_address,
+			.dev_addr       = sg_dma_address(s),
 			.size           = s->length,
 			.direction      = dir,
 			.sg_call_ents   = 0,
@@ -940,8 +940,8 @@ void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
-		check_sync(dev, s->dma_address, s->dma_length, 0,
-				direction, true);
+		check_sync(dev, sg_dma_address(s), s->dma_length, 0,
+			   direction, true);
 	}
 }
 EXPORT_SYMBOL(debug_dma_sync_sg_for_cpu);
@@ -956,8 +956,8 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
-		check_sync(dev, s->dma_address, s->dma_length, 0,
-				direction, false);
+		check_sync(dev, sg_dma_address(s), s->dma_length, 0,
+			   direction, false);
 	}
 }
 EXPORT_SYMBOL(debug_dma_sync_sg_for_device);
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -tip 2/3] dma-debug: use sg_dma_len accessor
  2009-05-27  0:43 [PATCH -tip 0/3] dma-debug fixes FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 1/3] dma-debug: use sg_dma_address accessor instead of using dma_address directly FUJITA Tomonori
@ 2009-05-27  0:43 ` FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 3/3] dma-debug: fix debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device FUJITA Tomonori
  2009-05-27 12:47 ` [PATCH -tip 0/3] dma-debug fixes Joerg Roedel
  3 siblings, 0 replies; 6+ messages in thread
From: FUJITA Tomonori @ 2009-05-27  0:43 UTC (permalink / raw)
  To: mingo; +Cc: joerg.roedel, fujita.tomonori, linux-kernel

debug_dma_map_sg() and debug_dma_unmap_sg() use length in struct
scatterlist while debug_dma_sync_sg_for_cpu() and
debug_dma_sync_sg_for_device() use dma_length. This causes bugs
warnings on some IOMMU implementations since these values are not
same; the length doesn't represent the dma length.

We always need to use sg_dma_len() accessor to get the dma length of a
scatterlist entry.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 lib/dma-debug.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 64aaa96..df9e475 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -783,7 +783,7 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
 		entry->type           = dma_debug_sg;
 		entry->dev            = dev;
 		entry->paddr          = sg_phys(s);
-		entry->size           = s->length;
+		entry->size           = sg_dma_len(s);
 		entry->dev_addr       = sg_dma_address(s);
 		entry->direction      = direction;
 		entry->sg_call_ents   = nents;
@@ -791,7 +791,7 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
 
 		if (!PageHighMem(sg_page(s))) {
 			check_for_stack(dev, sg_virt(s));
-			check_for_illegal_area(dev, sg_virt(s), s->length);
+			check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s));
 		}
 
 		add_dma_entry(entry);
@@ -817,7 +817,7 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
 			.dev            = dev,
 			.paddr          = sg_phys(s),
 			.dev_addr       = sg_dma_address(s),
-			.size           = s->length,
+			.size           = sg_dma_len(s),
 			.direction      = dir,
 			.sg_call_ents   = 0,
 		};
@@ -940,7 +940,7 @@ void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
-		check_sync(dev, sg_dma_address(s), s->dma_length, 0,
+		check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
 			   direction, true);
 	}
 }
@@ -956,7 +956,7 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
-		check_sync(dev, sg_dma_address(s), s->dma_length, 0,
+		check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
 			   direction, false);
 	}
 }
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -tip 3/3] dma-debug: fix debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device
  2009-05-27  0:43 [PATCH -tip 0/3] dma-debug fixes FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 1/3] dma-debug: use sg_dma_address accessor instead of using dma_address directly FUJITA Tomonori
  2009-05-27  0:43 ` [PATCH -tip 2/3] dma-debug: use sg_dma_len accessor FUJITA Tomonori
@ 2009-05-27  0:43 ` FUJITA Tomonori
  2009-05-27 12:47 ` [PATCH -tip 0/3] dma-debug fixes Joerg Roedel
  3 siblings, 0 replies; 6+ messages in thread
From: FUJITA Tomonori @ 2009-05-27  0:43 UTC (permalink / raw)
  To: mingo; +Cc: joerg.roedel, fujita.tomonori, linux-kernel

DMA-mapping.txt says that debug_dma_sync_sg family must be called with
the _same_ one you passed into the dma_map_sg call, it should _NOT_ be
the 'count' value _returned_ from the dma_map_sg call.

debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device can't
handle this properly; they need to use the sg_mapped_ents in struct
dma_debug_entry as debug_dma_unmap_sg() does.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 lib/dma-debug.c |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index df9e475..e10a981 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -799,13 +799,32 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
 }
 EXPORT_SYMBOL(debug_dma_map_sg);
 
+static int get_nr_mapped_entries(struct device *dev, struct scatterlist *s)
+{
+	struct dma_debug_entry *entry;
+	struct hash_bucket *bucket;
+	unsigned long flags;
+	int mapped_ents = 0;
+	struct dma_debug_entry ref;
+
+	ref.dev = dev;
+	ref.dev_addr = sg_dma_address(s);
+	ref.size = sg_dma_len(s),
+
+	bucket = get_hash_bucket(&ref, &flags);
+	entry = hash_bucket_find(bucket, &ref);
+	if (entry)
+		mapped_ents = entry->sg_mapped_ents;
+	put_hash_bucket(bucket, &flags);
+
+	return mapped_ents;
+}
+
 void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
 			int nelems, int dir)
 {
-	struct dma_debug_entry *entry;
 	struct scatterlist *s;
 	int mapped_ents = 0, i;
-	unsigned long flags;
 
 	if (unlikely(global_disable))
 		return;
@@ -825,14 +844,9 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
 		if (mapped_ents && i >= mapped_ents)
 			break;
 
-		if (mapped_ents == 0) {
-			struct hash_bucket *bucket;
+		if (!i) {
 			ref.sg_call_ents = nelems;
-			bucket = get_hash_bucket(&ref, &flags);
-			entry = hash_bucket_find(bucket, &ref);
-			if (entry)
-				mapped_ents = entry->sg_mapped_ents;
-			put_hash_bucket(bucket, &flags);
+			mapped_ents = get_nr_mapped_entries(dev, s);
 		}
 
 		check_unmap(&ref);
@@ -934,12 +948,18 @@ void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 			       int nelems, int direction)
 {
 	struct scatterlist *s;
-	int i;
+	int mapped_ents = 0, i;
 
 	if (unlikely(global_disable))
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
+		if (!i)
+			mapped_ents = get_nr_mapped_entries(dev, s);
+
+		if (i >= mapped_ents)
+			break;
+
 		check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
 			   direction, true);
 	}
@@ -950,12 +970,18 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 				  int nelems, int direction)
 {
 	struct scatterlist *s;
-	int i;
+	int mapped_ents = 0, i;
 
 	if (unlikely(global_disable))
 		return;
 
 	for_each_sg(sg, s, nelems, i) {
+		if (!i)
+			mapped_ents = get_nr_mapped_entries(dev, s);
+
+		if (i >= mapped_ents)
+			break;
+
 		check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
 			   direction, false);
 	}
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH -tip 0/3] dma-debug fixes
  2009-05-27  0:43 [PATCH -tip 0/3] dma-debug fixes FUJITA Tomonori
                   ` (2 preceding siblings ...)
  2009-05-27  0:43 ` [PATCH -tip 3/3] dma-debug: fix debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device FUJITA Tomonori
@ 2009-05-27 12:47 ` Joerg Roedel
  2009-05-27 23:33   ` Ingo Molnar
  3 siblings, 1 reply; 6+ messages in thread
From: Joerg Roedel @ 2009-05-27 12:47 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: mingo, linux-kernel

On Wed, May 27, 2009 at 09:43:00AM +0900, FUJITA Tomonori wrote:
> None of them is critical (we get bogus warnings due to the bugs but
> the bugs are in unpopular DMA mapping functions).
> 
> This patchset is against to tip/master.

Acked-by: Joerg Roedel <joerg.roedel@amd.com>

They all look good to me.

Ingo, do you want to pick them up youself or should I include them into
my dma-debug pull-request to you for 2.6.31?

Joerg

-- 
           | Advanced Micro Devices GmbH
 Operating | Karl-Hammerschmidt-Str. 34, 85609 Dornach bei München
 System    | 
 Research  | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
 Center    | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
           | Registergericht München, HRB Nr. 43632


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -tip 0/3] dma-debug fixes
  2009-05-27 12:47 ` [PATCH -tip 0/3] dma-debug fixes Joerg Roedel
@ 2009-05-27 23:33   ` Ingo Molnar
  0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-05-27 23:33 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: FUJITA Tomonori, linux-kernel


* Joerg Roedel <joerg.roedel@amd.com> wrote:

> On Wed, May 27, 2009 at 09:43:00AM +0900, FUJITA Tomonori wrote:
> > None of them is critical (we get bogus warnings due to the bugs but
> > the bugs are in unpopular DMA mapping functions).
> > 
> > This patchset is against to tip/master.
> 
> Acked-by: Joerg Roedel <joerg.roedel@amd.com>
> 
> They all look good to me.
> 
> Ingo, do you want to pick them up youself or should I include them 
> into my dma-debug pull-request to you for 2.6.31?

Sure, feel free to include them.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-27 23:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-27  0:43 [PATCH -tip 0/3] dma-debug fixes FUJITA Tomonori
2009-05-27  0:43 ` [PATCH -tip 1/3] dma-debug: use sg_dma_address accessor instead of using dma_address directly FUJITA Tomonori
2009-05-27  0:43 ` [PATCH -tip 2/3] dma-debug: use sg_dma_len accessor FUJITA Tomonori
2009-05-27  0:43 ` [PATCH -tip 3/3] dma-debug: fix debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device FUJITA Tomonori
2009-05-27 12:47 ` [PATCH -tip 0/3] dma-debug fixes Joerg Roedel
2009-05-27 23:33   ` Ingo Molnar

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).