Skip to content

Commit 133577c

Browse files
committed
Merge tag 'dma-mapping-6.13-2024-11-30' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping fix from Christoph Hellwig: - fix physical address calculation for struct dma_debug_entry (Fedor Pchelkin) * tag 'dma-mapping-6.13-2024-11-30' of git://git.infradead.org/users/hch/dma-mapping: dma-debug: fix physical address calculation for struct dma_debug_entry
2 parents c4bb3a2 + aef7ee7 commit 133577c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

kernel/dma/debug.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
12191219

12201220
entry->dev = dev;
12211221
entry->type = dma_debug_single;
1222-
entry->paddr = page_to_phys(page);
1222+
entry->paddr = page_to_phys(page) + offset;
12231223
entry->dev_addr = dma_addr;
12241224
entry->size = size;
12251225
entry->direction = direction;
@@ -1377,6 +1377,18 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
13771377
}
13781378
}
13791379

1380+
static phys_addr_t virt_to_paddr(void *virt)
1381+
{
1382+
struct page *page;
1383+
1384+
if (is_vmalloc_addr(virt))
1385+
page = vmalloc_to_page(virt);
1386+
else
1387+
page = virt_to_page(virt);
1388+
1389+
return page_to_phys(page) + offset_in_page(virt);
1390+
}
1391+
13801392
void debug_dma_alloc_coherent(struct device *dev, size_t size,
13811393
dma_addr_t dma_addr, void *virt,
13821394
unsigned long attrs)
@@ -1399,8 +1411,7 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
13991411

14001412
entry->type = dma_debug_coherent;
14011413
entry->dev = dev;
1402-
entry->paddr = page_to_phys((is_vmalloc_addr(virt) ?
1403-
vmalloc_to_page(virt) : virt_to_page(virt)));
1414+
entry->paddr = virt_to_paddr(virt);
14041415
entry->size = size;
14051416
entry->dev_addr = dma_addr;
14061417
entry->direction = DMA_BIDIRECTIONAL;
@@ -1423,8 +1434,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
14231434
if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
14241435
return;
14251436

1426-
ref.paddr = page_to_phys((is_vmalloc_addr(virt) ?
1427-
vmalloc_to_page(virt) : virt_to_page(virt)));
1437+
ref.paddr = virt_to_paddr(virt);
14281438

14291439
if (unlikely(dma_debug_disabled()))
14301440
return;

0 commit comments

Comments
 (0)