vlib: linux: fix wrong iommu_group value issue when using dpdk-plugin 05/22805/4
authorYulong Pei <yulong.pei@intel.com>
Thu, 17 Oct 2019 10:41:52 +0000 (18:41 +0800)
committerDamjan Marion <dmarion@me.com>
Sun, 20 Oct 2019 19:31:14 +0000 (19:31 +0000)
When VPP work with dpdk-plugin, linux_vfio_main_t->container_fd is always -1
since it never have chance to run open("/dev/vfio/vfio") to get the fd.

But this lead to a potential issue of VPP, that is, when start VPP without
uio-driver field setup in /etc/vpp/startup.conf, VPP will run to automatical
select uio driver in vlib_pci_bind_to_uio() and the function depend on
iommu_group value to decide to work on vfio or vfio-noiommu mode.

Since in vlib_pci_get_device_info() have the condition container_fd != -1,
so the iommu_group value will be always -1 at this scenario, this caused
that VPP mistake to run with vfio-noiommu driver on intel_iommu=on state.

Actually in order to get iommu_group and iommu_group/name value, no need to
depend on linux_vfio_main_t->container_fd value, so the fix remove the
condition lvm->container_fd != -1, then it can get the correct iommu_group
value.

Type: fix

Change-Id: I3f162fc4971b9a2b8717205f8f3b52e30c5e5b69
Signed-off-by: Yulong Pei <yulong.pei@intel.com>
src/vlib/linux/pci.c

index 82f5007..19c0c54 100644 (file)
@@ -202,12 +202,12 @@ vlib_pci_device_info_t *
 vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
                          clib_error_t ** error)
 {
-  linux_vfio_main_t *lvm = &vfio_main;
   clib_error_t *err;
   vlib_pci_device_info_t *di;
   u8 *f = 0;
   u32 tmp;
   int fd;
+  u8 *tmpstr;
 
   di = clib_mem_alloc (sizeof (vlib_pci_device_info_t));
   clib_memset (di, 0, sizeof (vlib_pci_device_info_t));
@@ -295,30 +295,27 @@ vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
     di->driver_name = format (0, "<NONE>%c", 0);
 
   di->iommu_group = -1;
-  if (lvm->container_fd != -1)
+  vec_reset_length (f);
+  f = format (f, "%v/iommu_group%c", dev_dir_name, 0);
+  tmpstr = clib_sysfs_link_to_name ((char *) f);
+  if (tmpstr)
     {
-      u8 *tmpstr;
-      vec_reset_length (f);
-      f = format (f, "%v/iommu_group%c", dev_dir_name, 0);
-      tmpstr = clib_sysfs_link_to_name ((char *) f);
-      if (tmpstr)
-       {
-         di->iommu_group = atoi ((char *) tmpstr);
-         vec_free (tmpstr);
-       }
-      vec_reset_length (f);
-      f = format (f, "%v/iommu_group/name%c", dev_dir_name, 0);
-      err = clib_sysfs_read ((char *) f, "%s", &tmpstr);
-      if (err == 0)
-       {
-         if (strncmp ((char *) tmpstr, "vfio-noiommu", 12) == 0)
-           di->flags |= VLIB_PCI_DEVICE_INFO_F_NOIOMMU;
-         vec_free (tmpstr);
-       }
-      else
-       clib_error_free (err);
+      di->iommu_group = atoi ((char *) tmpstr);
+      vec_free (tmpstr);
     }
 
+  vec_reset_length (f);
+  f = format (f, "%v/iommu_group/name%c", dev_dir_name, 0);
+  err = clib_sysfs_read ((char *) f, "%s", &tmpstr);
+  if (err == 0)
+    {
+      if (strncmp ((char *) tmpstr, "vfio-noiommu", 12) == 0)
+       di->flags |= VLIB_PCI_DEVICE_INFO_F_NOIOMMU;
+      vec_free (tmpstr);
+    }
+  else
+    clib_error_free (err);
+
   close (fd);
 
   vec_reset_length (f);