On Mon, 14 Jul 2025 16:59:27 +0100 Shameer Kolothum <shameerali.kolothum.th...@huawei.com> wrote:
> From: Nicolin Chen <nicol...@nvidia.com> > > Add a helper to allocate a viommu object. > > Signed-off-by: Nicolin Chen <nicol...@nvidia.com> > Reviewed-by: Eric Auger <eric.au...@redhat.com> > Signed-off-by: Shameer Kolothum <shameerali.kolothum.th...@huawei.com> One trivial comment inline. Feel free to ignore. > --- > backends/iommufd.c | 25 +++++++++++++++++++++++++ > backends/trace-events | 1 + > include/system/iommufd.h | 4 ++++ > 3 files changed, 30 insertions(+) > > diff --git a/backends/iommufd.c b/backends/iommufd.c > index 2a33c7ab0b..f3b95ee321 100644 > --- a/backends/iommufd.c > +++ b/backends/iommufd.c > @@ -446,6 +446,31 @@ bool iommufd_backend_invalidate_cache(IOMMUFDBackend > *be, uint32_t id, > return !ret; > } > > +bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be, uint32_t dev_id, > + uint32_t viommu_type, uint32_t hwpt_id, > + uint32_t *out_viommu_id, Error **errp) > +{ > + int ret, fd = be->fd; Not sure the fd local variable is worth bothering with given be->fd is very short and you only have a couple of users. > + struct iommu_viommu_alloc alloc_viommu = { > + .size = sizeof(alloc_viommu), > + .type = viommu_type, > + .dev_id = dev_id, > + .hwpt_id = hwpt_id, > + }; > + > + ret = ioctl(fd, IOMMU_VIOMMU_ALLOC, &alloc_viommu); > + > + trace_iommufd_backend_alloc_viommu(fd, viommu_type, dev_id, hwpt_id, > + alloc_viommu.out_viommu_id, ret); > + if (ret) { > + error_setg_errno(errp, errno, "IOMMU_VIOMMU_ALLOC failed"); > + return false; > + } > + > + *out_viommu_id = alloc_viommu.out_viommu_id; > + return true; > +}