From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 07E8E68AA for ; Fri, 19 Dec 2014 08:09:39 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 18 Dec 2014 23:09:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="431084145" Received: from kmsmsx153.gar.corp.intel.com ([172.21.73.88]) by FMSMGA003.fm.intel.com with ESMTP; 18 Dec 2014 22:58:23 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.110.14) by KMSMSX153.gar.corp.intel.com (172.21.73.88) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 19 Dec 2014 15:09:37 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.110]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.240]) with mapi id 14.03.0195.001; Fri, 19 Dec 2014 15:09:29 +0800 From: "Qiu, Michael" To: "dev@dpdk.org" , "thomas.monjalon@6wind.com" Thread-Topic: [PATCH v6] VFIO: Avoid to enable vfio while the module not loaded Thread-Index: AQHQFG78U6g7aYyFH06BPZipKqjrIg== Date: Fri, 19 Dec 2014 07:09:29 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286CA1227@SHSMSX101.ccr.corp.intel.com> References: <1418035455-9434-1-git-send-email-michael.qiu@intel.com> <1418211977-8218-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: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v6] 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: Fri, 19 Dec 2014 07:09:40 -0000 Hi Thomas,=0A= =0A= Will you plan to merge this patch? If yes, you plan to merge it into=0A= 1.8 or 2.0?=0A= =0A= Thanks,=0A= Michael=0A= On 12/10/2014 7:48 PM, Burakov, Anatoly wrote:=0A= >> When vfio module is not loaded when kernel support vfio feature, the=0A= >> routine still try to open the container to get file description.=0A= >>=0A= >> This action is not safe, and of cause got error messages:=0A= >>=0A= >> EAL: Detected 40 lcore(s)=0A= >> EAL: unsupported IOMMU type!=0A= >> EAL: VFIO support could not be initialized=0A= >> EAL: Setting up memory...=0A= >>=0A= >> This may make user confuse, this patch make it reasonable and much more= =0A= >> soomth to user.=0A= >>=0A= >> Signed-off-by: Michael Qiu =0A= >> ---=0A= >> v6 --> v5=0A= >> 1. Change rte_eal_check_module() to normal=0A= >> function instead of inline=0A= >> 2. limit fscanf to get 29 charactors not include '\0'=0A= >>=0A= >> lib/librte_eal/common/eal_private.h | 14 ++++++++++++++=0A= >> lib/librte_eal/linuxapp/eal/eal.c | 27 +++++++++++++++++++++++= ++++=0A= >> lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 26=0A= >> +++++++++++++++++++++++---=0A= >> 3 files changed, 64 insertions(+), 3 deletions(-)=0A= >>=0A= >> diff --git a/lib/librte_eal/common/eal_private.h=0A= >> b/lib/librte_eal/common/eal_private.h=0A= >> index 232fcec..2c751c6 100644=0A= >> --- a/lib/librte_eal/common/eal_private.h=0A= >> +++ b/lib/librte_eal/common/eal_private.h=0A= >> @@ -203,4 +203,18 @@ int rte_eal_alarm_init(void);=0A= >> */=0A= >> int rte_eal_dev_init(void);=0A= >>=0A= >> +/**=0A= >> + * Function is to check if the kernel module(like, vfio,=0A= >> +vfio_iommu_type1,=0A= >> + * etc.) loaded.=0A= >> + *=0A= >> + * @param module_name=0A= >> + * The module's name which need to be checked=0A= >> + *=0A= >> + * @return=0A= >> + * -1 means some error happens(NULL pointer or open failure)=0A= >> + * 0 means the module not loaded=0A= >> + * 1 means the module loaded=0A= >> + */=0A= >> +int rte_eal_check_module(const char *module_name);=0A= >> +=0A= >> #endif /* _EAL_PRIVATE_H_ */=0A= >> diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp= /eal/eal.c=0A= >> index 89f3b5e..9c1a1cc 100644=0A= >> --- a/lib/librte_eal/linuxapp/eal/eal.c=0A= >> +++ b/lib/librte_eal/linuxapp/eal/eal.c=0A= >> @@ -859,3 +859,30 @@ int rte_eal_has_hugepages(void) {=0A= >> return ! internal_config.no_hugetlbfs; }=0A= >> +=0A= >> +int=0A= >> +rte_eal_check_module(const char *module_name) {=0A= >> + char mod_name[30]; /* Any module names can be longer than 30=0A= >> bytes? */=0A= >> + int ret =3D 0;=0A= >> +=0A= >> + if (NULL =3D=3D module_name)=0A= >> + return -1;=0A= >> +=0A= >> + FILE * fd =3D fopen("/proc/modules", "r");=0A= >> + if (NULL =3D=3D fd) {=0A= >> + RTE_LOG(ERR, EAL, "Open /proc/modules failed!"=0A= >> + " error %i (%s)\n", errno, strerror(errno));=0A= >> + return -1;=0A= >> + }=0A= >> + while(!feof(fd)) {=0A= >> + fscanf(fd, "%29s %*[^\n]", mod_name);=0A= >> + if(!strcmp(mod_name, module_name)) {=0A= >> + ret =3D 1;=0A= >> + break;=0A= >> + }=0A= >> + }=0A= >> + fclose(fd);=0A= >> +=0A= >> + return ret;=0A= >> +}=0A= >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c=0A= >> b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c=0A= >> index c1246e8..16fe10f 100644=0A= >> --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c=0A= >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c=0A= >> @@ -44,6 +44,7 @@=0A= >> #include =0A= >> #include =0A= >> #include =0A= >> +#include =0A= >>=0A= >> #include "eal_filesystem.h"=0A= >> #include "eal_pci_init.h"=0A= >> @@ -339,10 +340,12 @@ pci_vfio_get_container_fd(void)=0A= >> ret =3D ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,=0A= >> VFIO_TYPE1_IOMMU);=0A= >> if (ret !=3D 1) {=0A= >> if (ret < 0)=0A= >> - RTE_LOG(ERR, EAL, " could not get IOMMU=0A= >> type, "=0A= >> - "error %i (%s)\n", errno,=0A= >> strerror(errno));=0A= >> + RTE_LOG(ERR, EAL, " could not get IOMMU=0A= >> type,"=0A= >> + " error %i (%s)\n", errno,=0A= >> + strerror(errno));=0A= >> else=0A= >> - RTE_LOG(ERR, EAL, " unsupported IOMMU=0A= >> type!\n");=0A= >> + RTE_LOG(ERR, EAL, " unsupported IOMMU=0A= >> type"=0A= >> + " detected in VFIO\n");=0A= >> close(vfio_container_fd);=0A= >> return -1;=0A= >> }=0A= >> @@ -783,11 +786,28 @@ pci_vfio_enable(void) {=0A= >> /* initialize group list */=0A= >> int i;=0A= >> + int module_vfio_type1;=0A= >>=0A= >> for (i =3D 0; i < VFIO_MAX_GROUPS; i++) {=0A= >> vfio_cfg.vfio_groups[i].fd =3D -1;=0A= >> vfio_cfg.vfio_groups[i].group_no =3D -1;=0A= >> }=0A= >> +=0A= >> + module_vfio_type1 =3D rte_eal_check_module("vfio_iommu_type1");=0A= >> +=0A= >> + /* return error directly */=0A= >> + if (module_vfio_type1 =3D=3D -1) {=0A= >> + RTE_LOG(INFO, EAL, "Could not get loaded module=0A= >> details!\n");=0A= >> + return -1;=0A= >> + }=0A= >> +=0A= >> + /* return 0 if VFIO modules not loaded */=0A= >> + if (module_vfio_type1 =3D=3D 0) {=0A= >> + RTE_LOG(INFO, EAL, "VFIO modules not all loaded,"=0A= >> + " skip VFIO support ...\n");=0A= >> + return 0;=0A= >> + }=0A= >> +=0A= >> vfio_cfg.vfio_container_fd =3D pci_vfio_get_container_fd();=0A= >>=0A= >> /* check if we have VFIO driver enabled */=0A= >> --=0A= >> 1.9.3=0A= > Acked-by: Anatoly Burakov =0A= >=0A= >=0A= =0A=