crypto: algif - change algif_skcipher to be asynchronous
Subsystems (3)
PATCH 1/1 crypto: algif - change algif_skcipher to be asynchronous
The way the algif_skcipher works currently is that on sendmsg/sendpage it builds an sgl for the input data and then on read/recvmsg it sends the job for encryption putting the user to sleep till the data is processed. This way it can only handle one job at a given time.
This patch changes it to be asynchronous.
The idea is to allow enqueue multiple jobs to get most of available crypto HW accelerators and then read when the data is processed without blocking. To allow that both the input and output sgl need to be know at sendmsg/sendpage or the operation needs to happen "in place" in the input sgl. The approach here is to use the "in place" operation and process the data in the sgl provided in sendmsg. To allow that new user visible flags are introduced:ALG_SET_OP_TYPEALG_OP_OUTOF_PLACEALG_OP_IN_PLACE
By default the operation type is ALG_OP_OUTOF_PLACE, which works the same way as without the change and allows existing application working without any update.
Using the test application from https://lkml.org/lkml/2011/8/28/87 with small modification to support in place operation, and reading after every 16th sendmsg these are the results:
# time ./crypto_user_test doing zero copy out of place
real 0m18.161s
user 0m0.253s
sys 0m5.356s
# time ./crypto_user_test inplace doing zero copy in place
real 0m4.808s
user 0m0.132s
sys 0m2.937s
--- crypto/af_alg.c | 6 + crypto/algif_skcipher.c | 284 ++++++++++++++++++++++++++++++++++++++++++- include/crypto/if_alg.h | 1 include/uapi/linux/if_alg.h | 9 + 4 files changed, 290 insertions(+), 10 deletions(-)
crypto/af_alg.c +6 -0
@@ -428,6 +428,12 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) con->op = *(u32 *)CMSG_DATA (cmsg);break ; +case ALG_SET_OP_TYPE : +if (cmsg->cmsg_len <CMSG_LEN (sizeof (u32))) +return -EINVAL ; + con->op_type = *(u32 *)CMSG_DATA (cmsg); +break ; +case ALG_SET_AEAD_ASSOCLEN :if (cmsg->cmsg_len <CMSG_LEN (sizeof (u32)))return -EINVAL ;
crypto/algif_skcipher.c +276 -8
450 lines not on this page · raw message
include/crypto/if_alg.h +1 -0
@@ -42,6 +42,7 @@ struct af_alg_completion {struct af_alg_control {struct af_alg_iv *iv;int op; +int op_type;unsigned int aead_assoclen; };
include/uapi/linux/if_alg.h +7 -2
@@ -32,11 +32,16 @@ struct af_alg_iv {#define ALG_SET_KEY 1#define ALG_SET_IV 2#define ALG_SET_OP 3 -#define ALG_SET_AEAD_ASSOCLEN 4 -#define ALG_SET_AEAD_AUTHSIZE 5 +#define ALG_SET_OP_TYPE 4 +#define ALG_SET_AEAD_ASSOCLEN 5 +#define ALG_SET_AEAD_AUTHSIZE 6/* Operations */ #define ALG_OP_DECRYPT 0#define ALG_OP_ENCRYPT 1 +/* Operation types */ +#define ALG_OP_OUTOF_PLACE 0 +#define ALG_OP_IN_PLACE 1 +#endif /* _LINUX_IF_ALG_H */
Herbert Xu
maintainerQuoted 17 lines · Tadeusz Struk
The way the
algif_skcipherworks currently is that on sendmsg/sendpage it builds an sgl for the input data and then on read/recvmsg it sends the job for encryption putting the user to sleep till the data is processed. This way it can only handle one job at a given time.
This patch changes it to be asynchronous.
The idea is to allow enqueue multiple jobs to get most of available crypto HW accelerators and then read when the data is processed without blocking. To allow that both the input and output sgl need to be know at sendmsg/sendpage or the operation needs to happen "in place" in the input sgl. The approach here is to use the "in place" operation and process the data in the sgl provided in sendmsg. To allow that new user visible flags are introduced:ALG_SET_OP_TYPEALG_OP_OUTOF_PLACEALG_OP_IN_PLACE
By default the operation type isALG_OP_OUTOF_PLACE, which works the same way as without the change and allows existing application working without any update.
Quoted 3 lines
Using the test application from https://lkml.org/lkml/2011/8/28/87 with small modification to support in place operation, and reading after every 16th sendmsg these are the results:
What you want is AIO so we should try to use that interface rather than creating some funky crypto-specific interface.
Dave, the AIO hooks in net/socket.c is currently simply pointing to the sync implementation. What are you thoughts on allowing socket implementations to supply these hooks?
The algif interface can then use these hooks to implement AIO which is useful for maximising the hardware performance without resorting to loads of threads.
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 10 lines · Herbert Xu
What you want is AIO so we should try to use that interface rather than creating some funky crypto-specific interface.
Dave, the AIO hooks in
net/socket.cis currently simply pointing to the sync implementation. What are you thoughts on allowing socket implementations to supply these hooks?The algif interface can then use these hooks to implement AIO which is useful for maximising the hardware performance without resorting to loads of threads.
But then would you like to extend AIO interface to take the IV and something that would indicate the encrypt/decrypt operation on aio_write()? Also as far as I can see AIO doesn't support splice() operation for zero copy, which is the main thing here.
Quoted 1 line
From the other hand it shouldn't be a problem to add crypto specific
stuff to include/uapi/linux/if_alg.h, because it is all about crypto anyway, is it not?
If you have a better way how to indicate that data processing should start on the last page in sendpage() instead of ALG_OP_IN_PLACE I would be happy to use it.
Thanks,
Tadeusz
Herbert Xu
maintainerQuoted 4 lines · Tadeusz Struk
But then would you like to extend AIO interface to take the IV and something that would indicate the encrypt/decrypt operation on
aio_write()? Also as far as I can see AIO doesn't supportsplice()
Any metadata such as the IV can still go through the existing sendmsg interface, just as you would do a sendmsg before a sendfile to set things up.
Quoted 1 line
operation for zero copy, which is the main thing here.
The AIO interface itself can accomodate zero-copy. It's just that we currently don't have any support for it in the network socket API.
Quoted 3 lines
Quoted 1 line
From the other hand it shouldn't be a problem to add crypto specific
stuff to
include/uapi/linux/if_alg.h, because it is all about crypto anyway, is it not?
Yes but you're violating the meaning of sendpage(). The latter is not crypto-specific so you shouldn't be adding things that prevent future optimisations to it.
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
Quoted 12 lines · Herbert Xu
Quoted 3 lines
But then would you like to extend AIO interface to take the IV and
Quoted 2 lines
something that would indicate the encrypt/decrypt operation on
aio_write()? Also as far as I can see AIO doesn't supportsplice()Any metadata such as the IV can still go through the existing sendmsg interface, just as you would do a sendmsg before a sendfile to set things up.
Quoted 1 line
Quoted 1 line
operation for zero copy, which is the main thing here.
The AIO interface itself can accomodate zero-copy. It's just that we currently don't have any support for it in the network socket API.
Hi,
Ok, It looks to me that we *do* have all we need to implement zero copy and AIO with algif_skcipher. The only thing we need to do is to add support for it in skcipher_recvmsg(). I think no change is required in neither skcipher_sendmsg(), skcipher_sendpage(), nor the if_alg interface. Then to start using the interface asynchronously an application will need to call aio_read() or lio_listio() instead of read(), but if someone will use read(), then it will still work in the same (synchronous) way as it is today.
How does this sound to you, Herbert?
I'll send a v2 shortly.
Thanks,
Tadeusz
Quoted 10 lines · Tadeusz Struk
Ok, It looks to me that we *do* have all we need to implement zero copy and AIO with
algif_skcipher. The only thing we need to do is to add support for it inskcipher_recvmsg(). I think no change is required in neitherskcipher_sendmsg(),skcipher_sendpage(), nor theif_alginterface. Then to start using the interface asynchronously an application will need to callaio_read()orlio_listio()instead ofread(), but if someone will useread(), then it will still work in the same (synchronous) way as it is today.
How does this sound to you, Herbert?
It sounds good but let's see the code first :)
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