cryptodev: Use CryptoDevBackendOpInfo for operation

Move queue_index, CryptoDevCompletionFunc and opaque into struct
CryptoDevBackendOpInfo, then cryptodev_backend_crypto_operation()
needs an argument CryptoDevBackendOpInfo *op_info only. And remove
VirtIOCryptoReq from cryptodev. It's also possible to hide
VirtIOCryptoReq into virtio-crypto.c in the next step. (In theory,
VirtIOCryptoReq is a private structure used by virtio-crypto only)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20230301105847.253084-9-pizhenwei@bytedance.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
zhenwei pi 2023-03-01 18:58:43 +08:00 committed by Michael S. Tsirkin
parent ef52091aeb
commit 2cb0692768
5 changed files with 25 additions and 44 deletions

View File

@ -539,10 +539,7 @@ static int cryptodev_builtin_asym_operation(
static int cryptodev_builtin_operation( static int cryptodev_builtin_operation(
CryptoDevBackend *backend, CryptoDevBackend *backend,
CryptoDevBackendOpInfo *op_info, CryptoDevBackendOpInfo *op_info)
uint32_t queue_index,
CryptoDevCompletionFunc cb,
void *opaque)
{ {
CryptoDevBackendBuiltin *builtin = CryptoDevBackendBuiltin *builtin =
CRYPTODEV_BACKEND_BUILTIN(backend); CRYPTODEV_BACKEND_BUILTIN(backend);
@ -574,8 +571,8 @@ static int cryptodev_builtin_operation(
if (local_error) { if (local_error) {
error_report_err(local_error); error_report_err(local_error);
} }
if (cb) { if (op_info->cb) {
cb(opaque, status); op_info->cb(op_info->opaque, status);
} }
return 0; return 0;
} }

View File

@ -469,10 +469,7 @@ static void *cryptodev_lkcf_worker(void *arg)
static int cryptodev_lkcf_operation( static int cryptodev_lkcf_operation(
CryptoDevBackend *backend, CryptoDevBackend *backend,
CryptoDevBackendOpInfo *op_info, CryptoDevBackendOpInfo *op_info)
uint32_t queue_index,
CryptoDevCompletionFunc cb,
void *opaque)
{ {
CryptoDevBackendLKCF *lkcf = CryptoDevBackendLKCF *lkcf =
CRYPTODEV_BACKEND_LKCF(backend); CRYPTODEV_BACKEND_LKCF(backend);
@ -495,8 +492,8 @@ static int cryptodev_lkcf_operation(
task = g_new0(CryptoDevLKCFTask, 1); task = g_new0(CryptoDevLKCFTask, 1);
task->op_info = op_info; task->op_info = op_info;
task->cb = cb; task->cb = op_info->cb;
task->opaque = opaque; task->opaque = op_info->opaque;
task->sess = sess; task->sess = sess;
task->lkcf = lkcf; task->lkcf = lkcf;
task->status = -VIRTIO_CRYPTO_ERR; task->status = -VIRTIO_CRYPTO_ERR;

View File

@ -143,29 +143,22 @@ int cryptodev_backend_close_session(
static int cryptodev_backend_operation( static int cryptodev_backend_operation(
CryptoDevBackend *backend, CryptoDevBackend *backend,
CryptoDevBackendOpInfo *op_info, CryptoDevBackendOpInfo *op_info)
uint32_t queue_index,
CryptoDevCompletionFunc cb,
void *opaque)
{ {
CryptoDevBackendClass *bc = CryptoDevBackendClass *bc =
CRYPTODEV_BACKEND_GET_CLASS(backend); CRYPTODEV_BACKEND_GET_CLASS(backend);
if (bc->do_op) { if (bc->do_op) {
return bc->do_op(backend, op_info, queue_index, cb, opaque); return bc->do_op(backend, op_info);
} }
return -VIRTIO_CRYPTO_NOTSUPP; return -VIRTIO_CRYPTO_NOTSUPP;
} }
int cryptodev_backend_crypto_operation( int cryptodev_backend_crypto_operation(
CryptoDevBackend *backend, CryptoDevBackend *backend,
void *opaque1, CryptoDevBackendOpInfo *op_info)
uint32_t queue_index,
CryptoDevCompletionFunc cb, void *opaque2)
{ {
VirtIOCryptoReq *req = opaque1; QCryptodevBackendAlgType algtype = op_info->algtype;
CryptoDevBackendOpInfo *op_info = &req->op_info;
QCryptodevBackendAlgType algtype = req->flags;
if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM)
&& (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) {
@ -173,8 +166,7 @@ int cryptodev_backend_crypto_operation(
return -VIRTIO_CRYPTO_NOTSUPP; return -VIRTIO_CRYPTO_NOTSUPP;
} }
return cryptodev_backend_operation(backend, op_info, queue_index, return cryptodev_backend_operation(backend, op_info);
cb, opaque2);
} }
static void static void

View File

@ -871,6 +871,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
opcode = ldl_le_p(&req.header.opcode); opcode = ldl_le_p(&req.header.opcode);
op_info->session_id = ldq_le_p(&req.header.session_id); op_info->session_id = ldq_le_p(&req.header.session_id);
op_info->op_code = opcode; op_info->op_code = opcode;
op_info->queue_index = queue_index;
op_info->cb = virtio_crypto_req_complete;
op_info->opaque = request;
switch (opcode) { switch (opcode) {
case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_ENCRYPT:
@ -898,9 +901,7 @@ check_result:
virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP); virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP);
} else { } else {
ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev, ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev,
request, queue_index, op_info);
virtio_crypto_req_complete,
request);
if (ret < 0) { if (ret < 0) {
virtio_crypto_req_complete(request, ret); virtio_crypto_req_complete(request, ret);
} }

View File

@ -174,9 +174,14 @@ typedef struct CryptoDevBackendAsymOpInfo {
uint8_t *dst; uint8_t *dst;
} CryptoDevBackendAsymOpInfo; } CryptoDevBackendAsymOpInfo;
typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret);
typedef struct CryptoDevBackendOpInfo { typedef struct CryptoDevBackendOpInfo {
QCryptodevBackendAlgType algtype; QCryptodevBackendAlgType algtype;
uint32_t op_code; uint32_t op_code;
uint32_t queue_index;
CryptoDevCompletionFunc cb;
void *opaque; /* argument for cb */
uint64_t session_id; uint64_t session_id;
union { union {
CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendSymOpInfo *sym_op_info;
@ -184,7 +189,6 @@ typedef struct CryptoDevBackendOpInfo {
} u; } u;
} CryptoDevBackendOpInfo; } CryptoDevBackendOpInfo;
typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret);
struct CryptoDevBackendClass { struct CryptoDevBackendClass {
ObjectClass parent_class; ObjectClass parent_class;
@ -204,10 +208,7 @@ struct CryptoDevBackendClass {
void *opaque); void *opaque);
int (*do_op)(CryptoDevBackend *backend, int (*do_op)(CryptoDevBackend *backend,
CryptoDevBackendOpInfo *op_info, CryptoDevBackendOpInfo *op_info);
uint32_t queue_index,
CryptoDevCompletionFunc cb,
void *opaque);
}; };
struct CryptoDevBackendClient { struct CryptoDevBackendClient {
@ -335,24 +336,17 @@ int cryptodev_backend_close_session(
/** /**
* cryptodev_backend_crypto_operation: * cryptodev_backend_crypto_operation:
* @backend: the cryptodev backend object * @backend: the cryptodev backend object
* @opaque1: pointer to a VirtIOCryptoReq object * @op_info: pointer to a CryptoDevBackendOpInfo object
* @queue_index: queue index of cryptodev backend client
* @errp: pointer to a NULL-initialized error object
* @cb: callbacks when operation is completed
* @opaque2: parameter passed to cb
* *
* Do crypto operation, such as encryption and * Do crypto operation, such as encryption, decryption, signature and
* decryption * verification
* *
* Returns: 0 for success and cb will be called when creation is completed, * Returns: 0 for success and cb will be called when creation is completed,
* negative value for error, and cb will not be called. * negative value for error, and cb will not be called.
*/ */
int cryptodev_backend_crypto_operation( int cryptodev_backend_crypto_operation(
CryptoDevBackend *backend, CryptoDevBackend *backend,
void *opaque1, CryptoDevBackendOpInfo *op_info);
uint32_t queue_index,
CryptoDevCompletionFunc cb,
void *opaque2);
/** /**
* cryptodev_backend_set_used: * cryptodev_backend_set_used: