From patchwork Thu Feb 6 11:39:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eneas U de Queiroz X-Patchwork-Id: 198134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71FAEC2D0B1 for ; Thu, 6 Feb 2020 11:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 491BF20661 for ; Thu, 6 Feb 2020 11:41:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bQuMdB3A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727646AbgBFLlZ (ORCPT ); Thu, 6 Feb 2020 06:41:25 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:33520 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbgBFLlZ (ORCPT ); Thu, 6 Feb 2020 06:41:25 -0500 Received: by mail-qk1-f195.google.com with SMTP id h4so5210489qkm.0 for ; Thu, 06 Feb 2020 03:41:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oFkkNUdzzqqQ4BTE/G04D5Na0zNjD/ys0WvHWqp3S+E=; b=bQuMdB3AMwmlKGJ8GH4U+CPk8GDrQVlbZR9ZLDfITsUrqK44sJpR9W/0BTDZcJxQP1 L34iaJPxIy5zbKKxD32koYp5AC/vYspTOSByxZOSd5tCXWCnPmBdy82DwRQfY41Zv1nh dyMU3noTM4DaVs9Bd8RmcTjaE/g1eLEQVdju/0gQ3DX8xCQuw4wwqBwki57oxSjua1QJ Mwd7cFso4HGr4Caz2pO/0aKfk4c0DmBYax51sm/AOUjRaBnMPUzBhA2dmSuHVzJaYRae 91krbhk3/vyhWam9/REdF/aLWrIih+bXLVtTz9icB92YbDGgs+zSjJrOO4BVXlhSdmN1 a8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oFkkNUdzzqqQ4BTE/G04D5Na0zNjD/ys0WvHWqp3S+E=; b=hCOnhaaN3WxV0DTMtbDfeEUkERJYx25B9Ahi0NV7TEYD7gXWoAm5c902V4RLcfdxTM LtjFnJMBm7KIErYHQLsj94OJGYzpyQ5l8x/DLhSLLl0D7ejn2exC5TUSoFuEyTJDsfVp BiYACjgTKoAeCIKYI6SfhFpI16xiAV1Lsj7XfFR2zCn/4l2/4YMB7wSOU/rojs21eulK VkYXoVmDwRYSitKBc8PopqyHgXU/UiXi63h97KfBDS4opTtyvkMctHhRnCml9Ig6ba0C CHKtbCLSi6w+ptzeaif3qNcJa319TW6YkHNWh5O3L5XAFd6iof4RWYNORKeiOeOFzOA8 b1FA== X-Gm-Message-State: APjAAAUPclMpe9tY8mgL9rAlx3DptV5p/KskZY11A0iBUVZrDUMqWdj/ jH0Uuz3qV6q2SzHEkTPBSTaUC/CW X-Google-Smtp-Source: APXvYqx2K2bY8moBMw9N2UABieFCnoIv+Fu3pmiIZqJk8opRfjiGNiazsK3N1DeYDltm/VnVMtEkNw== X-Received: by 2002:a37:f518:: with SMTP id l24mr1917808qkk.441.1580989284281; Thu, 06 Feb 2020 03:41:24 -0800 (PST) Received: from gateway.troianet.com.br ([2804:688:21:4::2]) by smtp.gmail.com with ESMTPSA id g37sm1507283qte.60.2020.02.06.03.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2020 03:41:23 -0800 (PST) From: Eneas U de Queiroz To: linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" Cc: Ard Biesheuvel , Eneas U de Queiroz Subject: [PATCH v3 1/3] crypto: qce - use cryptlen when adding extra sgl Date: Thu, 6 Feb 2020 08:39:45 -0300 Message-Id: <20200206113947.31396-2-cotequeiroz@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200206012036.25614-1-cotequeiroz@gmail.com> References: <20200206012036.25614-1-cotequeiroz@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The qce crypto driver appends an extra entry to the dst sgl, to maintain private state information. When the gcm driver sends requests to the ctr skcipher, it passes the authentication tag after the actual crypto payload, but it must not be touched. Commit 1336c2221bee ("crypto: qce - save a sg table slot for result buf") limited the destination sgl to avoid overwriting the authentication tag but it assumed the tag would be in a separate sgl entry. This is not always the case, so it is better to limit the length of the destination buffer to req->cryptlen before appending the result buf. Signed-off-by: Eneas U de Queiroz diff --git a/drivers/crypto/qce/dma.c b/drivers/crypto/qce/dma.c index 7da893dc00e7..46db5bf366b4 100644 --- a/drivers/crypto/qce/dma.c +++ b/drivers/crypto/qce/dma.c @@ -48,9 +48,10 @@ void qce_dma_release(struct qce_dma_data *dma) struct scatterlist * qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl, - int max_ents) + unsigned int max_len) { struct scatterlist *sg = sgt->sgl, *sg_last = NULL; + unsigned int new_len; while (sg) { if (!sg_page(sg)) @@ -61,13 +62,13 @@ qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl, if (!sg) return ERR_PTR(-EINVAL); - while (new_sgl && sg && max_ents) { - sg_set_page(sg, sg_page(new_sgl), new_sgl->length, - new_sgl->offset); + while (new_sgl && sg && max_len) { + new_len = new_sgl->length > max_len ? max_len : new_sgl->length; + sg_set_page(sg, sg_page(new_sgl), new_len, new_sgl->offset); sg_last = sg; sg = sg_next(sg); new_sgl = sg_next(new_sgl); - max_ents--; + max_len -= new_len; } return sg_last; diff --git a/drivers/crypto/qce/dma.h b/drivers/crypto/qce/dma.h index ed25a0d9829e..786402169360 100644 --- a/drivers/crypto/qce/dma.h +++ b/drivers/crypto/qce/dma.h @@ -43,6 +43,6 @@ void qce_dma_issue_pending(struct qce_dma_data *dma); int qce_dma_terminate_all(struct qce_dma_data *dma); struct scatterlist * qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add, - int max_ents); + unsigned int max_len); #endif /* _DMA_H_ */ diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index 4217b745f124..63ae75809cb7 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -97,13 +97,14 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req) sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ); - sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, rctx->dst_nents - 1); + sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, req->cryptlen); if (IS_ERR(sg)) { ret = PTR_ERR(sg); goto error_free; } - sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg, 1); + sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg, + QCE_RESULT_BUF_SZ); if (IS_ERR(sg)) { ret = PTR_ERR(sg); goto error_free; From patchwork Thu Feb 6 01:20:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eneas U de Queiroz X-Patchwork-Id: 198135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C6C7C35247 for ; Thu, 6 Feb 2020 01:21:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65B992082E for ; Thu, 6 Feb 2020 01:21:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PH+MhRUg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbgBFBVR (ORCPT ); Wed, 5 Feb 2020 20:21:17 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:43904 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727170AbgBFBVQ (ORCPT ); Wed, 5 Feb 2020 20:21:16 -0500 Received: by mail-qt1-f194.google.com with SMTP id d18so3223219qtj.10 for ; Wed, 05 Feb 2020 17:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m9EEloNQL6eZ3dm91bJ9GK6LSsi6Ei6R6xgKjvhZ/fg=; b=PH+MhRUg4SpXTAVHjTDnJGaiGNnOivSq0kOv2J4x46mYknS+BNueX8vC4YmmsHcpXe uRAgAoVILZ/HOy6fvup5LjMWTzcmUMqZFnxBArc55xX0QcURDTXGM+bGYz4SF6wSvajU IY/9ui3wV8lkamZg2yxz9j2uilLnPZn01tykcacppipNXzXTDFl99u372FLt53iZmLFp 67EYNwoXoebOzaZIEQv/dWoP+C/ofVcw1vdrdLQ+lg+IJNmLEma9myeCo15eFW7LxWL1 JeIHMJ3nyQ/W2kC5CFSzZbbi3kEFgO5qQG82xZLN2OSo1bQyksWtpmZFQjnx5a99tGA/ 6eIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m9EEloNQL6eZ3dm91bJ9GK6LSsi6Ei6R6xgKjvhZ/fg=; b=H2KhXvEewyjo18b8uKL3DEzN7BKMhFc3/HGEPpr7TbuR/+ZAyl1qrhLpp6b2pFCDw3 Z/L7/Yf2jwUOXQ/Ol4h0VgeWsR4sjvHyGmyemBHmviU/X2LHreMxlt2dl7hRYXjiSeDU 3T33KJZbQmZblYefBN8sGZZKwATSo2xIeBJ82/KFV/Gu4KPJHWxn6ax6PewWxMrY3jm4 mv8ziWYBmoXXf1QoRQ3krFlVDfbKPJEyp+1kF27kpWFNmFSZMT+pzchTGOheCrkEA+6k pWLhv+WQC9nTNt/svOGoYHlDYyjwmc2YrhmwUROHBf7NUpe9U25kwim0pItoT7WWh9gs dMPw== X-Gm-Message-State: APjAAAXKFSYLvcgcsg8lWnEhMgQalrdHAeAsLQXz0P0OCk33SpZwn7J0 ORiiHK0R+bINr4DtJAmqwFrmc2eY X-Google-Smtp-Source: APXvYqyBxbj7mn7KmTYGUKaMuMMGMBq7Paz599jWEL25SGeXSEp6mxiB/6PDX6j64PDbG1itlWjp9g== X-Received: by 2002:ac8:6b98:: with SMTP id z24mr547718qts.392.1580952074932; Wed, 05 Feb 2020 17:21:14 -0800 (PST) Received: from gateway.troianet.com.br (ipv6.troianet.com.br. [2804:688:21:4::2]) by smtp.gmail.com with ESMTPSA id c18sm719729qkk.5.2020.02.05.17.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 17:21:14 -0800 (PST) From: Eneas U de Queiroz To: linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" Cc: Ard Biesheuvel , Eneas U de Queiroz Subject: [PATCH v2 2/3] crypto: qce - use AES fallback for small requests Date: Wed, 5 Feb 2020 22:20:35 -0300 Message-Id: <20200206012036.25614-3-cotequeiroz@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200206012036.25614-1-cotequeiroz@gmail.com> References: <20200203165334.6185-1-cotequeiroz@gmail.com> <20200206012036.25614-1-cotequeiroz@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Process small blocks using the fallback cipher, as a workaround for an observed failure (DMA-related, apparently) when computing the GCM ghash key. This brings a speed gain as well, since it avoids the latency of using the hardware engine to process small blocks. Using software for all 16-byte requests would be enough to make GCM work, but to increase performance, a larger threshold would be better. Measuring the performance of supported ciphers with openssl speed, software matches hardware at around 768-1024 bytes. Considering the 256-bit ciphers, software is 2-3 times faster than qce at 256-bytes, 30% faster at 512, and about even at 768-bytes. With 128-bit keys, the break-even point would be around 1024-bytes. This adds the 'aes_sw_max_len' parameter, to set the largest request length processed by the software fallback. Its default is being set to 512 bytes, a little lower than the break-even point, to balance the cost in CPU usage. Signed-off-by: Eneas U de Queiroz crypto: qce - add aes_sw_max_len parameter This adds the AES fallback threshold as a parameter, so it can be changed by the user. Signed-off-by: Eneas U de Queiroz diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index c2767ed54dfe..052d3ff7fb20 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -685,6 +685,29 @@ choice endchoice +config CRYPTO_DEV_QCE_SW_MAX_LEN + int "Default maximum request size to use software for AES" + depends on CRYPTO_DEV_QCE && CRYPTO_DEV_QCE_SKCIPHER + default 512 + help + This sets the default maximum request size to perform AES requests + using software instead of the crypto engine. It can be changed by + setting the aes_sw_max_len parameter. + + Small blocks are processed faster in software than hardware. + Considering the 256-bit ciphers, software is 2-3 times faster than + qce at 256-bytes, 30% faster at 512, and about even at 768-bytes. + With 128-bit keys, the break-even point would be around 1024-bytes. + + The default is set a little lower, to 512 bytes, to balance the + cost in CPU usage. The minimum recommended setting is 16-bytes + (1 AES block), since AES-GCM will fail if you set it lower. + Setting this to zero will send all requests to the hardware. + + Note that 192-bit keys are not supported by the hardware and are + always processed by the software fallback, and all DES requests + are done by the hardware. + config CRYPTO_DEV_QCOM_RNG tristate "Qualcomm Random Number Generator Driver" depends on ARCH_QCOM || COMPILE_TEST diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index 63ae75809cb7..a3536495b6b0 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -12,6 +13,13 @@ #include "cipher.h" +unsigned int aes_sw_max_len = CONFIG_CRYPTO_DEV_QCE_SW_MAX_LEN; +module_param(aes_sw_max_len, uint, 0644); +MODULE_PARM_DESC(aes_sw_max_len, + "Only use hardware for AES requests larger than this " + "[0=always use hardware; anything <16 breaks AES-GCM; default=" + __stringify(CONFIG_CRYPTO_DEV_QCE_SOFT_THRESHOLD)"]"); + static LIST_HEAD(skcipher_algs); static void qce_skcipher_done(void *data) @@ -166,15 +174,10 @@ static int qce_skcipher_setkey(struct crypto_skcipher *ablk, const u8 *key, switch (IS_XTS(flags) ? keylen >> 1 : keylen) { case AES_KEYSIZE_128: case AES_KEYSIZE_256: + memcpy(ctx->enc_key, key, keylen); break; - default: - goto fallback; } - ctx->enc_keylen = keylen; - memcpy(ctx->enc_key, key, keylen); - return 0; -fallback: ret = crypto_sync_skcipher_setkey(ctx->fallback, key, keylen); if (!ret) ctx->enc_keylen = keylen; @@ -224,8 +227,9 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT; keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen; - if (IS_AES(rctx->flags) && keylen != AES_KEYSIZE_128 && - keylen != AES_KEYSIZE_256) { + if (IS_AES(rctx->flags) && + ((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) + || req->cryptlen <= aes_sw_max_len)) { SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback); skcipher_request_set_sync_tfm(subreq, ctx->fallback); From patchwork Thu Feb 6 11:39:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eneas U de Queiroz X-Patchwork-Id: 198133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9719CC2D0B1 for ; Thu, 6 Feb 2020 11:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D86720661 for ; Thu, 6 Feb 2020 11:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uMw7orJq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbgBFLla (ORCPT ); Thu, 6 Feb 2020 06:41:30 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:33527 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbgBFLl3 (ORCPT ); Thu, 6 Feb 2020 06:41:29 -0500 Received: by mail-qk1-f196.google.com with SMTP id h4so5210652qkm.0 for ; Thu, 06 Feb 2020 03:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qu7ooKR6DgewFpJKq46pIZD5BtoS5iVf4kRfIooEK68=; b=uMw7orJqxVfVoqrcXx0BZGUZ+WbJ8MWHwzr0LEbX7sRPEToqOismvLQvjvzsPRm6EV relXJWugDDne+z2RIgHhAQI0s96cxg1lsaBrNuWvBSRVXzcGichpSfNVFYauMBCPhqK6 41htdGPLxqm3x97QXsT+dFMP0zOvFaZfsm5dvQ1aa6qn1vrLlGddLTcDxomHkYMr+s6f bQYbe/X6kVMxLq0BQaKbX7RfZRxXoT3dEpgu0uv38wnliCbLMdP4q66enJq6MygWKUoB QYgmXbGAXtUN3dgQbcvrCQdBuo2vEjvSOyHToDDESClEa0HLKhYwe29L0nYL2D8OoLAa HX/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qu7ooKR6DgewFpJKq46pIZD5BtoS5iVf4kRfIooEK68=; b=EFeOgveBJHG0Uw8stMaIFUcxk9uLzM4v31+GN6UOxr68IeWTA7rYupq1VxqudfI0jk H+CjMKSijI89cdcWRNiNtlyRz6gdl4pcHTi7dKunWLBp1dA8pEjrPppnjJDlFErJ89XE c+e8OvB7iQ5mZgZuJmY7rFalPy0LagKnz2jPnNmbU0PdXXvIyfCCcWr8pXzEEnVmngOq +qRN5f4CgLqTpC+JwCv1Aym6gRsot8ZBPGLVW6oi5z9gqKYqL28KNcYVo0+qNHB2OAcy 4qQV7xFy1yTJjMAbYTE7oj1xzlY+mMoGfqMVLWN71oTud47URT7pPVtEZVeU9ZBU8C2I QGBQ== X-Gm-Message-State: APjAAAWIZpgpJg1slTYiTTFbHU2fArWVly4BEDSkuj0OdiEAEonb5KZ/ qO1qitwqNqBU/UQvUg7yr09k5JWs X-Google-Smtp-Source: APXvYqz2djPdV8c6dNH56nUw3S8TWpzDUui5mnIAp7hN7MlCw7kq9F9soVW/CYW7HEv5Pifr2q0S3g== X-Received: by 2002:a05:620a:210b:: with SMTP id l11mr2014170qkl.69.1580989288654; Thu, 06 Feb 2020 03:41:28 -0800 (PST) Received: from gateway.troianet.com.br ([2804:688:21:4::2]) by smtp.gmail.com with ESMTPSA id g37sm1507283qte.60.2020.02.06.03.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2020 03:41:28 -0800 (PST) From: Eneas U de Queiroz To: linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" Cc: Ard Biesheuvel , Eneas U de Queiroz Subject: [PATCH v3 3/3] crypto: qce - handle AES-XTS cases that qce fails Date: Thu, 6 Feb 2020 08:39:47 -0300 Message-Id: <20200206113947.31396-4-cotequeiroz@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200206012036.25614-1-cotequeiroz@gmail.com> References: <20200206012036.25614-1-cotequeiroz@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org QCE hangs when presented with an AES-XTS request whose length is larger than QCE_SECTOR_SIZE (512-bytes), and is not a multiple of it. Let the fallback cipher handle them. Signed-off-by: Eneas U de Queiroz diff --git a/drivers/crypto/qce/common.c b/drivers/crypto/qce/common.c index 629e7f34dc09..5006e74c40cd 100644 --- a/drivers/crypto/qce/common.c +++ b/drivers/crypto/qce/common.c @@ -15,8 +15,6 @@ #include "regs-v5.h" #include "sha.h" -#define QCE_SECTOR_SIZE 512 - static inline u32 qce_read(struct qce_device *qce, u32 offset) { return readl(qce->base + offset); diff --git a/drivers/crypto/qce/common.h b/drivers/crypto/qce/common.h index 282d4317470d..9f989cba0f1b 100644 --- a/drivers/crypto/qce/common.h +++ b/drivers/crypto/qce/common.h @@ -12,6 +12,9 @@ #include #include +/* xts du size */ +#define QCE_SECTOR_SIZE 512 + /* key size in bytes */ #define QCE_SHA_HMAC_KEY_SIZE 64 #define QCE_MAX_CIPHER_KEY_SIZE AES_KEYSIZE_256 diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index a3536495b6b0..377714cea23a 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -227,9 +227,14 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT; keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen; + /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and + * is not a multiple of it; pass such requests to the fallback + */ if (IS_AES(rctx->flags) && ((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) - || req->cryptlen <= aes_sw_max_len)) { + || req->cryptlen <= aes_sw_max_len) + || (IS_XTS(rctx->flags) && req->cryptlen > QCE_SECTOR_SIZE && + req->cryptlen % QCE_SECTOR_SIZE)) { SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback); skcipher_request_set_sync_tfm(subreq, ctx->fallback);