iommufd: Change the order of MSI setup
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 7 Dec 2022 20:44:43 +0000 (16:44 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 9 Dec 2022 19:24:30 +0000 (15:24 -0400)
commitd6c55c0a20e5059abdde81713ddf6324a946eb3c
tree4776645a117fe8140102f412a04b20f451a40bd6
parenta26fa392068d1dcdf781397b7a7dd908dd68f030
iommufd: Change the order of MSI setup

Eric points out this is wrong for the rare case of someone using
allow_unsafe_interrupts on ARM. We always have to setup the MSI window in
the domain if the iommu driver asks for it.

Move the iommu_get_msi_cookie() setup to the top of the function and
always do it, regardless of the security mode. Add checks to
iommufd_device_setup_msi() to ensure the driver is not doing something
incomprehensible. No current driver will set both a HW and SW MSI window,
or have more than one SW MSI window.

Fixes: e8d57210035b ("iommufd: Add kAPI toward external drivers for physical devices")
Link: https://lore.kernel.org/r/3-v1-0362a1a1c034+98-iommufd_fixes1_jgg@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reported-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/device.c
drivers/iommu/iommufd/io_pagetable.c