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 924DFA04B5 for ; Tue, 3 Dec 2019 19:29:03 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 88FD2235; Tue, 3 Dec 2019 19:29:03 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 0762F1BF97 for ; Tue, 3 Dec 2019 19:29:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575397741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BGjhu89RuIm8c1DaZcs8KLhkxruEQORS/nLoAmntzhs=; b=O8yNH2kKpngv/qhvJT40T1JgAFk974zKQeEbG5symi5Vv86x9w4RKnPe1Dk6y/I2CeL84U oP6vjAHznF+k7mmyEXqq6Y/N9h1EWIHBf+V5EuRBomyggSCP90Oiw+TXFqWw24efruowh+ 7kKQSoDkPYQhA7g/krOCbPubv66sXDg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-KdO-ptpDMPGpVWtj0_67gA-1; Tue, 03 Dec 2019 13:28:58 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41A34107ACC4; Tue, 3 Dec 2019 18:28:57 +0000 (UTC) Received: from rh.redhat.com (ovpn-117-10.ams2.redhat.com [10.36.117.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FE7B5C240; Tue, 3 Dec 2019 18:28:55 +0000 (UTC) From: Kevin Traynor To: Julien Meunier Cc: Akhil Goyal , dpdk stable Date: Tue, 3 Dec 2019 18:26:57 +0000 Message-Id: <20191203182714.17297-48-ktraynor@redhat.com> In-Reply-To: <20191203182714.17297-1-ktraynor@redhat.com> References: <20191203182714.17297-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: KdO-ptpDMPGpVWtj0_67gA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] patch 'cryptodev: fix checks related to device id' has been queued to LTS release 18.11.6 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/10/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasi= ng (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/8db57afd7ab9a3c12d= 73f1f5461415690b8c173c Thanks. Kevin. --- >From 8db57afd7ab9a3c12d73f1f5461415690b8c173c Mon Sep 17 00:00:00 2001 From: Julien Meunier Date: Wed, 16 Oct 2019 13:21:11 +0300 Subject: [PATCH] cryptodev: fix checks related to device id [ upstream commit 3dd4435cf473f5d10b99282098821fb40b72380f ] 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. 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. 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. Also, remove max_devs field and use RTE_CRYPTO_MAX_DEVS in order to unify the code. Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto dev= ices") Signed-off-by: Julien Meunier Acked-by: Akhil Goyal --- lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++------- lib/librte_cryptodev/rte_cryptodev_pmd.h | 1 - 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rt= e_cryptodev.c index 9c35e6d9c..f7566fc30 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -51,6 +51,5 @@ static struct rte_cryptodev_global cryptodev_globals =3D = { =09=09.devs=09=09=09=3D rte_crypto_devices, =09=09.data=09=09=09=3D { NULL }, -=09=09.nb_devs=09=09=3D 0, -=09=09.max_devs=09=09=3D RTE_CRYPTO_MAX_DEVS +=09=09.nb_devs=09=09=3D 0 }; =20 @@ -497,5 +496,5 @@ rte_cryptodev_pmd_get_named_dev(const char *name) =09=09return NULL; =20 -=09for (i =3D 0; i < cryptodev_globals.max_devs; i++) { +=09for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) { =09=09dev =3D &cryptodev_globals.devs[i]; =20 @@ -508,4 +507,13 @@ rte_cryptodev_pmd_get_named_dev(const char *name) } =20 +static inline uint8_t +rte_cryptodev_is_valid_device_data(uint8_t dev_id) +{ +=09if (rte_crypto_devices[dev_id].data =3D=3D NULL) +=09=09return 0; + +=09return 1; +} + unsigned int rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) @@ -513,5 +521,5 @@ rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) =09struct rte_cryptodev *dev =3D NULL; =20 -=09if (dev_id >=3D cryptodev_globals.nb_devs) +=09if (!rte_cryptodev_is_valid_device_data(dev_id)) =09=09return 0; =20 @@ -532,5 +540,7 @@ rte_cryptodev_get_dev_id(const char *name) =09=09return -1; =20 -=09for (i =3D 0; i < cryptodev_globals.nb_devs; i++) +=09for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) { +=09=09if (!rte_cryptodev_is_valid_device_data(i)) +=09=09=09continue; =09=09if ((strcmp(cryptodev_globals.devs[i].data->name, name) =09=09=09=09=3D=3D 0) && @@ -538,4 +548,5 @@ rte_cryptodev_get_dev_id(const char *name) =09=09=09=09=09=09RTE_CRYPTODEV_ATTACHED)) =09=09=09return i; +=09} =20 =09return -1; @@ -553,5 +564,5 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id) =09uint8_t i, dev_count =3D 0; =20 -=09for (i =3D 0; i < cryptodev_globals.max_devs; i++) +=09for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS; i++) =09=09if (cryptodev_globals.devs[i].driver_id =3D=3D driver_id && =09=09=09cryptodev_globals.devs[i].attached =3D=3D @@ -568,7 +579,8 @@ rte_cryptodev_devices_get(const char *driver_name, uint= 8_t *devices, =09uint8_t i, count =3D 0; =09struct rte_cryptodev *devs =3D cryptodev_globals.devs; -=09uint8_t max_devs =3D cryptodev_globals.max_devs; =20 -=09for (i =3D 0; i < max_devs && count < nb_devices;=09i++) { +=09for (i =3D 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) { +=09=09if (!rte_cryptodev_is_valid_device_data(i)) +=09=09=09continue; =20 =09=09if (devs[i].attached =3D=3D RTE_CRYPTODEV_ATTACHED) { @@ -1019,5 +1031,5 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cry= ptodev_info *dev_info) =09struct rte_cryptodev *dev; =20 -=09if (dev_id >=3D cryptodev_globals.nb_devs) { +=09if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { =09=09CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); =09=09return; diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptode= v/rte_cryptodev_pmd.h index 1b6cafd17..529791226 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -62,5 +62,4 @@ struct rte_cryptodev_global { =09/**< Device private data */ =09uint8_t nb_devs;=09=09/**< Number of devices found */ -=09uint8_t max_devs;=09=09/**< Max number of devices */ }; =20 --=20 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-= empty: --- --- -=092019-12-03 17:29:54.548620095 +0000 +++ 0048-cryptodev-fix-checks-related-to-device-id.patch=092019-12-03 17:29= :51.773749474 +0000 @@ -1 +1 @@ -From 3dd4435cf473f5d10b99282098821fb40b72380f Mon Sep 17 00:00:00 2001 +From 8db57afd7ab9a3c12d73f1f5461415690b8c173c Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 3dd4435cf473f5d10b99282098821fb40b72380f ] + @@ -23 +24,0 @@ -Cc: stable@dpdk.org @@ -33 +34 @@ -index b16ef7b2c..89aa2ed3e 100644 +index 9c35e6d9c..f7566fc30 100644 @@ -44 +45 @@ -@@ -513,5 +512,5 @@ rte_cryptodev_pmd_get_named_dev(const char *name) +@@ -497,5 +496,5 @@ rte_cryptodev_pmd_get_named_dev(const char *name) @@ -51 +52 @@ -@@ -524,4 +523,13 @@ rte_cryptodev_pmd_get_named_dev(const char *name) +@@ -508,4 +507,13 @@ rte_cryptodev_pmd_get_named_dev(const char *name) @@ -65 +66 @@ -@@ -529,5 +537,5 @@ rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) +@@ -513,5 +521,5 @@ rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) @@ -72 +73 @@ -@@ -548,5 +556,7 @@ rte_cryptodev_get_dev_id(const char *name) +@@ -532,5 +540,7 @@ rte_cryptodev_get_dev_id(const char *name) @@ -81 +82 @@ -@@ -554,4 +564,5 @@ rte_cryptodev_get_dev_id(const char *name) +@@ -538,4 +548,5 @@ rte_cryptodev_get_dev_id(const char *name) @@ -87 +88 @@ -@@ -569,5 +580,5 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id= ) +@@ -553,5 +564,5 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id= ) @@ -94 +95 @@ -@@ -584,7 +595,8 @@ rte_cryptodev_devices_get(const char *driver_name, uin= t8_t *devices, +@@ -568,7 +579,8 @@ rte_cryptodev_devices_get(const char *driver_name, uin= t8_t *devices, @@ -105 +106 @@ -@@ -1102,5 +1114,5 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cr= yptodev_info *dev_info) +@@ -1019,5 +1031,5 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cr= yptodev_info *dev_info) @@ -113 +114 @@ -index defe05ea0..fba14f2fa 100644 +index 1b6cafd17..529791226 100644