On 2/6/26 3:48 PM, Shameer Kolothum wrote:
> From: Nicolin Chen <[email protected]>
>
> The updated IOMMUFD VIOMMU_ALLOC uAPI allows userspace to provide a data
> buffer when creating a vIOMMU (e.g. for Tegra241 CMDQV). Extend
> iommufd_backend_alloc_viommu() to pass a user pointer and size to the
> kernel.
>
> Update the caller accordingly.
>
> Signed-off-by: Nicolin Chen <[email protected]>
> Reviewed-by: Eric Auger <[email protected]>
> Signed-off-by: Shameer Kolothum <[email protected]>
> ---
> backends/iommufd.c | 4 ++++
> backends/trace-events | 2 +-
> hw/arm/smmuv3-accel.c | 4 ++--
> include/system/iommufd.h | 1 +
> 4 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index 5daefe505e..8ab26eb786 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -460,6 +460,7 @@ bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be,
> uint32_t id,
>
> bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be, uint32_t dev_id,
> uint32_t viommu_type, uint32_t hwpt_id,
> + void *data_ptr, uint32_t data_len,
> uint32_t *out_viommu_id, Error **errp)
> {
> int ret;
> @@ -468,11 +469,14 @@ bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be,
> uint32_t dev_id,
> .type = viommu_type,
> .dev_id = dev_id,
> .hwpt_id = hwpt_id,
> + .data_len = data_len,
> + .data_uptr = (uintptr_t)data_ptr,
> };
>
> ret = ioctl(be->fd, IOMMU_VIOMMU_ALLOC, &alloc_viommu);
>
> trace_iommufd_backend_alloc_viommu(be->fd, dev_id, viommu_type, hwpt_id,
> + data_len, (uintptr_t)data_ptr,
> alloc_viommu.out_viommu_id, ret);
> if (ret) {
> error_setg_errno(errp, errno, "IOMMU_VIOMMU_ALLOC failed");
> diff --git a/backends/trace-events b/backends/trace-events
> index b9365113e7..332888a576 100644
> --- a/backends/trace-events
> +++ b/backends/trace-events
> @@ -21,7 +21,7 @@ iommufd_backend_free_id(int iommufd, uint32_t id, int ret)
> " iommufd=%d id=%d (%
> iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int
> ret) " iommufd=%d hwpt=%u enable=%d (%d)"
> iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t
> iova, uint64_t size, uint64_t flags, uint64_t page_size, int ret) "
> iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" flags=0x%"PRIx64"
> page_size=0x%"PRIx64" (%d)"
> iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t
> data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num,
> uint64_t data_ptr, int ret) " iommufd=%d id=%u data_type=%u entry_len=%u
> entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)"
> -iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type,
> uint32_t hwpt_id, uint32_t viommu_id, int ret) " iommufd=%d type=%u dev_id=%u
> hwpt_id=%u viommu_id=%u (%d)"
> +iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type,
> uint32_t hwpt_id, uint32_t data_len, uint64_t data_ptr, uint32_t viommu_id,
> int ret) " iommufd=%d type=%u dev_id=%u hwpt_id=%u data_len=%u
> data_ptr=0x%"PRIx64" viommu_id=%u (%d)"
nit: I would put the data_ptr first and then the data length to match
most prevalent pattern. Also use hexa format for the length?
Besides
Reviewed-by: Eric Auger <[email protected]>
Eric
> 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)"
>
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index 14ea4eac37..9036b14601 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -531,8 +531,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s,
> HostIOMMUDeviceIOMMUFD *idev,
> IOMMUFDViommu *viommu;
>
> if (!iommufd_backend_alloc_viommu(idev->iommufd, idev->devid,
> - IOMMU_VIOMMU_TYPE_ARM_SMMUV3,
> - s2_hwpt_id, &viommu_id, errp)) {
> + IOMMU_VIOMMU_TYPE_ARM_SMMUV3,
> s2_hwpt_id,
> + NULL, 0, &viommu_id, errp)) {
> return false;
> }
>
> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> index e4ca16da70..5ef23ad9e1 100644
> --- a/include/system/iommufd.h
> +++ b/include/system/iommufd.h
> @@ -87,6 +87,7 @@ bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be,
> uint32_t dev_id,
> Error **errp);
> bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be, uint32_t dev_id,
> uint32_t viommu_type, uint32_t hwpt_id,
> + void *data_ptr, uint32_t data_len,
> uint32_t *out_hwpt, Error **errp);
>
> bool iommufd_backend_alloc_vdev(IOMMUFDBackend *be, uint32_t dev_id,