crypto: algif - Mark sgl end at the end of data.
PATCH 1/1 crypto: algif - Mark sgl end at the end of data.
Hi,algif_skcipher sends 127 sgl buffers for encryption regardless of how many buffers acctually have data to process, where the few first with valid len and the rest with zero len. This is not very eficient and may cause problems when algs do something like this without checking the buff lenght:for_each_sg(sgl, sg, sg_nents, i)
sg_virt(sg)
This patch marks the last one with data as the last one to process. Also removed some unneeded code.
--- crypto/algif_skcipher.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
crypto/algif_skcipher.c +1 -5
@@ -359,8 +359,6 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock, err =0 ; ctx->more = msg->msg_flags &MSG_MORE ; -if (!ctx->more && !list_empty (&ctx->tsgl)) - sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list); unlock:skcipher_data_wakeup (sk);
@@ -408,9 +406,6 @@ static ssize_t skcipher_sendpage(struct socket *sock, struct page *page, done: ctx->more = flags &MSG_MORE ; -if (!ctx->more && !list_empty (&ctx->tsgl)) - sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list); - unlock:skcipher_data_wakeup (sk);release_sock (sk);
@@ -469,6 +464,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,if (!used) goto free; +sg_mark_end (&sg[sgl->cur -1 ]);ablkcipher_request_set_crypt (&ctx->req, sg, ctx->rsgl.sg, used, ctx->iv);
Herbert Xu
maintainerQuoted 15 lines · Tadeusz Struk
crypto/algif_skcipher.c +0
-2@@ -359,8 +359,6 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock, err =0 ; ctx->more = msg->msg_flags &MSG_MORE ; -if (!ctx->more && !list_empty (&ctx->tsgl)) - sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list); unlock:skcipher_data_wakeup (sk);
crypto/algif_skcipher.c static ssize_t skcipher_sendpage(struct socket *sock, struct page *page, · line 411
Quoted 9 lines
crypto/algif_skcipher.c +0
-3@@ -408,9 +406,6 @@ static ssize_t skcipher_sendpage(struct socket *sock, struct page *page, done: ctx->more = flags &MSG_MORE ; -if (!ctx->more && !list_empty (&ctx->tsgl)) - sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list); - unlock:skcipher_data_wakeup (sk);release_sock (sk);
Please put these clean-ups in a separate patch.
crypto/algif_skcipher.c static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock, · line 467
Quoted 5 lines
crypto/algif_skcipher.c +1
-0@@ -469,6 +464,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,if (!used) goto free; +sg_mark_end (&sg[sgl->cur -1 ]);
I don't think this will work as if we only partially use up the SGs and MSG_MORE is set then bad things will happen to the next send call on the socket.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Hi Herbert,
Quoted 1 line · Herbert Xu
Please put these clean-ups in a separate patch.
Ok, will do.
Quoted 9 lines
Quoted 6 lines
crypto/algif_skcipher.c static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock, · line 467
Quoted 6 lines
crypto/algif_skcipher.c +1
-0@@ -469,6 +464,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,if (!used) goto free; +sg_mark_end (&sg[sgl->cur -1 ]);I don't think this will work as if we only partially use up the SGs and
MSG_MOREis set then bad things will happen to the next send call on the socket.
Yes, I see now. I assumed that the user would want to read the same len that was first sent and thus the skcipher_pull_sgl() would clean the whole ctx->tsgl and then skcipher_alloc_sgl() would create a new one. I'll see if something else can be done to mark the end of data. Thanks,
Tadeusz