Skip to content

dmabuf: implement dma_buf_mmap_fileops#484

Open
yizishun wants to merge 1 commit into
freebsd:masterfrom
yizishun:dmabuf/mmap-implement
Open

dmabuf: implement dma_buf_mmap_fileops#484
yizishun wants to merge 1 commit into
freebsd:masterfrom
yizishun:dmabuf/mmap-implement

Conversation

@yizishun

@yizishun yizishun commented Jul 8, 2026

Copy link
Copy Markdown

As an fo_mmap handler, dma_buf_mmap_fileops() must produce a vm_object and insert a mapping into the target map. The previous version only filled a few fields of an uninitialized on-stack vm_area_struct and called the exporter's ->mmap callback, without ever creating an object, so mmap(2) on a dma-buf fd could not work.

The implementation is similar to linux_file_mmap(), except that it reuses vma->vm_obj to give the exporter a channel to create its own vm_object. This is primarily meant for the udmabuf driver of my GSoC 2026 project. When the exporter does not create its own object, we fall back to letting dmabuf build an OBJT_DEVICE/MGTDEVICE/SGT object for it; those paths are not implemented yet.

They are left unimplemented for two reasons. First, for now only udmabuf needs to mmap() a dma-buf fd. Second, the linux_file_mmap() model is questionable: vmf_insert_pfn() should carry OBJT_DEVICE/SGT semantics, but it is instead paired with OBJT_MGTDEVICE and grabs the page inside vmf_insert_pfn(). When the exporter has no page but only a pfn(paddr), or does not want others managing its pages, that does not fit the insert-pfn semantics -- it is really vmf_insert_page() semantics. For this reason udmabuf chooses to create its own vm_object.

As an fo_mmap handler, dma_buf_mmap_fileops() must produce a vm_object and
insert a mapping into the target map.  The previous version only filled a few
fields of an uninitialized on-stack vm_area_struct and called the exporter's
->mmap callback, without ever creating an object, so mmap(2) on a dma-buf fd
could not work.

The implementation is similar to linux_file_mmap(), except that it reuses
vma->vm_obj to give the exporter a channel to create its own vm_object. This is
primarily meant for the udmabuf driver of my GSoC 2026 project. When the
exporter does not create its own object, we fall back to letting dmabuf build
an OBJT_DEVICE/MGTDEVICE/SGT object for it; those paths are not implemented
yet.

They are left unimplemented for two reasons. First, for now only udmabuf needs
to mmap() a dma-buf fd. Second, the linux_file_mmap() model is questionable:
vmf_insert_pfn() should carry OBJT_DEVICE/SGT semantics, but it is instead
paired with OBJT_MGTDEVICE and grabs the page inside vmf_insert_pfn(). When the
exporter has no page but only a pfn(paddr), or does not want others managing
its pages, that does not fit the insert-pfn semantics -- it is really
vmf_insert_page() semantics. For this reason udmabuf chooses to create its own
vm_object.
@yizishun yizishun mentioned this pull request Jul 8, 2026
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant