All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gonglei <arei.gonglei@huawei.com>
To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org
Cc: peter.huangpeng@huawei.com, luonengjun@huawei.com,
	mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com,
	berrange@redhat.com, weidong.huang@huawei.com,
	mike.caraman@nxp.com, agraf@suse.de, xin.zeng@intel.com,
	claudio.fontana@huawei.com, nmorey@kalray.eu,
	vincent.jardin@6wind.com, Gonglei <arei.gonglei@huawei.com>
Subject: [Qemu-devel] [PATCH v2 13/15] virtio-crypto: get correct input data address for each request
Date: Tue, 13 Sep 2016 11:52:19 +0800	[thread overview]
Message-ID: <1473738741-220600-14-git-send-email-arei.gonglei@huawei.com> (raw)
In-Reply-To: <1473738741-220600-1-git-send-email-arei.gonglei@huawei.com>

We MUST use the original hva for input data, but not the
copyed address, otherwise the guest can't get the results.
Fix a non-initial problem in an exception case as well.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/virtio/virtio-crypto.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 0d7ab63..96c5a2a 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -62,7 +62,8 @@ static int64_t
 virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto,
                struct virtio_crypto_sym_create_session_req *sess_req,
                uint32_t queue_id,
-               uint64_t *session_id)
+               uint64_t *session_id,
+               VirtQueueElement *elem)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
     CryptoSymSessionInfo info;
@@ -74,6 +75,8 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto,
     void *auth_key_hva;
     struct virtio_crypto_session_input *input;
     hwaddr len;
+    size_t input_offset;
+    struct iovec *iov = elem->in_sg;
 
     memset(&info, 0, sizeof(info));
     op_type = sess_req->op_type;
@@ -83,13 +86,19 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto,
         virtio_crypto_cipher_session_helper(vdev, &info,
                            &sess_req->u.cipher.para,
                            &sess_req->u.cipher.out);
-        input = &sess_req->u.cipher.input;
+        /* calculate the offset of input data */
+        input_offset = offsetof(struct virtio_crypto_op_ctrl_req,
+                          u.sym_create_session.u.cipher.input);
+        input = (void *)iov[0].iov_base + input_offset;
     } else if (op_type == VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) {
         /* cipher part */
         virtio_crypto_cipher_session_helper(vdev, &info,
                            &sess_req->u.chain.para.cipher_param,
                            &sess_req->u.chain.out.cipher);
-        input = &sess_req->u.chain.input;
+        /* calculate the offset of input data */
+        input_offset = offsetof(struct virtio_crypto_op_ctrl_req,
+                                u.sym_create_session.u.chain.input);
+        input = (void *)iov[0].iov_base + input_offset;
         /* hash part */
         info.alg_chain_order = sess_req->u.chain.para.alg_chain_order;
         info.add_len = sess_req->u.chain.para.aad_len;
@@ -120,6 +129,10 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto,
             goto err;
         }
     } else {
+        /* calculate the offset of input data */
+        input_offset = offsetof(struct virtio_crypto_op_ctrl_req,
+                                u.sym_create_session.u.cipher.input);
+        input = (void *)iov[0].iov_base + input_offset;
         /* VIRTIO_CRYPTO_SYM_OP_NONE */
         error_report("unsupported cipher type");
         goto err;
@@ -149,13 +162,17 @@ err:
 static void
 virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto,
          struct virtio_crypto_destroy_session_req *close_sess_req,
-         uint32_t queue_id)
+         uint32_t queue_id,
+         VirtQueueElement *elem)
 {
     int ret;
     CryptoClientState *cc = vcrypto->crypto->ccs;
     uint64_t session_id;
     uint32_t status;
     int queue_index = virtio_crypto_vq2q(queue_id);
+    struct iovec *iov = elem->in_sg;
+    size_t status_offset;
+    void *in_status_ptr;
 
     session_id = close_sess_req->session_id;
     DPRINTF("close session, id=%" PRIu64 "\n", session_id);
@@ -168,8 +185,12 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto,
         status = VIRTIO_CRYPTO_OP_ERR;
     }
 
+    /* calculate the offset of status bits */
+    status_offset = offsetof(struct virtio_crypto_op_ctrl_req,
+                             u.destroy_session.status);
+    in_status_ptr = (void *)iov[0].iov_base + status_offset;
     /* Set the result, notify the frontend driver soon */
-    close_sess_req->status = status;
+    memcpy(in_status_ptr, &status, sizeof(status));
 }
 
 static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
@@ -207,7 +228,8 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
             virtio_crypto_create_sym_session(vcrypto,
                              &ctrl.u.sym_create_session,
                              queue_id,
-                             &session_id);
+                             &session_id,
+                             elem);
 
             break;
         case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION:
@@ -215,7 +237,8 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         case VIRTIO_CRYPTO_MAC_DESTROY_SESSION:
         case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION:
             virtio_crypto_handle_close_session(vcrypto,
-                   &ctrl.u.destroy_session, queue_id);
+                   &ctrl.u.destroy_session, queue_id,
+                   elem);
             break;
         case VIRTIO_CRYPTO_HASH_CREATE_SESSION:
         case VIRTIO_CRYPTO_MAC_CREATE_SESSION:
-- 
1.7.12.4

  parent reply	other threads:[~2016-09-13  3:56 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  3:52 [Qemu-devel] [PATCH v2 00/15] virtio-crypto: introduce framework and device emulation Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 01/15] crypto: introduce cryptodev backend and crypto legacy hardware Gonglei
2016-09-13  9:13   ` Daniel P. Berrange
2016-09-13  9:55     ` Gonglei (Arei)
2016-09-13  9:59       ` Daniel P. Berrange
2016-09-13 10:06         ` Gonglei (Arei)
2016-09-13 10:50     ` Paolo Bonzini
2016-09-13 11:04       ` Daniel P. Berrange
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 02/15] crypto: introduce crypto queue handler Gonglei
2016-09-13  9:20   ` Daniel P. Berrange
2016-09-13  9:58     ` Gonglei (Arei)
2016-09-13 10:58     ` Paolo Bonzini
2016-09-13 11:52       ` [Qemu-devel] [virtio-dev] " Ola Liljedahl
2016-09-14  1:07         ` Gonglei (Arei)
2016-09-14  8:24           ` Ola Liljedahl
2016-09-14  1:03       ` Gonglei (Arei)
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff Gonglei
2016-09-13  9:22   ` Daniel P. Berrange
2016-09-13 10:05     ` Gonglei (Arei)
2016-09-13 10:08       ` Daniel P. Berrange
2016-09-13 10:14         ` Gonglei (Arei)
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 04/15] crypto: add symetric algorithms support Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 05/15] crypto: add cryptodev-linux as a cryptodev backend Gonglei
2016-09-13  9:23   ` Daniel P. Berrange
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 06/15] crypto: add internal handle logic layer Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 07/15] virtio-crypto: introduce virtio-crypto.h Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 08/15] virtio-crypto-pci: add virtio crypto pci support Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 09/15] virtio-crypto: add virtio crypto realization Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 10/15] virtio-crypto: set capacity of crypto legacy hardware Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 11/15] virtio-crypto: add control queue handler Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 12/15] virtio-crypto: add destroy session logic Gonglei
2016-09-13  3:52 ` Gonglei [this message]
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 14/15] virtio-crypto: add data virtqueue processing handler Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 15/15] virtio-crypto: support scatter gather list Gonglei
2016-09-13  8:57 ` [Qemu-devel] [PATCH v2 00/15] virtio-crypto: introduce framework and device emulation Daniel P. Berrange
2016-09-13  9:45   ` Gonglei (Arei)
2016-09-13  9:54     ` Daniel P. Berrange
2016-09-13 10:08       ` Gonglei (Arei)
2016-09-13 10:58       ` Paolo Bonzini
2016-09-13 11:07         ` Daniel P. Berrange

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=1473738741-220600-14-git-send-email-arei.gonglei@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=agraf@suse.de \
    --cc=berrange@redhat.com \
    --cc=claudio.fontana@huawei.com \
    --cc=luonengjun@huawei.com \
    --cc=mike.caraman@nxp.com \
    --cc=mst@redhat.com \
    --cc=nmorey@kalray.eu \
    --cc=pbonzini@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vincent.jardin@6wind.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --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.