Skip to content

Commit d5b5e81

Browse files
shalsethmszyprow
authored andcommitted
sparc: Fix page alignment in dma mapping
'phys' may include an offset within the page, while previously used 'base_paddr' was already page-aligned. This caused incorrect DMA mapping in dma_4u_map_phys and dma_4v_map_phys. Fix both functions by masking 'phys' with IO_PAGE_MASK, covering both generic SPARC code and sun4v. Fixes: 38c0d0e ("sparc: Use physical address DMA mapping") Reported-by: Stian Halseth <stian@itx.no> Closes: sparclinux/issues#75 Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Stian Halseth <stian@itx.no> Tested-by: Nathaniel Roach <nroach44@nroach44.id.au> Tested-by: Han Gao <gaohan@iscas.ac.cn> # on SPARC Enterprise T5220 [mszyprow: adjusted commit description a bit] Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20260218120056.3366-2-stian@itx.no
1 parent 47322c4 commit d5b5e81

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

arch/sparc/kernel/iommu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ static dma_addr_t dma_4u_map_phys(struct device *dev, phys_addr_t phys,
312312
if (direction != DMA_TO_DEVICE)
313313
iopte_protection |= IOPTE_WRITE;
314314

315+
phys &= IO_PAGE_MASK;
316+
315317
for (i = 0; i < npages; i++, base++, phys += IO_PAGE_SIZE)
316318
iopte_val(*base) = iopte_protection | phys;
317319

arch/sparc/kernel/pci_sun4v.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ static dma_addr_t dma_4v_map_phys(struct device *dev, phys_addr_t phys,
410410

411411
iommu_batch_start(dev, prot, entry);
412412

413+
phys &= IO_PAGE_MASK;
414+
413415
for (i = 0; i < npages; i++, phys += IO_PAGE_SIZE) {
414416
long err = iommu_batch_add(phys, mask);
415417
if (unlikely(err < 0L))

0 commit comments

Comments
 (0)