From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CE76CA055F; Fri, 27 May 2022 10:28:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C2F4B42684; Fri, 27 May 2022 10:28:55 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id C13D142685 for ; Fri, 27 May 2022 10:28:50 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id b135so3742693pfb.12 for ; Fri, 27 May 2022 01:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=VNfxoHbA09oYB6XIJPLW0jkwMbmCoVUUHHmt73e6sRo=; b=hebArODjPNsv+vv+eBHQ5pFoAih6AHygwid4jqxu3jDZKsbmgMwnkC8cBSOEXvalFC u1xadzEYEb4Nt99O0j7hzyh+UEjxDHjpm4cKNfAm/BlljQjM+k7EgievK50ulG3ESaDA eQvekdPHTNozEl2hMA6xOSxzT70fnem/8GbTOfu9O/1HIDylVtfHbS05Uow1Qc1mxi7g iDGxPwliRxPxndmzKD4y2zJ2AnGPaoQS+ZEAgVSQIOx2Z+a2RfWa/8ykYcv7ncJQ50Y4 /5NHwctyNBsbxKcgTttmzbhTpjuGhjwU47Mje1+qPe0w9ioVjQzFP0gCcs7tjKXbe7ke uo/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=VNfxoHbA09oYB6XIJPLW0jkwMbmCoVUUHHmt73e6sRo=; b=PkYELLoNaqTV9GYFeYJZd2/zqMDf0xslWCSgkddW5pm8mnav8tuNvDvBFaH9/udRic TScDF5v5SIYo1/g40/kvq0flSJSqxa9StNV8M1XsgrdTPpsNKRBkCLQn/WJBkpfxofrs yy8w4HWrYz4yjRFrAPucK+M2tbulQu/e1+FPBg61Yz6cS9nHm9VuEGJy/woIxHAXLLht /kcLdrJHQs1gZXwf2njcSXOiM+e6RzcdZRzkLKJNb0ztvg/H2BEJ8Geay5OQsYQuJrFB xUYxC2bPj6dAKeOPb+nP8vlFoNwvk5fpQumEed0ntjZeyg1hCEuZiU4+Hdn2/O9F1rFO X8MQ== X-Gm-Message-State: AOAM532SyDgjF7YUusmx1SWQOpwjFWBdQX7u+SQg/C1wh/4HJK2VTfNM ObOwWsmE+ONPRmLV2yHMrdaxyALxMogUSChUsCFqYF6ctNJIDA== X-Google-Smtp-Source: ABdhPJwyGWbym56niZIF9O54vvcpZEITS0fshd90qc7uSI1N0rN04o0sfJwB5ih1IFP2n07Ru2xXQdpmdMlzqYiAFnk= X-Received: by 2002:a05:6a00:16c7:b0:4f7:e497:69b8 with SMTP id l7-20020a056a0016c700b004f7e49769b8mr42234478pfc.6.1653640129992; Fri, 27 May 2022 01:28:49 -0700 (PDT) MIME-Version: 1.0 From: Romain Delhomel Date: Fri, 27 May 2022 10:28:38 +0200 Message-ID: Subject: [RFC] bus/fslmc: fix invalid use of default vfio config To: hemant.agrawal@nxp.com, sachin.saxena@oss.nxp.com Cc: dev@dpdk.org, Olivier Matz Content-Type: multipart/alternative; boundary="00000000000088f03305dffa184b" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org --00000000000088f03305dffa184b Content-Type: text/plain; charset="UTF-8" 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 --- 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 --00000000000088f03305dffa184b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
At device probe, the fslmc bus driver calls rte_vfio_get_g= roup_fd() to
get a fd associated to a vfio group. This function first ch= ecks if the
group is already opened, else it opens /dev/vfio/%u, and inc= reases the
number of active groups in default_vfio_cfg (which references= the
default vfio container).

When adding the first group to a vf= io_cfg, the caller is supposed to
pick an IOMMU type and set up DMA mapp= ings 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.

T= his patch fixes the issue by always creating a new container (and its
as= sociated vfio_cfg) and bind the group to it.

Fixes: a69f79300262 (&q= uot;bus/fslmc: support multi VFIO group")
Signed-off-by: Romain Del= homel <romain.delhomel@6win= d.com>
---
=C2=A0drivers/bus/fslmc/fslmc_vfio.c | 10 +++++++++= -
=C2=A01 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<= br>+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -979,6 +979,7 @@ fslmc_vfio_s= etup_group(void)
=C2=A0{
=C2=A0 int groupid;
=C2=A0 int ret;
+ = int vfio_container_fd;
=C2=A0 struct vfio_group_status status =3D { .arg= sz =3D sizeof(status) };
=C2=A0
=C2=A0 /* if already done once */
= @@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
=C2=A0 return 0;
= =C2=A0 }
=C2=A0
+ ret =3D rte_vfio_container_create();
+ if (ret &= lt; 0) {
+ DPAA2_BUS_ERR("Failed to open VFIO container");+ return ret;
+ }
+ vfio_container_fd =3D ret;
+
=C2=A0 /* Ge= t the actual group fd */
- ret =3D rte_vfio_get_group_fd(groupid);
+ = ret =3D rte_vfio_container_group_bind(vfio_container_fd, groupid);
=C2= =A0 if (ret < 0)
=C2=A0 return ret;
=C2=A0 vfio_group.fd =3D ret;=
--
2.30.2
--00000000000088f03305dffa184b--