Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check

The existing SPAPR TCE driver advertises both VFIO_SPAPR_TCE_IOMMU and
VFIO_SPAPR_TCE_v2_IOMMU types to the userspace and the userspace usually
picks the v2.

Normally the userspace would create a container, attach an IOMMU group
to it and only then set the IOMMU type (which would normally be v2).

However a specific IOMMU group may not support v2, in other words
it may not implement set_window/unset_window/take_ownership/
release_ownership and such a group should not be attached to
a v2 container.

This adds extra checks that a new group can do what the selected IOMMU
type suggests. The userspace can then test the return value from
ioctl(VFIO_SET_IOMMU, VFIO_SPAPR_TCE_v2_IOMMU) and try
VFIO_SPAPR_TCE_IOMMU.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Alexey Kardashevskiy and committed by
Alex Williamson
1282ba7f 39da7c50

+8
+8
drivers/vfio/vfio_iommu_spapr_tce.c
··· 1335 1335 1336 1336 if (!table_group->ops || !table_group->ops->take_ownership || 1337 1337 !table_group->ops->release_ownership) { 1338 + if (container->v2) { 1339 + ret = -EPERM; 1340 + goto unlock_exit; 1341 + } 1338 1342 ret = tce_iommu_take_ownership(container, table_group); 1339 1343 } else { 1344 + if (!container->v2) { 1345 + ret = -EPERM; 1346 + goto unlock_exit; 1347 + } 1340 1348 ret = tce_iommu_take_ownership_ddw(container, table_group); 1341 1349 if (!tce_groups_attached(container) && !container->tables[0]) 1342 1350 container->def_window_pending = true;