From: Herbert Xu <herbert@gondor.apana.org.au>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [v2 PATCH] crypto: scatterwalk - Add memcpy_sglist
Date: Thu, 6 Mar 2025 11:20:25 +0800 [thread overview]
Message-ID: <Z8kUeU_SCFHU07-h@gondor.apana.org.au> (raw)
In-Reply-To: <20250306031359.GC1592@sol.localdomain>
On Wed, Mar 05, 2025 at 07:13:59PM -0800, Eric Biggers wrote:
>
> Local kmaps must be released in reverse order of the mapping, so
> scatterwalk_done_dst() must be done before scatterwalk_done_src() above.
Good catch. Thanks for the review!
---8<---
Add memcpy_sglist which copies one SG list to another.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/scatterwalk.c | 27 +++++++++++++++++++++++++++
include/crypto/scatterwalk.h | 3 +++
2 files changed, 30 insertions(+)
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index 20a28c6d94da..e57ce08e0d8d 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -86,6 +86,33 @@ void memcpy_to_sglist(struct scatterlist *sg, unsigned int start,
}
EXPORT_SYMBOL_GPL(memcpy_to_sglist);
+void memcpy_sglist(struct scatterlist *dst, struct scatterlist *src,
+ unsigned int nbytes)
+{
+ struct scatter_walk swalk;
+ struct scatter_walk dwalk;
+
+ if (unlikely(nbytes == 0)) /* in case sg == NULL */
+ return;
+
+ scatterwalk_start(&swalk, src);
+ scatterwalk_start(&dwalk, dst);
+
+ do {
+ unsigned int slen, dlen;
+ unsigned int len;
+
+ slen = scatterwalk_next(&swalk, nbytes);
+ dlen = scatterwalk_next(&dwalk, nbytes);
+ len = min(slen, dlen);
+ memcpy(dwalk.addr, swalk.addr, len);
+ scatterwalk_done_src(&swalk, len);
+ scatterwalk_done_dst(&dwalk, len);
+ nbytes -= len;
+ } while (nbytes);
+}
+EXPORT_SYMBOL_GPL(memcpy_sglist);
+
struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2],
struct scatterlist *src,
unsigned int len)
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 40c3c629e27f..1201543295f9 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -208,6 +208,9 @@ void memcpy_from_sglist(void *buf, struct scatterlist *sg,
void memcpy_to_sglist(struct scatterlist *sg, unsigned int start,
const void *buf, unsigned int nbytes);
+void memcpy_sglist(struct scatterlist *dst, struct scatterlist *src,
+ unsigned int nbytes);
+
/* In new code, please use memcpy_{from,to}_sglist() directly instead. */
static inline void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
unsigned int start,
--
2.39.5
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2025-03-06 3:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 3:03 [PATCH] crypto: scatterwalk - Add memcpy_sglist Herbert Xu
2025-03-06 3:13 ` Eric Biggers
2025-03-06 3:20 ` Herbert Xu [this message]
2025-03-06 3:33 ` [v3 PATCH] " Herbert Xu
2025-03-07 4:22 ` kernel test robot
2025-03-07 4:22 ` kernel test robot
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=Z8kUeU_SCFHU07-h@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=ebiggers@kernel.org \
--cc=linux-crypto@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