diff options
author | Miles Chen <miles.chen@mediatek.com> | 2017-11-17 18:26:19 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-17 19:10:00 -0500 |
commit | 3aaabbf1c39effa2ac0c11103ed07ef03b0a0d89 (patch) | |
tree | 59e46e30142dd3882d5100a8ee1fe9a861b53a26 /lib/dma-debug.c | |
parent | 5d03a6613957785e94af7a4a6212ad4af66aa5c2 (diff) |
lib/dma-debug.c: fix incorrect pfn calculation
dma-debug reports the following warning:
WARNING: CPU: 3 PID: 298 at kernel-4.4/lib/dma-debug.c:604
debug _dma_assert_idle+0x1a8/0x230()
DMA-API: cpu touching an active dma mapped cacheline [cln=0x00000882300]
CPU: 3 PID: 298 Comm: vold Tainted: G W O 4.4.22+ #1
Hardware name: MT6739 (DT)
Call trace:
debug_dma_assert_idle+0x1a8/0x230
wp_page_copy.isra.96+0x118/0x520
do_wp_page+0x4fc/0x534
handle_mm_fault+0xd4c/0x1310
do_page_fault+0x1c8/0x394
do_mem_abort+0x50/0xec
I found that debug_dma_alloc_coherent() and debug_dma_free_coherent()
assume that dma_alloc_coherent() always returns a linear address.
However it's possible that dma_alloc_coherent() returns a non-linear
address. In this case, page_to_pfn(virt_to_page(virt)) will return an
incorrect pfn. If the pfn is valid and mapped as a COW page, we will
hit the warning when doing wp_page_copy().
Fix this by calculating pfn for linear and non-linear addresses.
[miles.chen@mediatek.com: v4]
Link: http://lkml.kernel.org/r/1510872972-23919-1-git-send-email-miles.chen@mediatek.com
Link: http://lkml.kernel.org/r/1506484087-1177-1-git-send-email-miles.chen@mediatek.com
Signed-off-by: Miles Chen <miles.chen@mediatek.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/dma-debug.c')
-rw-r--r-- | lib/dma-debug.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index ea4cc3dde4f1..1b34d210452c 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
@@ -1495,14 +1495,22 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size, | |||
1495 | if (!entry) | 1495 | if (!entry) |
1496 | return; | 1496 | return; |
1497 | 1497 | ||
1498 | /* handle vmalloc and linear addresses */ | ||
1499 | if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) | ||
1500 | return; | ||
1501 | |||
1498 | entry->type = dma_debug_coherent; | 1502 | entry->type = dma_debug_coherent; |
1499 | entry->dev = dev; | 1503 | entry->dev = dev; |
1500 | entry->pfn = page_to_pfn(virt_to_page(virt)); | ||
1501 | entry->offset = offset_in_page(virt); | 1504 | entry->offset = offset_in_page(virt); |
1502 | entry->size = size; | 1505 | entry->size = size; |
1503 | entry->dev_addr = dma_addr; | 1506 | entry->dev_addr = dma_addr; |
1504 | entry->direction = DMA_BIDIRECTIONAL; | 1507 | entry->direction = DMA_BIDIRECTIONAL; |
1505 | 1508 | ||
1509 | if (is_vmalloc_addr(virt)) | ||
1510 | entry->pfn = vmalloc_to_pfn(virt); | ||
1511 | else | ||
1512 | entry->pfn = page_to_pfn(virt_to_page(virt)); | ||
1513 | |||
1506 | add_dma_entry(entry); | 1514 | add_dma_entry(entry); |
1507 | } | 1515 | } |
1508 | EXPORT_SYMBOL(debug_dma_alloc_coherent); | 1516 | EXPORT_SYMBOL(debug_dma_alloc_coherent); |
@@ -1513,13 +1521,21 @@ void debug_dma_free_coherent(struct device *dev, size_t size, | |||
1513 | struct dma_debug_entry ref = { | 1521 | struct dma_debug_entry ref = { |
1514 | .type = dma_debug_coherent, | 1522 | .type = dma_debug_coherent, |
1515 | .dev = dev, | 1523 | .dev = dev, |
1516 | .pfn = page_to_pfn(virt_to_page(virt)), | ||
1517 | .offset = offset_in_page(virt), | 1524 | .offset = offset_in_page(virt), |
1518 | .dev_addr = addr, | 1525 | .dev_addr = addr, |
1519 | .size = size, | 1526 | .size = size, |
1520 | .direction = DMA_BIDIRECTIONAL, | 1527 | .direction = DMA_BIDIRECTIONAL, |
1521 | }; | 1528 | }; |
1522 | 1529 | ||
1530 | /* handle vmalloc and linear addresses */ | ||
1531 | if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) | ||
1532 | return; | ||
1533 | |||
1534 | if (is_vmalloc_addr(virt)) | ||
1535 | ref.pfn = vmalloc_to_pfn(virt); | ||
1536 | else | ||
1537 | ref.pfn = page_to_pfn(virt_to_page(virt)); | ||
1538 | |||
1523 | if (unlikely(dma_debug_disabled())) | 1539 | if (unlikely(dma_debug_disabled())) |
1524 | return; | 1540 | return; |
1525 | 1541 | ||