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 74EA2A055F; Fri, 27 May 2022 10:34:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2F29040E5A; Fri, 27 May 2022 10:34:24 +0200 (CEST) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mails.dpdk.org (Postfix) with ESMTP id 0B9AC4003F for ; Fri, 27 May 2022 10:34:23 +0200 (CEST) Received: by mail-pj1-f42.google.com with SMTP id l20-20020a17090a409400b001dd2a9d555bso3798449pjg.0 for ; Fri, 27 May 2022 01:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=msMXl7ugiRz6fT1ZkafXjQ2X4GiByeDLyj581Rvlcpk=; b=BeqxBEdJCfb2jtfhZqFj/kFX1ZWh4ojN0Vyd4mXoga08qc/I1io+ysDPeCMkRslylZ qJxCVYpNIZ1III8gs4mmuF/mPMAIXu4pr5D+nJoBjHC/gBLtBx/UQDwPzOjMqr1t0mmw dDFxAZ17OO2V07FqNbp3kL2oBHgmaaUW78PkXB7J6j+n25KS91lNH0XiYt6Nvn/P9mNX iCswtrNkDxZCdlDwTGatGet5fQdK+T/WomFaNr8uv45D2YvXmM8x2XPPNyqKUu+hFnse UHD/69sVcIRGPtT+RboaZNvsiRv9yf03sUyXtf1Hv428T3LhWBnaT5sGPovM+5nGl13c j7yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=msMXl7ugiRz6fT1ZkafXjQ2X4GiByeDLyj581Rvlcpk=; b=WkX2MTN4q8VZN2OJCUJ4rORTOiW1Lvdf723kgkt2VREnyMtMaBSNKEdJ5Ymq3UDUXj zXJqZrTzcyLc+o57wUJqSRsikjuJbXJhQRJpMbC4K6Ej/6qpEpTfFaNpJFSsGp06MR5d kAB78aQ/22dMWro4oooehHJkj97sSvQ6jUhGZPDbq/T3XQLQaFfRhN/FZwmX4snUJ2Zh raqKm37cZ2tGdWqufRSp25xqp4adfkYQmfifynsGbtw4d+HM+DaGSul10FO5aLTv88m0 tTjsficbzC2nJeicDWUvmoQc+zcRq1yzxY2/+8+l/JJY5GVCW5cEonmwVKGXJ5HhDkHg Pcpg== X-Gm-Message-State: AOAM531uhPMWpTfNIeOIZiRxsxPiLvlXaP3yzNfcu4WInIWJfTyt79LY gYx8TVwYirgIM5gD0nlmgWzQyKtwWs3tjNT3G3Gvsg== X-Google-Smtp-Source: ABdhPJzheE/WzO+HGRhky4zfs9GtTbvBR0mnu6uLizdD+mpdptcStCrIFQPB8SqfUU2GDFtnAxrNBbVFxPrlHe3xT3Y= X-Received: by 2002:a17:90b:4c8f:b0:1e0:5b0e:eddc with SMTP id my15-20020a17090b4c8f00b001e05b0eeddcmr7199254pjb.23.1653640462207; Fri, 27 May 2022 01:34:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Romain Delhomel Date: Fri, 27 May 2022 10:34:10 +0200 Message-ID: Subject: Re: [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 , stephane gonauer , Guillaume Gaudonville Content-Type: multipart/alternative; boundary="00000000000056268b05dffa2c63" 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 --00000000000056268b05dffa2c63 Content-Type: text/plain; charset="UTF-8" On Fri, May 27, 2022 at 10:28 AM 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 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 > --00000000000056268b05dffa2c63 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, May 27, 2022 at 10:28 AM Romain Delhomel <<= a href=3D"mailto:romain.delhomel@6wind.com">romain.delhomel@6wind.com&g= t; wrote:
At device probe, the fslmc bus driver calls rte_vfio_get_group_f= d() to
get a fd associated to a vfio group. This function first checks i= f the
group is already opened, else it opens /dev/vfio/%u, and increases= the
number of active groups in default_vfio_cfg (which references thedefault 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 f= or container, as it's done
by pci bus, but it is not done here. Inst= ead, a new container is created
and used.

This prevents the pci b= us driver, which use the default_vfio_cfg
container, to configure the co= ntainer because
default_vfio_cfg->active_group > 1.

This pa= tch fixes the issue by always creating a new container (and its
associat= ed vfio_cfg) and bind the group to it.

Fixes: a69f79300262 ("bu= s/fslmc: support multi VFIO group")
Signed-off-by: Romain Delhomel = <romain.d= elhomel@6wind.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_vfi= o.c
index b4704eeae4e2..abe1cab2ee20 100644
--- a/drivers/bus/fslmc/f= slmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -979,6 +979,7 @@ = fslmc_vfio_setup_group(void)
=C2=A0{
=C2=A0 int groupid;
=C2=A0 in= t ret;
+ int vfio_container_fd;
=C2=A0 struct vfio_group_status statu= s =3D { .argsz =3D sizeof(status) };
=C2=A0
=C2=A0 /* if already done= once */
@@ -997,8 +998,15 @@ fslmc_vfio_setup_group(void)
=C2=A0 re= turn 0;
=C2=A0 }
=C2=A0
+ ret =3D rte_vfio_container_create();
= + if (ret < 0) {
+ DPAA2_BUS_ERR("Failed to open VFIO container= ");
+ return ret;
+ }
+ vfio_container_fd =3D ret;
+
= =C2=A0 /* Get the actual group fd */
- ret =3D rte_vfio_get_group_fd(gro= upid);
+ ret =3D rte_vfio_container_group_bind(vfio_container_fd, groupi= d);
=C2=A0 if (ret < 0)
=C2=A0 return ret;
=C2=A0 vfio_group.f= d =3D ret;
--
2.30.2
--00000000000056268b05dffa2c63--