DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] VFIO: Avoid to enable vfio while the module not loaded
@ 2014-12-04  3:36 Michael Qiu
  2014-12-04 10:00 ` [dpdk-dev] [PATCH v2] " Michael Qiu
                   ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Michael Qiu @ 2014-12-04  3:36 UTC (permalink / raw)
  To: dev

When vfio module is not loaded when kernel support vfio feature,
the routine still try to open the container to get file
description.

This action is not safe, and of cause got error messages:

EAL: Detected 40 lcore(s)
EAL:   unsupported IOMMU type!
EAL: VFIO support could not be initialized
EAL: Setting up memory...

This may make user confuse, this patch make it reasonable
and much more soomth to user.

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 lib/librte_eal/common/include/rte_common.h | 37 ++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 23 +++++++++++++------
 2 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 921b91f..333aa6b 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -50,6 +50,8 @@ extern "C" {
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
+#include <string.h>
+#include <stdio.h>
 
 /*********** Macros to eliminate unused variable warnings ********/
 
@@ -382,6 +384,41 @@ rte_exit(int exit_code, const char *format, ...)
 	__attribute__((noreturn))
 	__attribute__((format(printf, 2, 3)));
 
+/**
+ * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
+ * etc.) loaded.
+ *
+ * @param module_name
+ *	The module's name which need to be checked
+ *
+ * @return
+ * 	-1 means some error happens(NULL pointer or open failure)
+ * 	0  means the module not loaded
+ * 	1  means the module loaded
+ */
+static inline int
+check_module(const char *module_name)
+{
+	char mod_name[30]; /* Any module names can be longer than 30 bytes? */
+	int ret = 0;
+
+	if (NULL == module_name)
+		return -1;
+	FILE * fd = fopen("/proc/modules", "r");
+	if( fd == NULL)
+		return -1;
+	while(!feof(fd)) {
+		fscanf(fd, "%s %*[^\n]", mod_name);
+		if(!strcmp(mod_name, module_name)) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(fd);
+
+	return ret;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index c1246e8..a11cc4b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -44,6 +44,7 @@
 #include <rte_tailq.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
+#include <rte_common.h>
 
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
@@ -342,7 +343,8 @@ pci_vfio_get_container_fd(void)
 				RTE_LOG(ERR, EAL, "  could not get IOMMU type, "
 						"error %i (%s)\n", errno, strerror(errno));
 			else
-				RTE_LOG(ERR, EAL, "  unsupported IOMMU type!\n");
+				RTE_LOG(ERR, EAL, "  unsupported IOMMU type! "
+					"expect: 1, actual: %d\n", ret);
 			close(vfio_container_fd);
 			return -1;
 		}
@@ -788,13 +790,20 @@ pci_vfio_enable(void)
 		vfio_cfg.vfio_groups[i].fd = -1;
 		vfio_cfg.vfio_groups[i].group_no = -1;
 	}
-	vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
 
-	/* check if we have VFIO driver enabled */
-	if (vfio_cfg.vfio_container_fd != -1)
-		vfio_cfg.vfio_enabled = 1;
-	else
-		RTE_LOG(INFO, EAL, "VFIO support could not be initialized\n");
+	if (check_module("vfio") == 1 &&
+	    check_module("vfio_iommu_type1") == 1) {
+		vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
+
+		/* check if we have VFIO driver enabled */
+		if (vfio_cfg.vfio_container_fd != -1)
+			vfio_cfg.vfio_enabled = 1;
+		else
+			RTE_LOG(INFO, EAL, "VFIO support could not be"
+				" initialized\n");
+	} else
+		RTE_LOG(INFO, EAL, "VFIO modules are not all loaded,"
+			" skip VFIO support ...\n");
 
 	return 0;
 }
-- 
1.9.3

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2015-01-15 13:51 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-04  3:36 [dpdk-dev] [PATCH] VFIO: Avoid to enable vfio while the module not loaded Michael Qiu
2014-12-04 10:00 ` [dpdk-dev] [PATCH v2] " Michael Qiu
2014-12-05 10:00   ` Burakov, Anatoly
2014-12-08  7:25     ` Qiu, Michael
2014-12-08 18:47       ` Burakov, Anatoly
2014-12-09  2:47         ` Qiu, Michael
2014-12-09  9:51           ` Burakov, Anatoly
2014-12-08  8:27   ` [dpdk-dev] [PATCH v3] " Michael Qiu
2014-12-08  9:54     ` Burakov, Anatoly
2014-12-08 10:28       ` Qiu, Michael
2014-12-08 10:44   ` [dpdk-dev] [PATCH v4] " Michael Qiu
2014-12-08 12:19     ` Burakov, Anatoly
2014-12-08 15:28       ` Qiu, Michael
2014-12-10  0:17         ` Xie, Huawei
2014-12-10  2:06           ` Qiu, Michael
2014-12-10  2:22     ` [dpdk-dev] [PATCH v5] " Michael Qiu
2014-12-10  9:21       ` Burakov, Anatoly
2014-12-10 11:29         ` Qiu, Michael
2014-12-10 11:46     ` [dpdk-dev] [PATCH v6] " Michael Qiu
2014-12-10 11:48       ` Burakov, Anatoly
2014-12-19  7:09         ` Qiu, Michael
2014-12-19  8:23           ` Thomas Monjalon
2014-12-22  1:21             ` Qiu, Michael
2015-01-15 13:38         ` Thomas Monjalon
2015-01-15 13:42           ` Burakov, Anatoly
2015-01-15 13:51             ` Thomas Monjalon
2014-12-04 13:12 ` [dpdk-dev] [PATCH] " Burakov, Anatoly
2014-12-04 13:47   ` Qiu, Michael
2014-12-04 16:31     ` Burakov, Anatoly
2014-12-05  4:01       ` Qiu, Michael
2014-12-04 13:13 ` Burakov, Anatoly

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git