From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0061.outbound.protection.outlook.com [104.47.36.61]) by dpdk.org (Postfix) with ESMTP id 4441E2C16 for ; Tue, 9 May 2017 06:05:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=iqD13n9l/9ve6yBP/w9+o0UCsAVraWaBk+kbCVa4dR8=; b=ZcJ1bGk0m3C0ZmoyRnU34H8aTc9jtouShPDSFLtrnW1/gIH/fXdiMRNihwAmscFSgftOn09xISDorOqtA2Y5VlMQOF/k7UMrvgzavqe4PIFM6BTp07XEoRTcFmnd7Hr9tS9vs0tJrTwtMQqoqDAE6WguFtPqSsIVuMBS3HF60cw= Authentication-Results: netronome.com; dkim=none (message not signed) header.d=none;netronome.com; dmarc=none action=none header.from=caviumnetworks.com; Received: from jerin (111.93.218.67) by BLUPR0701MB1715.namprd07.prod.outlook.com (10.163.85.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1075.11; Tue, 9 May 2017 04:05:03 +0000 Date: Tue, 9 May 2017 09:34:48 +0530 From: Jerin Jacob To: Alejandro Lucero Cc: dev@dpdk.org, anatoly.burakov@intel.com, thomas@monjalon.net Message-ID: <20170509040447.GA6207@jerin> References: <1494265458-35709-1-git-send-email-alejandro.lucero@netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1494265458-35709-1-git-send-email-alejandro.lucero@netronome.com> User-Agent: Mutt/1.8.2 (2017-04-18) X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0110.INDPRD01.PROD.OUTLOOK.COM (10.174.208.26) To BLUPR0701MB1715.namprd07.prod.outlook.com (10.163.85.141) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 19231f93-0103-4751-981c-08d49690934d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:BLUPR0701MB1715; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1715; 3:uOTn6b9tfkreFmjPKDYDy2+I8dR/TlY8rfwE2ax8kgZgQIp+dY0GRBBYrnydU0jSlxywUf46/pNRNX9Bs4VSLYLp3I0qLn4zzH4xxresHgzGb2STmVFBz2nJ+7DPYuOaV4Cn+k4jKh033h5R6BTDCZZHWwgHMRMNdnae37q9sTpI2dwCp87KPM4geDA0JmtxpqAsl5BUlL+WVU6thit+iiGGHHgdSpy/wn+0KHHlGq7EnzV0tfyFJgW9kW8CN0vmI0YFYUKzhunxJBnM9Kjjc8J8AkHDdU0GcVEHWCkOozGcdimEzbS9A7zRY0O+sX6Q3Apcoow7rp7tkmxMSbdOzg==; 25:ihA2pgjLQZAGx48t/HF+nu8BIA5jo0kS4cJqe7GaQIq3GWNWkPboLGtKVn2dZ9QmTnCkby/vrxeEIiIN2iiOF4186riJkoHPZ9ljaPopwUIHJsU0E7BO3B+/FQ3e4lc1xs+HpfcBNSxaOs/FSvyh6FMFlT7BOeenlFQ+5vkzzelIZeVqYND0xtVrczThkgZDpv2782AXSzrRYEMHrwNIiFuahdUGNdhfWAmKOgcBAnrZY9u2e+EqBO0InoNbLRucqCC4tMABRVndPGeUm9FUG7BOxQvJhL31Wwno0IVXvRzBQ298SwyrylHmG89vJIvkY/lRaWhfraLevKM4wnPlwRTOdmxcmw1UVgJOvwQyhk1PGZ9y90s7JkdW2cakBGL7KcPdBZIGwnKwAXpwo5U7vswF1UF4PvLnHIZ7lbzoIr/X4m9hP9Ritn9MXYU45e03pAoRiMza6Lbp2aZRPPcb6drPeOiNquCD7t1hAp1a2AI= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1715; 31:SZ75+caHk5LsOs3meWCUYhp0KFnfhKtbJF7ldZc+GGbcK7JYCVOkSal/d5XzA9Lzd37kUcLwQ+GbRom5EhBFqw1KwaiIjsi/6AgXGQ7JrYFqWSonlxCvKyscjSw5/bplXnhW7ps++momEc6P59GL0C5Bfi8xq5grABNzmuieZOQgzlLovHFVy4oB12XYt5OCzCClbxwr3dqevHGPGi1AsiYrhy+vLQWuwN3lvlS1svyD13pl9uUWHtlyY81eBYMMIKrSVPHtqNwoXaF819zUWQ==; 20:K88ZVrBQIKyE1BMind5RlLDsUqI2+jow2ZCs2sBEmxVIOJmy5r9lp3VWr2zdc8yeuRlkGFxj7iNVW2EVNan2/BbGct0frxmv28aBQPSaIlf98xBAxTM19w6Cn74wmGp80SWnmhj/47mSmXhiaN87HBG5WFphH89SM7RBrAZBZFnzFkjSs/qkM972I5co2ovNGV6flaC7uQmdk+0U4Bv1jiVM8r0ru1rMlXafBuko9CbjciNM+Ie4FQapXehGA1wvmxkuC99oNBQPaRMIrOc9A4fEeZajKtYvSNBl4fc4TwIPGcZyL+KAqGXNnlAlnym6ZrlSk9BePxB2M+UCy+6N6M6D/bS3hwJUQOfcokSjeq7SU/mvx8H62z6M2FMG3pcuf2MO0PJORyuDsEMRFUFeKGpdMJlvGbL6pQc6FqoBSUlImp5jUaRD5QlCsSCn8JjtNMQ6DZ1cWDZoXJCH4ju2hBR4x0UKccPpxD9sL6wwEXphsxOP6oJC/HjQXoU1jrRD/X/g7L7kqjuYqMk2AJXIIimxLCz2usz0Zt8PMoJwT4nluI22qpfbFuER/Ost/NXrbYE+p1ShtJsEHXE7UtOvgmDH4Pnija8ezejzio3Nfuw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(3002001)(10201501046)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123562025)(20161123560025)(6072148); SRVR:BLUPR0701MB1715; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0701MB1715; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1715; 4:zX1kOPsxgyASAaI55EP2MOTVKaWnT1WYBSwawXpBmS7t9i3M1nNbYGtOxK1sKIKrB5piQQ2U5lOS9q/o27M8ry+mt+1YPxwOcqzwdCtSAda/0zbdvAIJAJlMdcN977+HCQgKoDimoFallALfd7bNOIdWFJC1ErXqDevp0G8OSspagGXklSi/OfQA0RUq7beHEvEkGd0DtZ8/5ig00cJOyb7inwfYyWLiJrFhGNI+FwtI4eaZgLxKW3IFqf9sY2oFyEUG6Hfx14ounGPqmD+CfpDcgdyeCCQAqYgTeBaCE6pUk5v8a+Zy73Brloy0vN7fMbvtXUUFOoByXi3sHz4zH3TR9TPskBn8n8ppbMjmByXLhIoiVrUMEtanK75T+OB0S5TecxJ4gtUj/YMsxinHJguPJ7Sbapq6CeA71kUI2BRoksHGuG75Ojvnya99qQVWmjQ+5bAydvzY5YZ+mzKnDeEQWB4cc0x3kUK2zLWSFQLqA9rN5Se7ioQ1afW5UvzVTjFGjuOV5rNJKFzgQ9lw6EHLSnGfz4w6u8UhixEVIv11iPm/+/PZ/UIQ21sX29PsaBRPmS5s3bBqBbjv7RJo1+6GU+zg/fWOGjItls5093AJxux3NMRRB7SrM+LyAr5DnT31cymP8xaOVBWjj5loZGI5lT2BtAZMOJkfrRVT5xy0l0sns01zl5wUwcw/O0gBvsupaooP7sn17rnALrAn20tp9LmT+ZIERwzkU1XiZACrgRn15ABI3+5ckkMU5t+MAFX445xGjvjulRGMxanJGN+1x9iHoQT9YDXDfY7g1EDoZby8NQxOsk6aGrY56rPl X-Forefront-PRVS: 0302D4F392 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39450400003)(39410400002)(39400400002)(13464003)(23726003)(4001350100001)(5660300001)(9686003)(189998001)(478600001)(8676002)(81166006)(33716001)(25786009)(50986999)(4326008)(76176999)(54356999)(33656002)(66066001)(42186005)(6496005)(38730400002)(1076002)(7736002)(229853002)(83506001)(6116002)(3846002)(47776003)(2906002)(110136004)(5009440100003)(305945005)(50466002)(55016002)(42882006)(2950100002)(6666003)(5890100001)(6916009)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1715; H:jerin; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0701MB1715; 23:XJHx6SS04GH7+3TgElUof50QYyjRT1y2MdO0oUY?= =?us-ascii?Q?564OZCU1BRsdD3wtj7WB7w9+3rVpmu9w+slhko/0WoGEYf+zD+JBrVxhb5bu?= =?us-ascii?Q?UtQf+MC1J4dnLAEF5etSv994sQAh3DDasR8Lo8biLhihRXpwP0B6jonozwVY?= =?us-ascii?Q?ZMm+QKl9cYDTY8jbEsqHinmlXKtYFjy1kMKbAv804y+HO/VggOZL9XAZnbkt?= =?us-ascii?Q?jPyNUKY04BhFrBJ1SCtY0QpqIIA+J8JHkUmvHiuz/upbAqCj5auyEIXA4PnP?= =?us-ascii?Q?2zyIBTDPekQp7WqMjVcKll8BpkP6sJ/vYmW0jkP4QjdGx+S2JLqtKBxqqCSQ?= =?us-ascii?Q?/Vn+6Qj3h/UPjifqzmi3QUdK7MAMYV8hn4OmqxVLUr44Wsns8n6qdsMIa05k?= =?us-ascii?Q?waUmfvQ7cV9Or7ThEYnIay6VonTvULU6jikfihWnjHwvbLXVhvuD4gGDfPPi?= =?us-ascii?Q?NX+7x+UHiBEii1rDWHYgHx2muIWC713HDESOatIkAuxFhKWX4ZrqB1stMAKB?= =?us-ascii?Q?QVA2QltzySC/1226zG5L23y4MgR1OYDoJ8S/Z1BfOcH46EusY8GbBrAvEq+S?= =?us-ascii?Q?NH6/YA01eVHyy8rWlEl4TLEawHPdPhT+jalkjKtg33gVxTOtW06aql3PSWOj?= =?us-ascii?Q?9rpCheBX1xRk7m49uWlVrL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rqZJIKw02qwftwNQb5qiHnxtzGgf9M1LCeHcXNPK3Nl5i+r7OXn15qq0b5xMDPq2kBTZX2B2aLDyJHMCodn4n0cShkdqog==; 5:NvV4YcB2i/5B7jsfw54rmGVevB5n6toNaTPEmv+RovYHrZeSwBTGVXTYyQ5q+botyqa0zuTApb20Eolk2rUwk7xMolszk6Cj6HhBcF0PO1lE5v/ZAfOW7sG6vkIONJK0zIOjXPHqOymSsFAVHa61YA==; 24:oQle66VY+F85cPO7fqdpyQNiWcu7nqizqV6NXBn33Wi6n2Idgk6L+MFLxN/1BeXQxfcZAVoAZZucA1aGMK/i6WgaY87VJFVVOPUim5h6EWc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1715; 7:mtbUNLraaK0BI2gAJ9l+Entrddih/uOfFMq/PeB0MP/YwTjVcMIdddNtyeOg27NfdeB5ZEMQodoW0tSnA7CEkSinEDOR1/SrlP6+byp+1GPWZn//VDcsVasm6g1xtnVrvQ054HpEM8Y+diKwA20GfFSSwAHetiUsYGy5kAJ34CoSF4k4ju0TvwNwFRA7WnEmP81XR4suAEe57d0N/jNFN2Unhx88dkv+fhHOyyXUiwT6+YaZoCdTOqTJxLU7KXIPeOZiHupzrnduNhMiSEkkDUYk9r32QRg1+XboaW5wsheZmsNiaseahfKBL8+SA9B4sNOWltWqbuiAyYuD+NI4DQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2017 04:05:03.7568 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1715 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 04:05:07 -0000 -----Original Message----- > Date: Mon, 8 May 2017 18:44:18 +0100 > From: Alejandro Lucero > To: dev@dpdk.org > CC: anatoly.burakov@intel.com, jerin.jacob@caviumnetworks.com, > thomas@monjalon.net > Subject: [PATCH] vfio: use right index when tracking devices in a vfio group > X-Mailer: git-send-email 1.9.1 > > Previous fix for properly handling devices from the same VFIO group > introduced another bug where the file descriptor of a kernel vfio > group is 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 vfio group object that file descriptor is > registered with has to be used. > > This patch introduces specific functions for incrementing or > decrementing the device counter for a specific vfio group using the > vfio file descriptor 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. > > Fixes: a9c349e3a100 ("vfio: fix device unplug when several devices per group") > > Signed-off-by: Alejandro Lucero Tested-by: Jerin Jacob > --- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 60 +++++++++++++++++++++++++++------- > 1 file changed, 49 insertions(+), 11 deletions(-) > > 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; > } > > + > +static int > +get_vfio_group_idx(int vfio_group_fd) > +{ > + int i; > + for (i = 0; i < VFIO_MAX_GROUPS; i++) > + if (vfio_cfg.vfio_groups[i].fd == vfio_group_fd) > + return i; > + return -1; > +} > + > +static void > +vfio_group_device_get(int vfio_group_fd) > +{ > + int i; > + > + i = get_vfio_group_idx(vfio_group_fd); > + vfio_cfg.vfio_groups[i].devices++; > +} > + > +static void > +vfio_group_device_put(int vfio_group_fd) > +{ > + int i; > + > + i = get_vfio_group_idx(vfio_group_fd); > + vfio_cfg.vfio_groups[i].devices--; > +} > + > +static int > +vfio_group_device_count(int vfio_group_fd) > +{ > + int i; > + > + i = get_vfio_group_idx(vfio_group_fd); > + return vfio_cfg.vfio_groups[i].devices; > +} > + > int > clear_group(int vfio_group_fd) > { > @@ -180,15 +218,14 @@ > > if (internal_config.process_type == RTE_PROC_PRIMARY) { > > - for (i = 0; i < VFIO_MAX_GROUPS; i++) > - if (vfio_cfg.vfio_groups[i].fd == vfio_group_fd) { > - vfio_cfg.vfio_groups[i].group_no = -1; > - vfio_cfg.vfio_groups[i].fd = -1; > - vfio_cfg.vfio_groups[i].devices = 0; > - vfio_cfg.vfio_active_groups--; > - return 0; > - } > - return -1; > + i = get_vfio_group_idx(vfio_group_fd); > + if ( i < 0) > + return -1; > + vfio_cfg.vfio_groups[i].group_no = -1; > + vfio_cfg.vfio_groups[i].fd = -1; > + vfio_cfg.vfio_groups[i].devices = 0; > + vfio_cfg.vfio_active_groups--; > + return 0; > } > > /* 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); > > 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 == 0) { > + vfio_group_device_put(vfio_group_fd); > + if (!vfio_group_device_count(vfio_group_fd)) { > > if (close(vfio_group_fd) < 0) { > RTE_LOG(INFO, EAL, "Error when closing vfio_group_fd for %s\n", > -- > 1.9.1 >