On Mon, Oct 28, 2024 at 03:11:32AM +0000, Tian, Kevin wrote:
From: Nicolin Chen nicolinc@nvidia.com Sent: Saturday, October 26, 2024 7:51 AM
+/**
- struct iommu_vdevice_alloc - ioctl(IOMMU_VDEVICE_ALLOC)
- @size: sizeof(struct iommu_vdevice_alloc)
- @viommu_id: vIOMMU ID to associate with the virtual device
- @dev_id: The pyhsical device to allocate a virtual instance on the
vIOMMU
s/pyhsical/physical/, or just say 'iommufd device"
Ack for "physical", aligning with other @dev_id lines.
+int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd) +{
struct iommu_vdevice_alloc *cmd = ucmd->cmd;struct iommufd_vdevice *vdev, *curr;struct iommufd_viommu *viommu;struct iommufd_device *idev;u64 virt_id = cmd->virt_id;int rc = 0;if (virt_id > ULONG_MAX)return -EINVAL;viommu = iommufd_get_viommu(ucmd, cmd->viommu_id);if (IS_ERR(viommu))return PTR_ERR(viommu);idev = iommufd_get_device(ucmd, cmd->dev_id);if (IS_ERR(idev)) {rc = PTR_ERR(idev);goto out_put_viommu;}mutex_lock(&idev->igroup->lock);if (idev->vdev) {rc = -EEXIST;goto out_unlock_igroup;}vdev = iommufd_object_alloc(ucmd->ictx, vdev,IOMMUFD_OBJ_VDEVICE);
if (IS_ERR(vdev)) {rc = PTR_ERR(vdev);goto out_unlock_igroup;}also need to check that the device and the viommu are associated to a same physical iommu.
Ack. Will add this prior to mutex_lock(&idev->igroup->lock);
+ if (viommu->iommu_dev != __iommu_get_iommu_dev(idev->dev)) { + rc = -EINVAL; + goto out_put_idev; + }
Thanks! Nicolin