From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 85F596AAE for ; Fri, 5 Dec 2014 11:00:56 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 05 Dec 2014 02:00:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,521,1413270000"; d="scan'208";a="633137178" Received: from irsmsx155.ger.corp.intel.com ([163.33.192.3]) by fmsmga001.fm.intel.com with ESMTP; 05 Dec 2014 02:00:54 -0800 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.244]) by IRSMSX155.ger.corp.intel.com ([169.254.14.228]) with mapi id 14.03.0195.001; Fri, 5 Dec 2014 10:00:53 +0000 From: "Burakov, Anatoly" To: Michael Qiu , "dev@dpdk.org" Thread-Topic: [PATCH v2] VFIO: Avoid to enable vfio while the module not loaded Thread-Index: AQHQEFe5ciA3i4rZ4ka+imWWJV+oY5yAv9SQ Date: Fri, 5 Dec 2014 10:00:53 +0000 Message-ID: References: <1417664219-19679-1-git-send-email-michael.qiu@intel.com> <1417687227-21854-1-git-send-email-michael.qiu@intel.com> In-Reply-To: <1417687227-21854-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.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] 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, 05 Dec 2014 10:00:57 -0000 Hi Michael, Few nitpicks :-) (wording of the log message I guess is up to Thomas, I won= 't comment on that) > lib/librte_eal/common/eal_private.h | 36 > ++++++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 24 +++++++++++++++++--- > 2 files changed, 57 insertions(+), 3 deletions(-) >=20 > diff --git a/lib/librte_eal/common/eal_private.h > b/lib/librte_eal/common/eal_private.h > index 232fcec..e741bdb 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -35,6 +35,7 @@ > #define _EAL_PRIVATE_H_ >=20 > #include > +#include >=20 > /** > * Initialize the memzone subsystem (private to eal). > @@ -203,4 +204,39 @@ 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 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) > + return -1; > + FILE * fd =3D fopen("/proc/modules", "r"); > + if (fd =3D=3D NULL) > + return -1; Can we add RTE_LOG statement here, with an strerror(errno) like in other pl= aces? Fopen failed, we should at least know why :-) > + while(!feof(fd)) { > + fscanf(fd, "%s %*[^\n]", mod_name); > + if(!strcmp(mod_name, module_name)) { Probably should use strncmp instead of strcmp. > + 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..52ab2d0 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,13 @@ 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"); > + RTE_LOG(ERR, EAL, " unsupported IOMMU > type! " > + "expect: VFIO_TYPE1_IOMMU, " > + "actual: %d\n", ret); I'm not even sure we need this "expected" bit at all. We don't get back the= IOMMU type VFIO currently supports; rather, this code checks if VFIO's sup= port for VFIO_TYPE1_IOMMU is enabled or not. So I would change the error me= ssage to something more descriptive, such as " required IOMMU type support = not present in VFIO!\n", and get rid of the "expected". > close(vfio_container_fd); > return -1; > } > @@ -788,6 +792,20 @@ pci_vfio_enable(void) > vfio_cfg.vfio_groups[i].fd =3D -1; > vfio_cfg.vfio_groups[i].group_no =3D -1; > } > + > + /* return error directly */ > + if (rte_eal_check_module("vfio") =3D=3D -1 || > + rte_eal_check_module("vfio_iommu_type1") =3D=3D -1) > + return -1; > + > + /* return 0 if not all VFIO modules loaded */ > + if (rte_eal_check_module("vfio") =3D=3D 0 || > + rte_eal_check_module("vfio_iommu_type1") =3D=3D 0) { > + RTE_LOG(INFO, EAL, "VFIO modules not all loaded," > + " skip VFIO support ...\n"); > + return 0; > + } Can we perhaps make one call per module instead of two? i.e. something like= : int vfio_ret, vfio_ type1_ret; vfio_ret =3D rte_eal_check_module("vfio"); vfio_type1_ret =3D rte_eal_check_module("vfio_iommu_type1"); if (vfio_ret =3D=3D -1 || vfio_type1_ret =3D=3D -1) return -1; else if (vfio_ret =3D=3D 0 || vfio_type1_ret =3D=3D 0) { .... return 0; } > + > vfio_cfg.vfio_container_fd =3D pci_vfio_get_container_fd(); >=20 > /* check if we have VFIO driver enabled */ > -- > 1.9.3