From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 7D5158025 for ; Mon, 8 Dec 2014 10:54:38 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 08 Dec 2014 01:52:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,537,1413270000"; d="scan'208";a="650180673" Received: from irsmsx154.ger.corp.intel.com ([163.33.192.96]) by orsmga002.jf.intel.com with ESMTP; 08 Dec 2014 01:54:35 -0800 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.244]) by IRSMSX154.ger.corp.intel.com ([169.254.12.18]) with mapi id 14.03.0195.001; Mon, 8 Dec 2014 09:54:33 +0000 From: "Burakov, Anatoly" To: "Qiu, Michael" , "dev@dpdk.org" Thread-Topic: [PATCH v3] VFIO: Avoid to enable vfio while the module not loaded Thread-Index: AQHQEsDwMXJaLU9ePkODU9V6trOWo5yFc7VA Date: Mon, 8 Dec 2014 09:54:33 +0000 Message-ID: References: <1417687227-21854-1-git-send-email-michael.qiu@intel.com> <1418027255-7727-1-git-send-email-michael.qiu@intel.com> In-Reply-To: <1418027255-7727-1-git-send-email-michael.qiu@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3] VFIO: Avoid to enable vfio while the module not loaded X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Dec 2014 09:54:39 -0000 > When vfio module is not loaded when kernel support vfio feature, the > routine still try to open the container to get file description. >=20 > This action is not safe, and of cause got error messages: >=20 > EAL: Detected 40 lcore(s) > EAL: unsupported IOMMU type! > EAL: VFIO support could not be initialized > EAL: Setting up memory... >=20 > This may make user confuse, this patch make it reasonable and much more > soomth to user. >=20 > Signed-off-by: Michael Qiu > --- > v3 --> v2: > 1. Add error log in rte_eal_check_module() > 2. Some code clean up. >=20 > 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. >=20 > lib/librte_eal/common/eal_private.h | 43 > ++++++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 30 ++++++++++++++++++--- > 2 files changed, 70 insertions(+), 3 deletions(-) >=20 > diff --git a/lib/librte_eal/common/eal_private.h > b/lib/librte_eal/common/eal_private.h > index 232fcec..d1d8126 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -35,6 +35,9 @@ > #define _EAL_PRIVATE_H_ >=20 > #include > +#include > +#include > +#include >=20 > /** > * Initialize the memzone subsystem (private to eal). > @@ -203,4 +206,44 @@ int rte_eal_alarm_init(void); > */ > int rte_eal_dev_init(void); >=20 > +/** > + * 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 > +rte_eal_check_module(const char *module_name) { > + char mod_name[30]; /* Any module names can be longer than 30 > bytes? */ > + int ret =3D 0; > + > + if (NULL =3D=3D module_name) { > + RTE_LOG(ERR, EAL, "The module name is NULL\n"); I don't think this RTE_LOG is necessary - we never RTE_LOG invalid paramete= rs. > + return -1; > + } > + FILE * fd =3D fopen("/proc/modules", "r"); > + if (NULL =3D=3D fd) { > + RTE_LOG(ERR, EAL, "Open /proc/modules failed!" > + " error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + while(!feof(fd)) { > + fscanf(fd, "%s %*[^\n]", mod_name); > + if(!strcmp(mod_name, module_name)) { > + ret =3D 1; > + break; > + } > + } > + fclose(fd); > + > + return ret; > +} > + > #endif /* _EAL_PRIVATE_H_ */ > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c > b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c > index c1246e8..b34b3f5 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 > #include > #include > +#include >=20 > #include "eal_filesystem.h" > #include "eal_pci_init.h" > @@ -339,10 +340,15 @@ pci_vfio_get_container_fd(void) > ret =3D ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, > VFIO_TYPE1_IOMMU); > if (ret !=3D 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"); > + /* Better to show the IOMMU type return > from > + * kernel for easy debug > + */ > + RTE_LOG(ERR, EAL, " unsupported IOMMU > type" > + " detected: %d in VFIO\n", ret); > close(vfio_container_fd); > return -1; > } > @@ -783,11 +789,29 @@ pci_vfio_enable(void) { > /* initialize group list */ > int i; > + int module_vfio, module_vfio_type1; >=20 > for (i =3D 0; i < VFIO_MAX_GROUPS; i++) { > vfio_cfg.vfio_groups[i].fd =3D -1; > vfio_cfg.vfio_groups[i].group_no =3D -1; > } > + > + module_vfio =3D rte_eal_check_module("vfio"); > + module_vfio_type1 =3D rte_eal_check_module("vfio_iommu_type1"); We can actually get away with checking just vfio_iommu_type1 (having it loa= ded implies that vfio is loaded as well). > + > + /* return error directly */ > + if (module_vfio =3D=3D -1 || module_vfio_type1 =3D=3D -1) { > + RTE_LOG(INFO, EAL, "Could not get loaded module > details!\n"); > + return -1; > + } > + > + /* return 0 if not all VFIO modules loaded */ > + if (module_vfio =3D=3D 0 || module_vfio_type1 =3D=3D 0) { > + RTE_LOG(INFO, EAL, "VFIO modules not all loaded," > + " skip VFIO support ...\n"); > + return 0; > + } > + > vfio_cfg.vfio_container_fd =3D pci_vfio_get_container_fd(); >=20 > /* check if we have VFIO driver enabled */ > -- > 1.9.3