linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corentin Labbe <clabbe@baylibre.com>
To: herbert@gondor.apana.org.au, jernej.skrabec@gmail.com,
	samuel@sholland.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, Corentin Labbe <clabbe@baylibre.com>
Subject: [PATCH v2 08/19] crypto: sun8i-ss: use sg_nents_for_len
Date: Mon,  2 May 2022 20:19:18 +0000	[thread overview]
Message-ID: <20220502201929.843194-9-clabbe@baylibre.com> (raw)
In-Reply-To: <20220502201929.843194-1-clabbe@baylibre.com>

When testing with some large SG list, the sun8i-ss drivers always
fallback even if it can handle it.
So use sg_nents_for_len() which permits to see less SGs than needed.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
 .../allwinner/sun8i-ss/sun8i-ss-cipher.c      | 23 ++++++++-----------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
index 70e2e6e37389..c4cb1ab1eeaa 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
@@ -29,7 +29,8 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
 	if (areq->cryptlen == 0 || areq->cryptlen % 16)
 		return true;
 
-	if (sg_nents(areq->src) > 8 || sg_nents(areq->dst) > 8)
+	if (sg_nents_for_len(areq->src, areq->cryptlen) > 8 ||
+		sg_nents_for_len(areq->dst, areq->cryptlen) > 8)
 		return true;
 
 	sg = areq->src;
@@ -169,6 +170,8 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
 	int nr_sgs = 0;
 	int nr_sgd = 0;
 	int err = 0;
+	int nsgs = sg_nents_for_len(areq->src, areq->cryptlen);
+	int nsgd = sg_nents_for_len(areq->dst, areq->cryptlen);
 	int i;
 
 	algt = container_of(alg, struct sun8i_ss_alg_template, alg.skcipher);
@@ -201,8 +204,7 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
 			goto theend_key;
 	}
 	if (areq->src == areq->dst) {
-		nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src),
-				    DMA_BIDIRECTIONAL);
+		nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_BIDIRECTIONAL);
 		if (nr_sgs <= 0 || nr_sgs > 8) {
 			dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
@@ -210,15 +212,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
 		}
 		nr_sgd = nr_sgs;
 	} else {
-		nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src),
-				    DMA_TO_DEVICE);
+		nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
 		if (nr_sgs <= 0 || nr_sgs > 8) {
 			dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend_iv;
 		}
-		nr_sgd = dma_map_sg(ss->dev, areq->dst, sg_nents(areq->dst),
-				    DMA_FROM_DEVICE);
+		nr_sgd = dma_map_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
 		if (nr_sgd <= 0 || nr_sgd > 8) {
 			dev_err(ss->dev, "Invalid sg number %d\n", nr_sgd);
 			err = -EINVAL;
@@ -274,13 +274,10 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
 
 theend_sgs:
 	if (areq->src == areq->dst) {
-		dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src),
-			     DMA_BIDIRECTIONAL);
+		dma_unmap_sg(ss->dev, areq->src, nsgs, DMA_BIDIRECTIONAL);
 	} else {
-		dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src),
-			     DMA_TO_DEVICE);
-		dma_unmap_sg(ss->dev, areq->dst, sg_nents(areq->dst),
-			     DMA_FROM_DEVICE);
+		dma_unmap_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
+		dma_unmap_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
 	}
 
 theend_iv:
-- 
2.35.1


  parent reply	other threads:[~2022-05-02 20:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 20:19 [PATCH v2 00/19] crypto: allwinner: lots of fixes Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 01/19] crypto: sun8i-ce: Fix minor style issue Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 02/19] crypto: sun8i-ce: do not allocate memory when handling requests Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 03/19] crypto: sun4i-ss: do not allocate backup IV on requests Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 04/19] crypto: sun8i-ss: rework handling of IV Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 05/19] crypto: sun8i-ss: handle zero sized sg Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 06/19] crypto: sun8i-ss: remove redundant test Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 07/19] crypto: sun8i-ss: test error before assigning Corentin Labbe
2022-05-02 20:19 ` Corentin Labbe [this message]
2022-05-02 20:19 ` [PATCH v2 09/19] crypto: sun8i-ss: do not allocate memory when handling hash requests Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 10/19] crypto: sun8i-ss: do not zeroize all pad Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 11/19] crypto: sun8i-ss: handle requests if last block is not modulo 64 Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 12/19] crypto: sun8i-ss: rework debugging Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 13/19] crypto: sun8i-ss: Add function for handling hash padding Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 14/19] crypto: sun8i-ss: add hmac(sha1) Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 15/19] crypto: sun8i-ss: do not fallback if cryptlen is less than sg length Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 16/19] crypto: sun8i-ce: Add function for handling hash padding Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 17/19] crypto: sun8i-ce: use sg_nents_for_len Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 18/19] crypto: sun8i-ce: rework debugging Corentin Labbe
2022-05-02 20:19 ` [PATCH v2 19/19] crypto: sun8i-ce: do not fallback if cryptlen is less than sg length Corentin Labbe
2022-05-13  9:34 ` [PATCH v2 00/19] crypto: allwinner: lots of fixes Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220502201929.843194-9-clabbe@baylibre.com \
    --to=clabbe@baylibre.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).