DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Michael Qiu <qdy220091330@gmail.com>, "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH v2] VFIO: Avoid to enable vfio while the module not loaded
Date: Fri, 5 Dec 2014 10:00:53 +0000
Message-ID: <C6ECDF3AB251BE4894318F4E4512369780C21F44@IRSMSX109.ger.corp.intel.com> (raw)
In-Reply-To: <1417687227-21854-1-git-send-email-michael.qiu@intel.com>

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(-)
> 
> 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_
> 
>  #include <stdio.h>
> +#include <string.h>
> 
>  /**
>   * Initialize the memzone subsystem (private to eal).
> @@ -203,4 +204,39 @@ 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 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 = 0;
> +
> +	if (NULL == module_name)
> +		return -1;
> +	FILE * fd = fopen("/proc/modules", "r");
> +	if (fd == NULL)
> +		return -1;

Can we add RTE_LOG statement here, with an strerror(errno) like in other places? 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 = 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 <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,13 @@ 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! "
> +					"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 support for VFIO_TYPE1_IOMMU is enabled or not. So I would change the error message 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 = -1;
>  		vfio_cfg.vfio_groups[i].group_no = -1;
>  	}
> +
> +	/* return error directly */
> +	if (rte_eal_check_module("vfio") == -1 ||
> +	    rte_eal_check_module("vfio_iommu_type1") == -1)
> +		return -1;
> +
> +	/* return 0 if not all VFIO modules loaded */
> +	if (rte_eal_check_module("vfio") == 0 ||
> +	    rte_eal_check_module("vfio_iommu_type1") == 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 = rte_eal_check_module("vfio");
vfio_type1_ret = rte_eal_check_module("vfio_iommu_type1");

if (vfio_ret == -1 || vfio_type1_ret == -1)
    return -1;
else if (vfio_ret == 0 || vfio_type1_ret == 0) {
     ....
    return 0;
}

> +
>  	vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
> 
>  	/* check if we have VFIO driver enabled */
> --
> 1.9.3

  reply	other threads:[~2014-12-05 10:00 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 [this message]
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

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=C6ECDF3AB251BE4894318F4E4512369780C21F44@IRSMSX109.ger.corp.intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=qdy220091330@gmail.com \
    /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

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