From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id CACBA2C3F for ; Tue, 9 May 2017 17:18:26 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2017 08:18:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,315,1491289200"; d="scan'208";a="84644589" Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31]) by orsmga002.jf.intel.com with ESMTP; 09 May 2017 08:18:23 -0700 Received: from irsmsx111.ger.corp.intel.com (10.108.20.4) by IRSMSX106.ger.corp.intel.com (163.33.3.31) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 9 May 2017 16:18:22 +0100 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.12]) by irsmsx111.ger.corp.intel.com ([169.254.2.58]) with mapi id 14.03.0319.002; Tue, 9 May 2017 16:18:22 +0100 From: "Burakov, Anatoly" To: Alejandro Lucero , "dev@dpdk.org" CC: "jerin.jacob@caviumnetworks.com" , "thomas@monjalon.net" Thread-Topic: [PATCH] vfio: use right index when tracking devices in a vfio group Thread-Index: AQHSyCLHTFAVGUuUR025iqlrk2MaoaHsHbKg Date: Tue, 9 May 2017 15:18:22 +0000 Message-ID: References: <1494265458-35709-1-git-send-email-alejandro.lucero@netronome.com> In-Reply-To: <1494265458-35709-1-git-send-email-alejandro.lucero@netronome.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNmEzMmExMDAtOTViNy00NzgwLWFiZTctM2Q4ZjQ3MTI3NmMzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6Im51NE14VTNwYnkzdVVsK1wvMDF1MG5CbnRjYUtvNXV3VGZmR1p2ckpNcnVzPSJ9 dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] vfio: use right index when tracking devices in a vfio group X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 May 2017 15:18:27 -0000 Hi Alejandro, > From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com] > Sent: Monday, May 8, 2017 6:44 PM > To: dev@dpdk.org > Cc: Burakov, Anatoly ; > jerin.jacob@caviumnetworks.com; thomas@monjalon.net > Subject: [PATCH] vfio: use right index when tracking devices in a vfio gr= oup >=20 > Previous fix for properly handling devices from the same VFIO group > introduced another bug where the file descriptor of a kernel vfio group i= s > used as the index for tracking number of devices of a vfio group struct > handled by dpdk vfio code. Instead of the file descriptor itself, the vfi= o group > object that file descriptor is registered with has to be used. >=20 > This patch introduces specific functions for incrementing or decrementing > the device counter for a specific vfio group using the vfio file descript= or as a > parameter. Note the code is not optimized as the vfio group is found > sequentially going through the vfio group array but this should not be a > problem as this is not related to packet handling at all. >=20 > Fixes: a9c349e3a100 ("vfio: fix device unplug when several devices per > group") >=20 > Signed-off-by: Alejandro Lucero > --- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 60 > +++++++++++++++++++++++++++------- > 1 file changed, 49 insertions(+), 11 deletions(-) >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c > b/lib/librte_eal/linuxapp/eal/eal_vfio.c > index d3eae20..21d126f 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c > @@ -172,6 +172,44 @@ > return -1; > } >=20 > + > +static int > +get_vfio_group_idx(int vfio_group_fd) > +{ > + int i; > + for (i =3D 0; i < VFIO_MAX_GROUPS; i++) > + if (vfio_cfg.vfio_groups[i].fd =3D=3D vfio_group_fd) > + return i; > + return -1; > +} > + > +static void > +vfio_group_device_get(int vfio_group_fd) { > + int i; > + > + i =3D get_vfio_group_idx(vfio_group_fd); > + vfio_cfg.vfio_groups[i].devices++; Maybe add a check for I < 0? > +} > + > +static void > +vfio_group_device_put(int vfio_group_fd) { > + int i; > + > + i =3D get_vfio_group_idx(vfio_group_fd); > + vfio_cfg.vfio_groups[i].devices--; Same here. > +} > + > +static int > +vfio_group_device_count(int vfio_group_fd) { > + int i; > + > + i =3D get_vfio_group_idx(vfio_group_fd); > + return vfio_cfg.vfio_groups[i].devices; } And here. > + > int > clear_group(int vfio_group_fd) > { > @@ -180,15 +218,14 @@ >=20 > if (internal_config.process_type =3D=3D RTE_PROC_PRIMARY) { >=20 > - for (i =3D 0; i < VFIO_MAX_GROUPS; i++) > - if (vfio_cfg.vfio_groups[i].fd =3D=3D vfio_group_fd) { > - vfio_cfg.vfio_groups[i].group_no =3D -1; > - vfio_cfg.vfio_groups[i].fd =3D -1; > - vfio_cfg.vfio_groups[i].devices =3D 0; > - vfio_cfg.vfio_active_groups--; > - return 0; > - } > - return -1; > + i =3D get_vfio_group_idx(vfio_group_fd); > + if ( i < 0) > + return -1; > + vfio_cfg.vfio_groups[i].group_no =3D -1; > + vfio_cfg.vfio_groups[i].fd =3D -1; > + vfio_cfg.vfio_groups[i].devices =3D 0; > + vfio_cfg.vfio_active_groups--; > + return 0; > } >=20 > /* This is just for SECONDARY processes */ @@ -358,7 +395,7 @@ > clear_group(vfio_group_fd); > return -1; > } > - vfio_cfg.vfio_groups[vfio_group_fd].devices++; > + vfio_group_device_get(vfio_group_fd); >=20 > return 0; > } > @@ -406,7 +443,8 @@ > /* An VFIO group can have several devices attached. Just when there > is > * no devices remaining should the group be closed. > */ > - if (--vfio_cfg.vfio_groups[vfio_group_fd].devices =3D=3D 0) { > + vfio_group_device_put(vfio_group_fd); > + if (!vfio_group_device_count(vfio_group_fd)) { >=20 > if (close(vfio_group_fd) < 0) { > RTE_LOG(INFO, EAL, "Error when closing > vfio_group_fd for %s\n", > -- > 1.9.1