> -----Original Message-----
> From: Eric Auger <[email protected]>
> Sent: 13 February 2026 10:19
> To: Shameer Kolothum Thodi <[email protected]>; qemu-
> [email protected]; [email protected]
> Cc: [email protected]; [email protected]; [email protected]; Nicolin
> Chen <[email protected]>; Nathan Chen <[email protected]>; Matt
> Ochs <[email protected]>; Jiandi An <[email protected]>; Jason Gunthorpe
> <[email protected]>; [email protected];
> [email protected]; [email protected]; Krishnakant Jaju
> <[email protected]>
> Subject: Re: [PATCH v2 04/24] backends/iommufd: Introduce
> iommufd_backend_viommu_mmap
> 
> External email: Use caution opening links or attachments
> 
> 
> On 2/6/26 3:48 PM, Shameer Kolothum wrote:
> > From: Nicolin Chen <[email protected]>
> >
> > Add a backend helper to mmap hardware MMIO regions exposed via
> iommufd for
> > a vIOMMU instance. This allows user space to access HW-accelerated MMIO
> > pages provided by the vIOMMU.
> >
> > The caller is responsible for unmapping the returned region.
> >
> > Signed-off-by: Nicolin Chen <[email protected]>
> > Reviewed-by: Eric Auger <[email protected]>
> > Signed-off-by: Shameer Kolothum <[email protected]>
> > ---
> >  backends/iommufd.c       | 22 ++++++++++++++++++++++
> >  backends/trace-events    |  1 +
> >  include/system/iommufd.h |  4 ++++
> >  3 files changed, 27 insertions(+)
> >
> > diff --git a/backends/iommufd.c b/backends/iommufd.c
> > index c6b79da0d4..9e30501d38 100644
> > --- a/backends/iommufd.c
> > +++ b/backends/iommufd.c
> > @@ -578,6 +578,28 @@ bool
> iommufd_backend_alloc_hw_queue(IOMMUFDBackend *be, uint32_t
> viommu_id,
> >      return true;
> >  }
> >
> > +/*
> > + * Helper to mmap HW MMIO regions exposed via iommufd for a vIOMMU
> instance.
> > + * The caller is responsible for unmapping the mapped region.
> > + */
> > +bool iommufd_backend_viommu_mmap(IOMMUFDBackend *be, uint32_t
> viommu_id,
> > +                                 uint64_t size, off_t offset, void 
> > **out_ptr,
> > +                                 Error **errp)
> Looking at this again, there is nothing really related to iommufd. This
> could simply end up as a static helper in tegra241-cmdqv.c

I had that thought as well. However, this operates on the
IOMMUFDBackend fd and is not tegra specific. It performs
an mmap on the backend fd associated with a vIOMMU instance,
which could potentially be reused by others.

Keeping it in backends/iommufd.c also centralizes fd related
operations (including tracing) for the IOMMUFD backend.

Thanks,
Shameer

> > +{
> > +    g_assert(viommu_id);
> > +    g_assert(out_ptr);
> > +
> > +    *out_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
> be->fd,
> > +                   offset);
> > +    trace_iommufd_backend_viommu_mmap(be->fd, viommu_id, size,
> offset);
> > +    if (*out_ptr == MAP_FAILED) {
> > +        error_setg_errno(errp, errno, "IOMMUFD vIOMMU mmap failed");
> > +        return false;
> > +    }
> > +
> > +    return true;
> > +}
> > +
> >  bool
> host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD
> *idev,
> >                                             uint32_t hwpt_id, Error **errp)
> >  {
> > diff --git a/backends/trace-events b/backends/trace-events
> > index 3e70338750..f824a8d197 100644
> > --- a/backends/trace-events
> > +++ b/backends/trace-events
> > @@ -25,6 +25,7 @@ iommufd_backend_alloc_viommu(int iommufd,
> uint32_t dev_id, uint32_t type, uint32
> >  iommufd_backend_alloc_vdev(int iommufd, uint32_t dev_id, uint32_t
> viommu_id, uint64_t virt_id, uint32_t vdev_id, int ret) " iommufd=%d
> dev_id=%u viommu_id=%u virt_id=0x%"PRIx64" vdev_id=%u (%d)"
> >  iommufd_viommu_alloc_eventq(int iommufd, uint32_t viommu_id,
> uint32_t type, uint32_t veventq_id, uint32_t veventq_fd, int ret) "
> iommufd=%d viommu_id=%u type=%u veventq_id=%u veventq_fd=%u (%d)"
> >  iommufd_backend_alloc_hw_queue(int iommufd, uint32_t viommu_id,
> uint32_t queue_type, uint32_t index, uint64_t addr, uint64_t size, uint32_t
> queue_id, int ret) " iommufd=%d viommu_id=%u queue_type=%u index=%u
> addr=0x%"PRIx64" size=0x%"PRIx64" queue_id=%u (%d)"
> > +iommufd_backend_viommu_mmap(int iommufd, uint32_t viommu_id,
> uint64_t size, uint64_t offset) " iommufd=%d viommu_id=%u
> size=0x%"PRIx64" offset=0x%"PRIx64
> >
> >  # igvm-cfg.c
> >  igvm_reset_enter(int type) "type=%u"
> > diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> > index f72ad545f8..87ddc39041 100644
> > --- a/include/system/iommufd.h
> > +++ b/include/system/iommufd.h
> > @@ -111,6 +111,10 @@ bool
> iommufd_backend_alloc_hw_queue(IOMMUFDBackend *be, uint32_t
> viommu_id,
> >                                      uint64_t length, uint32_t 
> > *out_hw_queue_id,
> >                                      Error **errp);
> >
> > +bool iommufd_backend_viommu_mmap(IOMMUFDBackend *be, uint32_t
> viommu_id,
> > +                                 uint64_t size, off_t offset, void 
> > **out_ptr,
> > +                                 Error **errp);
> > +
> >  bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be,
> uint32_t hwpt_id,
> >                                          bool start, Error **errp);
> >  bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,
> uint32_t hwpt_id,

Reply via email to