iommu: Consolidate the default_domain setup to one function
authorJason Gunthorpe <jgg@nvidia.com>
Thu, 11 May 2023 04:42:12 +0000 (01:42 -0300)
committerJoerg Roedel <jroedel@suse.de>
Tue, 23 May 2023 06:15:57 +0000 (08:15 +0200)
commitd99be00f42eac9fc35a164f3f6c8c7a56b295aa9
treea0575f349e1f37c65ccac10d53e257045e4a7450
parentfcbb0a4d738ce3ccc06d2c73ba227cce5094d885
iommu: Consolidate the default_domain setup to one function

Make iommu_change_dev_def_domain() general enough to setup the initial
default_domain or replace it with a new default_domain. Call the new
function iommu_setup_default_domain() and make it the only place in the
code that stores to group->default_domain.

Consolidate the three copies of the default_domain setup sequence. The flow
flow requires:

 - Determining the domain type to use
 - Checking if the current default domain is the same type
 - Allocating a domain
 - Doing iommu_create_device_direct_mappings()
 - Attaching it to devices
 - Store group->default_domain

This adjusts the domain allocation from the prior patch to be able to
detect if each of the allocation steps is already the domain we already
have, which is a more robust version of what change default domain was
already doing.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/14-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c