All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Yang Ming <ming.1.yang@nokia-sbell.com>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>, dev@dpdk.org
Subject: Re: [PATCH] Skip vfio in the scenario of non-privileged mode
Date: Wed, 26 Feb 2025 05:45:40 -0800	[thread overview]
Message-ID: <20250226054540.166dfd43@hermes.local> (raw)
In-Reply-To: <ba8c70c7-a738-4b01-8df6-2df5bb0e2d7d@nokia-sbell.com>

On Wed, 22 Jan 2025 16:15:03 +0800
Yang Ming <ming.1.yang@nokia-sbell.com> wrote:

> On 2025/1/18 00:47, Stephen Hemminger wrote:
> > Caution: This is an external email. Please be very careful when clicking links or opening attachments. See http://nok.it/nsb for additional information.
> >
> > On Fri, 17 Jan 2025 15:28:47 +0800
> > Yang Ming <ming.1.yang@nokia-sbell.com> wrote:
> >  
> >> DPDK detect vfio container according the existence of vfio
> >> module. But for container with non-privileged mode, there is
> >> possibility that no VFIO_DIR(/dev/vfio) mapping from host to
> >> container when host have both Intel NIC and Mellanox NIC but
> >> this conntainer only allocate VFs from Mellanox NIC.
> >> In this case, vfio kernel module has already been loaded from
> >> the host.
> >> This scenario will cause the error log occurs in DPDK primary
> >> process as below:
> >> 'EAL:   cannot open VFIO container, error 2 (No such file or
> >> directory)'
> >> 'EAL: VFIO support could not be initialized'
> >> Because `rte_vfio_enable()` call `rte_vfio_get_container_fd()`
> >> to execute `vfio_container_fd = open(VFIO_CONTAINER_PATH,
> >> O_RDWR);` but VFIO_CONTAINER_PATH(/dev/vfio/vfio) doesn't exist
> >> in this container.
> >> This scenario will also lead to the delay of DPDK secondary
> >> process because `default_vfio_cfg->vfio_enabled = 0` and
> >> `default_vfio_cfg->vfio_container_fd = -1`, socket error will
> >> be set in DPDK primary process when it sync this info to
> >> the secondary process.
> >> This patch use to skip this kind of useless detection for this
> >> scenario.
> >>
> >> Signed-off-by: Yang Ming <ming.1.yang@nokia-sbell.com>
> >> ---
> >>   lib/eal/linux/eal_vfio.c | 11 +++++++++++
> >>   1 file changed, 11 insertions(+)
> >>
> >> diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c
> >> index 7132e24cba..1679d29263 100644
> >> --- a/lib/eal/linux/eal_vfio.c
> >> +++ b/lib/eal/linux/eal_vfio.c
> >> @@ -7,6 +7,7 @@
> >>   #include <fcntl.h>
> >>   #include <unistd.h>
> >>   #include <sys/ioctl.h>
> >> +#include <dirent.h>
> >>   
> >>   #include <rte_errno.h>
> >>   #include <rte_log.h>
> >> @@ -1083,6 +1084,7 @@ rte_vfio_enable(const char *modname)
> >>   	/* initialize group list */
> >>   	int i, j;
> >>   	int vfio_available;
> >> +	DIR *dir;
> >>   	const struct internal_config *internal_conf =
> >>   		eal_get_internal_configuration();
> >>   
> >> @@ -1119,6 +1121,15 @@ rte_vfio_enable(const char *modname)
> >>   		return 0;
> >>   	}
> >>   
> >> +	/* return 0 if VFIO directory not exist for container with non-privileged mode */
> >> +	dir = opendir(VFIO_DIR);
> >> +	if (dir == NULL) {
> >> +		EAL_LOG(DEBUG,
> >> +			"VFIO directory not exist, skipping VFIO support...");
> >> +		return 0;
> >> +	}
> >> +	closedir(dir);  
> > You need to test the non-container cases.
> > If vfio is loaded /dev/vfio is a character device (not a directory)
> >
> > Also looks suspicious that VFIO_DIR is defined but never used currently.
> >  
> Hi Stephen,
> For non-container test, /dev/vfio/vfio will be character device, not 
> /dev/vfio.
> Here is the command result on my testing environment with Intel NIC.
> 
> [root@computer-1 testuser]# ls -l /dev/vfio
> total 0
> crw-rw-rw-. 1 root root 10, 196 Jan 22 01:50 vfio
> [root@computer-1 testuser]# dpdk-devbind.py -b vfio-pci 0000:04:10.2
> [root@computer-1 testuser]# ls -l /dev/vfio
> total 0
> crw-------. 1 root root 239,   0 Jan 22 01:52 59
> crw-rw-rw-. 1 root root  10, 196 Jan 22 01:50 vfio
> [root@computer-1 testuser]# dpdk-devbind.py -b ixgbevf 0000:04:10.2
> [root@computer-1 testuser]# ls -l /dev/vfio
> total 0
> crw-rw-rw-. 1 root root 10, 196 Jan 22 01:50 vfio
> 
> Can you confirm your test scenario?
> 
> 

When vfio-pci is loaded but no device bound:
$ ls -l /dev/vfio
total 0
crw-rw-rw- 1 root root 10, 196 Feb 26 05:39 vfio

After binding device
$ ls -l /dev/vfio
total 0
crw------- 1 root root 511,   0 Feb 26 05:42 15
crw-rw-rw- 1 root root  10, 196 Feb 26 05:39 vfio

So testing for /dev/vfio is good indication that module is loaded.
Not sure what I was thinking earlier.





  parent reply	other threads:[~2025-02-26 13:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-17  7:28 [PATCH] Skip vfio in the scenario of non-privileged mode Yang Ming
2025-01-17 16:47 ` Stephen Hemminger
2025-01-22  8:15   ` Yang Ming
2025-02-26  3:10     ` Yang Ming
2025-02-26 13:45     ` Stephen Hemminger [this message]
2025-02-28  5:23       ` Yang Ming
2025-03-27  7:57 ` [PATCH v2] eal/linux: skip vfio for non-privileged container Yang Ming
2025-05-16  6:46   ` David Marchand
2025-05-16 11:08     ` Moses Young
2025-05-16 13:30   ` Burakov, Anatoly
2025-05-17  7:55     ` Moses Young
2025-05-17  8:15   ` [PATCH] Skip vfio in the scenario of non-privileged mode Yang Ming
2025-05-17  8:21   ` [PATCH v3] " Yang Ming
2025-05-17  8:32   ` [PATCH v4] eal/linux: skip vfio for non-privileged container Yang Ming
2025-06-04 17:34     ` David Marchand

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=20250226054540.166dfd43@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=ming.1.yang@nokia-sbell.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.