iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 13 Sep 2023 13:43:41 +0000 (10:43 -0300)
committerJoerg Roedel <jroedel@suse.de>
Mon, 25 Sep 2023 09:40:56 +0000 (11:40 +0200)
commit59ddce4418da483c932bc7a08b88d6ba14020e83
tree99b2dd4904c88bd594302512dd30ebf050388713
parent90057dc095dca023ad3e8cd5a129f392b543fb9e
iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()

Except for dart (which forces IOMMU_DOMAIN_DMA) every driver returns 0 or
IDENTITY from ops->def_domain_type().

The drivers that return IDENTITY have some kind of good reason, typically
that quirky hardware really can't support anything other than IDENTITY.

Arrange things so that if the driver says it needs IDENTITY then
iommu_get_default_domain_type() either fails or returns IDENTITY.  It will
not ignore the driver's override to IDENTITY.

Split the function into two steps, reducing the group device list to the
driver's def_domain_type() and the untrusted flag.

Then compute the result based on those two reduced variables. Fully reject
combining untrusted with IDENTITY.

Remove the debugging print on the iommu_group_store_type() failure path,
userspace should not be able to trigger kernel prints.

This makes the next patch cleaner that wants to force IDENTITY always for
ARM_IOMMU because there is no support for DMA.

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/8-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c