vfio: Move IOMMU_CAP_CACHE_COHERENCY test to after we know we have a group
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 5 Jul 2022 01:10:50 +0000 (22:10 -0300)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 5 Jul 2022 22:06:50 +0000 (16:06 -0600)
commitafe4e376ac5d568367b447ca90c12858d0935b86
tree89e345299ad4ff7242765f11edc7694603b6756d
parent88084a3df1672e131ddc1b4e39eeacfd39864acf
vfio: Move IOMMU_CAP_CACHE_COHERENCY test to after we know we have a group

The test isn't going to work if a group doesn't exist. Normally this isn't
a problem since VFIO isn't going to create a device if there is no group,
but the special CONFIG_VFIO_NOIOMMU behavior allows bypassing this
prevention. The new cap test effectively forces a group and breaks this
config option.

Move the cap test to vfio_group_find_or_alloc() which is the earliest time
we know we have a group available and thus are not running in noiommu mode.

Fixes: e8ae0e140c05 ("vfio: Require that devices support DMA cache coherence")
Reported-by: Xiang Chen <chenxiang66@hisilicon.com>
Tested-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v1-e8934b490f36+f4-vfio_cap_fix_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c