FSLMC bus only supports operating in group mode, and relies on no-IOMMU
mode checks. Use the new VFIO API's to query no-IOMMU status as well as to
protect the bus from initializing in non-group mode.

Signed-off-by: Anatoly Burakov <[email protected]>
Acked-by: Hemant Agrawal <[email protected]>
---
 drivers/bus/fslmc/fslmc_bus.c  | 10 +++++++++-
 drivers/bus/fslmc/fslmc_vfio.c |  2 +-
 lib/eal/linux/eal_vfio.c       | 18 ++++++++++--------
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index d55c414ead..aeef49a5ff 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -332,6 +332,13 @@ rte_fslmc_scan(void)
                goto scan_fail;
        }
 
+       /* for container groups to work, VFIO must be in group mode */
+       if (dev_vfio_get_mode() != DEV_VFIO_MODE_GROUP) {
+               DPAA2_BUS_DEBUG("DPAA2: VFIO not in group mode");
+               ret = -EINVAL;
+               goto scan_fail;
+       }
+
        ret = fslmc_get_container_group(group_name, &groupid);
        if (ret != 0)
                goto scan_fail;
@@ -500,7 +507,8 @@ rte_dpaa2_get_iommu_class(void)
                return RTE_IOVA_DC;
 
        /* check if all devices on the bus support Virtual addressing or not */
-       if (fslmc_all_device_support_iova() != 0 && 
dev_vfio_noiommu_is_enabled() == 0)
+       if (fslmc_all_device_support_iova() != 0 &&
+                       dev_vfio_get_iommu_mode() == DEV_VFIO_IOMMU_MODE_UNSAFE)
                return RTE_IOVA_VA;
 
        return RTE_IOVA_PA;
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index c2b6ac1f3f..0926ec9349 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -204,7 +204,7 @@ fslmc_vfio_add_group(int vfio_group_fd,
        group->fd = vfio_group_fd;
        group->groupid = iommu_group_num;
        rte_strscpy(group->group_name, group_name, sizeof(group->group_name));
-       if (dev_vfio_noiommu_is_enabled() > 0)
+       if (dev_vfio_get_iommu_mode() == DEV_VFIO_IOMMU_MODE_UNSAFE)
                group->iommu_type = VFIO_NOIOMMU_IOMMU;
        else
                group->iommu_type = VFIO_TYPE1_IOMMU;
diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c
index 3d3a6c6bb0..f35bf77730 100644
--- a/lib/eal/linux/eal_vfio.c
+++ b/lib/eal/linux/eal_vfio.c
@@ -589,20 +589,22 @@ vfio_group_assign_device(struct vfio_container *cfg, 
const char *sysfs_base,
                return VFIO_EXISTS;
        }
 
+       /* allocate new device in config */
+       dev = vfio_device_create(cfg, vfio_global_cfg.mode);
+       if (dev == NULL) {
+               EAL_LOG(ERR, "No space to track new VFIO device");
+               return VFIO_NO_SPACE;
+       }
+
+       /* allocate strings for sysfs path and device address */
        sysfs_dup = strdup(sysfs_base);
        dev_dup = strdup(dev_addr);
        if (sysfs_dup == NULL || dev_dup == NULL) {
                EAL_LOG(ERR, "Cannot allocate memory for device %s", dev_addr);
                free(sysfs_dup);
                free(dev_dup);
-               return VFIO_NO_MEM;
-       }
-
-       /* allocate new device in config */
-       dev = vfio_device_create(cfg, vfio_global_cfg.mode);
-       if (dev == NULL) {
-               EAL_LOG(ERR, "No space to track new VFIO device");
-               return VFIO_NO_SPACE;
+               ret = VFIO_NO_MEM;
+               goto device_erase;
        }
 
        /* store sysfs path and device address */
-- 
2.52.0

Reply via email to