[5/5,CRYPTO] Optimise kmap calls in crypt()
diff mbox series

Message ID 20050321095322.GE23235@gondor.apana.org.au
State New, archived
Headers show
Series
  • Speed up crypt()
Related show

Commit Message

Herbert Xu March 21, 2005, 9:53 a.m. UTC
Hi:
 
Perform kmap once (or twice if the buffer is not aligned correctly)
per page in crypt() instead of the current code which does it once
per block.  Consequently it will yield once per page instead of once
per block.

Cheers,

Comments

Clemens Fruhwirth March 21, 2005, 11:30 a.m. UTC | #1
On Mon, 2005-03-21 at 20:53 +1100, Herbert Xu wrote:

> Perform kmap once (or twice if the buffer is not aligned correctly)
> per page in crypt() instead of the current code which does it once
> per block.  Consequently it will yield once per page instead of once
> per block.

Thanks for your work, Herbert. 

Applying all patches results in a "does not work for me". The decryption
result is different from the original and my LUKS managed partition
refuses to mount.

I assume you have a test environment already setup, so I would suggest
to find out up to which patch the following test succeeds (should be
paste-able)

cd /tmp
dd if=/dev/zero of=test-crypt count=100
losetup /dev/loop5 /tmp/test-crypt
echo 0 100 crypt aes-plain 0123456789abcdef0123456789abcdef 0 /dev/loop5 0 | dmsetup create test-map
sha1sum /dev/mapper/test-map

Result:
368d017dbdb4299ed7f27d3fc815442f7e438865  /dev/mapper/test-map

Cheers,
Herbert Xu March 22, 2005, 1:13 a.m. UTC | #2
On Mon, Mar 21, 2005 at 12:30:59PM +0100, Fruhwirth Clemens wrote:
> 
> Applying all patches results in a "does not work for me". The decryption
> result is different from the original and my LUKS managed partition
> refuses to mount.

Thanks for testing this Fruhwirth.  The problem is that walk->data wasn't
being incremented anymore after my last change.  This patch should fix it
up.

Cheers,
Clemens Fruhwirth March 22, 2005, 10:24 a.m. UTC | #3
On Tue, 2005-03-22 at 12:13 +1100, Herbert Xu wrote:
> On Mon, Mar 21, 2005 at 12:30:59PM +0100, Fruhwirth Clemens wrote:
> > 
> > Applying all patches results in a "does not work for me". The decryption
> > result is different from the original and my LUKS managed partition
> > refuses to mount.
> 
> Thanks for testing this Fruhwirth.  The problem is that walk->data wasn't
> being incremented anymore after my last change.  

I remember, that I almost forgot about that pointer too.

> This patch should fix it up.

Works for me now. Thanks.

Patch
diff mbox series

diff -Nru a/crypto/cipher.c b/crypto/cipher.c
--- a/crypto/cipher.c	2005-03-21 18:44:41 +11:00
+++ b/crypto/cipher.c	2005-03-21 18:44:41 +11:00
@@ -117,17 +117,21 @@ 
 
 		in_place = scatterwalk_samebuf(&walk_in, &walk_out);
 
-		src_p = prepare_src(&walk_in, bsize, tmp_src, in_place);
-		dst_p = prepare_dst(&walk_out, bsize, tmp_dst, in_place);
+		do {
+			src_p = prepare_src(&walk_in, bsize, tmp_src,
+					    in_place);
+			dst_p = prepare_dst(&walk_out, bsize, tmp_dst,
+					    in_place);
 
-		nbytes -= bsize;
+			prfn(tfm, dst_p, src_p, crfn, enc, info);
 
-		prfn(tfm, dst_p, src_p, crfn, enc, info);
+			complete_src(&walk_in, bsize, src_p, in_place);
+			complete_dst(&walk_out, bsize, dst_p, in_place);
 
-		complete_src(&walk_in, bsize, src_p, in_place);
-		scatterwalk_done(&walk_in, 0, nbytes);
+			nbytes -= bsize;
+		} while (nbytes && !scatterwalk_across_pages(&walk_in, bsize));
 
-		complete_dst(&walk_out, bsize, dst_p, in_place);
+		scatterwalk_done(&walk_in, 0, nbytes);
 		scatterwalk_done(&walk_out, 1, nbytes);
 
 		if (!nbytes)