iommu: Same critical region for device release and removal
authorLu Baolu <baolu.lu@linux.intel.com>
Wed, 22 Mar 2023 06:49:53 +0000 (14:49 +0800)
committerJoerg Roedel <jroedel@suse.de>
Wed, 22 Mar 2023 14:45:16 +0000 (15:45 +0100)
commitdba9ca9d41f5266194a5e8007db50985d271d0a4
tree93e7e2fcca587255b62de0376d7485367889e730
parent293f2564f3dd76b749fc31ae4226bd818f860e4f
iommu: Same critical region for device release and removal

In a non-driver context, it is crucial to ensure the consistency of a
device's iommu ops. Otherwise, it may result in a situation where a
device is released but it's iommu ops are still used.

Put the ops->release_device and __iommu_group_remove_device() in a same
group->mutext critical region, so that, as long as group->mutex is held
and the device is in its group's device list, its iommu ops are always
consistent. Add check of group ownership if the released device is the
last one.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20230322064956.263419-4-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c