From patchwork Wed Jan 26 21:04:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725803 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 49E5BC433EF for ; Wed, 26 Jan 2022 21:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbiAZVEw (ORCPT ); Wed, 26 Jan 2022 16:04:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231585AbiAZVEw (ORCPT ); Wed, 26 Jan 2022 16:04:52 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE41C06161C for ; Wed, 26 Jan 2022 13:04:51 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id v123so524127wme.2 for ; Wed, 26 Jan 2022 13:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UWL8x42G4N1mlzu+WAhCp4FrFZgbOxSegmwVdqQbXCc=; b=c9QwSRmxbkHtqyg3Uh1XyeWdr/bT2I/i1Hji99sMoRdk7hEvZYnwb3+zsdZBEjgTsD jMKZBuZqN31tOjUY8FtDuMKFvr3PdPRk2D3bIkcAcHKdVM1DMKJGLGoD2Z5+3gEPeWNx d3nnBGkxqeEnRyepp8lggh0qWR/VvdVo6jW4CbpFNbN8L/3drOzJNsUd4ASyuiMip7F2 yHqE7+7K5Fg249794TBd2CYythGOb4m8Vus9fok28hpCNTk7qj7zjOEa9G0Sml9mda0I DazCF0Xe+FvCDxD23jQnrW6QDjgRIjZwWPm1twk/D3cBt+beDfgSMUMF7tp56MT8G34c 6QmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UWL8x42G4N1mlzu+WAhCp4FrFZgbOxSegmwVdqQbXCc=; b=KiUTmJjdOA3TKY8N5q15fy0tv5B0m+qpXsfdxD22xolOOfcF1WLUvU+kvoTEj2o58v uo2jGHG5LqQSzMnVbhjSZz5lbX/OFdOGBIdvDCoYnrJqlqrzCGocR1QUduB/WN2gZkRL Y1wYiwkh6U0PlFoeB/5H9JdHNPihwBkm2N6emVS+gBgl5sDE2LzIkYq+SgWLs3o/Njbq yEJ3wj31hq1GkXitBOWiNCnt79YWDkdKD/yjJoqgPE4et4upY+g+ySn/HRWzl6PQbdeJ tGgZfFUaoDWFZm2e5FIkMui0/d3xLncQU9ZS9rADCaEIcL5USvSET0JwYIPpyw5/bWgi jIvA== X-Gm-Message-State: AOAM5315kfpEDdmFzcv3hn6sJzhSaOzC1Uro+bKJu/ipMQxAkCa1Ibyr o+tmrmVZ1sK/xcBb6WjkuBUJvg== X-Google-Smtp-Source: ABdhPJymHTxLjf2FgxbjiTu/XUpjTu+pXwe1QOMFEwpsZ+dU33AWK0VJw4YCcEvVi4G9m7gVdpSZpA== X-Received: by 2002:a05:600c:40b:: with SMTP id q11mr8804315wmb.43.1643231090439; Wed, 26 Jan 2022 13:04:50 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:49 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 1/8] crypto: sun8i-ce: do not allocate memory when handling requests Date: Wed, 26 Jan 2022 21:04:34 +0000 Message-Id: <20220126210441.3661782-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of allocate memory on each requests, it is easier to pre-allocate buffer for IV. This made error path easier. Signed-off-by: Corentin Labbe Reported-by: kernel test robot --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 28 ++++++------------- .../crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 20 ++++++++++--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 8 +++--- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 8f0031e45a03..f4221025d651 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -151,23 +151,13 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req ivsize = crypto_skcipher_ivsize(tfm); if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) { rctx->ivlen = ivsize; - rctx->bounce_iv = kzalloc(ivsize, GFP_KERNEL | GFP_DMA); - if (!rctx->bounce_iv) { - err = -ENOMEM; - goto theend_key; - } if (rctx->op_dir & CE_DECRYPTION) { - rctx->backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!rctx->backup_iv) { - err = -ENOMEM; - goto theend_key; - } offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(rctx->backup_iv, areq->src, + scatterwalk_map_and_copy(chan->backup_iv, areq->src, offset, ivsize, 0); } - memcpy(rctx->bounce_iv, areq->iv, ivsize); - rctx->addr_iv = dma_map_single(ce->dev, rctx->bounce_iv, rctx->ivlen, + memcpy(chan->bounce_iv, areq->iv, ivsize); + rctx->addr_iv = dma_map_single(ce->dev, chan->bounce_iv, rctx->ivlen, DMA_TO_DEVICE); if (dma_mapping_error(ce->dev, rctx->addr_iv)) { dev_err(ce->dev, "Cannot DMA MAP IV\n"); @@ -256,13 +246,13 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req dma_unmap_single(ce->dev, rctx->addr_iv, rctx->ivlen, DMA_TO_DEVICE); offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, rctx->backup_iv, ivsize); - kfree_sensitive(rctx->backup_iv); + memcpy(areq->iv, chan->backup_iv, ivsize); + memzero_explicit(chan->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - kfree(rctx->bounce_iv); + memzero_explicit(chan->bounce_iv, ivsize); } theend_key: @@ -319,13 +309,13 @@ static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_r dma_unmap_single(ce->dev, rctx->addr_iv, rctx->ivlen, DMA_TO_DEVICE); offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, rctx->backup_iv, ivsize); - kfree_sensitive(rctx->backup_iv); + memcpy(areq->iv, chan->backup_iv, ivsize); + memzero_explicit(chan->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - kfree(rctx->bounce_iv); + memzero_explicit(chan->bounce_iv, ivsize); } dma_unmap_single(ce->dev, rctx->addr_key, op->keylen, DMA_TO_DEVICE); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index ea2c655e4ff1..b57aed120d33 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -305,7 +305,7 @@ static struct sun8i_ce_alg_template ce_algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_ctxsize = sizeof(struct sun8i_cipher_tfm_ctx), .cra_module = THIS_MODULE, @@ -332,7 +332,7 @@ static struct sun8i_ce_alg_template ce_algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_ctxsize = sizeof(struct sun8i_cipher_tfm_ctx), .cra_module = THIS_MODULE, @@ -358,7 +358,7 @@ static struct sun8i_ce_alg_template ce_algs[] = { .cra_priority = 400, .cra_blocksize = DES3_EDE_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_ctxsize = sizeof(struct sun8i_cipher_tfm_ctx), .cra_module = THIS_MODULE, @@ -385,7 +385,7 @@ static struct sun8i_ce_alg_template ce_algs[] = { .cra_priority = 400, .cra_blocksize = DES3_EDE_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_ctxsize = sizeof(struct sun8i_cipher_tfm_ctx), .cra_module = THIS_MODULE, @@ -728,6 +728,18 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) err = -ENOMEM; goto error_engine; } + ce->chanlist[i].bounce_iv = devm_kmalloc(ce->dev, AES_BLOCK_SIZE, + GFP_KERNEL | GFP_DMA); + if (!ce->chanlist[i].bounce_iv) { + err = -ENOMEM; + goto error_engine; + } + ce->chanlist[i].backup_iv = devm_kmalloc(ce->dev, AES_BLOCK_SIZE, + GFP_KERNEL); + if (!ce->chanlist[i].backup_iv) { + err = -ENOMEM; + goto error_engine; + } } return 0; error_engine: diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 719f9a730857..229b696d5a2c 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -213,6 +213,8 @@ struct ce_task { * @status: set to 1 by interrupt if task is done * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow + * @backup_iv: buffer which contain the next IV to store + * @bounce_iv: buffer which contain the IV * @stat_req: number of request done by this flow */ struct sun8i_ce_flow { @@ -222,6 +224,8 @@ struct sun8i_ce_flow { dma_addr_t t_phy; int timeout; struct ce_task *tl; + void *backup_iv; + void *bounce_iv; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG unsigned long stat_req; #endif @@ -268,8 +272,6 @@ struct sun8i_ce_dev { * struct sun8i_cipher_req_ctx - context for a skcipher request * @op_dir: direction (encrypt vs decrypt) for this request * @flow: the flow to use for this request - * @backup_iv: buffer which contain the next IV to store - * @bounce_iv: buffer which contain the IV * @ivlen: size of bounce_iv * @nr_sgs: The number of source SG (as given by dma_map_sg()) * @nr_sgd: The number of destination SG (as given by dma_map_sg()) @@ -280,8 +282,6 @@ struct sun8i_ce_dev { struct sun8i_cipher_req_ctx { u32 op_dir; int flow; - void *backup_iv; - void *bounce_iv; unsigned int ivlen; int nr_sgs; int nr_sgd; From patchwork Wed Jan 26 21:04:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725804 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 8DAAAC433F5 for ; Wed, 26 Jan 2022 21:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231757AbiAZVE5 (ORCPT ); Wed, 26 Jan 2022 16:04:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231690AbiAZVEx (ORCPT ); Wed, 26 Jan 2022 16:04:53 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7B74C06161C for ; Wed, 26 Jan 2022 13:04:52 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id f202-20020a1c1fd3000000b0034dd403f4fbso628131wmf.1 for ; Wed, 26 Jan 2022 13:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uQfQxPxFJ18OHZiKr+H6x2uvjjAUEJks7M+mZV0XyDU=; b=gI5EvP3Vb93EkxWs5/NGdIKIUHXcZ9cD9PdxdQ7AihS1mp1WTtquESrkQ6JOACLki7 b2yp7STxQIt6XVZNAdkqGfgp+Lz/deN30PAjSTkDJl/MSHZLDhnBwPHPjpDB+t1qbsoN /3T5mHPFZmgSIkaDztl2MQfQto871u3/wf28GDMSsqYwmBdYWkQPqzZxA1n7iDQ6BJ2R RAe4PUYx4cn45hZeDcg6MRkKdyCcefKnagdZiyC32zANamTA1ve0rX2BC5g3wBrhqozr aW1epb7TiZPn/6GRVlyA6plsOHzrsfw5rr57aGhyuJWIHNE5hamLD6o5boZpoLi9gxN2 zMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQfQxPxFJ18OHZiKr+H6x2uvjjAUEJks7M+mZV0XyDU=; b=itTjbbhfsJHM89R0slqwUnJXwjQW7A6a0o3+2ezYGAjrRDxMl8Io3oiMfy9hb6bAil Wkp3sv9KjcPy4bAvEL4qn0aLi0GT0MxYx6KhSSbGUjA95M/kzOTmxNBXcJJGgUdRooLZ FUhuWgEwXM0+WYRyfyhCM+AVi7qLeM3JGmIs6iV1a+ZJ7KQzOtXG2onJ6KGochYc/reo NyX2F5XPAzU5SVISVBRfMBw3WSymvk3MrPnYGZjf3d0KP4uYHdfyhb0r7Fv80vxeEjaS ixxgyEIeuEEQ1SI8v+Voci8LMjdvFiHmp4hgSYsJuwcPNHPXS1F/3b2l3IhYR+kkFPHG uHWw== X-Gm-Message-State: AOAM532Nw2n6jXwHHOgNlwXxPgtPSQAUSdieQmx8V9DR47+wa/KJrFh9 4+fRLpP68j9ftkSJQ+bFv3IE0g== X-Google-Smtp-Source: ABdhPJz0wDzZ/chLZNIXRRbPWQZRsRz89OXrDdMn3YyXcTITc7q8YpCcfv3JsZnHYnOX78ChNWqaVw== X-Received: by 2002:a05:600c:1c16:: with SMTP id j22mr480719wms.60.1643231091453; Wed, 26 Jan 2022 13:04:51 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:50 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 2/8] crypto: sun4i-ss: do not allocate backup IV on requests Date: Wed, 26 Jan 2022 21:04:35 +0000 Message-Id: <20220126210441.3661782-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of allocate memory on each requests, it is easier to pre-allocate buffer for backup IV. This made error path easier. Signed-off-by: Corentin Labbe --- .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 22 +++++++------------ drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 1 + 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 8dc2a475c601..a8c784acce13 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -20,7 +20,6 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) unsigned int ivsize = crypto_skcipher_ivsize(tfm); struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq); u32 mode = ctx->mode; - void *backup_iv = NULL; /* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */ u32 rx_cnt = SS_RX_DEFAULT; u32 tx_cnt = 0; @@ -47,10 +46,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) } if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) - return -ENOMEM; - scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + scatterwalk_map_and_copy(ctx->backup_iv, areq->src, + areq->cryptlen - ivsize, ivsize, 0); } if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { @@ -133,8 +130,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) if (areq->iv) { if (mode & SS_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kfree_sensitive(backup_iv); + memcpy(areq->iv, ctx->backup_iv, ivsize); + memzero_explicit(ctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, ivsize, 0); @@ -198,7 +195,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int ileft = areq->cryptlen; unsigned int oleft = areq->cryptlen; unsigned int todo; - void *backup_iv = NULL; struct sg_mapping_iter mi, mo; unsigned long pi = 0, po = 0; /* progress for in and out */ bool miter_err; @@ -242,10 +238,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) return sun4i_ss_cipher_poll_fallback(areq); if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) - return -ENOMEM; - scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + scatterwalk_map_and_copy(ctx->backup_iv, areq->src, + areq->cryptlen - ivsize, ivsize, 0); } if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { @@ -382,8 +376,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) } if (areq->iv) { if (mode & SS_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kfree_sensitive(backup_iv); + memcpy(areq->iv, ctx->backup_iv, ivsize); + memzero_explicit(ctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, ivsize, 0); diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 0fee6f4e2d90..ba59c7a48825 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -183,6 +183,7 @@ struct sun4i_tfm_ctx { struct sun4i_cipher_req_ctx { u32 mode; + u8 backup_iv[AES_BLOCK_SIZE]; struct skcipher_request fallback_req; // keep at the end }; From patchwork Wed Jan 26 21:04:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725805 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 842DBC433FE for ; Wed, 26 Jan 2022 21:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbiAZVE6 (ORCPT ); Wed, 26 Jan 2022 16:04:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbiAZVEy (ORCPT ); Wed, 26 Jan 2022 16:04:54 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75E4C061748 for ; Wed, 26 Jan 2022 13:04:53 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id l35-20020a05600c1d2300b0034d477271c1so607127wms.3 for ; Wed, 26 Jan 2022 13:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UxtlnkkXzgY9MYBwxijbABK2S3Zir1EPcNhEeIERW3k=; b=uVMO09/XOuXmt4x6PARdjy4vvpLXI1ZXFgAAaumTVy2NmU1V9Si3lx4byYIB3x7chj 08qFPwH2UMUkXhDW5u4nBlrpLnp9pJ5dKEJRvTCu5PlK24n+cqMnrU1o2WPb+NzFb3Vl sGcbk/v5Z3EN1mJu2s8+S0gzCNlEQNLja4JS9JsNNN6W+KCkLOPDnOl8dLK9HRLp5HJq IEIX7k6TCn8B/7LseEBCNhhkj9RLE5ZhE5GJOmvu5iBtjGO6ObKMmENvmsLW3Q5c0lZb 3l24cLpAD2OWv0E3s/wj9x85O/+hfBZdd7q9//l/qodAgHe2kl7Exi/VFCBjTsTVx9tx Es+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UxtlnkkXzgY9MYBwxijbABK2S3Zir1EPcNhEeIERW3k=; b=V6I2xgYjA8ShkWX8sSk3G1eN0k8qXj4Jc08J2K2mXW/2zseFAIkifku0B+7Bd5tzRC b3USJFKQIcTcg9OEtSEkTk/iiKnW17XUAjxJJNP1i5q4ndd5B9WQtV4CEPEomUH2AcWQ ryHCQj/Dp+a2USVTRLj+t+Ft/no5prY6pmpMhDgBsfPT3ozPFDrsFVMpnXhWTdzmACKy 34jjOCtbHyLMTGA6zJ3o5BNyu5WE6KCJdRsN1E+5FcuK1jFzmXucC3CFk4oesAaJp11z 2+IGz/RcvXOFb/ZebV4PYJVexmTdv5x38UPZ1AXvoX+2G1hY3QTQEj/+D1GrdbwgUIwx LpYw== X-Gm-Message-State: AOAM533lJCWhbzTqGxxoUfPXSUX/37jsuSbklXwn1xYabyMUFx8JtSl3 YS5w8Up0u3srQ0ziQheYFvt6/Q== X-Google-Smtp-Source: ABdhPJyp6AGL1pT2Yn3YZ1lp/S6Ybp9E/UyigNbrZETxbAsiW7nMj83b0b2T42c9NT/o4PKPzyokVw== X-Received: by 2002:a05:600c:35c5:: with SMTP id r5mr435934wmq.195.1643231092344; Wed, 26 Jan 2022 13:04:52 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:51 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 3/8] crypto: sun8i-ss: handle zero sized sg Date: Wed, 26 Jan 2022 21:04:36 +0000 Message-Id: <20220126210441.3661782-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org sun8i-ss does not handle well the possible zero sized sg. Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms") Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index 3c073eb3db03..2557bb3fe7aa 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -379,13 +379,21 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) } len = areq->nbytes; - for_each_sg(areq->src, sg, nr_sgs, i) { + sg = areq->src; + i = 0; + while (len > 0 && sg) { + if (sg_dma_len(sg) == 0) { + sg = sg_next(sg); + continue; + } rctx->t_src[i].addr = sg_dma_address(sg); todo = min(len, sg_dma_len(sg)); rctx->t_src[i].len = todo / 4; len -= todo; rctx->t_dst[i].addr = addr_res; rctx->t_dst[i].len = digestsize / 4; + sg = sg_next(sg); + i++; } if (len > 0) { dev_err(ss->dev, "remaining len %d\n", len); From patchwork Wed Jan 26 21:04:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725807 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 EECDBC4332F for ; Wed, 26 Jan 2022 21:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231719AbiAZVE7 (ORCPT ); Wed, 26 Jan 2022 16:04:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbiAZVE4 (ORCPT ); Wed, 26 Jan 2022 16:04:56 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBA9C061753 for ; Wed, 26 Jan 2022 13:04:55 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso4568950wmj.2 for ; Wed, 26 Jan 2022 13:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ktDMlL8iZ2/3sijREuAuM+dmCDydSQ7poFBUP0oLczo=; b=Bcf1/J/JmjcL2kH4RMGo+wEKEkU7RNdbp/dUD/SMq9d16A9F3ZxfzpBe/WGhw5LKwS B6I6jCDxKuAFG7oNxPtidy5p6ovVXSM+zTRcs04Hexy+8sp8jnmz8Df85wRVf2nXlkNh I8NZhayNkaYAQLU9bI221UwNcKkcHWEinCsaaaAWls1eNTeepzoqs4/OcGce/YUURmpD qLAq+9Sq8rNNEvOToeVcmutc25KNOe5KXw0nwVWPkBylM4+pQeVvX0hYKBhWeB/ED1zf IDmVhmC0q4hdu7usPsN/FX5ds8q5c2IvJWhfoNoc4pE4ame8maYzvc47+fmkBUB2EdQ9 +lJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ktDMlL8iZ2/3sijREuAuM+dmCDydSQ7poFBUP0oLczo=; b=zhiBa6z2EANgKINWvpc/ZWjw39acnHA+Zyo30I0M+hRCzfLN2e4S0N54XBwWNR7nu/ Fk1OCPvoei00N1ekuiqZ4csI5LQiriAFfN81T5wlRYfLyvghcgpaz8Gu6lD96SGv9S2y pHBm4QSSUOjMgLYyjqV0dIwZe+kl3IYSjQFOWmdm1KzhgnCqK3RpFpGVDKXQtVPh+HA9 z3cqIRKYVEwRSD312vS2PLnVG526lJgHsZeu5reuQhLQQSGwv3dU6I7Ik062WOz+kf/7 Vc+N/3e6wRY/gpcJwddDOLdNcTafK4SjoRWFEccyk1RrFBWW8aCLU+FN9yab6YS6bgbB LHeg== X-Gm-Message-State: AOAM533+fCnj1koE8NIWSiACmYkhGgEikKFeNPURF1FxXX1PqkvJTOME z/kVERA9m6Kns3wD/N8DmO+kZw== X-Google-Smtp-Source: ABdhPJxiNZGsixA/dP4HPSBuINQsxbgvdDaaxpjkQ5Ww1hZP2upy4QOmEl+72jz0ry9zZys6s8Wb5Q== X-Received: by 2002:a7b:cb8c:: with SMTP id m12mr459302wmi.154.1643231093676; Wed, 26 Jan 2022 13:04:53 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:52 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 4/8] crypto: sun8i-ss: do not allocate memory when handling hash requests Date: Wed, 26 Jan 2022 21:04:37 +0000 Message-Id: <20220126210441.3661782-5-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of allocate memory on each requests, it is easier to pre-allocate buffers. This made error path easier. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c | 10 ++++++++++ drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 15 +++------------ drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h | 4 ++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c index 319fe3279a71..084261d7899c 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c @@ -474,6 +474,16 @@ static int allocate_flows(struct sun8i_ss_dev *ss) for (i = 0; i < MAXFLOW; i++) { init_completion(&ss->flows[i].complete); + /* the padding could be up to two block. */ + ss->flows[i].pad = devm_kmalloc(ss->dev, SHA256_BLOCK_SIZE * 2, + GFP_KERNEL | GFP_DMA); + if (!ss->flows[i].pad) + goto error_engine; + ss->flows[i].result = devm_kmalloc(ss->dev, SHA256_DIGEST_SIZE, + GFP_KERNEL | GFP_DMA); + if (!ss->flows[i].result) + goto error_engine; + ss->flows[i].engine = crypto_engine_alloc_init(ss->dev, true); if (!ss->flows[i].engine) { dev_err(ss->dev, "Cannot allocate engine\n"); diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index 2557bb3fe7aa..f7a9578e87f7 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -341,18 +341,11 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) if (digestsize == SHA224_DIGEST_SIZE) digestsize = SHA256_DIGEST_SIZE; - /* the padding could be up to two block. */ - pad = kzalloc(algt->alg.hash.halg.base.cra_blocksize * 2, GFP_KERNEL | GFP_DMA); - if (!pad) - return -ENOMEM; + result = ss->flows[rctx->flow].result; + pad = ss->flows[rctx->flow].pad; + memset(pad, 0, algt->alg.hash.halg.base.cra_blocksize * 2); bf = (__le32 *)pad; - result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); - if (!result) { - kfree(pad); - return -ENOMEM; - } - for (i = 0; i < MAX_SG; i++) { rctx->t_dst[i].addr = 0; rctx->t_dst[i].len = 0; @@ -448,8 +441,6 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) memcpy(areq->result, result, algt->alg.hash.halg.digestsize); theend: - kfree(pad); - kfree(result); crypto_finalize_hash_request(engine, breq, err); return 0; } diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h index 28188685b910..f9f089ede934 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h @@ -121,11 +121,15 @@ struct sginfo { * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done * @stat_req: number of request done by this flow + * @pad: padding buffer for hash operations + * @result: buffer for storing the result of hash operations */ struct sun8i_ss_flow { struct crypto_engine *engine; struct completion complete; int status; + void *pad; + void *result; #ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG unsigned long stat_req; #endif From patchwork Wed Jan 26 21:04:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725806 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 58932C43219 for ; Wed, 26 Jan 2022 21:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231771AbiAZVE7 (ORCPT ); Wed, 26 Jan 2022 16:04:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbiAZVE4 (ORCPT ); Wed, 26 Jan 2022 16:04:56 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E10C061756 for ; Wed, 26 Jan 2022 13:04:56 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id q9-20020a7bce89000000b00349e697f2fbso4590344wmj.0 for ; Wed, 26 Jan 2022 13:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=buaazu1WrMDzlwPQHqm8IQrYu7KI8/m+gyfaMuk4eCE=; b=1A4bnZJMdAQkBvC7PZ9mskNXQQhnZE6VRNKHHrWqzWuGTS1Z16M0qFlCtl/SufBbX6 ju7zpaQvvPl6/6yYxzVAG0qOGzlZEII7AF3FnhhTi8gxB2bibYzmW8UAoccwQyy+q2tQ nk3Y4gy280Pf5xsbL9gjfo7lTPTwpKmR3lYhx3vr2TS5qr61thhOlWKFDo4Nx4rbZQ4C mW8yQ9Hi+dQ6D8GfzdecOb6Dj2uvVs2GVkILNRnWPDyo2JaeDSd8sF+fP/NVnpwKGGUC vrEG0Hrce98hI4JJCkrSa3eKAmWNBmBsu70WuYFLzr7bX/qaa8EBe3iAGVn/Uc6wQ0OE H07Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=buaazu1WrMDzlwPQHqm8IQrYu7KI8/m+gyfaMuk4eCE=; b=j78+kyWTaCodBxDjYBOUY8KDtiAHfDbqPBMtlsv5if/In0rBcpiwiZf3XesMfeDbgA mrNtqTUkVrcJK9RbvXmP32AMRgp0KqaZZ9KmsklTI5mc5rsxoSbYMKTn1oAGtUBPuqyH NWpEzDFrYvgRozuRTRBYmW/fNnmDIIOGdkoGWFAG0nLzKKRULXenO+xil5sZJElKYeDk yIKgSGhMipVWbzLHTuVMJ5r5RneYmm7tP4qlg9bg2MTXnQMvlwaceZ8IULfMggAgYUo9 /eQZVhl5vjm227TbBTO6JB2sm3M4dV4ZSx0kXn+kW8kDPrjMc0Yy3v5WhiP9/PS4y913 cLOg== X-Gm-Message-State: AOAM533IWn76ET5NVqWNR+yGk2dK5wUAZ/9JoRkRWVdeGEczAhPy05PK D1trrxSl5TynF/sMt0Ooz3hCvQ== X-Google-Smtp-Source: ABdhPJwjF2ajoGSl2zYfi3anBFhjjlzUNBMG2st7gOW9X9MaMsEN3LPB/dFbwfDv5lsPqcizGI2x+w== X-Received: by 2002:a05:600c:1e86:: with SMTP id be6mr8890155wmb.79.1643231094782; Wed, 26 Jan 2022 13:04:54 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:54 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 5/8] crypto: sun8i-ss: do not zeroize all pad Date: Wed, 26 Jan 2022 21:04:38 +0000 Message-Id: <20220126210441.3661782-6-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of memset all pad buffer, it is faster to only put 0 where needed. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index f7a9578e87f7..ef3020bc9547 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -328,7 +328,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) unsigned int len; u64 fill, min_fill, byte_count; void *pad, *result; - int j, i, todo; + int j, i, k, todo; __be64 *bebits; __le64 *lebits; dma_addr_t addr_res, addr_pad; @@ -343,7 +343,6 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) result = ss->flows[rctx->flow].result; pad = ss->flows[rctx->flow].pad; - memset(pad, 0, algt->alg.hash.halg.base.cra_blocksize * 2); bf = (__le32 *)pad; for (i = 0; i < MAX_SG; i++) { @@ -404,7 +403,10 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) if (fill < min_fill) fill += 64; + k = j; j += (fill - min_fill) / sizeof(u32); + for (; k < j; k++) + bf[k] = 0; switch (algt->ss_algo_id) { case SS_ID_HASH_MD5: From patchwork Wed Jan 26 21:04:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725808 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 45C08C43217 for ; Wed, 26 Jan 2022 21:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbiAZVFA (ORCPT ); Wed, 26 Jan 2022 16:05:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbiAZVE6 (ORCPT ); Wed, 26 Jan 2022 16:04:58 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31F91C06161C for ; Wed, 26 Jan 2022 13:04:57 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso4568982wmj.2 for ; Wed, 26 Jan 2022 13:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=snYrFJ12aUfxHMb2aqbQr58aBrO9I7pzj7+8V1Dw+/A=; b=4ulCosohtZpKHKk1OWZvg15RfCT5UKS1+RX7vVL4SOremHHI031JCQQpK4rmR26rrz sncnRcjqlcn/aNLuhLe4gpkJdGxAwSaAVhujtXACxeo0tMhyIzkskAWEDshjgajbUUoL MbRYqeK7HlPbBOuLGz2L6FtBtVuHO34J9qm0UEcmJkTXsxGQbUKvq+K8PWToMHofCpNG wd+ln/PqR7hEzYAsc9qOup9JfzLBm7EN+RLBDTgA+lb5G0AnXlIjaGZhzAMnW5gxEoKx c/dstabSdqeOY1eOIDthWf6qFk12kiX5Hfz5wlAg5/tyBbYSkbpR6JTqUYSVEBVkWTh3 zOkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=snYrFJ12aUfxHMb2aqbQr58aBrO9I7pzj7+8V1Dw+/A=; b=IRLa6T5phKDY75Ue2kFL3HsXfmDjMMxLrrYBRhMCFR3mUE6iLBXsC6FRok2NaaGgFe PkiKjH0HWX7hvKhjaV6h799WKpVPN9f2hmiiB+wY+5fmxM//kbw1CxVr8fncNi9H6OuM TcPpOJuPoxfgz+GT2RPDzt+o1B9x3xADgjy+uG58rt6pHVtHbVBuZeBlROUoyvS0Z+yA x9m0WZUwr6kwMWqVFRH7LhXKf6XVt98KTawRjQyK3Lc2gb4IYdVAdcW/E3wo3C/Tbq+X tpmLMNfFF3t/IHfCOwMTgB3XmzyoUNmoW3v13HebPa6lOWZ68Bmt16E+bqe1I+CV41WV F9Dg== X-Gm-Message-State: AOAM531B+3jjJjvmFsoaYbYttFDzWmnNr54XnZQoZnbiv0b89VhlFqDv 6Yd9iz4oygsPL4t4saBN29HuGA== X-Google-Smtp-Source: ABdhPJw+yWKxm6iGT9HIPz6Vr8isQ+lpFIiKvyXZgf1R+aoAldml+w5ZXDElVXNYI3y5J0Jnqz5IVA== X-Received: by 2002:a7b:c3c3:: with SMTP id t3mr488729wmj.94.1643231095799; Wed, 26 Jan 2022 13:04:55 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:55 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 6/8] crypto: sun8i-ss: remove redundant test Date: Wed, 26 Jan 2022 21:04:39 +0000 Message-Id: <20220126210441.3661782-7-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Some fallback tests were redundant with what sun8i_ss_hash_need_fallback() already do. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index ef3020bc9547..7ebd11d3ff7d 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -287,21 +287,11 @@ int sun8i_ss_hash_digest(struct ahash_request *areq) struct sun8i_ss_alg_template *algt; struct sun8i_ss_dev *ss; struct crypto_engine *engine; - struct scatterlist *sg; - int nr_sgs, e, i; + int e; if (sun8i_ss_hash_need_fallback(areq)) return sun8i_ss_hash_digest_fb(areq); - nr_sgs = sg_nents(areq->src); - if (nr_sgs > MAX_SG - 1) - return sun8i_ss_hash_digest_fb(areq); - - for_each_sg(areq->src, sg, nr_sgs, i) { - if (sg->length % 4 || !IS_ALIGNED(sg->offset, sizeof(u32))) - return sun8i_ss_hash_digest_fb(areq); - } - algt = container_of(alg, struct sun8i_ss_alg_template, alg.hash); ss = algt->ss; From patchwork Wed Jan 26 21:04:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725809 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 2826AC433FE for ; Wed, 26 Jan 2022 21:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231727AbiAZVFD (ORCPT ); Wed, 26 Jan 2022 16:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbiAZVE6 (ORCPT ); Wed, 26 Jan 2022 16:04:58 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B3B4C061747 for ; Wed, 26 Jan 2022 13:04:58 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso607198wms.4 for ; Wed, 26 Jan 2022 13:04:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XtAZUKhGKHjYfajUS2uXJzGri3eZZgxbF/8hYjHFYEk=; b=OIn3/Ia6hAwycSnr3NZlODzPFqa/EJCMMeZcyRybAseGvz3913KKcmA/H91rkKTGRy PtQfeueRPyx6t8K6t93wVx+PCjkVS9zctVwzIZmUKYQxBwON5aRL824DYiXQ+itVlz2K Sw1cAgV59OhCPBW3P0QBhzyqft1TJ97SB8cwTqkSuNcoznMxv/t6isSSSbHhLDSJR5db d/iXOWT2ggnOB45ZQaTbXpOnPVIJiaeYwWznJHT1C0017g0wS3XHhlGOhyldhd0HhRd+ d01sgB7zQa3DNZMZp279y8Z+JC9O45fW0AYRLyQmW5sgpTSuKCIBqVj5mDDougmxO2K6 P9XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XtAZUKhGKHjYfajUS2uXJzGri3eZZgxbF/8hYjHFYEk=; b=RirqOe5WAwgZZDLRDu2VgQWWXAVLuKdKLPRkxfQ0MoSi6DSHaldBZb9W03zDs3IXKK iSrMUChUlAXFVxAgLmQa2jnanpHOE8KXRU7c4jZYM8Af/Kk/OSqJAGihI79vMF1WRRPp q8Lof+qvCh9hIf5/rbavRmOzSu/S7FzcyTGJNqH4ZctIwELiu/lpqKWCKL8L0eI2tF6J JtDKrHiSnC1/sB8A5uWG7NYSYYRPopZCN2lBOtWpt5bS9GVc9ZD9YjbOWxMPhW9UFZe0 2RweAHx/J/S0m9dIzOzOEly7HRkXzh2Lt8ZYXZRNdT09jxvab1oNrUBqMY7af7gnbCns pKdw== X-Gm-Message-State: AOAM533HJlvo+rVje/zQwg1y5i26HDIHV8xrXcLUOH4yrT1vqUqtNoz6 1WjZX/ZajSBU3tprcgDGqVgcnw== X-Google-Smtp-Source: ABdhPJwtxqNJuhVN5WLIINA4xCkD2h+AHjTXiZNUQMpu9OEiqy41TS1maJtKxXblKqGCfpR2TpM3KA== X-Received: by 2002:a05:600c:281:: with SMTP id 1mr462008wmk.134.1643231096680; Wed, 26 Jan 2022 13:04:56 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:56 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 7/8] crypto: sun8i-ss: test error before assigning Date: Wed, 26 Jan 2022 21:04:40 +0000 Message-Id: <20220126210441.3661782-8-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The first thing we should do after dma_map_single() is to test the result. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index 7ebd11d3ff7d..1aae36d541d8 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -414,15 +414,15 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) } addr_pad = dma_map_single(ss->dev, pad, j * 4, DMA_TO_DEVICE); - rctx->t_src[i].addr = addr_pad; - rctx->t_src[i].len = j; - rctx->t_dst[i].addr = addr_res; - rctx->t_dst[i].len = digestsize / 4; if (dma_mapping_error(ss->dev, addr_pad)) { dev_err(ss->dev, "DMA error on padding SG\n"); err = -EINVAL; goto theend; } + rctx->t_src[i].addr = addr_pad; + rctx->t_src[i].len = j; + rctx->t_dst[i].addr = addr_res; + rctx->t_dst[i].len = digestsize / 4; err = sun8i_ss_run_hash_task(ss, rctx, crypto_tfm_alg_name(areq->base.tfm)); From patchwork Wed Jan 26 21:04:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12725810 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 8F88FC433F5 for ; Wed, 26 Jan 2022 21:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbiAZVFD (ORCPT ); Wed, 26 Jan 2022 16:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbiAZVFC (ORCPT ); Wed, 26 Jan 2022 16:05:02 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1444CC06173B for ; Wed, 26 Jan 2022 13:04:59 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id i187-20020a1c3bc4000000b0034d2ed1be2aso4581406wma.1 for ; Wed, 26 Jan 2022 13:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7wnW9cjljKpRIDwPHBIabEh75SAX6Ok5P1VkPlwmXoE=; b=TNqd45zsvDFw4xElwZBPy2f9it1IFu9BRfjwTsvfLFoaZXD9u+yRtoMV2UkKGWOoOv E1Qny8J9CRjBw6Cr7IKPVs+8bKGAoARjBUGPBLrO4I8/NWz/9Vwcrp+g31DN7ivXkhX3 VmFE5VWzJJoWG/PzasdyB8JX5ivSIxzvHPBmrUKrFWPOAQ1e6FJWVK+RC2La47vVgfQo F81ZQY6vO2sYi5XtdF/yttCK1TlEVY1R0qblahqZ+rBobIA8dW8bV1NwDgDv1BOFqbah /NPcNpNeGS3DiPJCOBK9e1HTOPpKu3rCE5Nqam3arJuVSRp3rZk9qa0JV4veDLoWcdEu wTaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7wnW9cjljKpRIDwPHBIabEh75SAX6Ok5P1VkPlwmXoE=; b=JHIVADQR1oivY2LegO7FnsunHoWK04dOnAzn3qw8xt5kGPcUzb50yCBn3+y5gJLt9Y ekJajN3GfpbI72WIghIWutCYbnYBV8/y6OAo05zmfX5xkDxEIs0FYuac83KVOlDXin0Y GBsr0BUXI1Z29fMMAFdvKUYeK9tuXAXewhDxi3T8SWt3MxG4czOx43VdCbgDf7Y5l2Iz 9PLvpJOz6ex7uJ/4MYBT72edJxkhDyTI78dV/hmNiBHteRJZaQ4pJyKN4dITFaQLCzzE WDHWg7bnADTRgbUSetL7zzPqoQSrhx4jQwXy0VtbZOvH+Q2sIJxGCpRRZeNsneRRXSN9 QcQg== X-Gm-Message-State: AOAM533TO7FPtJhfVrWMm/7NfXjsDg7kkpk5VkWvF80P+tr5ffUTCDxU ibDpeqnn1uPmSslS2sDn07slzIh6aGd8nQ== X-Google-Smtp-Source: ABdhPJwBVnGfoDjyVtqqAIN/rwr6e1id+stGs09Zp6t39Zlb9GsJfHIPx9+9GrF60q+ST5Edgezktg== X-Received: by 2002:a7b:c4c5:: with SMTP id g5mr428047wmk.139.1643231097636; Wed, 26 Jan 2022 13:04:57 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:57 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 8/8] crypto: sun8i-ss: handle requests if last block is not modulo 64 Date: Wed, 26 Jan 2022 21:04:41 +0000 Message-Id: <20220126210441.3661782-9-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The current sun8i-ss handle only requests with all SG length being modulo 64. But the last SG could be always handled by copying it on the pad buffer. Signed-off-by: Corentin Labbe --- .../crypto/allwinner/sun8i-ss/sun8i-ss-core.c | 2 +- .../crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 35 ++++++++++++++----- drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h | 2 ++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c index 084261d7899c..c8c079f3b466 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c @@ -475,7 +475,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss) init_completion(&ss->flows[i].complete); /* the padding could be up to two block. */ - ss->flows[i].pad = devm_kmalloc(ss->dev, SHA256_BLOCK_SIZE * 2, + ss->flows[i].pad = devm_kmalloc(ss->dev, MAX_PAD_SIZE, GFP_KERNEL | GFP_DMA); if (!ss->flows[i].pad) goto error_engine; diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c index 1aae36d541d8..dd5e4f0fd5ab 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -261,6 +262,9 @@ static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq) if (areq->nbytes == 0) return true; + if (areq->nbytes >= MAX_PAD_SIZE - 64) + return true; + /* we need to reserve one SG for the padding one */ if (sg_nents(areq->src) > MAX_SG - 1) return true; @@ -269,10 +273,13 @@ static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq) /* SS can operate hash only on full block size * since SS support only MD5,sha1,sha224 and sha256, blocksize * is always 64 - * TODO: handle request if last SG is not len%64 - * but this will need to copy data on a new SG of size=64 */ - if (sg->length % 64 || !IS_ALIGNED(sg->offset, sizeof(u32))) + /* Only the last block could be bounced to the pad buffer */ + if (sg->length % 64 && sg_next(sg)) + return true; + if (!IS_ALIGNED(sg->offset, sizeof(u32))) + return true; + if (sg->length % 4) return true; sg = sg_next(sg); } @@ -360,6 +367,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) goto theend; } + j = 0; len = areq->nbytes; sg = areq->src; i = 0; @@ -368,12 +376,19 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) sg = sg_next(sg); continue; } - rctx->t_src[i].addr = sg_dma_address(sg); todo = min(len, sg_dma_len(sg)); - rctx->t_src[i].len = todo / 4; - len -= todo; - rctx->t_dst[i].addr = addr_res; - rctx->t_dst[i].len = digestsize / 4; + /* only the last SG could be with a size not modulo64 */ + if (todo % 64 == 0) { + rctx->t_src[i].addr = sg_dma_address(sg); + rctx->t_src[i].len = todo / 4; + rctx->t_dst[i].addr = addr_res; + rctx->t_dst[i].len = digestsize / 4; + len -= todo; + } else { + scatterwalk_map_and_copy(bf, sg, 0, todo, 0); + j += todo / 4; + len -= todo; + } sg = sg_next(sg); i++; } @@ -383,8 +398,10 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) goto theend; } + if (j > 0) + i--; + byte_count = areq->nbytes; - j = 0; bf[j++] = cpu_to_le32(0x80); fill = 64 - (byte_count % 64); diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h index f9f089ede934..8c9649bab88c 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h @@ -82,6 +82,8 @@ #define PRNG_DATA_SIZE (160 / 8) #define PRNG_SEED_SIZE DIV_ROUND_UP(175, 8) +#define MAX_PAD_SIZE 4096 + /* * struct ss_clock - Describe clocks used by sun8i-ss * @name: Name of clock needed by this variant