Skip to content

Commit 8d640a5

Browse files
Alexander Duycktorvalds
authored andcommitted
dma-debug: fix locking bug in check_unmap()
In check_unmap() it is possible to get into a dead-locked state if dma_mapping_error is called. The problem is that the bucket is locked in check_unmap, and locked again by debug_dma_mapping_error which is called by dma_mapping_error. To resolve that we must release the lock on the bucket before making the call to dma_mapping_error. [akpm@linux-foundation.org: restore 80-col trickery to be consistent with the rest of the file] Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Cc: Joerg Roedel <joro@8bytes.org> Reviewed-by: Shuah Khan <shuah.khan@hp.com> Tested-by: Shuah Khan <shuah.khan@hp.com> Cc: Jakub Kicinski <kubakici@wp.pl> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0ef1594 commit 8d640a5

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎lib/dma-debug.c‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,17 +862,21 @@ static void check_unmap(struct dma_debug_entry *ref)
862862
entry = bucket_find_exact(bucket, ref);
863863

864864
if (!entry) {
865+
/* must drop lock before calling dma_mapping_error */
866+
put_hash_bucket(bucket, &flags);
867+
865868
if (dma_mapping_error(ref->dev, ref->dev_addr)) {
866869
err_printk(ref->dev, NULL,
867-
"DMA-API: device driver tries "
868-
"to free an invalid DMA memory address\n");
869-
return;
870+
"DMA-API: device driver tries to free an "
871+
"invalid DMA memory address\n");
872+
} else {
873+
err_printk(ref->dev, NULL,
874+
"DMA-API: device driver tries to free DMA "
875+
"memory it has not allocated [device "
876+
"address=0x%016llx] [size=%llu bytes]\n",
877+
ref->dev_addr, ref->size);
870878
}
871-
err_printk(ref->dev, NULL, "DMA-API: device driver tries "
872-
"to free DMA memory it has not allocated "
873-
"[device address=0x%016llx] [size=%llu bytes]\n",
874-
ref->dev_addr, ref->size);
875-
goto out;
879+
return;
876880
}
877881

878882
if (ref->size != entry->size) {
@@ -936,7 +940,6 @@ static void check_unmap(struct dma_debug_entry *ref)
936940
hash_bucket_del(entry);
937941
dma_entry_free(entry);
938942

939-
out:
940943
put_hash_bucket(bucket, &flags);
941944
}
942945

0 commit comments

Comments
 (0)