> From: Alex Williamson <alex.williamson@xxxxxxxxxx> > Sent: Friday, August 27, 2021 6:47 AM > > On Thu, 26 Aug 2021 15:34:15 +0200 > Christoph Hellwig <hch@xxxxxx> wrote: > > +#ifdef CONFIG_VFIO_NOIOMMU > > +static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev) > > { > > struct iommu_group *iommu_group; > > struct vfio_group *group; > > + int ret; > > + > > + iommu_group = iommu_group_alloc(); > > + if (IS_ERR(iommu_group)) > > + return ERR_CAST(iommu_group); > > > > - iommu_group = vfio_iommu_group_get(dev); > > + iommu_group_set_name(iommu_group, "vfio-noiommu"); > > + iommu_group_set_iommudata(iommu_group, &noiommu, NULL); > > + ret = iommu_group_add_device(iommu_group, dev); > > + if (ret) > > + goto out_put_group; > > + > > + group = vfio_create_group(iommu_group); > > + if (IS_ERR(group)) { > > + ret = PTR_ERR(group); > > + goto out_remove_device; > > + } > > + > > + return group; > > + > > +out_remove_device: > > + iommu_group_remove_device(dev); > > +out_put_group: > > + iommu_group_put(iommu_group); > > + return ERR_PTR(ret); > > +} > > +#endif > > + > > +static struct vfio_group *vfio_group_find_or_alloc(struct device *dev) > > +{ > > + struct iommu_group *iommu_group; > > + struct vfio_group *group; > > + > > + iommu_group = iommu_group_get(dev); > > +#ifdef CONFIG_VFIO_NOIOMMU > > + if (!iommu_group && noiommu && !iommu_present(dev->bus)) { > > + /* > > + * With noiommu enabled, create an IOMMU group for > devices that > > + * don't already have one and don't have an iommu_ops on > their > > + * bus. Taint the kernel because we're about to give a DMA > > + * capable device to a user without IOMMU protection. > > + */ > > + group = vfio_noiommu_group_alloc(dev); > > + if (group) { > > + add_taint(TAINT_USER, LOCKDEP_STILL_OK); > > + dev_warn(dev, "Adding kernel taint for vfio- > noiommu group on device\n"); > > + } > > Perhaps what Kevin was pointing out here in the previous version, > vfio_noiommu_group_alloc() returns a pointer, so this should test > !IS_ERR(group). Thanks, > yes, that is what I meant.