* [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open
@ 2018-09-17 13:46 Darek Stojaczyk
2018-09-17 13:46 ` [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd Darek Stojaczyk
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Darek Stojaczyk @ 2018-09-17 13:46 UTC (permalink / raw)
To: dev
Cc: Alejandro Lucero, Anatoly Burakov, stable, Dariusz Stojaczyk,
xiao.w.wang
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd
2018-09-17 13:46 [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Darek Stojaczyk
@ 2018-09-17 13:46 ` Darek Stojaczyk
2018-09-26 12:34 ` Burakov, Anatoly
2018-09-25 7:56 ` [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Wang, Xiao W
2018-09-26 12:35 ` Burakov, Anatoly
2 siblings, 1 reply; 6+ messages in thread
From: Darek Stojaczyk @ 2018-09-17 13:46 UTC (permalink / raw)
To: dev; +Cc: Alejandro Lucero, Anatoly Burakov, stable, Dariusz Stojaczyk
From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Factor out duplicated code.
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_vfio.c | 119 ++++++++++---------------
1 file changed, 45 insertions(+), 74 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index bcb869be1..3e93a7934 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -345,46 +345,13 @@ get_vfio_cfg_by_group_num(int iommu_group_num)
return NULL;
}
-static struct vfio_config *
-get_vfio_cfg_by_group_fd(int vfio_group_fd)
-{
- struct vfio_config *vfio_cfg;
- int i, j;
-
- for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
- vfio_cfg = &vfio_cfgs[i];
- for (j = 0; j < VFIO_MAX_GROUPS; j++)
- if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd)
- return vfio_cfg;
- }
-
- return NULL;
-}
-
-static struct vfio_config *
-get_vfio_cfg_by_container_fd(int container_fd)
-{
- int i;
-
- for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
- if (vfio_cfgs[i].vfio_container_fd == container_fd)
- return &vfio_cfgs[i];
- }
-
- return NULL;
-}
-
-int
-rte_vfio_get_group_fd(int iommu_group_num)
+static int
+vfio_get_group_fd(struct vfio_config *vfio_cfg,
+ int iommu_group_num)
{
int i;
int vfio_group_fd;
struct vfio_group *cur_grp;
- struct vfio_config *vfio_cfg;
-
- /* get the vfio_config it belongs to */
- vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num);
- vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg;
/* check if we already have the group descriptor open */
for (i = 0; i < VFIO_MAX_GROUPS; i++)
@@ -423,6 +390,47 @@ rte_vfio_get_group_fd(int iommu_group_num)
return vfio_group_fd;
}
+static struct vfio_config *
+get_vfio_cfg_by_group_fd(int vfio_group_fd)
+{
+ struct vfio_config *vfio_cfg;
+ int i, j;
+
+ for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
+ vfio_cfg = &vfio_cfgs[i];
+ for (j = 0; j < VFIO_MAX_GROUPS; j++)
+ if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd)
+ return vfio_cfg;
+ }
+
+ return NULL;
+}
+
+static struct vfio_config *
+get_vfio_cfg_by_container_fd(int container_fd)
+{
+ int i;
+
+ for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
+ if (vfio_cfgs[i].vfio_container_fd == container_fd)
+ return &vfio_cfgs[i];
+ }
+
+ return NULL;
+}
+
+int
+rte_vfio_get_group_fd(int iommu_group_num)
+{
+ struct vfio_config *vfio_cfg;
+
+ /* get the vfio_config it belongs to */
+ vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num);
+ vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg;
+
+ return vfio_get_group_fd(vfio_cfg, iommu_group_num);
+}
+
static int
get_vfio_group_idx(int vfio_group_fd)
{
@@ -1670,9 +1678,6 @@ int
rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
{
struct vfio_config *vfio_cfg;
- struct vfio_group *cur_grp;
- int vfio_group_fd;
- int i;
vfio_cfg = get_vfio_cfg_by_container_fd(container_fd);
if (vfio_cfg == NULL) {
@@ -1680,41 +1685,7 @@ 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");
- return -1;
- }
-
- /* Get an index for the new group */
- for (i = 0; i < VFIO_MAX_GROUPS; i++)
- if (vfio_cfg->vfio_groups[i].group_num == -1) {
- cur_grp = &vfio_cfg->vfio_groups[i];
- break;
- }
-
- /* This should not happen */
- if (i == VFIO_MAX_GROUPS) {
- RTE_LOG(ERR, EAL, "No VFIO group free slot found\n");
- return -1;
- }
-
- vfio_group_fd = vfio_open_group_fd(iommu_group_num);
- if (vfio_group_fd < 0) {
- RTE_LOG(ERR, EAL, "Failed to open group %d\n", iommu_group_num);
- return -1;
- }
- cur_grp->group_num = iommu_group_num;
- cur_grp->fd = vfio_group_fd;
- cur_grp->devices = 0;
- vfio_cfg->vfio_active_groups++;
-
- return vfio_group_fd;
+ return vfio_get_group_fd(vfio_cfg, iommu_group_num);
}
int
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open
2018-09-17 13:46 [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Darek Stojaczyk
2018-09-17 13:46 ` [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd Darek Stojaczyk
@ 2018-09-25 7:56 ` Wang, Xiao W
2018-10-29 0:26 ` Thomas Monjalon
2018-09-26 12:35 ` Burakov, Anatoly
2 siblings, 1 reply; 6+ messages in thread
From: Wang, Xiao W @ 2018-09-25 7:56 UTC (permalink / raw)
To: Stojaczyk, Dariusz, dev; +Cc: Alejandro Lucero, Burakov, Anatoly, stable
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd
2018-09-17 13:46 ` [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd Darek Stojaczyk
@ 2018-09-26 12:34 ` Burakov, Anatoly
0 siblings, 0 replies; 6+ messages in thread
From: Burakov, Anatoly @ 2018-09-26 12:34 UTC (permalink / raw)
To: Darek Stojaczyk, dev; +Cc: Alejandro Lucero, stable, Dariusz Stojaczyk
On 17-Sep-18 2:46 PM, Darek Stojaczyk wrote:
> From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
>
> Factor out duplicated code.
>
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---
<snip>
> +
> +int
> +rte_vfio_get_group_fd(int iommu_group_num)
> +{
> + struct vfio_config *vfio_cfg;
> +
> + /* get the vfio_config it belongs to */
> + vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num);
> + vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg;
I tend to prefer being explicit rather than implicit (i.e. 'vfio_cfg ==
NULL' instead of 'vfio_cfg').
Otherwise,
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
--
Thanks,
Anatoly
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open
2018-09-17 13:46 [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Darek Stojaczyk
2018-09-17 13:46 ` [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd Darek Stojaczyk
2018-09-25 7:56 ` [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Wang, Xiao W
@ 2018-09-26 12:35 ` Burakov, Anatoly
2 siblings, 0 replies; 6+ messages in thread
From: Burakov, Anatoly @ 2018-09-26 12:35 UTC (permalink / raw)
To: Darek Stojaczyk, dev
Cc: Alejandro Lucero, stable, Dariusz Stojaczyk, xiao.w.wang
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>
--
Thanks,
Anatoly
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open
2018-09-25 7:56 ` [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Wang, Xiao W
@ 2018-10-29 0:26 ` Thomas Monjalon
0 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2018-10-29 0:26 UTC (permalink / raw)
To: Stojaczyk, Dariusz
Cc: dev, Wang, Xiao W, Alejandro Lucero, Burakov, Anatoly, stable
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-10-29 0:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17 13:46 [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Darek Stojaczyk
2018-09-17 13:46 ` [dpdk-dev] [PATCH 2/2] eal/vfio: cleanup getting group fd Darek Stojaczyk
2018-09-26 12:34 ` Burakov, Anatoly
2018-09-25 7:56 ` [dpdk-dev] [PATCH 1/2] eal/vfio: check if we already have the group fd open Wang, Xiao W
2018-10-29 0:26 ` Thomas Monjalon
2018-09-26 12:35 ` Burakov, Anatoly
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).