Re: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
From: Jason Gunthorpe
Date: Fri Mar 13 2026 - 14:43:38 EST
On Wed, Mar 11, 2026 at 09:35:55PM +0000, Jonathan Cameron wrote:
> > +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);
>
> I'd be tempted to do something with a helper function to simplify flow.
It is already
static inline struct iommufd_vdevice *
iommufd_get_vdevice(struct iommufd_ctx *ictx, u32 id)
{
return container_of(iommufd_get_object(ictx, id,
IOMMUFD_OBJ_VDEVICE),
struct iommufd_vdevice, obj);
}
> Then the helper function can do direct returns on errors given the
> iommfd_object is managed in outer function.
Use cleanup.h ? It is not the iommufd style the break things up into
little functions for error unwind reasons
> > + if (!vdev->viommu->kvm_filp) {
> > + rc = -ENODEV;
> > + goto out_put_vdev;
> > + }
> > +
> > + kvm = vdev->viommu->kvm_filp->private_data;
> > + if (!kvm) {
Ah this I don't think you should be doing. That needs a helper from
kvm
Jason