[PATCH] virtio-crypto: support crypto engine framework

2016-12-26 Thread Gonglei
crypto engine was introduced since 'commit 735d37b5424b ("crypto: engine
- Introduce the block request crypto engine framework")' which uses work
queue to realize the asynchronous processing for ablk_cipher and ahash.

For virtio-crypto device, I register an engine for each
data virtqueue so that we can use the capability of
multiple data queues in future.

Cc: Baolin Wang 
Cc: Herbert Xu 
Cc: Michael S. Tsirkin 
Signed-off-by: Gonglei 
---
 drivers/crypto/virtio/Kconfig|  1 +
 drivers/crypto/virtio/virtio_crypto_algs.c   | 52 ---
 drivers/crypto/virtio/virtio_crypto_common.h | 16 ++
 drivers/crypto/virtio/virtio_crypto_core.c   | 74 ++--
 4 files changed, 121 insertions(+), 22 deletions(-)

diff --git a/drivers/crypto/virtio/Kconfig b/drivers/crypto/virtio/Kconfig
index d80f733..5db0749 100644
--- a/drivers/crypto/virtio/Kconfig
+++ b/drivers/crypto/virtio/Kconfig
@@ -4,6 +4,7 @@ config CRYPTO_DEV_VIRTIO
select CRYPTO_AEAD
select CRYPTO_AUTHENC
select CRYPTO_BLKCIPHER
+   select CRYPTO_ENGINE
default m
help
  This driver provides support for virtio crypto device. If you
diff --git a/drivers/crypto/virtio/virtio_crypto_algs.c 
b/drivers/crypto/virtio/virtio_crypto_algs.c
index c2374df..970d0ca 100644
--- a/drivers/crypto/virtio/virtio_crypto_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_algs.c
@@ -288,8 +288,7 @@ static int virtio_crypto_ablkcipher_setkey(struct 
crypto_ablkcipher *tfm,
 static int
 __virtio_crypto_ablkcipher_do_req(struct virtio_crypto_request *vc_req,
struct ablkcipher_request *req,
-   struct data_queue *data_vq,
-   __u8 op)
+   struct data_queue *data_vq)
 {
struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
@@ -329,7 +328,7 @@ static int virtio_crypto_ablkcipher_setkey(struct 
crypto_ablkcipher *tfm,
vc_req->req_data = req_data;
vc_req->type = VIRTIO_CRYPTO_SYM_OP_CIPHER;
/* Head of operation */
-   if (op) {
+   if (vc_req->encrypt) {
req_data->header.session_id =
cpu_to_le64(ctx->enc_sess_info.session_id);
req_data->header.opcode =
@@ -424,19 +423,15 @@ static int virtio_crypto_ablkcipher_encrypt(struct 
ablkcipher_request *req)
struct virtio_crypto_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(atfm);
struct virtio_crypto_request *vc_req = ablkcipher_request_ctx(req);
struct virtio_crypto *vcrypto = ctx->vcrypto;
-   int ret;
/* Use the first data virtqueue as default */
struct data_queue *data_vq = >data_vq[0];
 
vc_req->ablkcipher_ctx = ctx;
vc_req->ablkcipher_req = req;
-   ret = __virtio_crypto_ablkcipher_do_req(vc_req, req, data_vq, 1);
-   if (ret < 0) {
-   pr_err("virtio_crypto: Encryption failed!\n");
-   return ret;
-   }
+   vc_req->encrypt = true;
+   vc_req->dataq = data_vq;
 
-   return -EINPROGRESS;
+   return crypto_transfer_cipher_request_to_engine(data_vq->engine, req);
 }
 
 static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
@@ -445,20 +440,16 @@ static int virtio_crypto_ablkcipher_decrypt(struct 
ablkcipher_request *req)
struct virtio_crypto_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(atfm);
struct virtio_crypto_request *vc_req = ablkcipher_request_ctx(req);
struct virtio_crypto *vcrypto = ctx->vcrypto;
-   int ret;
/* Use the first data virtqueue as default */
struct data_queue *data_vq = >data_vq[0];
 
vc_req->ablkcipher_ctx = ctx;
vc_req->ablkcipher_req = req;
 
-   ret = __virtio_crypto_ablkcipher_do_req(vc_req, req, data_vq, 0);
-   if (ret < 0) {
-   pr_err("virtio_crypto: Decryption failed!\n");
-   return ret;
-   }
+   vc_req->encrypt = false;
+   vc_req->dataq = data_vq;
 
-   return -EINPROGRESS;
+   return crypto_transfer_cipher_request_to_engine(data_vq->engine, req);
 }
 
 static int virtio_crypto_ablkcipher_init(struct crypto_tfm *tfm)
@@ -484,6 +475,33 @@ static void virtio_crypto_ablkcipher_exit(struct 
crypto_tfm *tfm)
ctx->vcrypto = NULL;
 }
 
+int virtio_crypto_ablkcipher_crypt_req(
+   struct crypto_engine *engine,
+   struct ablkcipher_request *req)
+{
+   struct virtio_crypto_request *vc_req = ablkcipher_request_ctx(req);
+   struct data_queue *data_vq = vc_req->dataq;
+   int ret;
+
+   ret = __virtio_crypto_ablkcipher_do_req(vc_req, req, data_vq);
+   if (ret < 0)
+   return ret;
+
+   virtqueue_kick(data_vq->vq);
+
+   return 0;
+}
+
+void virtio_crypto_ablkcipher_finalize_req(
+   struct virtio_crypto_request 

Re: [PATCH net 1/9] virtio-net: remove the warning before XDP linearizing

2016-12-26 Thread Jason Wang



On 2016年12月24日 03:31, Daniel Borkmann wrote:

Hi Jason,

On 12/23/2016 03:37 PM, Jason Wang wrote:

Since we use EWMA to estimate the size of rx buffer. When rx buffer
size is underestimated, it's usual to have a packet with more than one
buffers. Consider this is not a bug, remove the warning and correct
the comment before XDP linearizing.

Cc: John Fastabend 
Signed-off-by: Jason Wang 
---
  drivers/net/virtio_net.c | 8 +---
  1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 08327e0..1067253 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -552,14 +552,8 @@ static struct sk_buff *receive_mergeable(struct 
net_device *dev,

  struct page *xdp_page;
  u32 act;

-/* No known backend devices should send packets with
- * more than a single buffer when XDP conditions are
- * met. However it is not strictly illegal so the case
- * is handled as an exception and a warning is thrown.
- */
+/* This happens when rx buffer size is underestimated */
  if (unlikely(num_buf > 1)) {
-bpf_warn_invalid_xdp_buffer();


Could you also remove the bpf_warn_invalid_xdp_buffer(), which got added
just for this?

Thanks. 


Posted.

Thanks
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization