All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Longpeng(Mike)" <longpeng2@huawei.com>
To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org
Cc: luonengjun@huawei.com, mst@redhat.com, cohuck@redhat.com,
	stefanha@redhat.com, denglingli@chinamobile.com,
	Jani.Kokkonen@huawei.com, Ola.Liljedahl@arm.com,
	Varun.Sethi@freescale.com, xin.zeng@intel.com,
	brian.a.keating@intel.com, liang.j.ma@intel.com,
	john.griffin@intel.com, weidong.huang@huawei.com,
	mike.caraman@nxp.com, agraf@suse.de, jasowang@redhat.com,
	vincent.jardin@6wind.com, arei.gonglei@hotmail.com,
	pasic@linux.vnet.ibm.com, wangxinxin.wang@huawei.com,
	arei.gonglei@huawei.com, "Longpeng(Mike)" <longpeng2@huawei.com>
Subject: [Qemu-devel] [RFC 2/8] virtio-crypto: add session creation logic for mux mode
Date: Mon, 11 Sep 2017 09:10:34 +0800	[thread overview]
Message-ID: <1505092240-10864-3-git-send-email-longpeng2@huawei.com> (raw)
In-Reply-To: <1505092240-10864-1-git-send-email-longpeng2@huawei.com>

Adds the session creatation logic for MUX mode.

Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
---
 hw/virtio/virtio-crypto.c | 79 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 66 insertions(+), 13 deletions(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 19c82e0..78f75c2 100755
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -33,6 +33,11 @@ static inline int virtio_crypto_vq2q(int queue_index)
     return queue_index;
 }
 
+static inline bool virtio_crypto_in_mux_mode(VirtIODevice *vdev)
+{
+    return virtio_vdev_has_feature(vdev, VIRTIO_CRYPTO_F_MUX_MODE);
+}
+
 static int
 virtio_crypto_cipher_session_helper(VirtIODevice *vdev,
            CryptoDevBackendSymSessionInfo *info,
@@ -210,18 +215,24 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto,
 static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
-    struct virtio_crypto_op_ctrl_req ctrl;
     VirtQueueElement *elem;
+    struct virtio_crypto_session_input input;
+    struct virtio_crypto_ctrl_header *generic_hdr;
+    union {
+        struct virtio_crypto_op_ctrl_req ctrl;
+        struct virtio_crypto_op_ctrl_req_mux mux_ctrl;
+    } req;
+
     struct iovec *in_iov;
     struct iovec *out_iov;
     unsigned in_num;
     unsigned out_num;
     uint32_t queue_id;
     uint32_t opcode;
-    struct virtio_crypto_session_input input;
     int64_t session_id;
     uint8_t status;
-    size_t s;
+    size_t s, exp_len;
+    void *sess;
 
     for (;;) {
         elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
@@ -239,25 +250,49 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         out_iov = elem->out_sg;
         in_num = elem->in_num;
         in_iov = elem->in_sg;
-        if (unlikely(iov_to_buf(out_iov, out_num, 0, &ctrl, sizeof(ctrl))
-                    != sizeof(ctrl))) {
+
+        if (virtio_crypto_in_mux_mode(vdev)) {
+            exp_len = sizeof(req.mux_ctrl);
+            generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.mux_ctrl);
+        } else {
+            exp_len = sizeof(req.ctrl);
+            generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.ctrl);
+        }
+
+        s = iov_to_buf(out_iov, out_num, 0, generic_hdr, exp_len);
+        if (unlikely(s != exp_len)) {
             virtio_error(vdev, "virtio-crypto request ctrl_hdr too short");
             virtqueue_detach_element(vq, elem, 0);
             g_free(elem);
             break;
         }
-        iov_discard_front(&out_iov, &out_num, sizeof(ctrl));
 
-        opcode = ldl_le_p(&ctrl.header.opcode);
-        queue_id = ldl_le_p(&ctrl.header.queue_id);
+        iov_discard_front(&out_iov, &out_num, exp_len);
+
+        opcode = ldl_le_p(&generic_hdr->opcode);
+        queue_id = ldl_le_p(&generic_hdr->queue_id);
 
         switch (opcode) {
         case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION:
+            if (virtio_crypto_in_mux_mode(vdev)) {
+                sess = g_new0(struct virtio_crypto_sym_create_session_req, 1);
+                exp_len = sizeof(struct virtio_crypto_sym_create_session_req);
+                s = iov_to_buf(out_iov, out_num, 0, sess, exp_len);
+                if (unlikely(s != exp_len)) {
+                    virtio_error(vdev, "virtio-crypto request additional "
+                                 "parameters too short");
+                    virtqueue_detach_element(vq, elem, 0);
+                    break;
+                }
+                iov_discard_front(&out_iov, &out_num, exp_len);
+            } else {
+                sess = &req.ctrl.u.sym_create_session;
+            }
+
             memset(&input, 0, sizeof(input));
-            session_id = virtio_crypto_create_sym_session(vcrypto,
-                             &ctrl.u.sym_create_session,
-                             queue_id, opcode,
-                             out_iov, out_num);
+
+            session_id = virtio_crypto_create_sym_session(vcrypto, sess,
+                                    queue_id, opcode, out_iov, out_num);
             /* Serious errors, need to reset virtio crypto device */
             if (session_id == -EFAULT) {
                 virtqueue_detach_element(vq, elem, 0);
@@ -285,8 +320,23 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         case VIRTIO_CRYPTO_HASH_DESTROY_SESSION:
         case VIRTIO_CRYPTO_MAC_DESTROY_SESSION:
         case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION:
+            if (virtio_crypto_in_mux_mode(vdev)) {
+                sess = g_new0(struct virtio_crypto_destroy_session_req, 1);
+                exp_len = sizeof(struct virtio_crypto_destroy_session_req);
+                s = iov_to_buf(out_iov, out_num, 0, sess, exp_len);
+                if (unlikely(s != exp_len)) {
+                    virtio_error(vdev, "virtio-crypto request additional "
+                                 "parameters too short");
+                    virtqueue_detach_element(vq, elem, 0);
+                    break;
+                }
+                iov_discard_front(&out_iov, &out_num, exp_len);
+            } else {
+                sess = &req.ctrl.u.destroy_session;
+            }
+
             status = virtio_crypto_handle_close_session(vcrypto,
-                   &ctrl.u.destroy_session, queue_id);
+                                                sess, queue_id);
             /* The status only occupy one byte, we can directly use it */
             s = iov_from_buf(in_iov, in_num, 0, &status, sizeof(status));
             if (unlikely(s != sizeof(status))) {
@@ -316,6 +366,9 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
             break;
         } /* end switch case */
 
+        if (virtio_crypto_in_mux_mode(vdev)) {
+            g_free(sess);
+        }
         g_free(elem);
     } /* end for loop */
 }
-- 
1.8.3.1

WARNING: multiple messages have this Message-ID (diff)
From: "Longpeng(Mike)" <longpeng2@huawei.com>
To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org
Cc: luonengjun@huawei.com, mst@redhat.com, cohuck@redhat.com,
	stefanha@redhat.com, denglingli@chinamobile.com,
	Jani.Kokkonen@huawei.com, Ola.Liljedahl@arm.com,
	Varun.Sethi@freescale.com, xin.zeng@intel.com,
	brian.a.keating@intel.com, liang.j.ma@intel.com,
	john.griffin@intel.com, weidong.huang@huawei.com,
	mike.caraman@nxp.com, agraf@suse.de, jasowang@redhat.com,
	vincent.jardin@6wind.com, arei.gonglei@hotmail.com,
	pasic@linux.vnet.ibm.com, wangxinxin.wang@huawei.com,
	arei.gonglei@huawei.com, "Longpeng(Mike)" <longpeng2@huawei.com>
Subject: [virtio-dev] [RFC 2/8] virtio-crypto: add session creation logic for mux mode
Date: Mon, 11 Sep 2017 09:10:34 +0800	[thread overview]
Message-ID: <1505092240-10864-3-git-send-email-longpeng2@huawei.com> (raw)
In-Reply-To: <1505092240-10864-1-git-send-email-longpeng2@huawei.com>

Adds the session creatation logic for MUX mode.

Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
---
 hw/virtio/virtio-crypto.c | 79 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 66 insertions(+), 13 deletions(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 19c82e0..78f75c2 100755
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -33,6 +33,11 @@ static inline int virtio_crypto_vq2q(int queue_index)
     return queue_index;
 }
 
+static inline bool virtio_crypto_in_mux_mode(VirtIODevice *vdev)
+{
+    return virtio_vdev_has_feature(vdev, VIRTIO_CRYPTO_F_MUX_MODE);
+}
+
 static int
 virtio_crypto_cipher_session_helper(VirtIODevice *vdev,
            CryptoDevBackendSymSessionInfo *info,
@@ -210,18 +215,24 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto,
 static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
-    struct virtio_crypto_op_ctrl_req ctrl;
     VirtQueueElement *elem;
+    struct virtio_crypto_session_input input;
+    struct virtio_crypto_ctrl_header *generic_hdr;
+    union {
+        struct virtio_crypto_op_ctrl_req ctrl;
+        struct virtio_crypto_op_ctrl_req_mux mux_ctrl;
+    } req;
+
     struct iovec *in_iov;
     struct iovec *out_iov;
     unsigned in_num;
     unsigned out_num;
     uint32_t queue_id;
     uint32_t opcode;
-    struct virtio_crypto_session_input input;
     int64_t session_id;
     uint8_t status;
-    size_t s;
+    size_t s, exp_len;
+    void *sess;
 
     for (;;) {
         elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
@@ -239,25 +250,49 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         out_iov = elem->out_sg;
         in_num = elem->in_num;
         in_iov = elem->in_sg;
-        if (unlikely(iov_to_buf(out_iov, out_num, 0, &ctrl, sizeof(ctrl))
-                    != sizeof(ctrl))) {
+
+        if (virtio_crypto_in_mux_mode(vdev)) {
+            exp_len = sizeof(req.mux_ctrl);
+            generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.mux_ctrl);
+        } else {
+            exp_len = sizeof(req.ctrl);
+            generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.ctrl);
+        }
+
+        s = iov_to_buf(out_iov, out_num, 0, generic_hdr, exp_len);
+        if (unlikely(s != exp_len)) {
             virtio_error(vdev, "virtio-crypto request ctrl_hdr too short");
             virtqueue_detach_element(vq, elem, 0);
             g_free(elem);
             break;
         }
-        iov_discard_front(&out_iov, &out_num, sizeof(ctrl));
 
-        opcode = ldl_le_p(&ctrl.header.opcode);
-        queue_id = ldl_le_p(&ctrl.header.queue_id);
+        iov_discard_front(&out_iov, &out_num, exp_len);
+
+        opcode = ldl_le_p(&generic_hdr->opcode);
+        queue_id = ldl_le_p(&generic_hdr->queue_id);
 
         switch (opcode) {
         case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION:
+            if (virtio_crypto_in_mux_mode(vdev)) {
+                sess = g_new0(struct virtio_crypto_sym_create_session_req, 1);
+                exp_len = sizeof(struct virtio_crypto_sym_create_session_req);
+                s = iov_to_buf(out_iov, out_num, 0, sess, exp_len);
+                if (unlikely(s != exp_len)) {
+                    virtio_error(vdev, "virtio-crypto request additional "
+                                 "parameters too short");
+                    virtqueue_detach_element(vq, elem, 0);
+                    break;
+                }
+                iov_discard_front(&out_iov, &out_num, exp_len);
+            } else {
+                sess = &req.ctrl.u.sym_create_session;
+            }
+
             memset(&input, 0, sizeof(input));
-            session_id = virtio_crypto_create_sym_session(vcrypto,
-                             &ctrl.u.sym_create_session,
-                             queue_id, opcode,
-                             out_iov, out_num);
+
+            session_id = virtio_crypto_create_sym_session(vcrypto, sess,
+                                    queue_id, opcode, out_iov, out_num);
             /* Serious errors, need to reset virtio crypto device */
             if (session_id == -EFAULT) {
                 virtqueue_detach_element(vq, elem, 0);
@@ -285,8 +320,23 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         case VIRTIO_CRYPTO_HASH_DESTROY_SESSION:
         case VIRTIO_CRYPTO_MAC_DESTROY_SESSION:
         case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION:
+            if (virtio_crypto_in_mux_mode(vdev)) {
+                sess = g_new0(struct virtio_crypto_destroy_session_req, 1);
+                exp_len = sizeof(struct virtio_crypto_destroy_session_req);
+                s = iov_to_buf(out_iov, out_num, 0, sess, exp_len);
+                if (unlikely(s != exp_len)) {
+                    virtio_error(vdev, "virtio-crypto request additional "
+                                 "parameters too short");
+                    virtqueue_detach_element(vq, elem, 0);
+                    break;
+                }
+                iov_discard_front(&out_iov, &out_num, exp_len);
+            } else {
+                sess = &req.ctrl.u.destroy_session;
+            }
+
             status = virtio_crypto_handle_close_session(vcrypto,
-                   &ctrl.u.destroy_session, queue_id);
+                                                sess, queue_id);
             /* The status only occupy one byte, we can directly use it */
             s = iov_from_buf(in_iov, in_num, 0, &status, sizeof(status));
             if (unlikely(s != sizeof(status))) {
@@ -316,6 +366,9 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
             break;
         } /* end switch case */
 
+        if (virtio_crypto_in_mux_mode(vdev)) {
+            g_free(sess);
+        }
         g_free(elem);
     } /* end for loop */
 }
-- 
1.8.3.1



---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org


  parent reply	other threads:[~2017-09-11  1:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11  1:10 [Qemu-devel] [RFC 0/8] virtio-crypto: add multiplexing mode support Longpeng(Mike)
2017-09-11  1:10 ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 1/8] virtio-crypto: add new definations for multiplexing mode Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` Longpeng(Mike) [this message]
2017-09-11  1:10   ` [virtio-dev] [RFC 2/8] virtio-crypto: add session creation logic for mux mode Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 3/8] virtio-crypto: add dataq operation " Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 4/8] cryptodev: add stateless mode cipher support Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 5/8] virtio-crypto: add stateless crypto request handler Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 6/8] cryptodev: extract one util function Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 7/8] cryptodev-builtin: add stateless cipher support Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:10 ` [Qemu-devel] [RFC 8/8] virtio-crypto: add host feature bits support Longpeng(Mike)
2017-09-11  1:10   ` [virtio-dev] " Longpeng(Mike)
2017-09-11  1:26 ` [Qemu-devel] [RFC 0/8] virtio-crypto: add multiplexing mode support no-reply
2017-09-11  1:26   ` no-reply
2017-09-13 18:14 ` Halil Pasic
2017-09-13 18:14   ` [virtio-dev] " Halil Pasic
2017-09-14  0:58   ` [Qemu-devel] [virtio-dev] " Longpeng (Mike)
2017-09-14  0:58     ` [virtio-dev] Re: [Qemu-devel] " Longpeng (Mike)
2017-09-15 17:33     ` [Qemu-devel] [virtio-dev] " Halil Pasic
2017-09-15 17:33       ` [virtio-dev] " Halil Pasic
2017-09-18  1:17       ` [Qemu-devel] [virtio-dev] " Longpeng (Mike)
2017-09-18  1:17         ` [virtio-dev] Re: [Qemu-devel] " Longpeng (Mike)
2017-10-06 14:24         ` [Qemu-devel] [virtio-dev] " Halil Pasic
2017-10-06 14:24           ` [virtio-dev] " Halil Pasic
2017-10-09  9:22           ` Gonglei (Arei)
2017-10-09  9:22             ` [virtio-dev] " Gonglei (Arei)
2017-10-09 11:04             ` Halil Pasic
2017-10-09 11:04               ` [virtio-dev] " Halil Pasic
2017-10-09 11:17               ` Gonglei (Arei)
2017-10-09 11:17                 ` [virtio-dev] " Gonglei (Arei)
2017-10-10  8:35                 ` Longpeng (Mike)
2017-10-10  8:35                   ` [virtio-dev] " Longpeng (Mike)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505092240-10864-3-git-send-email-longpeng2@huawei.com \
    --to=longpeng2@huawei.com \
    --cc=Jani.Kokkonen@huawei.com \
    --cc=Ola.Liljedahl@arm.com \
    --cc=Varun.Sethi@freescale.com \
    --cc=agraf@suse.de \
    --cc=arei.gonglei@hotmail.com \
    --cc=arei.gonglei@huawei.com \
    --cc=brian.a.keating@intel.com \
    --cc=cohuck@redhat.com \
    --cc=denglingli@chinamobile.com \
    --cc=jasowang@redhat.com \
    --cc=john.griffin@intel.com \
    --cc=liang.j.ma@intel.com \
    --cc=luonengjun@huawei.com \
    --cc=mike.caraman@nxp.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vincent.jardin@6wind.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=wangxinxin.wang@huawei.com \
    --cc=weidong.huang@huawei.com \
    --cc=xin.zeng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.