From patchwork Wed Jul 27 09:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930273 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78A8BC04A68 for ; Wed, 27 Jul 2022 09:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbiG0JoV (ORCPT ); Wed, 27 Jul 2022 05:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbiG0JoN (ORCPT ); Wed, 27 Jul 2022 05:44:13 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2066.outbound.protection.outlook.com [40.107.94.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71A573FA1D for ; Wed, 27 Jul 2022 02:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hw2JAlIOMEcyVzOjVu1C8U/ecO4yEnbqOTbTnCmkTLeMfwG3Hk8XOHfWrgE+VUgQnvSgxdS4bb7YI+wEk/UYMIg9BATcgSdMOaqnz4KkNmz0XtoiqJyl6Z+ZDWpFH2DZIg3clgxcVUEZVG/YUFSzOoAoStpomPWs5Nsjdf8E4CAFHUYIBb4VHK8BL8xq06kmj5j+OHE/K3c5OnCyC32MxnHerbAlhR2iCRJl9yRRFBaPihLwIdn4GAVFfzLmrtq2pyQ55+zhoupGzDyXpxtZHHTTnFyFwD/tWXvCFnYtxy6t0hwyhkrPUi4z4cD9wXrMoOEvKvsCvdimbLNfdaHvlQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7XX4QrJ+IKkmo9qvqC02dC079qQqcebiEA8XWWYRrow=; b=HA3cBeVOSEDX/KvtQv9tBzLEvW1MY5blKMTW/b8zm0FkQUIZB0jC4y0lbpHXxAtIXEm5lsDy7STWd1dJalj3ovRDrseBpBay1c90/GPqJUTIkdC75mFx7DWx90rWcp+hDwTzDTCWPXIvG+blf8AtEq+XS9o1BfpFXdNMA94xqV7S/2+3IG3/1pzQJRxQgmfP9nrn4rEahGGG5TNz5g3M328c4cQA52bi8gDlJAp8MXmxY/wxI3VAh/yjs6QTgOO3liKxGtTM6EBsQ/sPGAHOlz4/Ybm5SIwQRPBMmW73JxHTjS13fYIV+63qThRssaoTYuIO5lOrw0ilwQQTwfyyfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7XX4QrJ+IKkmo9qvqC02dC079qQqcebiEA8XWWYRrow=; b=EFOADpYzHNU0Y4LVG+Lrvi8140651Y1oaewH32CBnNZa2sm+JVkJ+WKNrGya6bZ7sDD8ctMQa3TI0XMeyylJNvAVf39MCkpEQ3Ax9H7DRf5TvWI8oZH1PPO6w3xybfzF5IKll7gH5wPV49gZ6FOOKGui7+ozMpLiNhgkJr8ZHm2Wfyu51zJDwEF2b5jW6fEWu0oSGg77UBWgodoN/lyLsNXTo3m8jYIDG56EKJnm6vgf9NOmHSuOeWe4+sMTjvQjjU0t2FW4K9jornaYmb0IMm6KG2FYchCmZApwKC1kk4QIPWGH222BfIJEobFKXKSiWE0xEiU9rEJnjzdpYcKIVQ== Received: from MW4PR03CA0219.namprd03.prod.outlook.com (2603:10b6:303:b9::14) by SN6PR12MB2717.namprd12.prod.outlook.com (2603:10b6:805:68::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.18; Wed, 27 Jul 2022 09:44:10 +0000 Received: from CO1NAM11FT042.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::67) by MW4PR03CA0219.outlook.office365.com (2603:10b6:303:b9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19 via Frontend Transport; Wed, 27 Jul 2022 09:44:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT042.mail.protection.outlook.com (10.13.174.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:10 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:09 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:08 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:06 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan , Maxim Mikityanskiy Subject: [PATCH net-next V3 1/6] net/tls: Perform immediate device ctx cleanup when possible Date: Wed, 27 Jul 2022 12:43:41 +0300 Message-ID: <20220727094346.10540-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47d365bc-7ad5-451b-51f5-08da6fb48e92 X-MS-TrafficTypeDiagnostic: SN6PR12MB2717:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0U5xZxkmetiV1zBlFBuZjXgmIorLsvpJgjd3JPXF4HDU7MJyLUQp0Z/sG44mhi8OePNBF+G9vK784lakLAvpU5W3A4RFGFmpR8HHg3GfximzF1jR42CWSweNi9inm446ZvKME5u0oaH8r7pBAq7PGeVsXHtbhV3HyZ3mT9N1v8ULryteUdlM0y6UpO+cTVtyGQO6aGTD6Abt6BgE0KC7QVdJvlbSAVL2C8BHu86Ceca+E5Ec1IGExuxrVsqN+jTNBarlub2uToQXKc36hdQdQfr4LMp5U19lKsY34yU3S8TAMxLvUhei+C8yTBZcaRkS8BpLUiCMgiXDDr5tr+S1lYAzaiy9zq5gvhLCD/HHsPPO+WRe7NgvyMsbGfo9jxCdsSCQYleyMAkgiy/cgt0TamKmiJPvE4VydT6iUSN7PfjbYmYGe5xRK5EjS1uzzUJM2NOo1K47Gq6436U5RCdZ+7REzZF9+6yX6bL0a0Ye5A/zfFe6MxXMytC4KZ6MCvV/CyBXPcZ/is8RNx3Kbaf9LENOpGzIr931+qNJPl9wHhBoK6hp8MgpptTrXCts2a2XOsfQ837p1MZSX2YHXQ+CLieGXkuhpk9GNsrF9AeracW3GWzQtEl4FFFBXY2kQW7gdCKqQLvD/xiudRToBwuQk+zhdda5IQoZVCl9ofWBgVvmOil0WkN3OkiAmQzLpHMSv7mqrvBKIFMzP8YEHk4/KOIYQt66R1xvbVweTQmYKxUKKY45ShzNeVG5o9NYkJ2HyN2d7YzKi44ButIDkll0KGV12gHvvb2tyFjjKXq11bOzi6cdUsOtLzbbkg2d4h5WAHYRcvo3SwWXOe2InwlDH8Mb7tcNMy3VrxYUO2PgjQ0= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(396003)(136003)(376002)(39860400002)(36840700001)(40470700004)(46966006)(83380400001)(8936002)(1076003)(26005)(47076005)(5660300002)(82310400005)(426003)(336012)(107886003)(2616005)(6666004)(478600001)(186003)(36756003)(41300700001)(7696005)(81166007)(40460700003)(70586007)(36860700001)(82740400003)(86362001)(70206006)(40480700001)(2906002)(54906003)(4326008)(110136005)(316002)(356005)(8676002)(14773001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:10.2003 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47d365bc-7ad5-451b-51f5-08da6fb48e92 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT042.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2717 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org TLS context destructor can be run in atomic context. Cleanup operations for device-offloaded contexts could require access and interaction with the device callbacks, which might sleep. Hence, the cleanup of such contexts must be deferred and completed inside an async work. For all others, this is not necessary, as cleanup is atomic. Invoke cleanup immediately for them, avoiding queueing redundant gc work. Signed-off-by: Tariq Toukan Reviewed-by: Maxim Mikityanskiy Signed-off-by: Saeed Mahameed --- net/tls/tls_device.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) v3: To solve sync issue, rebased on top of f08d8c1bb97c net/tls: Fix race in TLS device down flow. diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index fc513c1806a0..7861086aaf76 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -96,19 +96,29 @@ static void tls_device_gc_task(struct work_struct *work) static void tls_device_queue_ctx_destruction(struct tls_context *ctx) { unsigned long flags; + bool async_cleanup; spin_lock_irqsave(&tls_device_lock, flags); - if (unlikely(!refcount_dec_and_test(&ctx->refcount))) - goto unlock; + if (unlikely(!refcount_dec_and_test(&ctx->refcount))) { + spin_unlock_irqrestore(&tls_device_lock, flags); + return; + } - list_move_tail(&ctx->list, &tls_device_gc_list); + async_cleanup = ctx->netdev && ctx->tx_conf == TLS_HW; + if (async_cleanup) { + list_move_tail(&ctx->list, &tls_device_gc_list); - /* schedule_work inside the spinlock - * to make sure tls_device_down waits for that work. - */ - schedule_work(&tls_device_gc_work); -unlock: + /* schedule_work inside the spinlock + * to make sure tls_device_down waits for that work. + */ + schedule_work(&tls_device_gc_work); + } else { + list_del(&ctx->list); + } spin_unlock_irqrestore(&tls_device_lock, flags); + + if (!async_cleanup) + tls_device_free_ctx(ctx); } /* We assume that the socket is already connected */ From patchwork Wed Jul 27 09:43:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930274 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 968B5C04A68 for ; Wed, 27 Jul 2022 09:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbiG0Jo0 (ORCPT ); Wed, 27 Jul 2022 05:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiG0JoQ (ORCPT ); Wed, 27 Jul 2022 05:44:16 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2085.outbound.protection.outlook.com [40.107.243.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529B03FA1D for ; Wed, 27 Jul 2022 02:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=etyIF957G0Nd8LuvARv1mAQQnySaTy4EiTfS0c1buFxxwVaZMkg/u/kbcy5WSh6J8Ez1D7P1ff0Ckdegif3eYU+358GoOTQdDr223Uk/BHSc4DwjHKua1eEO+RYtmEi6hITk+qPzN4cC/0213dm6mNSuzgn8XsBK0V68sS/o5cn3FJ9X+TOTzwtZDrALU21C/L1XzBMwqKY2WGKQ64OxCFwR4l51cPlurXif4G+1NJfCvM36FxXSDFYzmhbTRW5GdmQRmjmY0FdH0TfT3G/e3lyTLywBHVuuKiNRRq2/CmfJjTD63Mso8Ks2XrhRaTzuZvnqjH2dTjnCZtGNFXJj2g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7SqJxg7I/qApxRIIGirWw/WUl1XjW2wwdbCK6MxUuDw=; b=N3FOOKBMTOKxn0AbV4VpmDDyr2VUdqUqKC3LUGyIcslzOylLCICo5RWDry0FKWtZ8GW+In1+B6e3/qrCjl17gbJ1NVoysbxCdrRenEx2ggLgv2PyJPHXeoJS6S0c4A6hJ84KXbDEYDNKhjTJ9v7iKpJZcz2SkVJkg4lQGkQtOzgEl3MV49/GH0hs275RWA6aAAaTu7N6ltoU+XJV9crlqekgeL9vPBpnKCfbyCbykn4LMku2p4KLhPNsBtK2J9w1722YWMyGxoq6dSaiw5IvVz8JFyH+ly4xYcAm0U4qwYL9/TmvAro+Db1wviclnzvfX0HIUKP1GGTzXdz0uQyAVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7SqJxg7I/qApxRIIGirWw/WUl1XjW2wwdbCK6MxUuDw=; b=V2uQsizccBk5DmYEZoem2WmdI8+2zfNv2j/kmoacoPIqJ82PRKTdbWhYker0ELTgFHsSyWkcY7Ir8FQ943/Pa9WoA1JnMhWtWT0/mbnH03WBCG9ISWqFjBBl3s7sGmjvUhX/UJhI9OHti7Y41VYmIU/SaXB3RwR3fFOgwaKO/WPpLOt4aDFasxXgjaTwfHx0WXcFH7BQLVW6LgC5v4NuqKxI/Yf/9iPiecLBqqsbHny83F9swq6hT5bIXHSpFk1WLDPSnLwy0qQ4YaolaErg28CGql5EgSOpb3jgoNcl7JH347nouWZKMeL22cCjyPguheduqfJOvopFse2+Zvu3XQ== Received: from BN7PR06CA0044.namprd06.prod.outlook.com (2603:10b6:408:34::21) by DM6PR12MB2955.namprd12.prod.outlook.com (2603:10b6:5:181::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Wed, 27 Jul 2022 09:44:13 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:408:34:cafe::a9) by BN7PR06CA0044.outlook.office365.com (2603:10b6:408:34::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:13 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:12 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:11 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:09 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan , Maxim Mikityanskiy Subject: [PATCH net-next V3 2/6] net/tls: Multi-threaded calls to TX tls_dev_del Date: Wed, 27 Jul 2022 12:43:42 +0300 Message-ID: <20220727094346.10540-3-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38ffa0c0-0c45-4b26-b61e-08da6fb4907c X-MS-TrafficTypeDiagnostic: DM6PR12MB2955:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DtD2SCC0N1TES5SK2xZBcd05XK4Aaq3jvy9INy/oGqPk8AE6eBCTvzxeNzNLMsDTvCWtr2lI/IzaChQLg5i9QP6yBlIZkfrHjS8TsgqLqLi1wt43eqI6p/QxJyLhBvJk2S5oqyDABSz+KktPtAB4jGLGlAm/y2y7ggdkiAv4ncMutIgMxK7uWtM+Pk8weNgz1OKnMdp3vwIr9IcO7XvBXZ4LIlhc6hjXUs3VNjDPQkV3zsIoOo0MDd8/yt4X3GdU82lwYBUv0KdwRCpN3movsPvanrtRLcvMK/7RRMIo7Tm6q5jQX9u+4VT87+79LKR6wtB5Bfw091Xk4rNJPWHiR7Z0+7WSG/f+q/EBaIk1FbqerumObSgICmasIY2Cb+LtOJZz4+M4xgZROX90FP4ExjiHq+dDZbl16M6wRVL88kpYWnSWCafR96rjayopS4DdcAV5IdXdGGqecvdMTa/iELaeqlL6d74NHD4r2lLOCWUFuufXPWbFa6Xo/nGMGbPHzVazLuAxpuGIK6fiqepq35Ux4Hv4EdFaFoEXRuyu4XWALFE34JU6CsepOK1gv4Lk0fk6Batyh6XE1GBOmjkIsEY3TlnTpmahblUZ03xtYoCisFrboJvGJ4/uxL3AzZAc3u5iQA0Cdb80BqyY4AsRll1VADuDmF9AgHigDbde1XjcytNVWMzydYwdbY2xuxi5AjXTUsxIPFYVNvqtwGldGaiRMo/mQNmo93RZ+dfVsmkcbBL8A7+oVhcxwIPp/EzA9wbUOinHQ7YAjZih0DXiKLpjNH3VBbV+GCmeOs32QFs1k8rYg0Nu3YPLLOeaxXZws3pE/45hcfAYfuVxJPRY3w== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(136003)(39860400002)(376002)(396003)(46966006)(36840700001)(40470700004)(47076005)(336012)(36860700001)(86362001)(83380400001)(426003)(186003)(2616005)(7696005)(356005)(1076003)(6666004)(107886003)(26005)(82740400003)(478600001)(110136005)(54906003)(36756003)(5660300002)(81166007)(41300700001)(70586007)(70206006)(8676002)(8936002)(40460700003)(4326008)(40480700001)(2906002)(82310400005)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:13.3360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38ffa0c0-0c45-4b26-b61e-08da6fb4907c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2955 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Multiple TLS device-offloaded contexts can be added in parallel via concurrent calls to .tls_dev_add, while calls to .tls_dev_del are sequential in tls_device_gc_task. This is not a sustainable behavior. This creates a rate gap between add and del operations (addition rate outperforms the deletion rate). When running for enough time, the TLS device resources could get exhausted, failing to offload new connections. Replace the single-threaded garbage collector work with a per-context alternative, so they can be handled on several cores in parallel. Use a new dedicated destruct workqueue for this. Tested with mlx5 device: Before: 22141 add/sec, 103 del/sec After: 11684 add/sec, 11684 del/sec Signed-off-by: Tariq Toukan Reviewed-by: Maxim Mikityanskiy Signed-off-by: Saeed Mahameed --- include/net/tls.h | 2 ++ net/tls/tls_device.c | 63 ++++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 32 deletions(-) v3: Rebased on top of 3d8c51b25a23 net/tls: Check for errors in tls_device_init in which error handling for tls_device_init() is introduced. diff --git a/include/net/tls.h b/include/net/tls.h index abb050b0df83..b75b5727abdb 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -161,6 +161,8 @@ struct tls_offload_context_tx { struct scatterlist sg_tx_data[MAX_SKB_FRAGS]; void (*sk_destruct)(struct sock *sk); + struct work_struct destruct_work; + struct tls_context *ctx; u8 driver_state[] __aligned(8); /* The TLS layer reserves room for driver specific state * Currently the belief is that there is not enough diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 7861086aaf76..6167999e5000 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -46,10 +46,8 @@ */ static DECLARE_RWSEM(device_offload_lock); -static void tls_device_gc_task(struct work_struct *work); +static struct workqueue_struct *destruct_wq __read_mostly; -static DECLARE_WORK(tls_device_gc_work, tls_device_gc_task); -static LIST_HEAD(tls_device_gc_list); static LIST_HEAD(tls_device_list); static LIST_HEAD(tls_device_down_list); static DEFINE_SPINLOCK(tls_device_lock); @@ -68,29 +66,17 @@ static void tls_device_free_ctx(struct tls_context *ctx) tls_ctx_free(NULL, ctx); } -static void tls_device_gc_task(struct work_struct *work) +static void tls_device_tx_del_task(struct work_struct *work) { - struct tls_context *ctx, *tmp; - unsigned long flags; - LIST_HEAD(gc_list); - - spin_lock_irqsave(&tls_device_lock, flags); - list_splice_init(&tls_device_gc_list, &gc_list); - spin_unlock_irqrestore(&tls_device_lock, flags); - - list_for_each_entry_safe(ctx, tmp, &gc_list, list) { - struct net_device *netdev = ctx->netdev; + struct tls_offload_context_tx *offload_ctx = + container_of(work, struct tls_offload_context_tx, destruct_work); + struct tls_context *ctx = offload_ctx->ctx; + struct net_device *netdev = ctx->netdev; - if (netdev && ctx->tx_conf == TLS_HW) { - netdev->tlsdev_ops->tls_dev_del(netdev, ctx, - TLS_OFFLOAD_CTX_DIR_TX); - dev_put(netdev); - ctx->netdev = NULL; - } - - list_del(&ctx->list); - tls_device_free_ctx(ctx); - } + netdev->tlsdev_ops->tls_dev_del(netdev, ctx, TLS_OFFLOAD_CTX_DIR_TX); + dev_put(netdev); + ctx->netdev = NULL; + tls_device_free_ctx(ctx); } static void tls_device_queue_ctx_destruction(struct tls_context *ctx) @@ -104,16 +90,15 @@ static void tls_device_queue_ctx_destruction(struct tls_context *ctx) return; } + list_del(&ctx->list); /* Remove from tls_device_list / tls_device_down_list */ async_cleanup = ctx->netdev && ctx->tx_conf == TLS_HW; if (async_cleanup) { - list_move_tail(&ctx->list, &tls_device_gc_list); + struct tls_offload_context_tx *offload_ctx = tls_offload_ctx_tx(ctx); - /* schedule_work inside the spinlock + /* queue_work inside the spinlock * to make sure tls_device_down waits for that work. */ - schedule_work(&tls_device_gc_work); - } else { - list_del(&ctx->list); + queue_work(destruct_wq, &offload_ctx->destruct_work); } spin_unlock_irqrestore(&tls_device_lock, flags); @@ -1160,6 +1145,9 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx) start_marker_record->len = 0; start_marker_record->num_frags = 0; + INIT_WORK(&offload_ctx->destruct_work, tls_device_tx_del_task); + offload_ctx->ctx = ctx; + INIT_LIST_HEAD(&offload_ctx->records_list); list_add_tail(&start_marker_record->list, &offload_ctx->records_list); spin_lock_init(&offload_ctx->lock); @@ -1399,7 +1387,7 @@ static int tls_device_down(struct net_device *netdev) up_write(&device_offload_lock); - flush_work(&tls_device_gc_work); + flush_workqueue(destruct_wq); return NOTIFY_DONE; } @@ -1440,12 +1428,23 @@ static struct notifier_block tls_dev_notifier = { int __init tls_device_init(void) { - return register_netdevice_notifier(&tls_dev_notifier); + int err; + + destruct_wq = alloc_workqueue("ktls_device_destruct", 0, 0); + if (!destruct_wq) + return -ENOMEM; + + err = register_netdevice_notifier(&tls_dev_notifier); + if (err) + destroy_workqueue(destruct_wq); + + return err; } void __exit tls_device_cleanup(void) { unregister_netdevice_notifier(&tls_dev_notifier); - flush_work(&tls_device_gc_work); + flush_workqueue(destruct_wq); + destroy_workqueue(destruct_wq); clean_acked_data_flush(); } From patchwork Wed Jul 27 09:43:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930275 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0853C19F29 for ; Wed, 27 Jul 2022 09:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiG0Jo1 (ORCPT ); Wed, 27 Jul 2022 05:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbiG0JoU (ORCPT ); Wed, 27 Jul 2022 05:44:20 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2083.outbound.protection.outlook.com [40.107.237.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE3A247B8B for ; Wed, 27 Jul 2022 02:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jJFRuqVNOqFtLgUfChvC6iT97YwLkNUwZijXeDuHpK4PASaWuPA4LU9x+2rXLCmIfvyxhIDLGcRY6F2ClKD4TGgXH1WKgK/dIY/0LGx1giWJpP3c+Ujv1BkdBfBGcodngBa5Ms6vnN3X8mafh1mYx5THuh/8qJbPSYjjT37wj8npWJNfVmqBaBH19cNWt0uxvngbCXWiYhy/ck9IP5bb95I4VFEX8UD3SFbQGk/fo3a+LlBCd4rRm/RL9of0cbm9zaTXHFqpCb0TkjBh9JaHaivV1elBMysJTWxx+KAKP65FrK5mJsy04LqBNfygGCXZ4OLXVbvdDki8QkGGR20msw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J9zJ6KAOGsBwvJBd1eMFKjhJYygxnpE4EaTBYLzmNLw=; b=DYMsx26qXsgMq2ZU+jTVphR77p4yZ6ijMlZlJn04VDsbLWLFvcHlq/BiCP72QKKRjsnD4iv2UbzMyf6pJ4JjIa0Oyr0zxDDLMb16gOKBoFqCP27MmuAsB1B1ETjN/hKS7hfWEEi5WHAJOwEhgUkb9hI+TVbtlLV1pI0KU/SDzzyrUX3iqPaLEylAfU+pY3StKI01nnIMXI33rdvvB7tBZebJEY1di4Alsz6q4tn+M6O9KrTGPyQaf/cDNwbZb+xo8qTGkrUhNpg546KTjuetq2Dwm5MTXlqZZ8Q9DDYMOJe1TgA4arX8V2onQGnfptyWyvzzwpMt0zEwfLDU9Bnt3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J9zJ6KAOGsBwvJBd1eMFKjhJYygxnpE4EaTBYLzmNLw=; b=JTKsReAB1DFlsdBdjEygU0qKzg4ATdi/9sdgb0x6VN1zJQDhDImnQ39EVlOGoFnkGSSfraJikRR5v3tAkuoHVk2wypaArs0yA+GDa3axoFbmB/Kxgoecz9UsYEf4IjlzxeHKwdwR9OfEqHocSy/iNFfqqi85TGROF6pFgZ93CA5NPNIohvCVH1iLeCllzyW7V/g719vK2HpmoWjDvID3Uf92DL1qhWdNyMfOWUEpYSPlBRbPYAGojFOpipeCnZiqL7BOHswqF8r+tJTn6H4dk9qM5JkCoZcRImYHqJYor3S31MM68dPXHEj8Asbs+rjNP0ndb1HRs+eCZmTIP1P0lQ== Received: from BN9PR03CA0930.namprd03.prod.outlook.com (2603:10b6:408:107::35) by MN2PR12MB3407.namprd12.prod.outlook.com (2603:10b6:208:c5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Wed, 27 Jul 2022 09:44:16 +0000 Received: from BN8NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::25) by BN9PR03CA0930.outlook.office365.com (2603:10b6:408:107::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.24 via Frontend Transport; Wed, 27 Jul 2022 09:44:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT037.mail.protection.outlook.com (10.13.177.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:16 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:15 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:15 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:12 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan Subject: [PATCH net-next V3 3/6] net/mlx5e: kTLS, Introduce TLS-specific create TIS Date: Wed, 27 Jul 2022 12:43:43 +0300 Message-ID: <20220727094346.10540-4-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 954c42cd-b9b7-4a52-5a66-08da6fb49231 X-MS-TrafficTypeDiagnostic: MN2PR12MB3407:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UcnEWfLR2bjRfj0pJ1OGPywAz0OBtGcHm/aokuwdxiIyY9wp2s7OjkACH4aiV7FfrVElgEw1Wx8+DSabRaNerly/8gGuGsAAvEeIaC08z3+F3Y/pJyxLJYz8k5lasDkjPiRnHSlrMYktIzX0i6ehvLeEU7msiveGPWj3H0YCY+dv3aLEWnez4AZRDq7wPUl81hVMsJWFX67+LQSE2/d+u4fd/I0CZTD+3ciDDhIeSSA+7wHq5GSV8wnwVinTHHuBWxSHlVXEcNRQmWHolBFwCdiLoLOTGid7Q7eIgVAghdpMdlhbiuL0xdGXe88bxC+UCimr8tvCiH6q5rVOwy5/HHqYPsNrHvgOUHMUzscQm8qHni50q5t9DFW0EEanbO2EKjYXSM63fegiMThBzGft0NHykb7UaLwvcVXJWckJAudPIH9mXQV1e2+9Zs2Qd99RrADgunQ97ApTJItVGKKFw4JzLE9g54OsIwBHBeiiPSitJHxlIL223tB7WOASnG/QV7xv0Y5dVcZqoxOoOcUC3NXf/M/NyRnxIvi9rxqehoCwVfxhi7qB4RouNU+OFMr531KnKXbOajUgE1Z8D3UgtpYkIu4g3DrTSizQJEBz4LqtO31+oRlMV5XOcGG2PaBAnVqo+z7FkUdB4OTGLzwOcwg9fgjfxx0GK724urce+razAr0exS9vYjMfW4Vrrnweb4EkgbHINlXEIN8+vHd2W2qEucu1I8TR6p4/n11ooOZJOoMvwOGZAoZ3YQqX6nXZGUOwmE0KWMZPs1PlOUMvO19phdvyC2kvaUW8JdBihXHGyyxF9rWS+AcfS2b4OP3iOGzky1ZZRVYsIaK3EGM/og== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(376002)(346002)(136003)(39860400002)(396003)(46966006)(36840700001)(40470700004)(36756003)(110136005)(6666004)(41300700001)(186003)(2906002)(1076003)(7696005)(47076005)(4326008)(86362001)(316002)(107886003)(426003)(83380400001)(82310400005)(336012)(2616005)(40460700003)(356005)(5660300002)(26005)(40480700001)(8936002)(82740400003)(36860700001)(54906003)(81166007)(70586007)(8676002)(478600001)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:16.1975 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 954c42cd-b9b7-4a52-5a66-08da6fb49231 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org TLS TIS objects have a defined role in mapping and reaching the HW TLS contexts. Some standard TIS attributes (like LAG port affinity) are not relevant for them. Use a dedicated TLS TIS create function instead of the generic mlx5e_create_tis. Signed-off-by: Tariq Toukan Reviewed-by: Gal Pressman Signed-off-by: Saeed Mahameed --- .../ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index fba21edf88d8..73ba2501e441 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -39,16 +39,20 @@ u16 mlx5e_ktls_get_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *pa return stop_room; } +static void mlx5e_ktls_set_tisc(struct mlx5_core_dev *mdev, void *tisc) +{ + MLX5_SET(tisc, tisc, tls_en, 1); + MLX5_SET(tisc, tisc, pd, mdev->mlx5e_res.hw_objs.pdn); + MLX5_SET(tisc, tisc, transport_domain, mdev->mlx5e_res.hw_objs.td.tdn); +} + static int mlx5e_ktls_create_tis(struct mlx5_core_dev *mdev, u32 *tisn) { u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {}; - void *tisc; - - tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); - MLX5_SET(tisc, tisc, tls_en, 1); + mlx5e_ktls_set_tisc(mdev, MLX5_ADDR_OF(create_tis_in, in, ctx)); - return mlx5e_create_tis(mdev, in, tisn); + return mlx5_core_create_tis(mdev, in, tisn); } struct mlx5e_ktls_offload_context_tx { From patchwork Wed Jul 27 09:43:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930276 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3E3CC19F29 for ; Wed, 27 Jul 2022 09:44:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230339AbiG0Jo2 (ORCPT ); Wed, 27 Jul 2022 05:44:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbiG0JoW (ORCPT ); Wed, 27 Jul 2022 05:44:22 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2043.outbound.protection.outlook.com [40.107.237.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05D0C47BB3 for ; Wed, 27 Jul 2022 02:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M12vHw83/AGdjY0d/Rk9bbYgEoj3iWdbw1bN5cgbYNn71h+v6PfwzoKe5NlONJtwcjRK8pQ8f6ufEAVi9ljCmfRGuZoS7wc3eDa7CPXgx7+O01fRfwlc6tkIfqa4YVpB2kK9J3n0gTHiOhtJIHA3KqMjm0Jz5K6yZxSIP/xk3BCs+ZQfJYerdwIzU+7hdDhp0GkutIxRXSU1ouKHlBJkUpti7LqaOzuOPyfNDG9pgAsNnFsXkTN3WWz2BQ2ddLJijEaNrxvBCqLOYOu1QIwW7yOM3X6W+Jwv6HfISZgEaC4C82wInz74FzgFEi1qU2x0pOhyb+gfYz22Ere2G1tsyA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UW3yLImHEDxQj807LUd3qS63/3DWM1RXr75b5qaYC+A=; b=V4VQQvkkySDa9dke6mrHTBZG7FbV4atIUX0ew+gRFTfdXj+po0jzhnEHNnmEoBNgoyqaxEjIvSnvd2mD/Hu/SDMC6RVZjlZjWIoctrH8YgpMeMLObMYYNA09EewJbqj617yvUTOZpjWcSUV70/3TAVAn07QfdGi0KGu90s0RvfTdRlmw091CgM/OZsJ5mHGRkpX6VYJyF1JZNprgLN7fkhlwQhGCcHzgKFKEzeTNnkyU1LVYZpeBDMDTO+IOIOnoAVQyq4j8THyO9lNdopS/PnDbdZa4y+2RUlcxFykAK7DxRS8S07HIgrQeamWCDzHIKu1VTJHwu3+J+0KKywYP0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UW3yLImHEDxQj807LUd3qS63/3DWM1RXr75b5qaYC+A=; b=ll7ph5gL5gCk6MgVSypf21oVHljow0BAaDe1bHMc71Wd2ciAlwWqChDEiUhrvHiZcVW7jaPHGe2PkZBT5cs5LYio2XWVSuXz1aDADYeqP8gd+fRtVs63CsHKATcunMTbe2Y3PaboHnoQwjT5E4AIz/1EMvaFHvgavJI8RD1YMbAzetbUD9S8y52SzCbcmb4mfhmByzl0GZabUnavfnS6lJbCB6damX6bHR7x8NJ8ofqw4KcoFFcBwfuYtuIwKhmsd8yMm0R4sI7qrd6ijKhWdkgEb/1HgLzn9MKqCJmsJ6oZ9/YHAb8md16WQn6XcxgckAnyTBiJCTM0HmUY/B0e1Q== Received: from BN0PR04CA0064.namprd04.prod.outlook.com (2603:10b6:408:ea::9) by MN2PR12MB4469.namprd12.prod.outlook.com (2603:10b6:208:268::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Wed, 27 Jul 2022 09:44:19 +0000 Received: from BN8NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ea:cafe::b8) by BN0PR04CA0064.outlook.office365.com (2603:10b6:408:ea::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19 via Frontend Transport; Wed, 27 Jul 2022 09:44:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT036.mail.protection.outlook.com (10.13.177.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:19 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:18 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:17 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:15 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan Subject: [PATCH net-next V3 4/6] net/mlx5e: kTLS, Take stats out of OOO handler Date: Wed, 27 Jul 2022 12:43:44 +0300 Message-ID: <20220727094346.10540-5-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3f944a5b-71b0-4e4d-c6b0-08da6fb493e5 X-MS-TrafficTypeDiagnostic: MN2PR12MB4469:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DobcObyZO8axAB//VY3J6uxJcB5LIBajkU6NONszUjPUmaWwnmk8GT0Gki8BXePux9JYUgN93F/UZn7Vr5AoEHFhDnUg/I/cAO0JdkRc7djKWWuYyb0bmhAs4AIDq4g9OImf6GON4EP1Mw5hc0wFio+oUXs22dB+OhRy2D+JiI+avUtiNCiTbDsSooKNQRVHZKjjq1RIUHaOoaDVegKgX5f4KsutUQmrMKfcgZK4lzdNnrelBrCsCZpN13qXdvtadMdIoqnQnkcIsBOhcLNKpGrpcSzbyZ74W+VvIVcvTNQaqdP/uGNzonMup8FPdm28wf1xkxhynF6P5H81xt54A0Cb5wXk3T/DGuI5YZSzKdrwE0887wU3ITWSUnRTAcLShkhmHcVvGmLsx04DWHPrUqJEuN+vvCuiR31r7IpX+l4+YbHtB6/pvTWpJz7vRtUeaWjk3ykKKjMv4uZg2KgvctKHoF8P98VbfOpbKTQC3533w1P7LWH2uGsmzuoIN2JM8IzxAPSvu0ruhBNcutI8KbGsIhcbl2fZJZGeuMvymXpmG6pCtfVPx/ccynU3Ah7MyO+bXzhsdEu/unTWKm479GaG+3AcgDjkMJ3LJSL66VnKm8KldrhaTHgwkTbxxL43vu9Hc62jc2l+K1JKQiCUNzsnJODTnewtK63WF1lJj7DFx4RBNpNPLpGeCYaywhXHDRGiWCWdYZIKpuATyT5/3bEumuZb2aJUD5Dn8haUKrFkaVz7Xpp/7NPAjGKd+2Kle5pJ2pTwnYd0QnMm4S07r6b84/jKBg1kDCFQZBPDq/GtNiuQd01fw/zjnzUXRZiwWfE8gl1wEFU/vtNRIWHf6g== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(396003)(39860400002)(376002)(136003)(46966006)(36840700001)(40470700004)(356005)(5660300002)(186003)(82740400003)(82310400005)(4326008)(86362001)(336012)(8936002)(1076003)(81166007)(36756003)(426003)(70586007)(6666004)(7696005)(26005)(36860700001)(47076005)(41300700001)(316002)(107886003)(2616005)(110136005)(83380400001)(478600001)(70206006)(40460700003)(8676002)(2906002)(54906003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:19.0577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f944a5b-71b0-4e4d-c6b0-08da6fb493e5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4469 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Let the caller of mlx5e_ktls_tx_handle_ooo() take care of updating the stats, according to the returned value. As the switch/case blocks are already there, this change saves unnecessary branches in the handler. Signed-off-by: Tariq Toukan Reviewed-by: Gal Pressman Signed-off-by: Saeed Mahameed --- .../mellanox/mlx5/core/en_accel/ktls_tx.c | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index 73ba2501e441..82281b1d7555 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -381,26 +381,17 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, int datalen, u32 seq) { - struct mlx5e_sq_stats *stats = sq->stats; enum mlx5e_ktls_sync_retval ret; struct tx_sync_info info = {}; - int i = 0; + int i; ret = tx_sync_info_get(priv_tx, seq, datalen, &info); - if (unlikely(ret != MLX5E_KTLS_SYNC_DONE)) { - if (ret == MLX5E_KTLS_SYNC_SKIP_NO_DATA) { - stats->tls_skip_no_sync_data++; - return MLX5E_KTLS_SYNC_SKIP_NO_DATA; - } - /* We might get here if a retransmission reaches the driver - * after the relevant record is acked. + if (unlikely(ret != MLX5E_KTLS_SYNC_DONE)) + /* We might get here with ret == FAIL if a retransmission + * reaches the driver after the relevant record is acked. * It should be safe to drop the packet in this case */ - stats->tls_drop_no_sync_data++; - goto err_out; - } - - stats->tls_ooo++; + return ret; tx_post_resync_params(sq, priv_tx, info.rcd_sn); @@ -412,7 +403,7 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, return MLX5E_KTLS_SYNC_DONE; } - for (; i < info.nr_frags; i++) { + for (i = 0; i < info.nr_frags; i++) { unsigned int orig_fsz, frag_offset = 0, n = 0; skb_frag_t *f = &info.frags[i]; @@ -482,15 +473,19 @@ bool mlx5e_ktls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq, enum mlx5e_ktls_sync_retval ret = mlx5e_ktls_tx_handle_ooo(priv_tx, sq, datalen, seq); + stats->tls_ooo++; + switch (ret) { case MLX5E_KTLS_SYNC_DONE: break; case MLX5E_KTLS_SYNC_SKIP_NO_DATA: + stats->tls_skip_no_sync_data++; if (likely(!skb->decrypted)) goto out; WARN_ON_ONCE(1); - fallthrough; + goto err_out; case MLX5E_KTLS_SYNC_FAIL: + stats->tls_drop_no_sync_data++; goto err_out; } } From patchwork Wed Jul 27 09:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930277 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63114C04A68 for ; Wed, 27 Jul 2022 09:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbiG0Jog (ORCPT ); Wed, 27 Jul 2022 05:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbiG0Jo1 (ORCPT ); Wed, 27 Jul 2022 05:44:27 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2056.outbound.protection.outlook.com [40.107.237.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1480A481CC for ; Wed, 27 Jul 2022 02:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qh5iWYAMcNoKhkEvuufRN9JmQIdjDD429oytQOLkVqc0eBDRAGCpakbaSWvRXx9qpFi7AzBuGFoV5c77rGEE1+xQa+Q25UNaLld8lHWhgXDYR73I3I9n4Q17jCZ8fJDECaPO/sL2kkmWnQWUEgt4EgJTZoStjMGzc/PAenp+rfUNxwjNaHJRWjTAy3VakziHSbEu+fNesJfT4eOR6gclMBlyO7E1mNDiOP3DdmeOoppynSOr6xfwepRxC4UVfU7IibM4AbjV2zxUviNalxAG+af+VHCrwJ8sLL16zq837o93UWP2fYxUgAdYxvK8xBR9fbxZxA0g1GKbpPPrEgNyQQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/Mnp+f9awP6cfzNAbUBRm6TaHfs52Vkvs9HQbfZ7yj4=; b=nNNKQmGuD/iYzAlRktSDeoRGOKnKk6AWGK0JkZKjjdfAF/TzQl9qXQP2bRQO2t89fbw9Hu84ZOGIQaQ/Np87gwFVjS70rgK12kRqbmF6FkFdKvYkRZTIeSJeUg6bkM4h5WfBYjvnoiiEiKsbZdrhimI59Ea69MGUZWIHUjc0HKTsRUh4UzC3C+airnLZjFPJiwtYh4QD+ILtsamXZ6sgcaDmsIA9p8Ah/A0GS1trpbh2l825ePO+6Db/1D/HOgOXqL/gILLHYTZ4uMUE52X+Jmh1v60xtEGeCKc4xDj3QyPkyvCqtZ4Y2wW7RlDubD4ZwSsBo8aPehLUFb13X39Xzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/Mnp+f9awP6cfzNAbUBRm6TaHfs52Vkvs9HQbfZ7yj4=; b=usV3qOknQARaJrhBn6LV053Blrue4E2HuE+HdhdCAsifCMP+IUIl34GeRBejMgAjf1Fym3hZ+IYpYLsAN0/1NlsTsJkBpYEksHmOzSQpLzY9KqXDLE1i08F7jFm6ta2qhy3IqqN02k2r/kZVTwmNiZiqZxRci1EReiCdiOaOZ7bko2AI73H10cyplP3dJyJVMzzsBBWYCHyPHHqcRpK2wu/JPFyrDurIDi4pLIwo2orMlnUttlneuZYB8oI35ehj4RZ4xv4tHypByjhMc4WjavXZah6UEaSDg3344tRYECpO1kRpJU/y8r3X9X8EeoVfP27KsJPA6zJlmS780I50mw== Received: from MW4PR04CA0064.namprd04.prod.outlook.com (2603:10b6:303:6b::9) by PH7PR12MB5949.namprd12.prod.outlook.com (2603:10b6:510:1d8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.25; Wed, 27 Jul 2022 09:44:22 +0000 Received: from CO1NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::fe) by MW4PR04CA0064.outlook.office365.com (2603:10b6:303:6b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.25 via Frontend Transport; Wed, 27 Jul 2022 09:44:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT052.mail.protection.outlook.com (10.13.174.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:21 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:21 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:20 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:18 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan Subject: [PATCH net-next V3 5/6] net/mlx5e: kTLS, Recycle objects of device-offloaded TLS TX connections Date: Wed, 27 Jul 2022 12:43:45 +0300 Message-ID: <20220727094346.10540-6-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f3cb519-7ef7-4203-737c-08da6fb49552 X-MS-TrafficTypeDiagnostic: PH7PR12MB5949:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ti4KFKjku9Prj5fc2awtea0nnAEkHSVPx9hySDRwMDWlPomxnqezKgYv4IFYd/WeMTqZbJ/uE48XEPLbdfUXmx+c31LrE9wKRBA0QzPhNuJU2eGsTDiyQ/cggX8dSKOli1+NkGXcIZnlzxhsdfZPsBuSjrIuHYP8hszNRDcJ8o8Bjc6o+Imgv2HPFA1uUu6ZK8RlLP0k0CX55RjMrCIkEXdNUxhVjwKyq+cmDaw/BK7UkmtEf4VXF3W8+5EXFOm9e3eTf9VFge1JVYQLUuyYC4sHGR089ZixxnrK6FMocCYSmez+PgXibaNNOxr7T5YXsxP+231um2RxFByxqYteNKGTsI8FnVEz7JlQJh0SWx4H5XdKZwmXxTod/QDX/YuQYS/huVmPYxBpfIqDfwCiJ0cu4wNRa1IK3FixB6p48U/ZoBqPaFFXj8HbcUFoqItbQSRwtGpTDx7dWXp8e9JtHXGfV/Ti8pn9UXdO3Sei6ZwClrzvMZuHGtmroGGu6CK3koS0PvDK3gtyiJBKcFZAV8mvD7hHeDZlWsIBlg4fNnb5lgYSmIINZUMkRQwNqzHrmTtpv4ZT2ZllSRklnUuvsiBU0dHlU/zp2Jajmy/wFtFmf7TwAJzv6qHwwTknbMLpHkNe3kM+cVnLpfnS9yaWKUCQ8xd57We5RPwTewdOFd+RDTXsB/tMoKu6j6UDHDy6Yg1p1RRmNbHhqTetW03M0iLnCT6M4VL0JoG9lGIL5jQysLeV1MSQxHO6P9WNbXKrOjjwpfNm0mAHIPIdwGH55OsEMs//KZLkoq/Zdcgk74yb+i4CpQ0IZrjqETVqCNRRMtmrUh64OPte8M08sL+KJw== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(39860400002)(376002)(346002)(396003)(46966006)(36840700001)(40470700004)(70586007)(2616005)(82310400005)(47076005)(426003)(8676002)(26005)(336012)(2906002)(70206006)(83380400001)(54906003)(81166007)(82740400003)(86362001)(356005)(40460700003)(40480700001)(110136005)(4326008)(186003)(1076003)(107886003)(8936002)(478600001)(36860700001)(5660300002)(36756003)(7696005)(30864003)(316002)(41300700001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:21.5101 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f3cb519-7ef7-4203-737c-08da6fb49552 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5949 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The transport interface send (TIS) object is responsible for performing all transport related operations of the transmit side. The ConnectX HW uses a TIS object to save and access the TLS crypto information and state of an offloaded TX kTLS connection. Before this patch, we used to create a new TIS per connection and destroy it once it’s closed. Every create and destroy of a TIS is a FW command. Same applies for the private TLS context, where we used to dynamically allocate and free it per connection. Resources recycling reduce the impact of the allocation/free operations and helps speeding up the connection rate. In this feature we maintain a pool of TX objects and use it to recycle the resources instead of re-creating them per connection. A cached TIS popped from the pool is updated to serve the new connection via the fast-path HW interface, updating the tls static and progress params. This is a very fast operation, significantly faster than FW commands. On recycling, a WQE fence is required after the context params change. This guarantees that the data is sent after the context has been successfully updated in hardware, and that the context modification doesn't interfere with existing traffic. Signed-off-by: Tariq Toukan Reviewed-by: Gal Pressman Signed-off-by: Saeed Mahameed --- .../mellanox/mlx5/core/en_accel/en_accel.h | 10 + .../mellanox/mlx5/core/en_accel/ktls.h | 14 ++ .../mellanox/mlx5/core/en_accel/ktls_stats.c | 2 + .../mellanox/mlx5/core/en_accel/ktls_tx.c | 211 ++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/en_main.c | 9 + 5 files changed, 199 insertions(+), 47 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h index 04c0a5e1c89a..1839f1ab1ddd 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h @@ -194,4 +194,14 @@ static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv) { mlx5e_ktls_cleanup_rx(priv); } + +static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv) +{ + return mlx5e_ktls_init_tx(priv); +} + +static inline void mlx5e_accel_cleanup_tx(struct mlx5e_priv *priv) +{ + mlx5e_ktls_cleanup_tx(priv); +} #endif /* __MLX5E_EN_ACCEL_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h index d016624fbc9d..948400dee525 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h @@ -42,6 +42,8 @@ static inline bool mlx5e_ktls_type_check(struct mlx5_core_dev *mdev, } void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv); +int mlx5e_ktls_init_tx(struct mlx5e_priv *priv); +void mlx5e_ktls_cleanup_tx(struct mlx5e_priv *priv); int mlx5e_ktls_init_rx(struct mlx5e_priv *priv); void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv); int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable); @@ -62,6 +64,8 @@ static inline bool mlx5e_is_ktls_rx(struct mlx5_core_dev *mdev) struct mlx5e_tls_sw_stats { atomic64_t tx_tls_ctx; atomic64_t tx_tls_del; + atomic64_t tx_tls_pool_alloc; + atomic64_t tx_tls_pool_free; atomic64_t rx_tls_ctx; atomic64_t rx_tls_del; }; @@ -69,6 +73,7 @@ struct mlx5e_tls_sw_stats { struct mlx5e_tls { struct mlx5e_tls_sw_stats sw_stats; struct workqueue_struct *rx_wq; + struct mlx5e_tls_tx_pool *tx_pool; }; int mlx5e_ktls_init(struct mlx5e_priv *priv); @@ -83,6 +88,15 @@ static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv) { } +static inline int mlx5e_ktls_init_tx(struct mlx5e_priv *priv) +{ + return 0; +} + +static inline void mlx5e_ktls_cleanup_tx(struct mlx5e_priv *priv) +{ +} + static inline int mlx5e_ktls_init_rx(struct mlx5e_priv *priv) { return 0; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_stats.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_stats.c index 2ab46c4247ff..7c1c0eb16787 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_stats.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_stats.c @@ -41,6 +41,8 @@ static const struct counter_desc mlx5e_ktls_sw_stats_desc[] = { { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, tx_tls_ctx) }, { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, tx_tls_del) }, + { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, tx_tls_pool_alloc) }, + { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, tx_tls_pool_free) }, { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, rx_tls_ctx) }, { MLX5E_DECLARE_STAT(struct mlx5e_tls_sw_stats, rx_tls_del) }, }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index 82281b1d7555..b60331bc6fe9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -35,6 +35,7 @@ u16 mlx5e_ktls_get_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *pa stop_room += mlx5e_stop_room_for_wqe(mdev, MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS); stop_room += mlx5e_stop_room_for_wqe(mdev, MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS); stop_room += num_dumps * mlx5e_stop_room_for_wqe(mdev, MLX5E_KTLS_DUMP_WQEBBS); + stop_room += 1; /* fence nop */ return stop_room; } @@ -56,13 +57,17 @@ static int mlx5e_ktls_create_tis(struct mlx5_core_dev *mdev, u32 *tisn) } struct mlx5e_ktls_offload_context_tx { - struct tls_offload_context_tx *tx_ctx; - struct tls12_crypto_info_aes_gcm_128 crypto_info; - struct mlx5e_tls_sw_stats *sw_stats; + /* fast path */ u32 expected_seq; u32 tisn; - u32 key_id; bool ctx_post_pending; + /* control / resync */ + struct list_head list_node; /* member of the pool */ + struct tls12_crypto_info_aes_gcm_128 crypto_info; + struct tls_offload_context_tx *tx_ctx; + struct mlx5_core_dev *mdev; + struct mlx5e_tls_sw_stats *sw_stats; + u32 key_id; }; static void @@ -86,28 +91,136 @@ mlx5e_get_ktls_tx_priv_ctx(struct tls_context *tls_ctx) return *ctx; } +static struct mlx5e_ktls_offload_context_tx * +mlx5e_tls_priv_tx_init(struct mlx5_core_dev *mdev, struct mlx5e_tls_sw_stats *sw_stats) +{ + struct mlx5e_ktls_offload_context_tx *priv_tx; + int err; + + priv_tx = kzalloc(sizeof(*priv_tx), GFP_KERNEL); + if (!priv_tx) + return ERR_PTR(-ENOMEM); + + priv_tx->mdev = mdev; + priv_tx->sw_stats = sw_stats; + + err = mlx5e_ktls_create_tis(mdev, &priv_tx->tisn); + if (err) { + kfree(priv_tx); + return ERR_PTR(err); + } + + return priv_tx; +} + +static void mlx5e_tls_priv_tx_cleanup(struct mlx5e_ktls_offload_context_tx *priv_tx) +{ + mlx5e_destroy_tis(priv_tx->mdev, priv_tx->tisn); + kfree(priv_tx); +} + +static void mlx5e_tls_priv_tx_list_cleanup(struct list_head *list) +{ + struct mlx5e_ktls_offload_context_tx *obj; + + list_for_each_entry(obj, list, list_node) + mlx5e_tls_priv_tx_cleanup(obj); +} + +/* Recycling pool API */ + +struct mlx5e_tls_tx_pool { + struct mlx5_core_dev *mdev; + struct mlx5e_tls_sw_stats *sw_stats; + struct mutex lock; /* Protects access to the pool */ + struct list_head list; +#define MLX5E_TLS_TX_POOL_MAX_SIZE (256) + size_t size; +}; + +static struct mlx5e_tls_tx_pool *mlx5e_tls_tx_pool_init(struct mlx5_core_dev *mdev, + struct mlx5e_tls_sw_stats *sw_stats) +{ + struct mlx5e_tls_tx_pool *pool; + + pool = kvzalloc(sizeof(*pool), GFP_KERNEL); + if (!pool) + return NULL; + + INIT_LIST_HEAD(&pool->list); + mutex_init(&pool->lock); + + pool->mdev = mdev; + pool->sw_stats = sw_stats; + + return pool; +} + +static void mlx5e_tls_tx_pool_cleanup(struct mlx5e_tls_tx_pool *pool) +{ + mlx5e_tls_priv_tx_list_cleanup(&pool->list); + atomic64_add(pool->size, &pool->sw_stats->tx_tls_pool_free); + kvfree(pool); +} + +static void pool_push(struct mlx5e_tls_tx_pool *pool, struct mlx5e_ktls_offload_context_tx *obj) +{ + mutex_lock(&pool->lock); + if (pool->size >= MLX5E_TLS_TX_POOL_MAX_SIZE) { + mutex_unlock(&pool->lock); + mlx5e_tls_priv_tx_cleanup(obj); + atomic64_inc(&pool->sw_stats->tx_tls_pool_free); + return; + } + list_add(&obj->list_node, &pool->list); + pool->size++; + mutex_unlock(&pool->lock); +} + +static struct mlx5e_ktls_offload_context_tx *pool_pop(struct mlx5e_tls_tx_pool *pool) +{ + struct mlx5e_ktls_offload_context_tx *obj; + + mutex_lock(&pool->lock); + if (pool->size == 0) { + obj = mlx5e_tls_priv_tx_init(pool->mdev, pool->sw_stats); + if (!IS_ERR(obj)) + atomic64_inc(&pool->sw_stats->tx_tls_pool_alloc); + goto out; + } + + obj = list_first_entry(&pool->list, struct mlx5e_ktls_offload_context_tx, + list_node); + list_del(&obj->list_node); + pool->size--; +out: + mutex_unlock(&pool->lock); + return obj; +} + +/* End of pool API */ + int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk, struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn) { struct mlx5e_ktls_offload_context_tx *priv_tx; + struct mlx5e_tls_tx_pool *pool; struct tls_context *tls_ctx; - struct mlx5_core_dev *mdev; struct mlx5e_priv *priv; int err; tls_ctx = tls_get_ctx(sk); priv = netdev_priv(netdev); - mdev = priv->mdev; + pool = priv->tls->tx_pool; - priv_tx = kzalloc(sizeof(*priv_tx), GFP_KERNEL); - if (!priv_tx) - return -ENOMEM; + priv_tx = pool_pop(pool); + if (IS_ERR(priv_tx)) + return PTR_ERR(priv_tx); - err = mlx5_ktls_create_key(mdev, crypto_info, &priv_tx->key_id); + err = mlx5_ktls_create_key(pool->mdev, crypto_info, &priv_tx->key_id); if (err) goto err_create_key; - priv_tx->sw_stats = &priv->tls->sw_stats; priv_tx->expected_seq = start_offload_tcp_sn; priv_tx->crypto_info = *(struct tls12_crypto_info_aes_gcm_128 *)crypto_info; @@ -115,36 +228,29 @@ int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk, mlx5e_set_ktls_tx_priv_ctx(tls_ctx, priv_tx); - err = mlx5e_ktls_create_tis(mdev, &priv_tx->tisn); - if (err) - goto err_create_tis; - priv_tx->ctx_post_pending = true; atomic64_inc(&priv_tx->sw_stats->tx_tls_ctx); return 0; -err_create_tis: - mlx5_ktls_destroy_key(mdev, priv_tx->key_id); err_create_key: - kfree(priv_tx); + pool_push(pool, priv_tx); return err; } void mlx5e_ktls_del_tx(struct net_device *netdev, struct tls_context *tls_ctx) { struct mlx5e_ktls_offload_context_tx *priv_tx; - struct mlx5_core_dev *mdev; + struct mlx5e_tls_tx_pool *pool; struct mlx5e_priv *priv; priv_tx = mlx5e_get_ktls_tx_priv_ctx(tls_ctx); priv = netdev_priv(netdev); - mdev = priv->mdev; + pool = priv->tls->tx_pool; atomic64_inc(&priv_tx->sw_stats->tx_tls_del); - mlx5e_destroy_tis(mdev, priv_tx->tisn); - mlx5_ktls_destroy_key(mdev, priv_tx->key_id); - kfree(priv_tx); + mlx5_ktls_destroy_key(priv_tx->mdev, priv_tx->key_id); + pool_push(pool, priv_tx); } static void tx_fill_wi(struct mlx5e_txqsq *sq, @@ -205,6 +311,16 @@ post_progress_params(struct mlx5e_txqsq *sq, sq->pc += num_wqebbs; } +static void tx_post_fence_nop(struct mlx5e_txqsq *sq) +{ + struct mlx5_wq_cyc *wq = &sq->wq; + u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); + + tx_fill_wi(sq, pi, 1, 0, NULL); + + mlx5e_post_nop_fence(wq, sq->sqn, &sq->pc); +} + static void mlx5e_ktls_tx_post_param_wqes(struct mlx5e_txqsq *sq, struct mlx5e_ktls_offload_context_tx *priv_tx, @@ -216,6 +332,7 @@ mlx5e_ktls_tx_post_param_wqes(struct mlx5e_txqsq *sq, post_static_params(sq, priv_tx, fence_first_post); post_progress_params(sq, priv_tx, progress_fence); + tx_post_fence_nop(sq); } struct tx_sync_info { @@ -308,7 +425,7 @@ tx_post_resync_params(struct mlx5e_txqsq *sq, } static int -tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool first) +tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn) { struct mlx5_wqe_ctrl_seg *cseg; struct mlx5_wqe_data_seg *dseg; @@ -330,7 +447,6 @@ tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool fir cseg->opmod_idx_opcode = cpu_to_be32((sq->pc << 8) | MLX5_OPCODE_DUMP); cseg->qpn_ds = cpu_to_be32((sq->sqn << 8) | ds_cnt); cseg->tis_tir_num = cpu_to_be32(tisn << 8); - cseg->fm_ce_se = first ? MLX5_FENCE_MODE_INITIATOR_SMALL : 0; fsz = skb_frag_size(frag); dma_addr = skb_frag_dma_map(sq->pdev, frag, 0, fsz, @@ -365,16 +481,6 @@ void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq, stats->tls_dump_bytes += wi->num_bytes; } -static void tx_post_fence_nop(struct mlx5e_txqsq *sq) -{ - struct mlx5_wq_cyc *wq = &sq->wq; - u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); - - tx_fill_wi(sq, pi, 1, 0, NULL); - - mlx5e_post_nop_fence(wq, sq->sqn, &sq->pc); -} - static enum mlx5e_ktls_sync_retval mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, struct mlx5e_txqsq *sq, @@ -395,14 +501,6 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, tx_post_resync_params(sq, priv_tx, info.rcd_sn); - /* If no dump WQE was sent, we need to have a fence NOP WQE before the - * actual data xmit. - */ - if (!info.nr_frags) { - tx_post_fence_nop(sq); - return MLX5E_KTLS_SYNC_DONE; - } - for (i = 0; i < info.nr_frags; i++) { unsigned int orig_fsz, frag_offset = 0, n = 0; skb_frag_t *f = &info.frags[i]; @@ -410,13 +508,12 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, orig_fsz = skb_frag_size(f); do { - bool fence = !(i || frag_offset); unsigned int fsz; n++; fsz = min_t(unsigned int, sq->hw_mtu, orig_fsz - frag_offset); skb_frag_size_set(f, fsz); - if (tx_post_resync_dump(sq, f, priv_tx->tisn, fence)) { + if (tx_post_resync_dump(sq, f, priv_tx->tisn)) { page_ref_add(skb_frag_page(f), n - 1); goto err_out; } @@ -464,9 +561,8 @@ bool mlx5e_ktls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq, priv_tx = mlx5e_get_ktls_tx_priv_ctx(tls_ctx); - if (unlikely(mlx5e_ktls_tx_offload_test_and_clear_pending(priv_tx))) { + if (unlikely(mlx5e_ktls_tx_offload_test_and_clear_pending(priv_tx))) mlx5e_ktls_tx_post_param_wqes(sq, priv_tx, false, false); - } seq = ntohl(tcp_hdr(skb)->seq); if (unlikely(priv_tx->expected_seq != seq)) { @@ -504,3 +600,24 @@ bool mlx5e_ktls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq, dev_kfree_skb_any(skb); return false; } + +int mlx5e_ktls_init_tx(struct mlx5e_priv *priv) +{ + if (!mlx5e_is_ktls_tx(priv->mdev)) + return 0; + + priv->tls->tx_pool = mlx5e_tls_tx_pool_init(priv->mdev, &priv->tls->sw_stats); + if (!priv->tls->tx_pool) + return -ENOMEM; + + return 0; +} + +void mlx5e_ktls_cleanup_tx(struct mlx5e_priv *priv) +{ + if (!mlx5e_is_ktls_tx(priv->mdev)) + return; + + mlx5e_tls_tx_pool_cleanup(priv->tls->tx_pool); + priv->tls->tx_pool = NULL; +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 180b2f418339..24ddd438c066 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -3144,6 +3144,7 @@ static void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv) mlx5e_mqprio_rl_free(priv->mqprio_rl); priv->mqprio_rl = NULL; } + mlx5e_accel_cleanup_tx(priv); mlx5e_destroy_tises(priv); } @@ -5147,9 +5148,17 @@ static int mlx5e_init_nic_tx(struct mlx5e_priv *priv) return err; } + err = mlx5e_accel_init_tx(priv); + if (err) + goto err_destroy_tises; + mlx5e_set_mqprio_rl(priv); mlx5e_dcbnl_initialize(priv); return 0; + +err_destroy_tises: + mlx5e_destroy_tises(priv); + return err; } static void mlx5e_nic_enable(struct mlx5e_priv *priv) From patchwork Wed Jul 27 09:43:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 12930278 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D47CC04A68 for ; Wed, 27 Jul 2022 09:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230487AbiG0Joj (ORCPT ); Wed, 27 Jul 2022 05:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbiG0Jof (ORCPT ); Wed, 27 Jul 2022 05:44:35 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2201A481DD for ; Wed, 27 Jul 2022 02:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A96WWBNtxQ4z4JnYsDzfG8OFLYnqIYJoIK7DOuaj9Udea3u1VxiAYS8eE1dkWfadiiddiK36AYpAnwbfxXNhFuy14BhfeRiC1tsUsPd4o34Ws04x554SqLNegIQTvAElymJsA3BIZ5Ak9j5hfGzX8UoG93aeiSBxSjJ3z69/Cmx50h98coOVaNPQ1Fpjw2rn7uxhF8Iv29X2ss0ff38Phs+myvvXycqthTnUUxaJKXzHAM4FCSDCNRo9F/odC61af8EQd5ju2bSXgIAzvYWgztsdLVspP7GsavIZdqebOKOVMr/DH6wCpxy0bZ1mS03V7Vthxw+bwi/lpoJY10UscA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0Ti6mumvA+bBRz6LB9ozAZ5KnWTq2vgA3CazFHorX7Y=; b=TfUcg/bGO4FSvjx5wLhqivmfOvJ2zCRjCWM4zwnxNmJqKWRVyYkVPcEDxudV6cW75v55251LBJtVatowRx/utosPqxlcEzHAxnKNLiV8GkMu+MrpqwKMBjjnBO4d+NEYyWoHmqPL/adKjTCFCwa81spD0kGEs+lScrXaBaS6kEjiEAzwnO5XTq123pH843cRIAQ4dCfc0eTIGCo4Y56Q8hBFDIbFcrMxSYB2WB/TdCISDhohIebmPucYZU6Nd/B4a9eNHaNqeTmIThkmiuGKFp4UUpWWP7El6e9oRhLfkInIQ5nN15YkuY4amQMLzwSsuHgbbjWdrRUOc3ixAdrFjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Ti6mumvA+bBRz6LB9ozAZ5KnWTq2vgA3CazFHorX7Y=; b=IyWc4rQiOaTIWyNpqZDWMLrAwCwz68RXcxOECl6wesDP11KwzSxF56j0ETOqyN/fJuhzCeV5cPy5bedGp8ITHJhe5qDXEQQJiyfK4vaknSa0d0GTV0aLt4TYNYE5nUsi/sxWCU8Y5peAC9NAaPFB02RvcCxBswLe4PkZuEPg9L3KbHNNEh0dGi9rUL+9CkvKhTdnPaPoExvAe5kYRsB/G16NiBMh7pBD7m76glxOSuvkjvR1Br+BUuGSGbnjKte3TFmd9sftTjyMoUm8xle4kOSlDNFSSelrqcbqOqlzzDoMN2gx8oUza6Af5NEsSLK4xqFje9sRlOVl3Qo0uMTffg== Received: from BN9PR03CA0584.namprd03.prod.outlook.com (2603:10b6:408:10d::19) by DM8PR12MB5446.namprd12.prod.outlook.com (2603:10b6:8:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Wed, 27 Jul 2022 09:44:25 +0000 Received: from BN8NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10d:cafe::e8) by BN9PR03CA0584.outlook.office365.com (2603:10b6:408:10d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.20 via Frontend Transport; Wed, 27 Jul 2022 09:44:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT068.mail.protection.outlook.com (10.13.177.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 09:44:25 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 09:44:24 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 27 Jul 2022 02:44:23 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Wed, 27 Jul 2022 02:44:21 -0700 From: Tariq Toukan To: Boris Pismenny , John Fastabend , Jakub Kicinski CC: "David S. Miller" , Eric Dumazet , Paolo Abeni , , Saeed Mahameed , Gal Pressman , Tariq Toukan Subject: [PATCH net-next V3 6/6] net/mlx5e: kTLS, Dynamically re-size TX recycling pool Date: Wed, 27 Jul 2022 12:43:46 +0300 Message-ID: <20220727094346.10540-7-tariqt@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220727094346.10540-1-tariqt@nvidia.com> References: <20220727094346.10540-1-tariqt@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e681921-814f-46e4-943e-08da6fb49778 X-MS-TrafficTypeDiagnostic: DM8PR12MB5446:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IjsmPjEnoKreid3BeuTYkgt1CFi8K0KDWxc0tgMUucHxcEdzaH0CwR2eFAl+NgUgvuUmv5V9GFX/MC3+31AIPBs3lsA21lJ3iJ7y7GRK+0//N+Vt9SdxbrcoXGAozPdjEGBBwC+VTJjA9eD7VrCiVm3Fb/UP9JK6b6+6kzDfWmt+oahNG2ZbauAnXRw26YBZVBOxjAFqJj+i56SK59lZdD+Qji/BTgVnerNk7V5aZ86xFxpAp23LMta2p4d9auR2s3IKqwuNuHm7NpTf643AHTlgeK68hDuumUUWwgJ10XvgLzSfrm0SLc8RK27hc+kE/f0bOSXvoUZbbgV3YCAvw6WNcRPrBQKiPIxW9zjB67xsgV2wnQ7FikaKGDs4xV/vCjReL7z/0owB51MDglR+Pa0i0klk/5B31LafEjel/0kqgGRFbR774sEU46SrKZuxo4Esb/pKiX2QSpfYVF40UJ5X41+2qPxQpINH1A72eykV0YNn9KBCsvmph8FkJmbZ7ZcJE+mkQiOimh+bp1wGQhJEG5Tv8RzMeMNuO36ZNFDtc28G5rr4OuydzhsCBgbaXG9ZB1GCb8NwkLdJyNa6gquLkt48IGtYpVl/Bp+yj5NQlpaY/6eBGzmjEHq0iJYKqbET2QeLKEH2TVmtgvCRWsoiPsBzw1qnuUNNueYAbRQtb1vqaDiDQ785cfuNNCLtxigWmTtUR524FTbaaVi/FBZ4Z/ScqE37pyrwvLONsURK0SfZsY/P3oD4alr1LeNpIqYKviiD4MB5tZQGPZekRmRmAZZqh66b1LDw2r/BJk8tS69mevXDWAoEgwjxPVC/tZssvTYhmt0Fl5fkx9DZzQ== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(136003)(376002)(396003)(346002)(46966006)(36840700001)(40470700004)(356005)(70586007)(36756003)(81166007)(8936002)(426003)(47076005)(5660300002)(336012)(40460700003)(83380400001)(2616005)(1076003)(30864003)(70206006)(107886003)(2906002)(8676002)(40480700001)(186003)(82740400003)(7696005)(41300700001)(478600001)(36860700001)(82310400005)(110136005)(26005)(316002)(54906003)(4326008)(86362001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 09:44:25.0217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e681921-814f-46e4-943e-08da6fb49778 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5446 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Let the TLS TX recycle pool be more flexible in size, by continuously and dynamically allocating and releasing HW resources in response to changes in the connections rate and load. Allocate and release pool entries in bulks (16). Use a workqueue to release/allocate in the background. Allocate a new bulk when the pool size goes lower than the low threshold (1K). Symmetric operation is done when the pool size gets greater than the upper threshold (4K). Every idle pool entry holds: 1 TIS, 1 DEK (HW resources), in addition to ~100 bytes in host memory. Start with an empty pool to minimize memory and HW resources waste for non-TLS users that have the device-offload TLS enabled. Upon a new request, in case the pool is empty, do not wait for a whole bulk allocation to complete. Instead, trigger an instant allocation of a single resource to reduce latency. Performance tests: Before: 11,684 CPS After: 16,556 CPS Signed-off-by: Tariq Toukan Signed-off-by: Saeed Mahameed --- .../mellanox/mlx5/core/en_accel/ktls_tx.c | 315 ++++++++++++++++-- 1 file changed, 289 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index b60331bc6fe9..6b6c7044b64a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -56,6 +56,36 @@ static int mlx5e_ktls_create_tis(struct mlx5_core_dev *mdev, u32 *tisn) return mlx5_core_create_tis(mdev, in, tisn); } +static int mlx5e_ktls_create_tis_cb(struct mlx5_core_dev *mdev, + struct mlx5_async_ctx *async_ctx, + u32 *out, int outlen, + mlx5_async_cbk_t callback, + struct mlx5_async_work *context) +{ + u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {}; + + mlx5e_ktls_set_tisc(mdev, MLX5_ADDR_OF(create_tis_in, in, ctx)); + MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS); + + return mlx5_cmd_exec_cb(async_ctx, in, sizeof(in), + out, outlen, callback, context); +} + +static int mlx5e_ktls_destroy_tis_cb(struct mlx5_core_dev *mdev, u32 tisn, + struct mlx5_async_ctx *async_ctx, + u32 *out, int outlen, + mlx5_async_cbk_t callback, + struct mlx5_async_work *context) +{ + u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {}; + + MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS); + MLX5_SET(destroy_tis_in, in, tisn, tisn); + + return mlx5_cmd_exec_cb(async_ctx, in, sizeof(in), + out, outlen, callback, context); +} + struct mlx5e_ktls_offload_context_tx { /* fast path */ u32 expected_seq; @@ -68,6 +98,7 @@ struct mlx5e_ktls_offload_context_tx { struct mlx5_core_dev *mdev; struct mlx5e_tls_sw_stats *sw_stats; u32 key_id; + u8 create_err : 1; }; static void @@ -91,8 +122,81 @@ mlx5e_get_ktls_tx_priv_ctx(struct tls_context *tls_ctx) return *ctx; } +/* struct for callback API management */ +struct mlx5e_async_ctx { + struct mlx5_async_work context; + struct mlx5_async_ctx async_ctx; + struct work_struct work; + struct mlx5e_ktls_offload_context_tx *priv_tx; + struct completion complete; + int err; + union { + u32 out_create[MLX5_ST_SZ_DW(create_tis_out)]; + u32 out_destroy[MLX5_ST_SZ_DW(destroy_tis_out)]; + }; +}; + +static struct mlx5e_async_ctx *mlx5e_bulk_async_init(struct mlx5_core_dev *mdev, int n) +{ + struct mlx5e_async_ctx *bulk_async; + int i; + + bulk_async = kvcalloc(n, sizeof(struct mlx5e_async_ctx), GFP_KERNEL); + if (!bulk_async) + return NULL; + + for (i = 0; i < n; i++) { + struct mlx5e_async_ctx *async = &bulk_async[i]; + + mlx5_cmd_init_async_ctx(mdev, &async->async_ctx); + init_completion(&async->complete); + } + + return bulk_async; +} + +static void mlx5e_bulk_async_cleanup(struct mlx5e_async_ctx *bulk_async, int n) +{ + int i; + + for (i = 0; i < n; i++) { + struct mlx5e_async_ctx *async = &bulk_async[i]; + + mlx5_cmd_cleanup_async_ctx(&async->async_ctx); + } + kvfree(bulk_async); +} + +static void create_tis_callback(int status, struct mlx5_async_work *context) +{ + struct mlx5e_async_ctx *async = + container_of(context, struct mlx5e_async_ctx, context); + struct mlx5e_ktls_offload_context_tx *priv_tx = async->priv_tx; + + if (status) { + async->err = status; + priv_tx->create_err = 1; + goto out; + } + + priv_tx->tisn = MLX5_GET(create_tis_out, async->out_create, tisn); +out: + complete(&async->complete); +} + +static void destroy_tis_callback(int status, struct mlx5_async_work *context) +{ + struct mlx5e_async_ctx *async = + container_of(context, struct mlx5e_async_ctx, context); + struct mlx5e_ktls_offload_context_tx *priv_tx = async->priv_tx; + + complete(&async->complete); + kfree(priv_tx); +} + static struct mlx5e_ktls_offload_context_tx * -mlx5e_tls_priv_tx_init(struct mlx5_core_dev *mdev, struct mlx5e_tls_sw_stats *sw_stats) +mlx5e_tls_priv_tx_init(struct mlx5_core_dev *mdev, struct mlx5e_tls_sw_stats *sw_stats, + struct mlx5e_async_ctx *async) { struct mlx5e_ktls_offload_context_tx *priv_tx; int err; @@ -104,76 +208,229 @@ mlx5e_tls_priv_tx_init(struct mlx5_core_dev *mdev, struct mlx5e_tls_sw_stats *sw priv_tx->mdev = mdev; priv_tx->sw_stats = sw_stats; - err = mlx5e_ktls_create_tis(mdev, &priv_tx->tisn); - if (err) { - kfree(priv_tx); - return ERR_PTR(err); + if (!async) { + err = mlx5e_ktls_create_tis(mdev, &priv_tx->tisn); + if (err) + goto err_out; + } else { + async->priv_tx = priv_tx; + err = mlx5e_ktls_create_tis_cb(mdev, &async->async_ctx, + async->out_create, sizeof(async->out_create), + create_tis_callback, &async->context); + if (err) + goto err_out; } return priv_tx; + +err_out: + kfree(priv_tx); + return ERR_PTR(err); } -static void mlx5e_tls_priv_tx_cleanup(struct mlx5e_ktls_offload_context_tx *priv_tx) +static void mlx5e_tls_priv_tx_cleanup(struct mlx5e_ktls_offload_context_tx *priv_tx, + struct mlx5e_async_ctx *async) { - mlx5e_destroy_tis(priv_tx->mdev, priv_tx->tisn); - kfree(priv_tx); + if (priv_tx->create_err) { + complete(&async->complete); + kfree(priv_tx); + return; + } + async->priv_tx = priv_tx; + mlx5e_ktls_destroy_tis_cb(priv_tx->mdev, priv_tx->tisn, + &async->async_ctx, + async->out_destroy, sizeof(async->out_destroy), + destroy_tis_callback, &async->context); } -static void mlx5e_tls_priv_tx_list_cleanup(struct list_head *list) +static void mlx5e_tls_priv_tx_list_cleanup(struct mlx5_core_dev *mdev, + struct list_head *list, int size) { struct mlx5e_ktls_offload_context_tx *obj; + struct mlx5e_async_ctx *bulk_async; + int i; + + bulk_async = mlx5e_bulk_async_init(mdev, size); + if (!bulk_async) + return; - list_for_each_entry(obj, list, list_node) - mlx5e_tls_priv_tx_cleanup(obj); + i = 0; + list_for_each_entry(obj, list, list_node) { + mlx5e_tls_priv_tx_cleanup(obj, &bulk_async[i]); + i++; + } + + for (i = 0; i < size; i++) { + struct mlx5e_async_ctx *async = &bulk_async[i]; + + wait_for_completion(&async->complete); + } + mlx5e_bulk_async_cleanup(bulk_async, size); } /* Recycling pool API */ +#define MLX5E_TLS_TX_POOL_BULK (16) +#define MLX5E_TLS_TX_POOL_HIGH (4 * 1024) +#define MLX5E_TLS_TX_POOL_LOW (MLX5E_TLS_TX_POOL_HIGH / 4) + struct mlx5e_tls_tx_pool { struct mlx5_core_dev *mdev; struct mlx5e_tls_sw_stats *sw_stats; struct mutex lock; /* Protects access to the pool */ struct list_head list; -#define MLX5E_TLS_TX_POOL_MAX_SIZE (256) size_t size; + + struct workqueue_struct *wq; + struct work_struct create_work; + struct work_struct destroy_work; }; +static void create_work(struct work_struct *work) +{ + struct mlx5e_tls_tx_pool *pool = + container_of(work, struct mlx5e_tls_tx_pool, create_work); + struct mlx5e_ktls_offload_context_tx *obj; + struct mlx5e_async_ctx *bulk_async; + LIST_HEAD(local_list); + int i, j, err = 0; + + bulk_async = mlx5e_bulk_async_init(pool->mdev, MLX5E_TLS_TX_POOL_BULK); + if (!bulk_async) + return; + + for (i = 0; i < MLX5E_TLS_TX_POOL_BULK; i++) { + obj = mlx5e_tls_priv_tx_init(pool->mdev, pool->sw_stats, &bulk_async[i]); + if (IS_ERR(obj)) { + err = PTR_ERR(obj); + break; + } + list_add(&obj->list_node, &local_list); + } + + for (j = 0; j < i; j++) { + struct mlx5e_async_ctx *async = &bulk_async[j]; + + wait_for_completion(&async->complete); + if (!err && async->err) + err = async->err; + } + atomic64_add(i, &pool->sw_stats->tx_tls_pool_alloc); + mlx5e_bulk_async_cleanup(bulk_async, MLX5E_TLS_TX_POOL_BULK); + if (err) + goto err_out; + + mutex_lock(&pool->lock); + if (pool->size + MLX5E_TLS_TX_POOL_BULK >= MLX5E_TLS_TX_POOL_HIGH) { + mutex_unlock(&pool->lock); + goto err_out; + } + list_splice(&local_list, &pool->list); + pool->size += MLX5E_TLS_TX_POOL_BULK; + if (pool->size <= MLX5E_TLS_TX_POOL_LOW) + queue_work(pool->wq, work); + mutex_unlock(&pool->lock); + return; + +err_out: + mlx5e_tls_priv_tx_list_cleanup(pool->mdev, &local_list, i); + atomic64_add(i, &pool->sw_stats->tx_tls_pool_free); +} + +static void destroy_work(struct work_struct *work) +{ + struct mlx5e_tls_tx_pool *pool = + container_of(work, struct mlx5e_tls_tx_pool, destroy_work); + struct mlx5e_ktls_offload_context_tx *obj; + LIST_HEAD(local_list); + int i = 0; + + mutex_lock(&pool->lock); + if (pool->size < MLX5E_TLS_TX_POOL_HIGH) { + mutex_unlock(&pool->lock); + return; + } + + list_for_each_entry(obj, &pool->list, list_node) + if (++i == MLX5E_TLS_TX_POOL_BULK) + break; + + list_cut_position(&local_list, &pool->list, &obj->list_node); + pool->size -= MLX5E_TLS_TX_POOL_BULK; + if (pool->size >= MLX5E_TLS_TX_POOL_HIGH) + queue_work(pool->wq, work); + mutex_unlock(&pool->lock); + + mlx5e_tls_priv_tx_list_cleanup(pool->mdev, &local_list, MLX5E_TLS_TX_POOL_BULK); + atomic64_add(MLX5E_TLS_TX_POOL_BULK, &pool->sw_stats->tx_tls_pool_free); +} + static struct mlx5e_tls_tx_pool *mlx5e_tls_tx_pool_init(struct mlx5_core_dev *mdev, struct mlx5e_tls_sw_stats *sw_stats) { struct mlx5e_tls_tx_pool *pool; + BUILD_BUG_ON(MLX5E_TLS_TX_POOL_LOW + MLX5E_TLS_TX_POOL_BULK >= MLX5E_TLS_TX_POOL_HIGH); + pool = kvzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return NULL; + pool->wq = create_singlethread_workqueue("mlx5e_tls_tx_pool"); + if (!pool->wq) + goto err_free; + INIT_LIST_HEAD(&pool->list); mutex_init(&pool->lock); + INIT_WORK(&pool->create_work, create_work); + INIT_WORK(&pool->destroy_work, destroy_work); + pool->mdev = mdev; pool->sw_stats = sw_stats; return pool; + +err_free: + kvfree(pool); + return NULL; +} + +static void mlx5e_tls_tx_pool_list_cleanup(struct mlx5e_tls_tx_pool *pool) +{ + while (pool->size > MLX5E_TLS_TX_POOL_BULK) { + struct mlx5e_ktls_offload_context_tx *obj; + LIST_HEAD(local_list); + int i = 0; + + list_for_each_entry(obj, &pool->list, list_node) + if (++i == MLX5E_TLS_TX_POOL_BULK) + break; + + list_cut_position(&local_list, &pool->list, &obj->list_node); + mlx5e_tls_priv_tx_list_cleanup(pool->mdev, &local_list, MLX5E_TLS_TX_POOL_BULK); + atomic64_add(MLX5E_TLS_TX_POOL_BULK, &pool->sw_stats->tx_tls_pool_free); + pool->size -= MLX5E_TLS_TX_POOL_BULK; + } + if (pool->size) { + mlx5e_tls_priv_tx_list_cleanup(pool->mdev, &pool->list, pool->size); + atomic64_add(pool->size, &pool->sw_stats->tx_tls_pool_free); + } } static void mlx5e_tls_tx_pool_cleanup(struct mlx5e_tls_tx_pool *pool) { - mlx5e_tls_priv_tx_list_cleanup(&pool->list); - atomic64_add(pool->size, &pool->sw_stats->tx_tls_pool_free); + mlx5e_tls_tx_pool_list_cleanup(pool); + destroy_workqueue(pool->wq); kvfree(pool); } static void pool_push(struct mlx5e_tls_tx_pool *pool, struct mlx5e_ktls_offload_context_tx *obj) { mutex_lock(&pool->lock); - if (pool->size >= MLX5E_TLS_TX_POOL_MAX_SIZE) { - mutex_unlock(&pool->lock); - mlx5e_tls_priv_tx_cleanup(obj); - atomic64_inc(&pool->sw_stats->tx_tls_pool_free); - return; - } list_add(&obj->list_node, &pool->list); - pool->size++; + if (++pool->size == MLX5E_TLS_TX_POOL_HIGH) + queue_work(pool->wq, &pool->destroy_work); mutex_unlock(&pool->lock); } @@ -182,18 +439,24 @@ static struct mlx5e_ktls_offload_context_tx *pool_pop(struct mlx5e_tls_tx_pool * struct mlx5e_ktls_offload_context_tx *obj; mutex_lock(&pool->lock); - if (pool->size == 0) { - obj = mlx5e_tls_priv_tx_init(pool->mdev, pool->sw_stats); + if (unlikely(pool->size == 0)) { + /* pool is empty: + * - trigger the populating work, and + * - serve the current context via the regular blocking api. + */ + queue_work(pool->wq, &pool->create_work); + mutex_unlock(&pool->lock); + obj = mlx5e_tls_priv_tx_init(pool->mdev, pool->sw_stats, NULL); if (!IS_ERR(obj)) atomic64_inc(&pool->sw_stats->tx_tls_pool_alloc); - goto out; + return obj; } obj = list_first_entry(&pool->list, struct mlx5e_ktls_offload_context_tx, list_node); list_del(&obj->list_node); - pool->size--; -out: + if (--pool->size == MLX5E_TLS_TX_POOL_LOW) + queue_work(pool->wq, &pool->create_work); mutex_unlock(&pool->lock); return obj; }