All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] bus/fslmc: fix invalid use of default vfio config
@ 2022-05-27  8:28 Romain Delhomel
  2022-05-27  8:34 ` Romain Delhomel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Romain Delhomel @ 2022-05-27  8:28 UTC (permalink / raw)
  To: hemant.agrawal, sachin.saxena; +Cc: dev, Olivier Matz

[-- Attachment #1: Type: text/plain, Size: 1825 bytes --]

At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
get a fd associated to a vfio group. This function first checks if the
group is already opened, else it opens /dev/vfio/%u, and increases the
number of active groups in default_vfio_cfg (which references the
default vfio container).

When adding the first group to a vfio_cfg, the caller is supposed to
pick an IOMMU type and set up DMA mappings for container, as it's done
by pci bus, but it is not done here. Instead, a new container is created
and used.

This prevents the pci bus driver, which use the default_vfio_cfg
container, to configure the container because
default_vfio_cfg->active_group > 1.

This patch fixes the issue by always creating a new container (and its
associated vfio_cfg) and bind the group to it.

Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
---
 drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index b4704eeae4e2..abe1cab2ee20 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
 {
  int groupid;
  int ret;
+ int vfio_container_fd;
  struct vfio_group_status status = { .argsz = sizeof(status) };

  /* if already done once */
@@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
  return 0;
  }

+ ret = rte_vfio_container_create();
+ if (ret < 0) {
+ DPAA2_BUS_ERR("Failed to open VFIO container");
+ return ret;
+ }
+ vfio_container_fd = ret;
+
  /* Get the actual group fd */
- ret = rte_vfio_get_group_fd(groupid);
+ ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
  if (ret < 0)
  return ret;
  vfio_group.fd = ret;
-- 
2.30.2

[-- Attachment #2: Type: text/html, Size: 2119 bytes --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC] bus/fslmc: fix invalid use of default vfio config
  2022-05-27  8:28 [RFC] bus/fslmc: fix invalid use of default vfio config Romain Delhomel
@ 2022-05-27  8:34 ` Romain Delhomel
  2022-05-27  8:38   ` Romain Delhomel
  2022-05-31  9:27 ` [RFC v2] bus/fslmc: fix invalid use of default VFIO config Romain Delhomel
  2022-06-03 15:18 ` [PATCH] " Romain Delhomel
  2 siblings, 1 reply; 7+ messages in thread
From: Romain Delhomel @ 2022-05-27  8:34 UTC (permalink / raw)
  To: hemant.agrawal, sachin.saxena
  Cc: dev, Olivier Matz, stephane gonauer, Guillaume Gaudonville

[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]

On Fri, May 27, 2022 at 10:28 AM Romain Delhomel <romain.delhomel@6wind.com>
wrote:

> At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
> get a fd associated to a vfio group. This function first checks if the
> group is already opened, else it opens /dev/vfio/%u, and increases the
> number of active groups in default_vfio_cfg (which references the
> default vfio container).
>
> When adding the first group to a vfio_cfg, the caller is supposed to
> pick an IOMMU type and set up DMA mappings for container, as it's done
> by pci bus, but it is not done here. Instead, a new container is created
> and used.
>
> This prevents the pci bus driver, which use the default_vfio_cfg
> container, to configure the container because
> default_vfio_cfg->active_group > 1.
>
> This patch fixes the issue by always creating a new container (and its
> associated vfio_cfg) and bind the group to it.
>
> Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
> Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
> ---
>  drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bus/fslmc/fslmc_vfio.c
> b/drivers/bus/fslmc/fslmc_vfio.c
> index b4704eeae4e2..abe1cab2ee20 100644
> --- a/drivers/bus/fslmc/fslmc_vfio.c
> +++ b/drivers/bus/fslmc/fslmc_vfio.c
> @@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
>  {
>   int groupid;
>   int ret;
> + int vfio_container_fd;
>   struct vfio_group_status status = { .argsz = sizeof(status) };
>
>   /* if already done once */
> @@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
>   return 0;
>   }
>
> + ret = rte_vfio_container_create();
> + if (ret < 0) {
> + DPAA2_BUS_ERR("Failed to open VFIO container");
> + return ret;
> + }
> + vfio_container_fd = ret;
> +
>   /* Get the actual group fd */
> - ret = rte_vfio_get_group_fd(groupid);
> + ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
>   if (ret < 0)
>   return ret;
>   vfio_group.fd = ret;
> --
> 2.30.2
>

[-- Attachment #2: Type: text/html, Size: 2511 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC] bus/fslmc: fix invalid use of default vfio config
  2022-05-27  8:34 ` Romain Delhomel
@ 2022-05-27  8:38   ` Romain Delhomel
  0 siblings, 0 replies; 7+ messages in thread
From: Romain Delhomel @ 2022-05-27  8:38 UTC (permalink / raw)
  To: hemant.agrawal, sachin.saxena
  Cc: dev, Olivier Matz, stephane gonauer, Guillaume Gaudonville,
	Elias Boutaleb

[-- Attachment #1: Type: text/plain, Size: 2170 bytes --]

On Fri, May 27, 2022 at 10:34 AM Romain Delhomel <romain.delhomel@6wind.com>
wrote:

>
>
> On Fri, May 27, 2022 at 10:28 AM Romain Delhomel <
> romain.delhomel@6wind.com> wrote:
>
>> At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
>> get a fd associated to a vfio group. This function first checks if the
>> group is already opened, else it opens /dev/vfio/%u, and increases the
>> number of active groups in default_vfio_cfg (which references the
>> default vfio container).
>>
>> When adding the first group to a vfio_cfg, the caller is supposed to
>> pick an IOMMU type and set up DMA mappings for container, as it's done
>> by pci bus, but it is not done here. Instead, a new container is created
>> and used.
>>
>> This prevents the pci bus driver, which use the default_vfio_cfg
>> container, to configure the container because
>> default_vfio_cfg->active_group > 1.
>>
>> This patch fixes the issue by always creating a new container (and its
>> associated vfio_cfg) and bind the group to it.
>>
>> Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
>> Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
>> ---
>>  drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/bus/fslmc/fslmc_vfio.c
>> b/drivers/bus/fslmc/fslmc_vfio.c
>> index b4704eeae4e2..abe1cab2ee20 100644
>> --- a/drivers/bus/fslmc/fslmc_vfio.c
>> +++ b/drivers/bus/fslmc/fslmc_vfio.c
>> @@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
>>  {
>>   int groupid;
>>   int ret;
>> + int vfio_container_fd;
>>   struct vfio_group_status status = { .argsz = sizeof(status) };
>>
>>   /* if already done once */
>> @@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
>>   return 0;
>>   }
>>
>> + ret = rte_vfio_container_create();
>> + if (ret < 0) {
>> + DPAA2_BUS_ERR("Failed to open VFIO container");
>> + return ret;
>> + }
>> + vfio_container_fd = ret;
>> +
>>   /* Get the actual group fd */
>> - ret = rte_vfio_get_group_fd(groupid);
>> + ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
>>   if (ret < 0)
>>   return ret;
>>   vfio_group.fd = ret;
>> --
>> 2.30.2
>>
>

[-- Attachment #2: Type: text/html, Size: 2903 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC v2] bus/fslmc: fix invalid use of default VFIO config
  2022-05-27  8:28 [RFC] bus/fslmc: fix invalid use of default vfio config Romain Delhomel
  2022-05-27  8:34 ` Romain Delhomel
@ 2022-05-31  9:27 ` Romain Delhomel
  2022-06-03 13:58   ` Hemant Agrawal
  2022-06-03 15:18 ` [PATCH] " Romain Delhomel
  2 siblings, 1 reply; 7+ messages in thread
From: Romain Delhomel @ 2022-05-31  9:27 UTC (permalink / raw)
  To: hemant.agrawal, sachin.saxena
  Cc: dev, olivier.matz, stephane.gonauer, guillaume.gaudonville,
	elias.boutaleb

At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
get a fd associated to a vfio group. This function first checks if the
group is already opened, else it opens /dev/vfio/%u, and increases the
number of active groups in default_vfio_cfg (which references the
default vfio container).

When adding the first group to a vfio_cfg, the caller is supposed to
pick an IOMMU type and set up DMA mappings for container, as it's done
by pci bus, but it is not done here. Instead, a new container is created
and used.

This prevents the pci bus driver, which uses the default_vfio_cfg
container, to configure the container because
default_vfio_cfg->active_group > 1.

This patch fixes the issue by always creating a new container (and its
associated vfio_cfg) and binding the group to it.

Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
---
v2:
* Fix wrong indentation

 drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index b4704eeae4e2..abe1cab2ee20 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
 {
 	int groupid;
 	int ret;
+	int vfio_container_fd;
 	struct vfio_group_status status = { .argsz = sizeof(status) };
 
 	/* if already done once */
@@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
 		return 0;
 	}
 
+	ret = rte_vfio_container_create();
+	if (ret < 0) {
+		DPAA2_BUS_ERR("Failed to open VFIO container");
+		return ret;
+	}
+	vfio_container_fd = ret;
+
 	/* Get the actual group fd */
-	ret = rte_vfio_get_group_fd(groupid);
+	ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
 	if (ret < 0)
 		return ret;
 	vfio_group.fd = ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC v2] bus/fslmc: fix invalid use of default VFIO config
  2022-05-31  9:27 ` [RFC v2] bus/fslmc: fix invalid use of default VFIO config Romain Delhomel
@ 2022-06-03 13:58   ` Hemant Agrawal
  0 siblings, 0 replies; 7+ messages in thread
From: Hemant Agrawal @ 2022-06-03 13:58 UTC (permalink / raw)
  To: Romain Delhomel, hemant.agrawal, sachin.saxena
  Cc: dev, olivier.matz, stephane.gonauer, guillaume.gaudonville,
	elias.boutaleb

Tested ok

Acked-by:  Hemant Agrawal <hemant.agrawal@nxp.com>

On 5/31/2022 2:57 PM, Romain Delhomel wrote:
> At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
> get a fd associated to a vfio group. This function first checks if the
> group is already opened, else it opens /dev/vfio/%u, and increases the
> number of active groups in default_vfio_cfg (which references the
> default vfio container).
>
> When adding the first group to a vfio_cfg, the caller is supposed to
> pick an IOMMU type and set up DMA mappings for container, as it's done
> by pci bus, but it is not done here. Instead, a new container is created
> and used.
>
> This prevents the pci bus driver, which uses the default_vfio_cfg
> container, to configure the container because
> default_vfio_cfg->active_group > 1.
>
> This patch fixes the issue by always creating a new container (and its
> associated vfio_cfg) and binding the group to it.
>
> Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
> Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
> ---
> v2:
> * Fix wrong indentation
>
>   drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
> index b4704eeae4e2..abe1cab2ee20 100644
> --- a/drivers/bus/fslmc/fslmc_vfio.c
> +++ b/drivers/bus/fslmc/fslmc_vfio.c
> @@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
>   {
>   	int groupid;
>   	int ret;
> +	int vfio_container_fd;
>   	struct vfio_group_status status = { .argsz = sizeof(status) };
>   
>   	/* if already done once */
> @@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
>   		return 0;
>   	}
>   
> +	ret = rte_vfio_container_create();
> +	if (ret < 0) {
> +		DPAA2_BUS_ERR("Failed to open VFIO container");
> +		return ret;
> +	}
> +	vfio_container_fd = ret;
> +
>   	/* Get the actual group fd */
> -	ret = rte_vfio_get_group_fd(groupid);
> +	ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
>   	if (ret < 0)
>   		return ret;
>   	vfio_group.fd = ret;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] bus/fslmc: fix invalid use of default VFIO config
  2022-05-27  8:28 [RFC] bus/fslmc: fix invalid use of default vfio config Romain Delhomel
  2022-05-27  8:34 ` Romain Delhomel
  2022-05-31  9:27 ` [RFC v2] bus/fslmc: fix invalid use of default VFIO config Romain Delhomel
@ 2022-06-03 15:18 ` Romain Delhomel
  2022-06-07 15:41   ` Thomas Monjalon
  2 siblings, 1 reply; 7+ messages in thread
From: Romain Delhomel @ 2022-06-03 15:18 UTC (permalink / raw)
  To: dev
  Cc: elias.boutaleb, guillaume.gaudonville, hemant.agrawal,
	olivier.matz, sachin.saxena, stephane.gonauer, stable

At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
get a fd associated to a vfio group. This function first checks if the
group is already opened, else it opens /dev/vfio/%u, and increases the
number of active groups in default_vfio_cfg (which references the
default vfio container).

When adding the first group to a vfio_cfg, the caller is supposed to
pick an IOMMU type and set up DMA mappings for container, as it's done
by pci bus, but it is not done here. Instead, a new container is created
and used.

This prevents the pci bus driver, which uses the default_vfio_cfg
container, to configure the container because
default_vfio_cfg->active_group > 1.

This patch fixes the issue by always creating a new container (and its
associated vfio_cfg) and binding the group to it.

Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
Cc: stable@dpdk.org

Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index b4704eeae4e2..abe1cab2ee20 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -979,6 +979,7 @@ fslmc_vfio_setup_group(void)
 {
 	int groupid;
 	int ret;
+	int vfio_container_fd;
 	struct vfio_group_status status = { .argsz = sizeof(status) };
 
 	/* if already done once */
@@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
 		return 0;
 	}
 
+	ret = rte_vfio_container_create();
+	if (ret < 0) {
+		DPAA2_BUS_ERR("Failed to open VFIO container");
+		return ret;
+	}
+	vfio_container_fd = ret;
+
 	/* Get the actual group fd */
-	ret = rte_vfio_get_group_fd(groupid);
+	ret = rte_vfio_container_group_bind(vfio_container_fd, groupid);
 	if (ret < 0)
 		return ret;
 	vfio_group.fd = ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] bus/fslmc: fix invalid use of default VFIO config
  2022-06-03 15:18 ` [PATCH] " Romain Delhomel
@ 2022-06-07 15:41   ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2022-06-07 15:41 UTC (permalink / raw)
  To: Romain Delhomel
  Cc: dev, elias.boutaleb, guillaume.gaudonville, hemant.agrawal,
	olivier.matz, sachin.saxena, stephane.gonauer, stable

03/06/2022 17:18, Romain Delhomel:
> At device probe, the fslmc bus driver calls rte_vfio_get_group_fd() to
> get a fd associated to a vfio group. This function first checks if the
> group is already opened, else it opens /dev/vfio/%u, and increases the
> number of active groups in default_vfio_cfg (which references the
> default vfio container).
> 
> When adding the first group to a vfio_cfg, the caller is supposed to
> pick an IOMMU type and set up DMA mappings for container, as it's done
> by pci bus, but it is not done here. Instead, a new container is created
> and used.
> 
> This prevents the pci bus driver, which uses the default_vfio_cfg
> container, to configure the container because
> default_vfio_cfg->active_group > 1.
> 
> This patch fixes the issue by always creating a new container (and its
> associated vfio_cfg) and binding the group to it.
> 
> Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Romain Delhomel <romain.delhomel@6wind.com>
> Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

Applied, thanks.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-07 15:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27  8:28 [RFC] bus/fslmc: fix invalid use of default vfio config Romain Delhomel
2022-05-27  8:34 ` Romain Delhomel
2022-05-27  8:38   ` Romain Delhomel
2022-05-31  9:27 ` [RFC v2] bus/fslmc: fix invalid use of default VFIO config Romain Delhomel
2022-06-03 13:58   ` Hemant Agrawal
2022-06-03 15:18 ` [PATCH] " Romain Delhomel
2022-06-07 15:41   ` Thomas Monjalon

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.