Re: [PATCH v6 16/24] iommu/amd: Add IOMMUFD vDevice and DevID mapping
From: Jason Gunthorpe
Date: Thu Oct 15 2026 - 19:41:08 EST
> [ ... 128 lines skipped ... ]
> +/*
> + * Called from drivers/iommu/iommufd/viommu.c: iommufd_vdevice_alloc_ioctl()
> + */
> +static int _amd_viommu_vdevice_init(struct iommufd_vdevice *vdev)
> +{
> + struct device *dev = iommufd_vdevice_to_device(vdev);
> + struct pci_dev *pdev;
> + struct iommufd_viommu *viommu = vdev->viommu;
> + struct amd_iommu_viommu *aviommu = container_of(viommu, struct amd_iommu_viommu, core);
> +
> + if (!dev_is_pci(dev))
> + return -EINVAL;
> + pdev = to_pci_dev(dev);
> +
> + if (vdev->virt_id > VIOMMU_MAX_GDEVID) {
> + pr_err("%s: Invalid virtual ID (virt_id=%#llx)\n", __func__, vdev->virt_id);
> + return -EINVAL;
Do not print on user triggerable flows
> + }
> +
> + pr_debug("%s: gid=%#x, hdev_id=%#x, gdev_id=%#llx\n", __func__,
> + aviommu->gid, pci_dev_id(pdev), vdev->virt_id);
> +
> + amd_viommu_set_device_mapping(aviommu, pci_dev_id(pdev),
> + (u16)vdev->virt_id);
I spotted several pointless casts like this
Anyhow this looks like the right use of a vdevice to me and broadly
matches what arm vcmdq is doing
Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
--
Jason