From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7BEE5A3168 for ; Wed, 16 Oct 2019 09:02:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CF2F51E8C4; Wed, 16 Oct 2019 09:02:17 +0200 (CEST) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10065.outbound.protection.outlook.com [40.107.1.65]) by dpdk.org (Postfix) with ESMTP id BE8B31E8C3; Wed, 16 Oct 2019 09:02:16 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bHmRPHcCPXWAxSQ2wOcYtNuoKKS+o/I3kcAaZXEs32pPRAIkSWoj72kppDm5k/tgtz1v0VkLRH7Mc8nRaKKpKVbhBLOmIEO65jVUes0sDXBYtTPmOnRX1cBn+zyx8cHBddrZHBeXm/Fd1oMhKaYhaki+Xb7Fz2G0A5U5QesWNMzvkSZ+IZ0PybF+UoBz9neLiM3BinNcZzIhjrrrgFmovmZLF/3krjfSlMEwXRtFr1FR2A9T7+06Hcx0nBJuoL7EDyHlCiAfPssGy85QkYb/Cs1JUuZPwI1YIL1YImFAB0HhJg6RX7j+LkP3aeu93nI7d2Dwa0J+zjRt7mzF0k3wYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2YmTm99QfA95G7DZuJ+eZkjZRe5DOTrE+WMAbI9MwR0=; b=mikjeBAt1BGuu7sj9BustYPrMF7sv+VVE6u9yGiogasRUfXN5PnTZ4zCy0/syEPct3AIABu0oq1TrmycLlfvhnGIGSqu4d1CB5vdkntNHZOruh7138S9COjE4PTkDTv8zCZXNsKh1o2GGuD22PoJ1/+abjxhidqUWGyhQn3d7Lggzxd/SU4qQUU7UqO66nauLAuGphmw2d4tuxZUy/5c8ASjJYPoaLCTo6UMDph3UZE6Mo3h0ksBIoei5urx08fMCWmFnq3AFBFELcsrI3j5SniQ4nZwPMprdRvj2erD3c1yB4gYeDBQhgplEC9/HU2ernpbMRqFL67Q71rnnOy7oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2YmTm99QfA95G7DZuJ+eZkjZRe5DOTrE+WMAbI9MwR0=; b=hpgskkThN0OzmY6py340LbkQsu3K4vmNJltoL6ucowmTZmkkn91ACZX+jV2Wb0q5i/Wq/SHWhmBDWsgn7yn2HHYlxmRA34Pz2Pt0bfigqke8Ne77pYmiBT4XlR1hqDUGhALGqd0b0u/eL/BiRGjfXh7vP3tIH0RzrE1IfoLY5aQ= Received: from VE1PR04MB6639.eurprd04.prod.outlook.com (10.255.118.11) by VE1PR04MB6558.eurprd04.prod.outlook.com (20.179.232.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Wed, 16 Oct 2019 07:02:15 +0000 Received: from VE1PR04MB6639.eurprd04.prod.outlook.com ([fe80::c045:5df2:ba1f:c3ee]) by VE1PR04MB6639.eurprd04.prod.outlook.com ([fe80::c045:5df2:ba1f:c3ee%5]) with mapi id 15.20.2347.023; Wed, 16 Oct 2019 07:02:15 +0000 From: Akhil Goyal To: Julien Meunier , Declan Doherty CC: "dev@dpdk.org" , "stable@dpdk.org" , Anoob Joseph , Fiona Trahe , "Ananyev, Konstantin" Thread-Topic: [PATCH v2] cryptodev: fix check related to device id Thread-Index: AQHVg3iyCw7GPO86zkay15ddZe1xw6dc0/ag Date: Wed, 16 Oct 2019 07:02:15 +0000 Message-ID: References: <20190807083946.39309-1-julien.meunier@nokia.com> <20191015165034.24276-1-julien.meunier@nokia.com> In-Reply-To: <20191015165034.24276-1-julien.meunier@nokia.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=akhil.goyal@nxp.com; x-originating-ip: [92.120.1.65] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 27b9b4af-1ca8-4707-a32f-08d75206c711 x-ms-office365-filtering-ht: Tenant x-ms-traffictypediagnostic: VE1PR04MB6558: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1417; x-forefront-prvs: 0192E812EC x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(366004)(39860400002)(396003)(136003)(376002)(346002)(199004)(189003)(66946007)(446003)(44832011)(11346002)(186003)(478600001)(26005)(33656002)(486006)(76116006)(64756008)(66476007)(66446008)(66556008)(8936002)(476003)(74316002)(7736002)(81156014)(81166006)(8676002)(4326008)(6246003)(102836004)(305945005)(14454004)(25786009)(316002)(71190400001)(54906003)(9686003)(110136005)(71200400001)(7696005)(76176011)(5024004)(296002)(52536014)(5660300002)(55016002)(2906002)(66066001)(99286004)(3846002)(6436002)(229853002)(14444005)(6116002)(256004)(86362001)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR04MB6558; H:VE1PR04MB6639.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jv5ACOuzDAMhXu/S4WzpMGkGVfmoVqJGQ8oPl8p6M4iJrbhebhDretlAf9ynznK8wqgOKdPux3DdMMufn9KmD4wbcMRo0Or9XI8shlw5ZL8u31YoNyFMzbM4s7ki5JEUbz+76Zc30RW0AK40x87Oi+cWOy1w9hL9PUjIdu+PyCfEeimQodFnbW05Co4NAs/YRPRAqwDHFG1+7HfgP2GKe44x0P544UjsKblRfdpUjvVC3iLIMYiomvp96t1IqlMZcLdxmkmYjX6oROAg2qmLikfa8PUFmgMAQMvGcpEydPMgAkAsdE7/Og9fWNJpxYvsdnNhDzJUT2oEF758ANSX2osa36XynpVAzuX6g741vO7IsUVGrLQSQdmmrYC22oO7Mta1ar4iJHsfDNSTBKwzTKTdsS6/eR1LkNRkdQNx9dQ= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27b9b4af-1ca8-4707-a32f-08d75206c711 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2019 07:02:15.7069 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Z3LAkdr0HIDAw3zNB4uARRpq1shCGBVDftwKJocHnr5xomtJQXMwI8z+cHrUnaQRUyx3JcrlCTrZa8ysrFhUgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6558 Subject: Re: [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Julien, A couple of nits. Please see inline. Apart from that Acked-by: Akhil Goyal >=20 > Each cryptodev are indexed with dev_id in the global rte_crypto_devices > variable. nb_devs is incremented / decremented each time a cryptodev is > created / deleted. The goal of nb_devs was to prevent the user to get an > invalid dev_id. >=20 > Let's imagine DPDK has configured N cryptodevs. If the cryptodev=3D1 is > removed at runtime, the latest cryptodev N cannot be accessible, because > nb_devs=3DN-1 with the current implementaion. >=20 > In order to prevent this kind of behavior, let's remove the check with > nb_devs and iterate in all the rte_crypto_devices elements: if data is > not NULL, that means a valid cryptodev is available. >=20 > Also, remove max_devs field and use RTE_CRYPTO_MAX_DEVS in order to > unify the code. >=20 > Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto > devices") > Cc: stable@dpdk.org >=20 > Signed-off-by: Julien Meunier > --- > v2: > * Restore nb_devs > * Update headline (check-git-log.sh) > * Update commit log >=20 > lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) >=20 > diff --git a/lib/librte_cryptodev/rte_cryptodev.c > b/lib/librte_cryptodev/rte_cryptodev.c > index b16ef7b..933c38d 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.c > +++ b/lib/librte_cryptodev/rte_cryptodev.c > @@ -50,8 +50,7 @@ > static struct rte_cryptodev_global cryptodev_globals =3D { > .devs =3D rte_crypto_devices, > .data =3D { NULL }, > - .nb_devs =3D 0, > - .max_devs =3D RTE_CRYPTO_MAX_DEVS > + .nb_devs =3D 0 > }; Max_devs field shall also be removed from struct rte_cryptodev_global in "l= ib/librte_cryptodev/rte_cryptodev_pmd.h" >=20 > /* spinlock for crypto device callbacks */ > @@ -512,7 +511,7 @@ struct rte_cryptodev * > if (name =3D=3D NULL) > return NULL; >=20 > - for (i =3D 0; i < cryptodev_globals.max_devs; i++) { > + for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) { > dev =3D &cryptodev_globals.devs[i]; >=20 > if ((dev->attached =3D=3D RTE_CRYPTODEV_ATTACHED) && > @@ -523,12 +522,21 @@ struct rte_cryptodev * > return NULL; > } >=20 > +static uint8_t > +rte_cryptodev_is_valid_device_data(uint8_t dev_id) > +{ > + if (rte_crypto_devices[dev_id].data =3D=3D NULL) > + return 0; > + > + return 1; > +} rte_cryptodev_is_valid_device_data should be a static inline function. > + > unsigned int > rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) > { > struct rte_cryptodev *dev =3D NULL; >=20 > - if (dev_id >=3D cryptodev_globals.nb_devs) > + if (!rte_cryptodev_is_valid_device_data(dev_id)) > return 0; >=20 > dev =3D rte_cryptodev_pmd_get_dev(dev_id); > @@ -547,12 +555,15 @@ struct rte_cryptodev * > if (name =3D=3D NULL) > return -1; >=20 > - for (i =3D 0; i < cryptodev_globals.nb_devs; i++) > + for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) { > + if (!rte_cryptodev_is_valid_device_data(i)) > + continue; > if ((strcmp(cryptodev_globals.devs[i].data->name, name) > =3D=3D 0) && > (cryptodev_globals.devs[i].attached =3D=3D > RTE_CRYPTODEV_ATTACHED)) > return i; > + } >=20 > return -1; > } > @@ -568,7 +579,7 @@ struct rte_cryptodev * > { > uint8_t i, dev_count =3D 0; >=20 > - for (i =3D 0; i < cryptodev_globals.max_devs; i++) > + for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) > if (cryptodev_globals.devs[i].driver_id =3D=3D driver_id && > cryptodev_globals.devs[i].attached =3D=3D > RTE_CRYPTODEV_ATTACHED) > @@ -583,9 +594,10 @@ struct rte_cryptodev * > { > uint8_t i, count =3D 0; > struct rte_cryptodev *devs =3D cryptodev_globals.devs; > - uint8_t max_devs =3D cryptodev_globals.max_devs; >=20 > - for (i =3D 0; i < max_devs && count < nb_devices; i++) { > + for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) { > + if (!rte_cryptodev_is_valid_device_data(i)) > + continue; >=20 > if (devs[i].attached =3D=3D RTE_CRYPTODEV_ATTACHED) { > int cmp; > @@ -1101,7 +1113,7 @@ struct rte_cryptodev * > { > struct rte_cryptodev *dev; >=20 > - if (dev_id >=3D cryptodev_globals.nb_devs) { > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > return; > } > -- > 1.8.3.1