Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1231460pxk; Fri, 4 Sep 2020 04:24:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMdB6o0ZiZURXO1rOrAe0C1RmpMSgWnbiHabAMxeFN/6NE1VRwhwwpHZUV9Dctavr73Pu6 X-Received: by 2002:a17:906:c10c:: with SMTP id do12mr6696996ejc.92.1599218642370; Fri, 04 Sep 2020 04:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599218642; cv=none; d=google.com; s=arc-20160816; b=Z2nweKW1eld7+XjTsgQOSx+3UbaAvGd/HqIL76MYD5zXlg9KtaJRSllRHjawum1UcK pA3wrC5yJbv74qA1ZdCZskrmsQRnEDlpYNsxg9ovwITU9yr/vIm60LHAqL3RgEYJ8c7u uQWgEF41txF9TTjoJogFUyHOor7h6lPVZ+2I0ekNDbgWUTA0PdKSvfhnG3jpbg9IPPDE 7/2zL19OoQKOJSJ7T0Alplvd5yAOjjEhDVEkoOYrlcG6rlE36UH0dvfy0PrlgXuD9II5 w+ACEuukMFqHiA1FKvY+cUID19CqVzIRlK4BaypdT3cvCsgZr0cyAx+UDuzriwk4HrLO xbqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=rIUFQhQ64oF2ROvS3z6Ch/i8dVROC3dNchz1WEDXahs=; b=OX4BGAMS2eohgch2E0IBA70i9hX/BQe7lksK2hGyDxGRawkTcYAfQg7g2B2tSLE1PX KylBd81CguCv+pEa7k4mQtKvEw1aKOLV5OU9faXypXf8mwopsaY9dBkTt/RJxyIgyoU1 OB9V4Z1rlnpt2n3iygiLu9yrP/xJ508qQ8tsOaJ5kq3bHmyD6yX9B645/TypAWF0QpCn Z3wJeI7XJjLzQan+27URat2O1nYAG7FxqazTp2Md/nH1DNI9QOzdbtviRz912PV4IoMQ yW+LxA30Ek+d8FLLv/LGKjVwHF/aH0tNuOVJ0rYPGHYantqk8LVfyJgY5m+isYh9Oere sgcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=0sIGOVJX; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si3712747eja.658.2020.09.04.04.23.37; Fri, 04 Sep 2020 04:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=0sIGOVJX; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729954AbgIDLW4 (ORCPT + 99 others); Fri, 4 Sep 2020 07:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbgIDLKW (ORCPT ); Fri, 4 Sep 2020 07:10:22 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA11BC061263 for ; Fri, 4 Sep 2020 04:10:20 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id w2so5715831wmi.1 for ; Fri, 04 Sep 2020 04:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rIUFQhQ64oF2ROvS3z6Ch/i8dVROC3dNchz1WEDXahs=; b=0sIGOVJXEsr89QEmWtEuiX110YPalPawiLKbMfjhFUDKDhw2dkPEUkFcAj/sVth/Tz pVrevWj8xRJeSVAFTgy/PFqbeTkdpf9DhwYMLpDljhtjvKDL4m/o496SW2Pw5KjcvNmW Bwy3NJKM9MYsQOxOez9Yzdys4KccS6h8tEhj8uXN5H3s9lt/uIyp6L7ALsnxGR8WsU9d XtywOiYF+5/vmrDOZsKFODUJ66ZW6JiC8qdh6lkwn88WNZGrZXD9mxfyGJeDxUomonDK vULkqFgtncaiIiMhxNO/JCZn93enjet9MchRCwcsQNej9nk8C0BOH7uwSjpc4Ryhj9MA ZrDQ== 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; bh=rIUFQhQ64oF2ROvS3z6Ch/i8dVROC3dNchz1WEDXahs=; b=FIUeOJjTlOhxqqSVOsw/7Dg/X+vjy+EHufDDEK2uc0bNuWfS3kNc4G1NnkSaOSngK7 +rcCFmOFddK3RmreSl+7yHlYeBc13rpw5BZmbUjAfK3jqhgfTLPelg/cG6vYrHYWYL0G JIXvLCJrISAYmM5GL2gP/8qUsjF+NdKt3qjeHrOWyaJEGU2E1v5VmKgmnL3HSN+X8JKm kBk4G1pejoRxFxS2pcTLHttuuGdL6tbhGwEyAUo6Y7o7uUOmyUvgYnT7qdIU8PEMMGqE fUnvAtFJ/V/cQ+8ebO3KXe1WUK8/A+5UoLJ60BXuQdL53lZu2Jt5prJfS6i5fahJwyH0 kDkw== X-Gm-Message-State: AOAM530nP4ZT1zfoQ5dcCUQj5F/nkKRywIGYl+rjKBV8IZUVgE0MZgSN kcGONOqapQu9NcrafzHRKcCFyA== X-Received: by 2002:a7b:c753:: with SMTP id w19mr6905677wmk.157.1599217819570; Fri, 04 Sep 2020 04:10:19 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id m3sm10622743wmb.26.2020.09.04.04.10.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Sep 2020 04:10:18 -0700 (PDT) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, 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@googlegroups.com, Corentin Labbe Subject: [PATCH v6 08/18] crypto: sun8i-ce: move iv data to request context Date: Fri, 4 Sep 2020 11:09:53 +0000 Message-Id: <1599217803-29755-9-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599217803-29755-1-git-send-email-clabbe@baylibre.com> References: <1599217803-29755-1-git-send-email-clabbe@baylibre.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of storing IV data in the channel context, store them in the request context. Storing them in the channel structure was conceptualy wrong since they are per request related. Signed-off-by: Corentin Labbe --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 27 +++++++++---------- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 10 ++++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index b4d5fea27d20..2252604d821b 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -88,7 +88,6 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) struct scatterlist *sg; unsigned int todo, len, offset, ivsize; dma_addr_t addr_iv = 0, addr_key = 0; - void *backup_iv = NULL; u32 common, sym; int flow, i; int nr_sgs = 0; @@ -151,24 +150,24 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) ivsize = crypto_skcipher_ivsize(tfm); if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) { - chan->ivlen = ivsize; - chan->bounce_iv = kzalloc(ivsize, GFP_KERNEL | GFP_DMA); - if (!chan->bounce_iv) { + 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) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) { + rctx->backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!rctx->backup_iv) { err = -ENOMEM; goto theend_key; } offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(backup_iv, areq->src, offset, - ivsize, 0); + scatterwalk_map_and_copy(rctx->backup_iv, areq->src, + offset, ivsize, 0); } - memcpy(chan->bounce_iv, areq->iv, ivsize); - addr_iv = dma_map_single(ce->dev, chan->bounce_iv, chan->ivlen, + memcpy(rctx->bounce_iv, areq->iv, ivsize); + addr_iv = dma_map_single(ce->dev, rctx->bounce_iv, rctx->ivlen, DMA_TO_DEVICE); cet->t_iv = cpu_to_le32(addr_iv); if (dma_mapping_error(ce->dev, addr_iv)) { @@ -249,17 +248,17 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) theend_iv: if (areq->iv && ivsize > 0) { if (addr_iv) - dma_unmap_single(ce->dev, addr_iv, chan->ivlen, + dma_unmap_single(ce->dev, addr_iv, rctx->ivlen, DMA_TO_DEVICE); offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kfree_sensitive(backup_iv); + memcpy(areq->iv, rctx->backup_iv, ivsize); + kfree_sensitive(rctx->backup_iv); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - kfree(chan->bounce_iv); + kfree(rctx->bounce_iv); } theend_key: diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 963645fe4adb..f5555c4800e8 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -129,8 +129,6 @@ struct ce_task { /* * struct sun8i_ce_flow - Information used by each flow * @engine: ptr to the crypto_engine for this flow - * @bounce_iv: buffer which contain the IV - * @ivlen: size of bounce_iv * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done * @t_phy: Physical address of task @@ -139,8 +137,6 @@ struct ce_task { */ struct sun8i_ce_flow { struct crypto_engine *engine; - void *bounce_iv; - unsigned int ivlen; struct completion complete; int status; dma_addr_t t_phy; @@ -183,11 +179,17 @@ 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 * @fallback_req: request struct for invoking the fallback skcipher TFM */ struct sun8i_cipher_req_ctx { u32 op_dir; int flow; + void *backup_iv; + void *bounce_iv; + unsigned int ivlen; struct skcipher_request fallback_req; // keep at the end }; -- 2.26.2