aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2014-01-29 17:05:53 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-29 19:22:40 -0500
commit59f2e7df574c78e952d79435de3f4867349403aa (patch)
treee03333701756e783f4a5085c8df2777651900970 /lib
parentf544e14f3e765b5241d7f234fee677506b8ce07f (diff)
dma-debug: fix overlap detection
Commit 0abdd7a81b7e ("dma-debug: introduce debug_dma_assert_idle()") was reworked to expand the overlap counter to the full range expressable by 3 tag bits, but it has a thinko in treating the overlap counter as a pure reference count for the entry. Instead of deleting when the reference-count drops to zero, we need to delete when the overlap-count drops below zero. Also, when detecting overflow we can just test the overlap-count > MAX rather than applying special meaning to 0. Regression report available here: http://marc.info/?l=linux-netdev&m=139073373932386&w=2 This patch, now tested on the original net_dma case, sees the expected handful of reports before the eventual data corruption occurs. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reported-by: Sander Eikelenboom <linux@eikelenboom.it> Cc: Francois Romieu <romieu@fr.zoreil.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/dma-debug.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index c38083871f11..2defd1308b04 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -463,7 +463,7 @@ static int active_pfn_set_overlap(unsigned long pfn, int overlap)
463 int i; 463 int i;
464 464
465 if (overlap > ACTIVE_PFN_MAX_OVERLAP || overlap < 0) 465 if (overlap > ACTIVE_PFN_MAX_OVERLAP || overlap < 0)
466 return 0; 466 return overlap;
467 467
468 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--) 468 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--)
469 if (overlap & 1 << i) 469 if (overlap & 1 << i)
@@ -486,7 +486,7 @@ static void active_pfn_inc_overlap(unsigned long pfn)
486 * debug_dma_assert_idle() as the pfn may be marked idle 486 * debug_dma_assert_idle() as the pfn may be marked idle
487 * prematurely. 487 * prematurely.
488 */ 488 */
489 WARN_ONCE(overlap == 0, 489 WARN_ONCE(overlap > ACTIVE_PFN_MAX_OVERLAP,
490 "DMA-API: exceeded %d overlapping mappings of pfn %lx\n", 490 "DMA-API: exceeded %d overlapping mappings of pfn %lx\n",
491 ACTIVE_PFN_MAX_OVERLAP, pfn); 491 ACTIVE_PFN_MAX_OVERLAP, pfn);
492} 492}
@@ -517,7 +517,11 @@ static void active_pfn_remove(struct dma_debug_entry *entry)
517 unsigned long flags; 517 unsigned long flags;
518 518
519 spin_lock_irqsave(&radix_lock, flags); 519 spin_lock_irqsave(&radix_lock, flags);
520 if (active_pfn_dec_overlap(entry->pfn) == 0) 520 /* since we are counting overlaps the final put of the
521 * entry->pfn will occur when the overlap count is 0.
522 * active_pfn_dec_overlap() returns -1 in that case
523 */
524 if (active_pfn_dec_overlap(entry->pfn) < 0)
521 radix_tree_delete(&dma_active_pfn, entry->pfn); 525 radix_tree_delete(&dma_active_pfn, entry->pfn);
522 spin_unlock_irqrestore(&radix_lock, flags); 526 spin_unlock_irqrestore(&radix_lock, flags);
523} 527}