Re: [PATCH 1/3] dma-buf: align large mappings to PMD boundaries

From: Christian König

Date: Mon Nov 23 2026 - 04:10:26 EST


On 11/22/26 08:37, Qiliang Yuan wrote:
> A dma-buf exporter whose buffer is backed by physically contiguous memory
> can map it with PMDs from a ->huge_fault() handler, which only works where
> the user address and the buffer offset are aligned alike to PMD_SIZE.
>
> dma_buf_fops has no ->get_unmapped_area(), so mmap() places a dma-buf at
> whatever page aligned address the default allocator returns. A 4 GiB
> udmabuf, for one, lands 616 KiB past a 2 MiB boundary, and then none of
> its PMD-sized ranges can be mapped with a PMD.
>
> Use thp_get_unmapped_area(), as filesystems that support huge mappings
> do. It aligns a mapping that covers at least one whole PMD to the buffer
> offset and leaves smaller mappings where they would be placed anyway.
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>

Reviewed-by: Christian König <christian.koenig@xxxxxxx>

> ---
> drivers/dma-buf/dma-buf.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 5c6957f8839a8..015a03c8d04db 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -608,6 +608,7 @@ static void dma_buf_show_fdinfo(struct seq_file *m, struct file *file)
> static const struct file_operations dma_buf_fops = {
> .release = dma_buf_file_release,
> .mmap = dma_buf_mmap_internal,
> + .get_unmapped_area = thp_get_unmapped_area,
> .llseek = dma_buf_llseek,
> .poll = dma_buf_poll,
> .unlocked_ioctl = dma_buf_ioctl,
>
> --
> 2.43.0
>