DPDK patches and discussions
 help / color / mirror / Atom feed
From: Michael Qiu <michael.qiu@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v5] VFIO: Avoid to enable vfio while the module not loaded
Date: Wed, 10 Dec 2014 10:22:36 +0800	[thread overview]
Message-ID: <1418178156-4153-1-git-send-email-michael.qiu@intel.com> (raw)
In-Reply-To: <1418035455-9434-1-git-send-email-michael.qiu@intel.com>

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>
---
 v5 --> v4
	1. Move rte_eal_check_module() body to eal.c
	2. Clean up "unsupported IOMMU type" log

v4 --> v3:
	1. Remove RTE_LOG for params check
	2. Remove "vfio" module check as "vfio_iommu_type1"
	   loaded indecated "vfio" loaded

v3 --> v2:
        1. Add error log in rte_eal_check_module()
        2. Some code clean up.

v2 --> v1:
        1. Move check_module() from rte_common.h to eal_private.h
           and rename to rte_eal_check_module().
           To make it linuxapp only.
        2. Some code clean up.

 lib/librte_eal/common/eal_private.h        | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c          | 27 +++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 26 +++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 232fcec..4183b54 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -203,4 +203,19 @@ int rte_eal_alarm_init(void);
  */
 int rte_eal_dev_init(void);
 
+/**
+ * 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
+ */
+inline int
+rte_eal_check_module(const char *module_name);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 89f3b5e..40b462e 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -859,3 +859,30 @@ int rte_eal_has_hugepages(void)
 {
 	return ! internal_config.no_hugetlbfs;
 }
+
+inline int
+rte_eal_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 (NULL == fd) {
+		RTE_LOG(ERR, EAL, "Open /proc/modules failed!"
+			" error %i (%s)\n", errno, strerror(errno));
+		return -1;
+	}
+	while(!feof(fd)) {
+		fscanf(fd, "%30s %*[^\n]", mod_name);
+		if(!strcmp(mod_name, module_name)) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(fd);
+
+	return ret;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index c1246e8..16fe10f 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 <eal_private.h>
 
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
@@ -339,10 +340,12 @@ pci_vfio_get_container_fd(void)
 		ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU);
 		if (ret != 1) {
 			if (ret < 0)
-				RTE_LOG(ERR, EAL, "  could not get IOMMU type, "
-						"error %i (%s)\n", errno, strerror(errno));
+				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"
+					" detected in VFIO\n");
 			close(vfio_container_fd);
 			return -1;
 		}
@@ -783,11 +786,28 @@ pci_vfio_enable(void)
 {
 	/* initialize group list */
 	int i;
+	int module_vfio_type1;
 
 	for (i = 0; i < VFIO_MAX_GROUPS; i++) {
 		vfio_cfg.vfio_groups[i].fd = -1;
 		vfio_cfg.vfio_groups[i].group_no = -1;
 	}
+
+	module_vfio_type1 = rte_eal_check_module("vfio_iommu_type1");
+
+	/* return error directly */
+	if (module_vfio_type1 == -1) {
+		RTE_LOG(INFO, EAL, "Could not get loaded module details!\n");
+		return -1;
+	}
+
+	/* return 0 if VFIO modules not loaded */
+	if (module_vfio_type1 == 0) {
+		RTE_LOG(INFO, EAL, "VFIO modules not all loaded,"
+			" skip VFIO support ...\n");
+		return 0;
+	}
+
 	vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
 
 	/* check if we have VFIO driver enabled */
-- 
1.9.3

  parent reply	other threads:[~2014-12-10  2:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04  3:36 [dpdk-dev] [PATCH] " 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     ` Michael Qiu [this message]
2014-12-10  9:21       ` [dpdk-dev] [PATCH v5] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418178156-4153-1-git-send-email-michael.qiu@intel.com \
    --to=michael.qiu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).