Skip to content

Commit 59f2e7d

Browse files
djbwtorvalds
authored andcommitted
dma-debug: fix overlap detection
Commit 0abdd7a ("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>
1 parent f544e14 commit 59f2e7d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎lib/dma-debug.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int active_pfn_set_overlap(unsigned long pfn, int overlap)
463463
int i;
464464

465465
if (overlap > ACTIVE_PFN_MAX_OVERLAP || overlap < 0)
466-
return 0;
466+
return overlap;
467467

468468
for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--)
469469
if (overlap & 1 << i)
@@ -486,7 +486,7 @@ static void active_pfn_inc_overlap(unsigned long pfn)
486486
* debug_dma_assert_idle() as the pfn may be marked idle
487487
* prematurely.
488488
*/
489-
WARN_ONCE(overlap == 0,
489+
WARN_ONCE(overlap > ACTIVE_PFN_MAX_OVERLAP,
490490
"DMA-API: exceeded %d overlapping mappings of pfn %lx\n",
491491
ACTIVE_PFN_MAX_OVERLAP, pfn);
492492
}
@@ -517,7 +517,11 @@ static void active_pfn_remove(struct dma_debug_entry *entry)
517517
unsigned long flags;
518518

519519
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)
521525
radix_tree_delete(&dma_active_pfn, entry->pfn);
522526
spin_unlock_irqrestore(&radix_lock, flags);
523527
}

0 commit comments

Comments
 (0)