mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia Jie Ho <jiajie.ho@starfivetech.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access
Date: Mon, 29 Apr 2024 14:06:40 +0800	[thread overview]
Message-ID: <20240429060640.2451685-5-jiajie.ho@starfivetech.com> (raw)
In-Reply-To: <20240429060640.2451685-1-jiajie.ho@starfivetech.com>

Dma address mapping fails on unaligned scatterlist offset. Use sw
fallback for these cases.

Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
 drivers/crypto/starfive/jh7110-aes.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 9d6e2f936f03..86a1a1fa9f8f 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -314,7 +314,7 @@ static int starfive_aes_read_authtag(struct starfive_cryp_ctx *ctx)
 					 cryp->total_in, cryp->authsize, 1);
 	} else {
 		if (crypto_memneq(cryp->tag_in, cryp->tag_out, cryp->authsize))
-			return dev_err_probe(cryp->dev, -EBADMSG, "Failed tag verification\n");
+			return -EBADMSG;
 	}
 
 	return 0;
@@ -753,14 +753,16 @@ static bool starfive_aes_check_unaligned(struct starfive_cryp_dev *cryp,
 	int i;
 
 	for_each_sg(src, tsg, sg_nents(src), i)
-		if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
-		    !sg_is_last(tsg))
+		if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+		    (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+		     !sg_is_last(tsg)))
 			return true;
 
 	if (src != dst)
 		for_each_sg(dst, tsg, sg_nents(dst), i)
-			if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
-			    !sg_is_last(tsg))
+			if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+			    (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+			     !sg_is_last(tsg)))
 				return true;
 
 	return false;
-- 
2.40.1


  parent reply	other threads:[~2024-04-29  6:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29  6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
2024-04-29  6:06 ` [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message Jia Jie Ho
2024-04-29  6:06 ` [PATCH -next 2/4] crypto: starfive: Skip unneeded fallback allocation Jia Jie Ho
2024-04-29  6:06 ` [PATCH -next 3/4] crypto: starfive: Do not free stack buffer Jia Jie Ho
2024-04-29  6:06 ` Jia Jie Ho [this message]
2024-05-10  9:18 ` [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA 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=20240429060640.2451685-5-jiajie.ho@starfivetech.com \
    --to=jiajie.ho@starfivetech.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®