From patchwork Wed Jan 31 16:04:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vakul Garg X-Patchwork-Id: 10193873 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0772260380 for ; Wed, 31 Jan 2018 10:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A0AF20416 for ; Wed, 31 Jan 2018 10:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E5B727861; Wed, 31 Jan 2018 10:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 733D920416 for ; Wed, 31 Jan 2018 10:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751700AbeAaKmC (ORCPT ); Wed, 31 Jan 2018 05:42:02 -0500 Received: from mail-eopbgr00081.outbound.protection.outlook.com ([40.107.0.81]:52048 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750904AbeAaKmB (ORCPT ); Wed, 31 Jan 2018 05:42:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ucUENoBmR19w/djPt0svTqnJT4N8ewViwg0zcveNhR4=; b=akbu7QGbSjqZ0yEFGzArMBner72uvX53ULFi3dibDAC0rEowoOuPq0ZKJrj2gg2UynN/aY8hFox7ugTCE8l0uvLCS5ZLgRJxw5de1SBR8Np+PCUYWfpHNLaDn1DI2Tqj2gtJD28O5w3GbYG6NFceuzTPtkQoByfImDk5owzx/NY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vakul.garg@nxp.com; Received: from lti.ap.freescale.net (192.88.169.1) by DB6PR04MB3080.eurprd04.prod.outlook.com (2603:10a6:6:b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Wed, 31 Jan 2018 10:41:55 +0000 From: Vakul Garg To: linux-crypto@vger.kernel.org Cc: ilyal@mellanox.com, aviadye@mellanox.com, davejwatson@fb.com, davem@davemloft.net, netdev@vger.kernel.org, Vakul Garg Subject: [PATCHv2] tls: Add support for encryption using async offload accelerator Date: Wed, 31 Jan 2018 21:34:37 +0530 Message-Id: <20180131160437.6583-1-vakul.garg@nxp.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Originating-IP: [192.88.169.1] X-ClientProxiedBy: PN1PR0101CA0018.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::28) To DB6PR04MB3080.eurprd04.prod.outlook.com (2603:10a6:6:b::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a1340ca4-3cda-4110-9040-08d568974101 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:DB6PR04MB3080; X-Microsoft-Exchange-Diagnostics: 1; DB6PR04MB3080; 3:g1Z81cYpQRxMCKJW0Sh5s2z5BY7n2NAcqfcBitPz5AL8ErSlLTNb+tF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F+IF9OqwCvyj3s+LhkzfH1kRV0+rNIqv0INrlMamO626JpEmGI9ZCtjkXkX21dosqYrDMl1h3SExwTwbavU6rqZUEJ5LowI259pLUbZ/4qAKiTfK90IRXzcWh6/6aY8Jev8AtoK/6wba5i9yvrAULQl/jN58pXo0qSNiLBDxO2BA4DT4yMS6NMjBBPhaxnPSVHd3MI47AvBarlwo8h0saJ+23foaxY3Skp3Eow/VBKVJbUhh3GeExNTCAMIUOheXgL8wLspvu8v9mk5frlgcq48lfryQuqC7PxncVn7; 4:qWs3koFkCMgfoKHWBX0JxrkNRQhhOWT+BIrfIswNeRLqY4JuNlLuRu7Lmdd83gd6kTHtWfQPjr8IUyAPx9kCuaJ9Eop1h01k2mFslnfBu6cd3pssCJSnHzQ4e+Pe/mbltyLoiEJPSMlgklK6A7laUOHpdMs6PKwk47MjJwurEn1jAN6WvrNMG8VAw9k9HQpEUlgyPgl0bHGwHwTvaJO66ZAdLY1V4uSbE5x0KKxwKAdPEt2L/cARLUUs4TgRrftseOmq+oBnuYhEAJdZDt/Xc8qtiqOPSvKC6AjZQzOILvZvXXAyjms6EoeyIWU4UcNQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(3231101)(2400082)(944501161)(3002001)(93006095)(93001095)(6055026)(6041288)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:DB6PR04MB3080; BCL:0; PCL:0; RULEID:; SRVR:DB6PR04MB3080; X-Forefront-PRVS: 056929CBB8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(39860400002)(376002)(396003)(366004)(189003)(199004)(386003)(6116002)(1076002)(3846002)(51416003)(6506007)(316002)(81166006)(59450400001)(16586007)(52116002)(8676002)(2361001)(2351001)(86362001)(478600001)(106356001)(575784001)(8936002)(81156014)(26005)(66066001)(6486002)(6916009)(16526019)(305945005)(68736007)(50466002)(105586002)(4326008)(36756003)(47776003)(186003)(53936002)(50226002)(7736002)(6512007)(6666003)(48376002)(25786009)(5660300001)(2906002)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR04MB3080; H:lti.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR04MB3080; 23:43y3SJYljQn8gdNOybtopqA5tOsM8Ys0vbW+agu26?= =?us-ascii?Q?PmRUjgjvgxC3YCUbWVL7hI3EaTIl4wAzGsGFW+NxFGC0ukUpaGheISlXbDVW?= =?us-ascii?Q?aPckknuRzShrOwE/KiHfunDru63xaYtQ17rbTeAzSGsfUsPj370M80PWOE8K?= =?us-ascii?Q?WDNL2P33jTilU+ugqPfGGyViIuVoLp/ednjXFIE1cyNS0uVP/8TcIT0hI9+m?= =?us-ascii?Q?2qz2adedTUOFIXHOEi4FgGSC4w3JkQiy4FJ4TDj/hfcyFCFhWrhm3kKGcI4M?= =?us-ascii?Q?2VqDF3nmpcTuWbPaE/lmI3JZqfzMPh0xNY5Tj4XEmsyAIUrjuR9jBrR21pyG?= =?us-ascii?Q?TNGFSrr8ONoIlT2bHawwMX9sFw3DXb/WBnJUXSTzWWM8IUePjRrd9Tut3KfJ?= =?us-ascii?Q?2a3BHmLxaqCZXK0a0rl/gO2UWZffMq7XMfaEP18wuY+ItK3v0uDFRZL//wDa?= =?us-ascii?Q?Y8k0MC4ICBN6X5KKMg9EJ1r2v8AQEZ6gFNaxiz2vZ6zTZViHSC6k5d+76PLF?= =?us-ascii?Q?EhZVpu0CYVjwGwQjsVN+1kOwDfh70wuhXFOT3aI2sHkP/WEytLeA+HiT52Qz?= =?us-ascii?Q?1Tkav8vT/rIr5bk6JuRe2z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mDW4249MJGot0BrFTopjOdqI/d0=; 5:/VPfqudIvJYD108Stw0Bnx6w67JhkCvpF2uB6SErL8ff8QFEQYJcpjKkTSZrTm6rGIiUlLvPQcnEpHqBcJOcHEyg57iN/278r3S16ojVt5PtW4b6bEY3hETG9BnDMZxmStqwsYLVyz19IcT7AFelrMweu+dTW7RvZSITm5VNxUU=; 24:PqdBb8wF1b/H4OWs7R8PGkK8knpNxHap3TGGt8hDgbMQZk364rbcjg6HEDbnuBqCsi5pHnp19bKLRtCEime+ggRfBnqst1QXufAV1MaSWqw=; 7:0WWx6ubZlY8SINh1yy+Gy1TReMRSwwPJcefzOqomXQhY/BardEtVyucCMSQPC5QWoW/+iOWBERFdvhET3c25YIaEoj8jO6OIVRi9cf8AH2OS8uQ6EC1VoUrne8fIpstola8NtTcpyXTjY5QQx8XZRje3PiWKACGPj4rlUNpkuQAnpsapk1XCiGSv9EbTbjs0PH7LLkIY8wgOCTrXCOTWHhInRe/7cHoLjoWWfUwXZSoHgj0s+mYVwhKMIxykdqhU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2018 10:41:55.1983 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1340ca4-3cda-4110-9040-08d568974101 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB3080 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Async crypto accelerators (e.g. drivers/crypto/caam) support offloading GCM operation. If they are enabled, crypto_aead_encrypt() return error code -EINPROGRESS. In this case tls_do_encryption() needs to wait on a completion till the time the response for crypto offload request is received. Signed-off-by: Vakul Garg --- v1-v2: - Used crypto_wait_req() to wait for async operation completion - Passed CRYPTO_TFM_REQ_MAY_BACKLOG to crypto_aead_encrypt include/net/tls.h | 2 ++ net/tls/tls_sw.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/net/tls.h b/include/net/tls.h index 936cfc5cab7d..8a8e1256caee 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,7 @@ struct tls_sw_context { struct crypto_aead *aead_send; + struct crypto_wait async_wait; /* Sending context */ char aad_space[TLS_AAD_SPACE_SIZE]; diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 73d19210dd49..31a9f0ef8af6 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -214,7 +214,11 @@ static int tls_do_encryption(struct tls_context *tls_ctx, aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE); aead_request_set_crypt(aead_req, ctx->sg_aead_in, ctx->sg_aead_out, data_len, tls_ctx->iv); - rc = crypto_aead_encrypt(aead_req); + + aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &ctx->async_wait); + + rc = crypto_wait_req(crypto_aead_encrypt(aead_req), &ctx->async_wait); ctx->sg_encrypted_data[0].offset -= tls_ctx->prepend_size; ctx->sg_encrypted_data[0].length += tls_ctx->prepend_size; @@ -663,6 +667,8 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx) goto out; } + crypto_init_wait(&sw_ctx->async_wait); + ctx->priv_ctx = (struct tls_offload_context *)sw_ctx; crypto_info = &ctx->crypto_send;