Re: [PATCH v4 3/3] hw/vfio/region: Create dmabuf for PCI BAR per region
Jason Gunthorpe <[email protected]> Wed, 5 Aug 2026 09:18:52 -0300
| Newsgroups | org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 05, 2026 at 08:33:06AM +0000, Shameer Kolothum Thodi wrote:
> > > + dma_buf = (void *)feature->data;
> > > + *dma_buf = (struct vfio_device_feature_dma_buf) {
> > > + .region_index = region->nr,
> > > + .open_flags = O_RDWR,
> > > + .nr_ranges = region->nr_mmaps,
> > > + };
> > > +
> > > + for (i = 0; i < region->nr_mmaps; i++) {
> > > + dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
> > > + dma_buf->dma_ranges[i].length = region->mmaps[i].size;
> > > + }
> > > +
> >
> > Shall we check if @offset and @size is aligned to PAGE_SIZE? If they're not,
> > I guess we need to skip populating DMA buffer instead of preventing the
> > device from being passed through to the guest.
>
> Hmm..does it prevent passthrough in this case? The intention was not to do that.
> vfio_region_mmap() returns 0 irrespective of dma-buf outcome.
I think you should always be able to create a dmabuf, even with
irregular offsets and sizes.
The resulting dmabuf may not be mmap'able though.
Jason