diff mbox series

[RFC] bus/fslmc: fix invalid use of default vfio config

Message ID CAC9qv4BEL9c80k7s6SF6n53v_kXU=EvuOC2CHSNOZpqyPavfDw@mail.gmail.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series [RFC] bus/fslmc: fix invalid use of default vfio config | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Romain Delhomel May 27, 2022, 8:28 a.m. UTC
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(-)

Comments

Romain Delhomel May 27, 2022, 8:34 a.m. UTC | #1
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
>
Romain Delhomel May 27, 2022, 8:38 a.m. UTC | #2
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
>>
>
diff mbox series

Patch

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;