[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/47] cryptodev: introduce an unified wrapper for cr
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 25/47] cryptodev: introduce an unified wrapper for crypto operation |
Date: |
Sun, 30 Oct 2016 23:24:28 +0200 |
From: Gonglei <address@hidden>
We use an opaque point to the VirtIOCryptoReq which
can support different packets based on different
algorithms.
Signed-off-by: Gonglei <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/sysemu/cryptodev.h | 13 +++++++------
backends/cryptodev.c | 28 ++++++++++++++++++++++++++--
hw/virtio/virtio-crypto.c | 10 +++++-----
3 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index e66bd4b..84526c0 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -278,20 +278,21 @@ int cryptodev_backend_sym_close_session(
uint32_t queue_index, Error **errp);
/**
- * cryptodev_backend_sym_operation:
+ * cryptodev_backend_crypto_operation:
* @backend: the cryptodev backend object
- * @op_info: parameters needed by symmetric crypto operation
+ * @opaque: pointer to a VirtIOCryptoReq object
* @queue_index: queue index of cryptodev backend client
* @errp: pointer to a NULL-initialized error object
*
- * Do symmetric crypto operation, such as encryption and
+ * Do crypto operation, such as encryption and
* decryption
*
- * Returns: 0 on success, or Negative on error
+ * Returns: VIRTIO_CRYPTO_OK on success,
+ * or -VIRTIO_CRYPTO_* on error
*/
-int cryptodev_backend_sym_operation(
+int cryptodev_backend_crypto_operation(
CryptoDevBackend *backend,
- CryptoDevBackendSymOpInfo *op_info,
+ void *opaque,
uint32_t queue_index, Error **errp);
#endif /* CRYPTODEV_H */
diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 47521cf..4a49f97 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -30,6 +30,8 @@
#include "qapi-visit.h"
#include "qemu/config-file.h"
#include "qom/object_interfaces.h"
+#include "hw/virtio/virtio-crypto.h"
+
static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients;
@@ -105,7 +107,7 @@ int cryptodev_backend_sym_close_session(
return -1;
}
-int cryptodev_backend_sym_operation(
+static int cryptodev_backend_sym_operation(
CryptoDevBackend *backend,
CryptoDevBackendSymOpInfo *op_info,
uint32_t queue_index, Error **errp)
@@ -117,7 +119,29 @@ int cryptodev_backend_sym_operation(
return bc->do_sym_op(backend, op_info, queue_index, errp);
}
- return -1;
+ return -VIRTIO_CRYPTO_ERR;
+}
+
+int cryptodev_backend_crypto_operation(
+ CryptoDevBackend *backend,
+ void *opaque,
+ uint32_t queue_index, Error **errp)
+{
+ VirtIOCryptoReq *req = opaque;
+
+ if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
+ CryptoDevBackendSymOpInfo *op_info;
+ op_info = req->u.sym_op_info;
+
+ return cryptodev_backend_sym_operation(backend,
+ op_info, queue_index, errp);
+ } else {
+ error_setg(errp, "Unsupported cryptodev alg type: %" PRIu32 "",
+ req->flags);
+ return -VIRTIO_CRYPTO_NOTSUPP;
+ }
+
+ return -VIRTIO_CRYPTO_ERR;
}
static void
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 6c8770a..6faacb7 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -634,15 +634,15 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
/* Set request's parameter */
request->flags = CRYPTODEV_BACKEND_ALG_SYM;
request->u.sym_op_info = sym_op_info;
- ret = cryptodev_backend_sym_operation(vcrypto->cryptodev,
- sym_op_info, queue_index, &local_err);
+ ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev,
+ request, queue_index, &local_err);
if (ret < 0) {
- status = VIRTIO_CRYPTO_ERR;
+ status = -ret;
if (local_err) {
error_report_err(local_err);
}
- } else { /* ret >= 0 */
- status = VIRTIO_CRYPTO_OK;
+ } else { /* ret == VIRTIO_CRYPTO_OK */
+ status = ret;
}
virtio_crypto_req_complete(request, status);
virtio_crypto_free_request(request);
--
MST
- [Qemu-devel] [PULL 15/47] virtio: inline set_host_notifier_internal, (continued)
- [Qemu-devel] [PULL 15/47] virtio: inline set_host_notifier_internal, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 16/47] cryptodev: introduce cryptodev backend interface, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 17/47] cryptodev: add symmetric algorithm operation stuff, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 18/47] virtio-crypto: introduce virtio_crypto.h, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 19/47] cryptodev: introduce a new cryptodev backend, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 20/47] virtio-crypto: add virtio crypto device emulation, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 21/47] virtio-crypto-pci: add virtio crypto pci support, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 22/47] virtio-crypto: set capacity of algorithms supported, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 23/47] virtio-crypto: add control queue handler, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 24/47] virtio-crypto: add data queue processing handler, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 25/47] cryptodev: introduce an unified wrapper for crypto operation,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 26/47] virtio-crypto: using bh to handle dataq's requests, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 27/47] virtio-crypto: add myself as virtio-crypto and cryptodev backends maintainer, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 28/47] acpi nvdimm: fix wrong buffer size returned by DSM method, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 29/47] acpi nvdimm: fix OperationRegion definition, Michael S. Tsirkin, 2016/10/30
- [Qemu-devel] [PULL 30/47] acpi nvdimm: fix device physical address base, Michael S. Tsirkin, 2016/10/30