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 90471A2EFC for ; Tue, 15 Oct 2019 18:50:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6BF3F1EDD7; Tue, 15 Oct 2019 18:50:47 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140104.outbound.protection.outlook.com [40.107.14.104]) by dpdk.org (Postfix) with ESMTP id 426FD1EDBF; Tue, 15 Oct 2019 18:50:46 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BqlzkhDsVCf9+bNf7A2Ts7CIR7EV5PAMKmsWgcB2kGelYtPNJqLLKPz0ClvOT573mHvnVTiMIQo/8+VQtpCwRmQB+/PBnqbi0Fm8Acw9m1kZiJtJF42295/mRWsc/mQ44ytajwklCp0nEQLVwxoJ/JCWkjdetDlF3KpvQCeAQlOklV95W2gB2PCuWH0G9ZJ8oWlqCgCT+evMKfnT6PvzGscR3uI+64sv2vOUhOHT3xBA275Fs1ZzdYX/e5ICq/jMs7Zu1LNF/8Mnq4G6t20r3yzMClRjLoASpXKaFeucq+/n4Umh/X7/U751+zPmV+00kcr+oTjSU2DXkYDw3Jrt3A== 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=V0rNCAopTT4BumRg9VAq6taBKgjE/ZE4uQBHJe6kuus=; b=CcaiBeSMVzrwQC0VNC1trcLaBwTteX+L6v6tijSBPKORo70f/P9aJBHdlLbkegJxLPWxXSZwcMYqPCgV+cbyc1wnXxnjk1a9OwbP54NvGEUI9DTXBDyqLYGf+gEhN1yBQOkG1zevo75wbOtC7KmZ1ONMR1NLQ0O+tljeozuHBNozWUI9106pm62Da98gHsFGynfs2aMwKGHWK49cL81/R4NoUuZD6hDwiYfGRqDWMNViMJ1xjgEm+uy5oy031F4Gelq59V/hqrkaEYFbzoyvpUVqZ+4nSVEgX8wmCb1IWIbsuMSFuxgTQHusIvDNF4ZkG42AJZ2EY45A0U3Sfh9FOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.17) 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=V0rNCAopTT4BumRg9VAq6taBKgjE/ZE4uQBHJe6kuus=; b=kI4A+oJ1wxk0I9sk9T/9etzkzLx19Y6Xzhob8c61p07T2JQfq45HWY8WWSXETyeq1e1Ph+blM4c7ti0HGnYXFRqTvVNudKxLXq8nJ2Xa27NwHox4mOMqxoIGOoD7XTeSiXlnnpy2PWY+WIMbgr74IhVCdAk9DdNUeWeVPSbd1qs= Received: from HE1PR07CA0004.eurprd07.prod.outlook.com (2603:10a6:7:67::14) by AM4PR07MB3427.eurprd07.prod.outlook.com (2603:10a6:205:e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.13; Tue, 15 Oct 2019 16:50:45 +0000 Received: from AM5EUR03FT063.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::204) by HE1PR07CA0004.outlook.office365.com (2603:10a6:7:67::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.5 via Frontend Transport; Tue, 15 Oct 2019 16:50:45 +0000 Authentication-Results: spf=pass (sender IP is 131.228.2.17) 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.17 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.17; helo=fihe3nok0735.emea.nsn-net.net; Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.17) by AM5EUR03FT063.mail.protection.outlook.com (10.152.16.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.15 via Frontend Transport; Tue, 15 Oct 2019 16:50:45 +0000 Received: from lfs-up-04.novalocal ([10.157.84.234]) by fihe3nok0735.emea.nsn-net.net (GMO) with ESMTP id x9FGoiqH012962; Tue, 15 Oct 2019 16:50:44 GMT Received: by lfs-up-04.novalocal (Postfix, from userid 62146483) id EE5E6A4B9; Tue, 15 Oct 2019 19:50:43 +0300 (EEST) From: Julien Meunier To: Declan Doherty Cc: dev@dpdk.org, stable@dpdk.org, akhil.goyal@nxp.com Date: Tue, 15 Oct 2019 19:50:33 +0300 Message-Id: <20191015165034.24276-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.17; IPV:CAL; SCL:-1; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(376002)(346002)(136003)(39860400002)(396003)(189003)(199004)(14444005)(70586007)(5024004)(2906002)(76130400001)(81166006)(126002)(81156014)(44832011)(50226002)(86362001)(36756003)(70206006)(8936002)(6266002)(4326008)(305945005)(26005)(47776003)(8676002)(446003)(2616005)(476003)(186003)(486006)(336012)(48376002)(11346002)(6916009)(26826003)(5660300002)(478600001)(50466002)(51416003)(16586007)(6666004)(356004)(1076003)(42186006)(106002)(76176011)(103686004)(316002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR07MB3427; H:fihe3nok0735.emea.nsn-net.net; FPR:; SPF:Pass; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88a4b66e-d50e-4fbd-55cf-08d7518fd2ad X-MS-TrafficTypeDiagnostic: AM4PR07MB3427: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1091; X-Forefront-PRVS: 01917B1794 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: naVgQQnlJ469QxKk/r4BCvgGbHjy0KRYegUjvV6h/RQLMhJ5XrMzLkFL7iDiZ95chsNi3oi7feGDp0cnqrQMBRs3Lc6wi+s/9NBwp0Y2CrsYN7hHLVDcUVyT34yIfuQuWVWlFMAl71g1jzFO95Edd2cToHUGE7JKdUMNYO7pPA0ftPwFQ90r9m6s7r8GGQDxJWhBYwHyk143Zf/Y9sleFGy4TIFBGiZIRG92QA1TL+q8R3uTwZ1aTTQ0J9Z8DOqbbWaIeKIIeNOcHdKsTv3B7WXaoglBTA3+0vVK0/30AhEOPTlQfN5I8hiJwxv9MoiJhD2romyv7oEIXhk2+rWrRqs4WLbIG+P2UyuVxSvvC8wFu9sNbMVB0rZ+PqgD2j2vsJIYc0I7AaU4Km6QsXY4ZzBoOMRJwP1d1hyusRgN/aw= X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2019 16:50:45.2352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88a4b66e-d50e-4fbd-55cf-08d7518fd2ad 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.17]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR07MB3427 Subject: [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" 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 --- v2: * Restore nb_devs * Update headline (check-git-log.sh) * Update commit log lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) 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 = { .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 @@ struct rte_cryptodev * 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 @@ struct rte_cryptodev * return NULL; } +static 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 @@ struct rte_cryptodev * 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 @@ struct rte_cryptodev * { 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 @@ struct rte_cryptodev * { 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 @@ struct rte_cryptodev * { 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; } -- 1.8.3.1