2004-06-04 23:24:19

by James Morris

[permalink] [raw]
Subject: Re: Crypto digests and kmapping sg entries larger than a page, with [PATCH]

On Fri, 4 Jun 2004, Clay Haapala wrote:

> He supplies a patch, below.
>
> If you agree with the implementation, I'll re-diff and test against a
> recent BitKeeper extract and submit a patch.

Thanks, please do so.


- James
--
James Morris
<[email protected]>


2004-06-07 20:43:40

by Clay Haapala

[permalink] [raw]
Subject: [PATCH] Fix Crypto digest.c kmapping sg entries > page in length

Below is the patch, against 2.6.7-rc2, to fix crypto/digest.c to do
multiple kmap()/kunmap() for scatterlist entries which have a size
greater than a single page, originally found and fixed by
N.C.Krishna Murthy <[email protected]>.
--
Clay Haapala ([email protected]) Cisco Systems SRBU +1 763-398-1056
6450 Wedgwood Rd, Suite 130 Maple Grove MN 55311 PGP: C89240AD
"We're serious about this campaign now! The training wheels are coming off!"
- a high White Horse Souse

Signed-off-by: Clay Haapala <[email protected]>

diff -uNr --exclude=SCCS --exclude '*.mod.c' --exclude='*.o' --exclude='*.ko' --exclude '.*' linux-2.6.6-bk.orig/crypto/digest.c linux-2.6.6-bk/crypto/digest.c
--- linux-2.6.6-bk.orig/crypto/digest.c 2004-06-07 10:58:36.000000000 -0500
+++ linux-2.6.6-bk/crypto/digest.c 2004-06-07 15:21:05.000000000 -0500
@@ -27,13 +27,28 @@
struct scatterlist *sg, unsigned int nsg)
{
unsigned int i;
-
+
for (i = 0; i < nsg; i++) {
- char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
- tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
- p, sg[i].length);
- crypto_kunmap(p, 0);
- crypto_yield(tfm);
+
+ struct page *pg = sg[i].page;
+ unsigned int offset = sg[i].offset;
+ unsigned int l = sg[i].length;
+
+ do {
+ unsigned int bytes_from_page = min(l, ((unsigned int)
+ (PAGE_SIZE)) -
+ offset);
+ char *p = crypto_kmap(pg, 0) + offset;
+
+ tfm->__crt_alg->cra_digest.dia_update
+ (crypto_tfm_ctx(tfm), p,
+ bytes_from_page);
+ crypto_kunmap(p, 0);
+ crypto_yield(tfm);
+ offset = 0;
+ pg++;
+ l -= bytes_from_page;
+ } while (l > 0);
}
}


2004-06-11 05:01:38

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] Fix Crypto digest.c kmapping sg entries > page in length

On Mon, 07 Jun 2004 15:43:27 -0500
Clay Haapala <[email protected]> wrote:

> Below is the patch, against 2.6.7-rc2, to fix crypto/digest.c to do
> multiple kmap()/kunmap() for scatterlist entries which have a size
> greater than a single page, originally found and fixed by
> N.C.Krishna Murthy <[email protected]>.

Applied, thanks a lot Clay.