From patchwork Wed Jan 22 10:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11345495 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FB87139A for ; Wed, 22 Jan 2020 10:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E3ED205F4 for ; Wed, 22 Jan 2020 10:45:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zp1qs90x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729702AbgAVKpv (ORCPT ); Wed, 22 Jan 2020 05:45:51 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52820 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729680AbgAVKpu (ORCPT ); Wed, 22 Jan 2020 05:45:50 -0500 Received: by mail-wm1-f65.google.com with SMTP id p9so6287953wmc.2; Wed, 22 Jan 2020 02:45:48 -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=TI5Ket0oHU3CmX2xCQ1OoRU2M4/444tV0dOG88eOBg8=; b=Zp1qs90xTXdiRybMjYcTvKqYxCWpCdg02mmS0TSWLyDMNna1QZMWESJcD3xB7lcFAP 7/CGaMzcraJzWYIN83GmyC5m9wThpSRZC8qBDsfoRfxHR5ActzM672CihcrRk1VJ8ko5 UyU9lLi5NDFuEEus/xUtWZvH8is1HCJuQ4h5uaq9DxLX5qSzzkHBp6CeuFarp/wWeNOc g1D2GxdJBA8cX6sgqqK7psF2/yKQZpHFX7bkTSSNs2y0EMN0XmOtGl8PRU7oZD7TAZ6L tCVsKMT0Z/WCUxM0TFD9T4oMfstim/yspJlSqP8SBrhDKGLrzq2QP6wchVgETdO+0QMR BUpw== 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=TI5Ket0oHU3CmX2xCQ1OoRU2M4/444tV0dOG88eOBg8=; b=G6CdaqVhFtZrT1zMRiSN0f0EHjo05RS5HIQYGXIHPTtfskk6JtvrhCvq4Jqnw+NZu/ CZJ8iHlo9f6I7nmVOlQ96PTAcIAyliy4/hJYlLpGg+LPxGLicLezYzD96NGT/QRoT6EQ adE3TK6W/sAwHv+zjCJrcZV0c2NT4J9lbormTIKVd6/TGI2W104QwRZL+gMZ9WVGIIHK 8wiFuV/Jk3zbArq4WkFsHsY+ZgtarTBCBP9nm6Jld0pgtmefG6Ox6xyrEBlXnpSUdLAd exRwN2zT6FojVQfu5OAhl+xrGThxwk8lbAGWb4OVGKFWovM132zE+uxA61mkkZc4MfZG 1AEA== X-Gm-Message-State: APjAAAVN/zfEhF64Ik7O4OIGhKRyXXItj5mQA3T884P7camMgPV1psr7 rzto3nvq6m8T12MXhrBoIrg= X-Google-Smtp-Source: APXvYqxMJM+x11aOz5TYgEFK0SMpVcyst9jWiL6qC6T47vNDGao8DcuesTOhT2OY3IbIMvVUV6eLDw== X-Received: by 2002:a05:600c:2215:: with SMTP id z21mr2316858wml.55.1579689948285; Wed, 22 Jan 2020 02:45:48 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:3d5:a100:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id n3sm3443953wmc.27.2020.01.22.02.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:45:46 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com 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 6/9] crypto: sun8i-ce: move iv data to request context Date: Wed, 22 Jan 2020 11:45:25 +0100 Message-Id: <20200122104528.30084-7-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122104528.30084-1-clabbe.montjoie@gmail.com> References: <20200122104528.30084-1-clabbe.montjoie@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 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 a5fd8975f3d3..7fd19667bceb 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -91,7 +91,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; @@ -154,24 +153,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)) { @@ -252,17 +251,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); - kzfree(backup_iv); + memcpy(areq->iv, rctx->backup_iv, ivsize); + kzfree(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 8f8404c84a4d..49507ef2ec63 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,10 +179,16 @@ 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 a copy of IV + * @ivlen: size of bounce_iv */ struct sun8i_cipher_req_ctx { u32 op_dir; int flow; + void *backup_iv; + void *bounce_iv; + unsigned int ivlen; }; /*