Re: [PATCH] dma-remap: fix dma_common_find_pages() page lookup for offsets
From: Marek Szyprowski
Date: Mon Dec 15 2025 - 03:13:47 EST
On 15.12.2025 06:57, Christoph Hellwig wrote:
> On Fri, Dec 12, 2025 at 10:09:14PM +0200, Andrei-Edward Popa wrote:
>> dma_common_find_pages() previously assumed that the CPU virtual address
>> always pointed to the start of a DMA-coherent allocation. This fails when
>> memory is allocated via dma_alloc_attrs() without DMA_ATTR_FORCE_CONTIGUOUS
>> and then subdivided into smaller blocks using a gen_pool, relevant only
>> when an IOMMU is enabled.
>>
>> In such cases, userspace may request a mapping via dma_mmap_attrs()
>> for a CPU address that is offset inside the original allocation. The
>> previous code could return the wrong struct page pointer.
> No, you can't mmap part of a dma coherent allocation. What caller is
> trying to do this? It needs to be fixed instead.
I wonder if this was ever explicitly stated.
dma_mmap_coherent() was initially added for mmapeing a
dma_alloc_coherent()-allocated buffer for fbdev and alsa, and at least
the first one allowed to mmap the buffer partially or starting at
non-zero offset. I doubt that this feature was useful for anything, but
I'm quite sure this was at least allowed and there were some comments in
the code about that.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland