On Sun, May 21, 2023 at 07:31:38PM +0800, Baolu Lu wrote: > I revisited this patch. And I still have some questions. > > On 5/20/23 2:42 AM, Jason Gunthorpe wrote: > > -/* > > - * Remove the iommu_group from the struct device. The attached group must be put > > - * by the caller after releaseing the group->mutex. > > - */ > > +/* Remove the iommu_group from the struct device. */ > > static void __iommu_group_remove_device(struct device *dev) > > { > > struct iommu_group *group = dev->iommu_group; > > struct group_device *device; > > + mutex_lock(&group->mutex); > > lockdep_assert_held(&group->mutex); > > By moving mutex_lock/unlock into this helper, above > lockdep_assert_held() is unnecessary. Woops, got it thanks > The group->devices_kobj was increased on the probe device path twice: > > - iommu_init_device() - allocate the group > - iommu_group_add_device() - add device to the group > > But, on the release path, it seems that group->devices_kobj is only > decreased once. > > Did I overlook anything? Otherwise, the group will never be released, > right? Your answer was right, when VFIO uses add/remove device it doesn't do init_device. Jason