RE: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl

From: Aneesh Kumar K . V

Date: Mon Mar 16 2026 - 04:47:38 EST


"Tian, Kevin" <kevin.tian@xxxxxxxxx> writes:

>> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
>> Sent: Monday, March 9, 2026 7:17 PM
>>
>> Introduce IOMMU_VDEVICE_TSM_OP to allow userspace to issue TSM
>> bind/unbind
>> operations for an iommufd vdevice.
>
> How many ops are planned? If just a few I'd prefer to openly defining
> it:
>
> IOMMU_VDEVICE_ALLOC,
> IOMMU_VDEVICE_TSM_BIND,
> IOMMU_VDEVICE_TSM_UNBIND,
>
> just like how we did for IOAS.
>

Right now only TSM_BIND and TSM_UNBIND. This was done based on earlier
review feedback.

https://lore.kernel.org/all/20250530181842.GU233377@xxxxxxxxxx/

>
>> @@ -432,6 +432,7 @@ union ucmd_buffer {
>> struct iommu_veventq_alloc veventq;
>> struct iommu_vfio_ioas vfio_ioas;
>> struct iommu_viommu_alloc viommu;
>> + struct iommu_vdevice_tsm_op tsm_op;
>
> please follow the alphabetical order
>
>> @@ -493,6 +494,8 @@ static const struct iommufd_ioctl_op
>> iommufd_ioctl_ops[] = {
>> __reserved),
>> IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl,
>> struct iommu_viommu_alloc, out_viommu_id),
>> + IOCTL_OP(IOMMU_VDEVICE_TSM_OP,
>> iommufd_vdevice_tsm_op_ioctl,
>> + struct iommu_vdevice_tsm_op, vdevice_id),
>
> ditto
>
>> +int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
>> +{
>> + int rc;
>> + struct kvm *kvm;
>> + struct iommufd_vdevice *vdev;
>> + struct iommu_vdevice_tsm_op *cmd = ucmd->cmd;
>> +
>> + if (cmd->flags)
>> + return -EOPNOTSUPP;
>> +
>> + vdev = container_of(iommufd_get_object(ucmd->ictx, cmd-
>> >vdevice_id,
>> + IOMMUFD_OBJ_VDEVICE),
>> + struct iommufd_vdevice, obj);
>> + if (IS_ERR(vdev))
>> + return PTR_ERR(vdev);
>> +
>> + if (!vdev->viommu->kvm_filp) {
>> + rc = -ENODEV;
>> + goto out_put_vdev;
>> + }
>> +
>> + kvm = vdev->viommu->kvm_filp->private_data;
>> + if (!kvm) {
>> + rc = -ENODEV;
>> + goto out_put_vdev;
>> + }
>
> if (!vdev->viommu->kvm_filp ||
> !vdev->viommu->kvm_filp->private_data) {
> rc = -ENODEV;
> goto out_put_vdev;
> }
>
> kvm = vdev->viommu->kvm_filp->private_data;

-aneesh