[PATCH v1 09/16] iommufd/viommmu: Add IOMMUFD_CMD_VCMDQ_ALLOC ioctl

Nicolin Chen nicolinc at nvidia.com
Mon Apr 21 08:42:50 PDT 2025


On Mon, Apr 21, 2025 at 08:05:40AM +0000, Tian, Kevin wrote:
> > From: Nicolin Chen <nicolinc at nvidia.com>
> > Sent: Friday, April 11, 2025 2:38 PM
> > 
> > +
> > +/**
> > + * enum iommu_vcmdq_type - Virtual Queue Type
> 
> "Virtual Command Queue Type"
> 
> > + * @IOMMU_VCMDQ_TYPE_DEFAULT: Reserved for future use
> > + */
> > +enum iommu_vcmdq_data_type {
> > +	IOMMU_VCMDQ_TYPE_DEFAULT = 0,
> > +};
> > +
> > +/**
> > + * struct iommu_vcmdq_alloc - ioctl(IOMMU_VCMDQ_ALLOC)
> > + * @size: sizeof(struct iommu_vcmdq_alloc)
> > + * @flags: Must be 0
> > + * @viommu_id: viommu ID to associate the virtual queue with
> > + * @type: One of enum iommu_vcmdq_type
> 
> s/ iommu_vcmdq_type/ iommu_vcmdq_data_type/
> 
> > +int iommufd_vcmdq_alloc_ioctl(struct iommufd_ucmd *ucmd)
> > +{
> > +	struct iommu_vcmdq_alloc *cmd = ucmd->cmd;
> > +	const struct iommu_user_data user_data = {
> > +		.type = cmd->type,
> > +		.uptr = u64_to_user_ptr(cmd->data_uptr),
> > +		.len = cmd->data_len,
> > +	};
> > +	struct iommufd_vcmdq *vcmdq;
> > +	struct iommufd_viommu *viommu;
> > +	int rc;
> > +
> > +	if (cmd->flags || cmd->type == IOMMU_VCMDQ_TYPE_DEFAULT)
> > +		return -EOPNOTSUPP;
> > +	if (!cmd->data_len)
> > +		return -EINVAL;
> > +
> > +	viommu = iommufd_get_viommu(ucmd, cmd->viommu_id);
> > +	if (IS_ERR(viommu))
> > +		return PTR_ERR(viommu);
> > +
> > +	if (!viommu->ops || !viommu->ops->vcmdq_alloc) {
> > +		rc = -EOPNOTSUPP;
> > +		goto out_put_viommu;
> > +	}
> > +
> > +	vcmdq = viommu->ops->vcmdq_alloc(viommu,
> > +					 user_data.len ? &user_data : NULL);
> 
> the length cannot be zero at this point due to earlier check.

Yes. Will fix them all.

Thanks!
Nicolin



More information about the linux-arm-kernel mailing list