]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Fri, 24 Mar 2017 06:44:06 +0000 (17:44 +1100)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 11 Apr 2017 19:38:46 +0000 (13:38 -0600)
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>
drivers/vfio/vfio_iommu_spapr_tce.c

index cf3de91fbfe7a522456d00bff9005df9a3662ed4..a7d8115240929a247bb53e5bde1ac4cd8a64f372 100644 (file)
@@ -1335,8 +1335,16 @@ static int tce_iommu_attach_group(void *iommu_data,
 
        if (!table_group->ops || !table_group->ops->take_ownership ||
                        !table_group->ops->release_ownership) {
+               if (container->v2) {
+                       ret = -EPERM;
+                       goto unlock_exit;
+               }
                ret = tce_iommu_take_ownership(container, table_group);
        } else {
+               if (!container->v2) {
+                       ret = -EPERM;
+                       goto unlock_exit;
+               }
                ret = tce_iommu_take_ownership_ddw(container, table_group);
                if (!tce_groups_attached(container) && !container->tables[0])
                        container->def_window_pending = true;