From: "Cédric Le Goater" <clg@redhat.com>
To: Gavin Shan <gshan@redhat.com>,
Shameer Kolothum <skolothumtho@nvidia.com>,
qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: eric.auger@redhat.com, alex@shazbot.org, cohuck@redhat.com,
mst@redhat.com, nicolinc@nvidia.com, nathanc@nvidia.com,
mochs@nvidia.com, jgg@nvidia.com, jonathan.cameron@huawei.com,
zhenzhong.duan@intel.com, vivek.kasireddy@intel.com,
kjaju@nvidia.com, meshetty@redhat.com
Subject: Re: [PATCH v4 3/3] hw/vfio/region: Create dmabuf for PCI BAR per region
Date: Wed, 5 Aug 2026 10:49:48 +0200 [thread overview]
Message-ID: <5a71ad53-5c4e-4a06-8d31-59b1329d20bc@redhat.com> (raw)
In-Reply-To: <aa45597c-aed8-49a0-b9bd-3c637c154ee5@redhat.com>
On 8/5/26 03:09, Gavin Shan wrote:
> Hi Nicolin and Shameer,
>
> On 1/21/26 9:41 PM, Shameer Kolothum wrote:
>> From: Nicolin Chen <nicolinc@nvidia.com>
>>
>> Linux now provides a VFIO dmabuf exporter to expose PCI BAR memory for P2P
>> use cases. Create a dmabuf for each mapped BAR region after the mmap is set
>> up, and store the returned fd in the region’s RAMBlock. This allows QEMU to
>> pass the fd to dma_map_file(), enabling iommufd to import the dmabuf and map
>> the BAR correctly in the host IOMMU page table.
>>
>> If the kernel lacks support or dmabuf setup fails, QEMU skips the setup
>> and continues with normal mmap handling.
>>
>> Tested-by: Nicolin Chen <nicolinc@nvidia.com>
>> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> Reviewed-by: Cédric Le Goater <clg@redhat.com>
>> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
>> ---
>> hw/vfio/region.c | 65 +++++++++++++++++++++++++++++++++++++++++++-
>> hw/vfio/trace-events | 1 +
>> 2 files changed, 65 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/vfio/region.c b/hw/vfio/region.c
>> index ca75ab1be4..ab39d77574 100644
>> --- a/hw/vfio/region.c
>> +++ b/hw/vfio/region.c
>> @@ -29,6 +29,7 @@
>> #include "qemu/error-report.h"
>> #include "qemu/units.h"
>> #include "monitor/monitor.h"
>> +#include "system/ramblock.h"
>> #include "vfio-helpers.h"
>> /*
>> @@ -238,13 +239,71 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
>> region->mmaps[index].mmap = NULL;
>> }
>> +static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp)
>> +{
>> + g_autofree struct vfio_device_feature *feature = NULL;
>> + VFIODevice *vbasedev = region->vbasedev;
>> + struct vfio_device_feature_dma_buf *dma_buf;
>> + size_t total_size;
>> + int i, ret;
>> +
>> + total_size = sizeof(*feature) + sizeof(*dma_buf) +
>> + sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
>> + feature = g_malloc0(total_size);
>> + *feature = (struct vfio_device_feature) {
>> + .argsz = total_size,
>> + .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
>> + };
>> +
>> + 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.
>
> Meghana <meshetty@redhat.com> runs into issue when passing through an NVMe
> card. The only memory BAR on the NVMe card is 16K, which is not aligned to
> 64KB (host page size).
>
> -device vfio-pci,id=nvme,host=0004:01:00.0,addr=0x2.0x1,bus=pcie.0
>
> host$ sh vfio.sh
> QEMU 10.1.0 monitor - type 'help' for more information
> (qemu) qemu-kvm: -device vfio-pci,id=nvme,host=0004:01:00.0,addr=0x2.0x1,bus=pcie.0: \
> 0004:01:00.0 BAR 0: failed to create dma-buf: PCI BAR IOMMU mappings may fail: Invalid argument
To avoid confusion, the reported error message was slightly
improved in :
https://lore.kernel.org/qemu-devel/20260721170518.4160785-3-clg@redhat.com/
Thanks,
C.
next prev parent reply other threads:[~2026-08-05 8:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 11:41 [PATCH v4 0/3] vfio: Add DMABUF support for PCI BAR regions Shameer Kolothum
2026-01-21 11:41 ` [PATCH v4 1/3] linux-headers: Update to Linux v6.19-rc1 Shameer Kolothum
2026-01-21 14:00 ` Cédric Le Goater
2026-01-21 14:21 ` Peter Maydell
2026-01-21 17:12 ` Jason Gunthorpe
2026-01-23 14:26 ` Cédric Le Goater
2026-01-21 11:41 ` [PATCH v4 2/3] hw/vfio: Add helper to retrieve device feature Shameer Kolothum
2026-01-21 11:41 ` [PATCH v4 3/3] hw/vfio/region: Create dmabuf for PCI BAR per region Shameer Kolothum
2026-08-05 1:09 ` Gavin Shan
2026-08-05 8:33 ` Shameer Kolothum Thodi
2026-08-05 9:43 ` Gavin Shan
2026-08-05 12:18 ` Jason Gunthorpe
2026-08-05 8:49 ` Cédric Le Goater [this message]
2026-08-05 9:45 ` Gavin Shan
2026-01-21 12:36 ` [PATCH v4 0/3] vfio: Add DMABUF support for PCI BAR regions Michael S. Tsirkin
2026-01-21 12:49 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a71ad53-5c4e-4a06-8d31-59b1329d20bc@redhat.com \
--to=clg@redhat.com \
--cc=alex@shazbot.org \
--cc=cohuck@redhat.com \
--cc=eric.auger@redhat.com \
--cc=gshan@redhat.com \
--cc=jgg@nvidia.com \
--cc=jonathan.cameron@huawei.com \
--cc=kjaju@nvidia.com \
--cc=meshetty@redhat.com \
--cc=mochs@nvidia.com \
--cc=mst@redhat.com \
--cc=nathanc@nvidia.com \
--cc=nicolinc@nvidia.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=skolothumtho@nvidia.com \
--cc=vivek.kasireddy@intel.com \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.