[1/2] eal/vfio: check if we already have the group fd open

Message ID 20180917134643.103871-1-dariusz.stojaczyk@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [1/2] eal/vfio: check if we already have the group fd open |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Stojaczyk, Dariusz Sept. 17, 2018, 1:46 p.m. UTC
  From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>

Always attempt to find already opened fd for an iommu
group as subsequent attempts to open it will fail.

There's no public API to check if a group was already
bound and has a container, so rte_vfio_container_group_bind()
shouldn't fail in such case.

Fixes: ea2dc1066870 ("vfio: add multi container support")
Cc: xiao.w.wang@intel.com

Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_vfio.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Xiao Wang Sept. 25, 2018, 7:56 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Stojaczyk, Dariusz
> Sent: Monday, September 17, 2018 9:47 PM
> To: dev@dpdk.org
> Cc: Alejandro Lucero <alejandro.lucero@netronome.com>; Burakov, Anatoly
> <anatoly.burakov@intel.com>; stable@dpdk.org; Stojaczyk, Dariusz
> <dariusz.stojaczyk@intel.com>; Wang, Xiao W <xiao.w.wang@intel.com>
> Subject: [PATCH 1/2] eal/vfio: check if we already have the group fd open
> 
> From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> 
> Always attempt to find already opened fd for an iommu
> group as subsequent attempts to open it will fail.
> 
> There's no public API to check if a group was already
> bound and has a container, so rte_vfio_container_group_bind()
> shouldn't fail in such case.
> 
> Fixes: ea2dc1066870 ("vfio: add multi container support")
> Cc: xiao.w.wang@intel.com
> 
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---
>  lib/librte_eal/linuxapp/eal/eal_vfio.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> index c68dc38e0..bcb869be1 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -1680,6 +1680,11 @@ rte_vfio_container_group_bind(int container_fd,
> int iommu_group_num)
>  		return -1;
>  	}
> 
> +	/* check if we already have the group descriptor open */
> +	for (i = 0; i < VFIO_MAX_GROUPS; i++)
> +		if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num)
> +			return vfio_cfg->vfio_groups[i].fd;
> +
>  	/* Check room for new group */
>  	if (vfio_cfg->vfio_active_groups == VFIO_MAX_GROUPS) {
>  		RTE_LOG(ERR, EAL, "Maximum number of VFIO groups
> reached!\n");
> --
> 2.17.1

Acked-by: Xiao Wang <xiao.w.wang@intel.com>

BRs,
Xiao
  
Burakov, Anatoly Sept. 26, 2018, 12:35 p.m. UTC | #2
On 17-Sep-18 2:46 PM, Darek Stojaczyk wrote:
> From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> 
> Always attempt to find already opened fd for an iommu
> group as subsequent attempts to open it will fail.
> 
> There's no public API to check if a group was already
> bound and has a container, so rte_vfio_container_group_bind()
> shouldn't fail in such case.
> 
> Fixes: ea2dc1066870 ("vfio: add multi container support")
> Cc: xiao.w.wang@intel.com
> 
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon Oct. 29, 2018, 12:26 a.m. UTC | #3
25/09/2018 09:56, Wang, Xiao W:
> Hi,
> 
> > From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> > 
> > Always attempt to find already opened fd for an iommu
> > group as subsequent attempts to open it will fail.
> > 
> > There's no public API to check if a group was already
> > bound and has a container, so rte_vfio_container_group_bind()
> > shouldn't fail in such case.
> > 
> > Fixes: ea2dc1066870 ("vfio: add multi container support")
> > Cc: xiao.w.wang@intel.com
> > 
> > Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> 
> Acked-by: Xiao Wang <xiao.w.wang@intel.com>

+Cc: stable@dpdk.org

Series applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index c68dc38e0..bcb869be1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -1680,6 +1680,11 @@  rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
 		return -1;
 	}
 
+	/* check if we already have the group descriptor open */
+	for (i = 0; i < VFIO_MAX_GROUPS; i++)
+		if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num)
+			return vfio_cfg->vfio_groups[i].fd;
+
 	/* Check room for new group */
 	if (vfio_cfg->vfio_active_groups == VFIO_MAX_GROUPS) {
 		RTE_LOG(ERR, EAL, "Maximum number of VFIO groups reached!\n");