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 A0203A3168 for ; Wed, 16 Oct 2019 12:21:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6CAA91E8F9; Wed, 16 Oct 2019 12:21:23 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150125.outbound.protection.outlook.com [40.107.15.125]) by dpdk.org (Postfix) with ESMTP id 4C21F1E91A; Wed, 16 Oct 2019 12:21:22 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OgsbPLJUeyxqqur/hqCUiqXaext+EW8pfEptOaMPzp0ouhff2kDUqDIJbBhq3STt9waeRgql1wOjWCbJxZXXJIA8/E/78NzFHcyzYZsjgK80fawnQaUNZNQHUPS/u0n1R4J/Il8lh+hWhqPSvBKPUrvGRuWtWIumxo1L6uzRpL57VMqNxpghEUn7ACRd4kNQWPDEodX29ylUX+MM61Eq0K2fiO0hcxMpVkxLzvCI9jEfzBIAFfsUQhbsOr6uco0cAK+GrTaLZUYb7m3Ht1Vg6rntQagXb07vRqJR05ON9i9JJ1Kfuq56R3oPU7a75GWcgcR+FD2nRAt44waPwiAa0w== 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=o4MhVYic1iLQVwITq20uT9UqTtSFcAmzhP1kKBsAKpY=; b=c3L1g98ZW8xHSJJvvwexFdjQMMPrt3r0XNuZmPnridpmlR2RHQl/74Ao/I3sYqQyn1iipYiRPl0HCeAurPFKAJGRrBYmImEfNcKC/nvHNnZfL6AItO90V1tdBW7bRfSlgESB89e6f+OUAfcVsUPGeQZ1w6avC2+SuOh6BGg0QwP65Tm65Fsdpu2N3HH7wIlWckJMVJ5uCtQviS+LAWuvP33A2hynG0Z4ohXWpXeI23mPLnEeaK1n6l8vsaJk3QkjvQ/pvKyRJ9/vTM4fY2dq+HjLegNh8q2AAEuERModQY9tS9WsIXdKkSuVXJAkZDe87FyW8953yrzfD5L9JV/WKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.8) smtp.rcpttodomain=nxp.com smtp.mailfrom=nokia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nokia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o4MhVYic1iLQVwITq20uT9UqTtSFcAmzhP1kKBsAKpY=; b=ByXMMYYmjPHRx4Sdlj2C850AjhPtNNLCin2uK/SZsYFIPPGCDaRoRuWcKIK32CHJCvTIt/G5bvKEIUyo+MG1wAL3AnvlRPYnGn1ubnY4+WA1BsNRvrG1+u4osnagwE9faKfmIBfXrKwVsaIozWN53qv9zF4FeMpfW8vumIAGHNI= Received: from VI1PR07CA0220.eurprd07.prod.outlook.com (2603:10a6:802:58::23) by DB7PR07MB4139.eurprd07.prod.outlook.com (2603:10a6:5:6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.13; Wed, 16 Oct 2019 10:21:21 +0000 Received: from VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::203) by VI1PR07CA0220.outlook.office365.com (2603:10a6:802:58::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2347.14 via Frontend Transport; Wed, 16 Oct 2019 10:21:21 +0000 Authentication-Results: spf=pass (sender IP is 131.228.2.8) smtp.mailfrom=nokia.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=pass action=none header.from=nokia.com; Received-SPF: Pass (protection.outlook.com: domain of nokia.com designates 131.228.2.8 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.8; helo=fihe3nok0734.emea.nsn-net.net; Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.8) by VE1EUR03FT053.mail.protection.outlook.com (10.152.19.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.15 via Frontend Transport; Wed, 16 Oct 2019 10:21:20 +0000 Received: from lfs-up-04.novalocal ([10.157.84.234]) by fihe3nok0734.emea.nsn-net.net (GMO) with ESMTP id x9GALKSR000524; Wed, 16 Oct 2019 10:21:20 GMT Received: by lfs-up-04.novalocal (Postfix, from userid 62146483) id 24968A4DA; Wed, 16 Oct 2019 13:21:20 +0300 (EEST) From: Julien Meunier To: Declan Doherty Cc: dev@dpdk.org, stable@dpdk.org, akhil.goyal@nxp.com Date: Wed, 16 Oct 2019 13:21:11 +0300 Message-Id: <20191016102111.57077-1-julien.meunier@nokia.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20190807083946.39309-1-julien.meunier@nokia.com> References: <20190807083946.39309-1-julien.meunier@nokia.com> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:131.228.2.8; IPV:CAL; SCL:-1; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(136003)(39860400002)(376002)(346002)(396003)(199004)(189003)(186003)(86362001)(48376002)(305945005)(50466002)(44832011)(486006)(476003)(11346002)(4326008)(2616005)(70586007)(51416003)(47776003)(76130400001)(76176011)(336012)(316002)(42186006)(26826003)(70206006)(126002)(5660300002)(6916009)(50226002)(81156014)(8676002)(81166006)(106002)(6666004)(6266002)(5024004)(14444005)(26005)(356004)(478600001)(103686004)(36756003)(446003)(2906002)(8936002)(1076003)(16586007); DIR:OUT; SFP:1102; SCL:1; SRVR:DB7PR07MB4139; H:fihe3nok0734.emea.nsn-net.net; FPR:; SPF:Pass; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e7efadc-2e2e-4107-d6c7-08d7522296eb X-MS-TrafficTypeDiagnostic: DB7PR07MB4139: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1332; X-Forefront-PRVS: 0192E812EC X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nyilAPnLRo081gr/yX5qvwYJrah0lt1Z192iC1HavrN8IzBTqZs8QW1vWq0Z0LENVtqQ4yWL3Y2raeQ9sNqfEJzhtHyPq2CutZ9uGkuEA9QHsgQ4LMb0c9Vp0xTw2e3jZjwJ13K3L4iI3pEqckfQZa9ee+eP3WL/eL/A8sBTxEK4M0mRhw62CN21T50+oQicS0DAwlsoy1IKt4m+0w8+icLfm2S0wkAbkE+GgToRH5v2BpptxvBRH1oIrC9zGONxhbtm/XZ8mMtHAk3Jr5UXu+2KeCsSAz5ZWiBREWtX5u1oPdQfx+r7xXPhzWGGVijI4bZbHEQ2PJyXS6iCgkW+2AGEroScKahVGJs7QGUsL/C2o3KzfE1BXQiKV++TniDdegxjUkHd70KM1mXIAmguRGTr/Uh219FAm0dLZqWs0ms= X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2019 10:21:20.9777 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e7efadc-2e2e-4107-d6c7-08d7522296eb X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.8]; Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR07MB4139 Subject: [dpdk-dev] [PATCH v3] 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" 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=1 is removed at runtime, the latest cryptodev N cannot be accessible, because nb_devs=N-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 devices") Cc: stable@dpdk.org Signed-off-by: Julien Meunier --- v3: * Set rte_cryptodev_is_valid_device_data as inline * Remove max_devs in rte_cryptodev_global v2: * Restore nb_devs * Update headline (check-git-log.sh) * Update commit log 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/rte_cryptodev.c index b16ef7b..89aa2ed 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -50,8 +50,7 @@ struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices; static struct rte_cryptodev_global cryptodev_globals = { .devs = rte_crypto_devices, .data = { NULL }, - .nb_devs = 0, - .max_devs = RTE_CRYPTO_MAX_DEVS + .nb_devs = 0 }; /* spinlock for crypto device callbacks */ @@ -512,7 +511,7 @@ rte_cryptodev_pmd_get_named_dev(const char *name) if (name == NULL) return NULL; - for (i = 0; i < cryptodev_globals.max_devs; i++) { + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) { dev = &cryptodev_globals.devs[i]; if ((dev->attached == RTE_CRYPTODEV_ATTACHED) && @@ -523,12 +522,21 @@ rte_cryptodev_pmd_get_named_dev(const char *name) return NULL; } +static inline uint8_t +rte_cryptodev_is_valid_device_data(uint8_t dev_id) +{ + if (rte_crypto_devices[dev_id].data == NULL) + return 0; + + return 1; +} + unsigned int rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id) { struct rte_cryptodev *dev = NULL; - if (dev_id >= cryptodev_globals.nb_devs) + if (!rte_cryptodev_is_valid_device_data(dev_id)) return 0; dev = rte_cryptodev_pmd_get_dev(dev_id); @@ -547,12 +555,15 @@ rte_cryptodev_get_dev_id(const char *name) if (name == NULL) return -1; - for (i = 0; i < cryptodev_globals.nb_devs; i++) + for (i = 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) == 0) && (cryptodev_globals.devs[i].attached == RTE_CRYPTODEV_ATTACHED)) return i; + } return -1; } @@ -568,7 +579,7 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id) { uint8_t i, dev_count = 0; - for (i = 0; i < cryptodev_globals.max_devs; i++) + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) if (cryptodev_globals.devs[i].driver_id == driver_id && cryptodev_globals.devs[i].attached == RTE_CRYPTODEV_ATTACHED) @@ -583,9 +594,10 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices, { uint8_t i, count = 0; struct rte_cryptodev *devs = cryptodev_globals.devs; - uint8_t max_devs = cryptodev_globals.max_devs; - for (i = 0; i < max_devs && count < nb_devices; i++) { + for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) { + if (!rte_cryptodev_is_valid_device_data(i)) + continue; if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) { int cmp; @@ -1101,7 +1113,7 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info) { struct rte_cryptodev *dev; - if (dev_id >= cryptodev_globals.nb_devs) { + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { CDEV_LOG_ERR("Invalid dev_id=%d", dev_id); return; } diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index defe05e..fba14f2 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -61,7 +61,6 @@ struct rte_cryptodev_global { struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS]; /**< Device private data */ uint8_t nb_devs; /**< Number of devices found */ - uint8_t max_devs; /**< Max number of devices */ }; /* Cryptodev driver, containing the driver ID */ -- 2.10.2