2 * Virtio crypto Support
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
7 * Gonglei <arei.gonglei@huawei.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or
10 * (at your option) any later version. See the COPYING file in the
11 * top-level directory.
14 #include "qemu/osdep.h"
16 #include "qemu/main-loop.h"
17 #include "qemu/module.h"
18 #include "qapi/error.h"
19 #include "qemu/error-report.h"
21 #include "hw/virtio/virtio.h"
22 #include "hw/virtio/virtio-crypto.h"
23 #include "hw/qdev-properties.h"
24 #include "hw/virtio/virtio-access.h"
25 #include "standard-headers/linux/virtio_ids.h"
26 #include "sysemu/cryptodev-vhost.h"
28 #define VIRTIO_CRYPTO_VM_VERSION 1
30 typedef struct VirtIOCryptoSessionReq
{
33 VirtQueueElement
*elem
;
34 CryptoDevBackendSessionInfo info
;
35 CryptoDevCompletionFunc cb
;
36 } VirtIOCryptoSessionReq
;
38 static void virtio_crypto_free_create_session_req(VirtIOCryptoSessionReq
*sreq
)
40 switch (sreq
->info
.op_code
) {
41 case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION
:
42 g_free(sreq
->info
.u
.sym_sess_info
.cipher_key
);
43 g_free(sreq
->info
.u
.sym_sess_info
.auth_key
);
46 case VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION
:
47 g_free(sreq
->info
.u
.asym_sess_info
.key
);
50 case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION
:
51 case VIRTIO_CRYPTO_HASH_DESTROY_SESSION
:
52 case VIRTIO_CRYPTO_MAC_DESTROY_SESSION
:
53 case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION
:
54 case VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION
:
58 error_report("Unknown opcode: %u", sreq
->info
.op_code
);
64 * Transfer virtqueue index to crypto queue index.
65 * The control virtqueue is after the data virtqueues
66 * so the input value doesn't need to be adjusted
68 static inline int virtio_crypto_vq2q(int queue_index
)
74 virtio_crypto_cipher_session_helper(VirtIODevice
*vdev
,
75 CryptoDevBackendSymSessionInfo
*info
,
76 struct virtio_crypto_cipher_session_para
*cipher_para
,
77 struct iovec
**iov
, unsigned int *out_num
)
79 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
80 unsigned int num
= *out_num
;
82 info
->cipher_alg
= ldl_le_p(&cipher_para
->algo
);
83 info
->key_len
= ldl_le_p(&cipher_para
->keylen
);
84 info
->direction
= ldl_le_p(&cipher_para
->op
);
85 DPRINTF("cipher_alg=%" PRIu32
", info->direction=%" PRIu32
"\n",
86 info
->cipher_alg
, info
->direction
);
88 if (info
->key_len
> vcrypto
->conf
.max_cipher_key_len
) {
89 error_report("virtio-crypto length of cipher key is too big: %u",
91 return -VIRTIO_CRYPTO_ERR
;
94 if (info
->key_len
> 0) {
96 DPRINTF("keylen=%" PRIu32
"\n", info
->key_len
);
98 info
->cipher_key
= g_malloc(info
->key_len
);
99 s
= iov_to_buf(*iov
, num
, 0, info
->cipher_key
, info
->key_len
);
100 if (unlikely(s
!= info
->key_len
)) {
101 virtio_error(vdev
, "virtio-crypto cipher key incorrect");
104 iov_discard_front(iov
, &num
, info
->key_len
);
112 virtio_crypto_create_sym_session(VirtIOCrypto
*vcrypto
,
113 struct virtio_crypto_sym_create_session_req
*sess_req
,
116 struct iovec
*iov
, unsigned int out_num
,
117 VirtIOCryptoSessionReq
*sreq
)
119 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
120 CryptoDevBackendSymSessionInfo
*sym_info
= &sreq
->info
.u
.sym_sess_info
;
125 op_type
= ldl_le_p(&sess_req
->op_type
);
126 sreq
->info
.op_code
= opcode
;
128 sym_info
= &sreq
->info
.u
.sym_sess_info
;
129 sym_info
->op_type
= op_type
;
131 if (op_type
== VIRTIO_CRYPTO_SYM_OP_CIPHER
) {
132 ret
= virtio_crypto_cipher_session_helper(vdev
, sym_info
,
133 &sess_req
->u
.cipher
.para
,
138 } else if (op_type
== VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING
) {
141 ret
= virtio_crypto_cipher_session_helper(vdev
, sym_info
,
142 &sess_req
->u
.chain
.para
.cipher_param
,
148 sym_info
->alg_chain_order
= ldl_le_p(
149 &sess_req
->u
.chain
.para
.alg_chain_order
);
150 sym_info
->add_len
= ldl_le_p(&sess_req
->u
.chain
.para
.aad_len
);
151 sym_info
->hash_mode
= ldl_le_p(&sess_req
->u
.chain
.para
.hash_mode
);
152 if (sym_info
->hash_mode
== VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH
) {
154 ldl_le_p(&sess_req
->u
.chain
.para
.u
.mac_param
.algo
);
155 sym_info
->auth_key_len
= ldl_le_p(
156 &sess_req
->u
.chain
.para
.u
.mac_param
.auth_key_len
);
157 sym_info
->hash_result_len
= ldl_le_p(
158 &sess_req
->u
.chain
.para
.u
.mac_param
.hash_result_len
);
159 if (sym_info
->auth_key_len
> vcrypto
->conf
.max_auth_key_len
) {
160 error_report("virtio-crypto length of auth key is too big: %u",
161 sym_info
->auth_key_len
);
162 return -VIRTIO_CRYPTO_ERR
;
165 if (sym_info
->auth_key_len
> 0) {
166 sym_info
->auth_key
= g_malloc(sym_info
->auth_key_len
);
167 s
= iov_to_buf(iov
, out_num
, 0, sym_info
->auth_key
,
168 sym_info
->auth_key_len
);
169 if (unlikely(s
!= sym_info
->auth_key_len
)) {
171 "virtio-crypto authenticated key incorrect");
174 iov_discard_front(&iov
, &out_num
, sym_info
->auth_key_len
);
176 } else if (sym_info
->hash_mode
== VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN
) {
177 sym_info
->hash_alg
= ldl_le_p(
178 &sess_req
->u
.chain
.para
.u
.hash_param
.algo
);
179 sym_info
->hash_result_len
= ldl_le_p(
180 &sess_req
->u
.chain
.para
.u
.hash_param
.hash_result_len
);
182 /* VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED */
183 error_report("unsupported hash mode");
184 return -VIRTIO_CRYPTO_NOTSUPP
;
187 /* VIRTIO_CRYPTO_SYM_OP_NONE */
188 error_report("unsupported cipher op_type: VIRTIO_CRYPTO_SYM_OP_NONE");
189 return -VIRTIO_CRYPTO_NOTSUPP
;
192 queue_index
= virtio_crypto_vq2q(queue_id
);
193 return cryptodev_backend_create_session(vcrypto
->cryptodev
, &sreq
->info
,
194 queue_index
, sreq
->cb
, sreq
);
198 virtio_crypto_create_asym_session(VirtIOCrypto
*vcrypto
,
199 struct virtio_crypto_akcipher_create_session_req
*sess_req
,
200 uint32_t queue_id
, uint32_t opcode
,
201 struct iovec
*iov
, unsigned int out_num
,
202 VirtIOCryptoSessionReq
*sreq
)
204 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
205 CryptoDevBackendAsymSessionInfo
*asym_info
= &sreq
->info
.u
.asym_sess_info
;
207 uint32_t algo
, keytype
, keylen
;
209 algo
= ldl_le_p(&sess_req
->para
.algo
);
210 keytype
= ldl_le_p(&sess_req
->para
.keytype
);
211 keylen
= ldl_le_p(&sess_req
->para
.keylen
);
213 if ((keytype
!= VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC
)
214 && (keytype
!= VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE
)) {
215 error_report("unsupported asym keytype: %d", keytype
);
216 return -VIRTIO_CRYPTO_NOTSUPP
;
220 asym_info
->key
= g_malloc(keylen
);
221 if (iov_to_buf(iov
, out_num
, 0, asym_info
->key
, keylen
) != keylen
) {
222 virtio_error(vdev
, "virtio-crypto asym key incorrect");
225 iov_discard_front(&iov
, &out_num
, keylen
);
228 sreq
->info
.op_code
= opcode
;
229 asym_info
= &sreq
->info
.u
.asym_sess_info
;
230 asym_info
->algo
= algo
;
231 asym_info
->keytype
= keytype
;
232 asym_info
->keylen
= keylen
;
233 switch (asym_info
->algo
) {
234 case VIRTIO_CRYPTO_AKCIPHER_RSA
:
235 asym_info
->u
.rsa
.padding_algo
=
236 ldl_le_p(&sess_req
->para
.u
.rsa
.padding_algo
);
237 asym_info
->u
.rsa
.hash_algo
=
238 ldl_le_p(&sess_req
->para
.u
.rsa
.hash_algo
);
241 /* TODO DSA&ECDSA handling */
244 return -VIRTIO_CRYPTO_ERR
;
247 queue_index
= virtio_crypto_vq2q(queue_id
);
248 return cryptodev_backend_create_session(vcrypto
->cryptodev
, &sreq
->info
,
249 queue_index
, sreq
->cb
, sreq
);
253 virtio_crypto_handle_close_session(VirtIOCrypto
*vcrypto
,
254 struct virtio_crypto_destroy_session_req
*close_sess_req
,
256 VirtIOCryptoSessionReq
*sreq
)
260 session_id
= ldq_le_p(&close_sess_req
->session_id
);
261 DPRINTF("close session, id=%" PRIu64
"\n", session_id
);
263 return cryptodev_backend_close_session(
264 vcrypto
->cryptodev
, session_id
, queue_id
, sreq
->cb
, sreq
);
267 static void virtio_crypto_create_session_completion(void *opaque
, int ret
)
269 VirtIOCryptoSessionReq
*sreq
= (VirtIOCryptoSessionReq
*)opaque
;
270 VirtQueue
*vq
= sreq
->vq
;
271 VirtQueueElement
*elem
= sreq
->elem
;
272 VirtIODevice
*vdev
= sreq
->vdev
;
273 struct virtio_crypto_session_input input
;
274 struct iovec
*in_iov
= elem
->in_sg
;
275 unsigned in_num
= elem
->in_num
;
278 memset(&input
, 0, sizeof(input
));
279 /* Serious errors, need to reset virtio crypto device */
280 if (ret
== -EFAULT
) {
281 virtqueue_detach_element(vq
, elem
, 0);
283 } else if (ret
== -VIRTIO_CRYPTO_NOTSUPP
) {
284 stl_le_p(&input
.status
, VIRTIO_CRYPTO_NOTSUPP
);
285 } else if (ret
== -VIRTIO_CRYPTO_KEY_REJECTED
) {
286 stl_le_p(&input
.status
, VIRTIO_CRYPTO_KEY_REJECTED
);
287 } else if (ret
!= VIRTIO_CRYPTO_OK
) {
288 stl_le_p(&input
.status
, VIRTIO_CRYPTO_ERR
);
290 /* Set the session id */
291 stq_le_p(&input
.session_id
, sreq
->info
.session_id
);
292 stl_le_p(&input
.status
, VIRTIO_CRYPTO_OK
);
295 s
= iov_from_buf(in_iov
, in_num
, 0, &input
, sizeof(input
));
296 if (unlikely(s
!= sizeof(input
))) {
297 virtio_error(vdev
, "virtio-crypto input incorrect");
298 virtqueue_detach_element(vq
, elem
, 0);
301 virtqueue_push(vq
, elem
, sizeof(input
));
302 virtio_notify(vdev
, vq
);
306 virtio_crypto_free_create_session_req(sreq
);
309 static void virtio_crypto_destroy_session_completion(void *opaque
, int ret
)
311 VirtIOCryptoSessionReq
*sreq
= (VirtIOCryptoSessionReq
*)opaque
;
312 VirtQueue
*vq
= sreq
->vq
;
313 VirtQueueElement
*elem
= sreq
->elem
;
314 VirtIODevice
*vdev
= sreq
->vdev
;
315 struct iovec
*in_iov
= elem
->in_sg
;
316 unsigned in_num
= elem
->in_num
;
321 status
= VIRTIO_CRYPTO_ERR
;
323 status
= VIRTIO_CRYPTO_OK
;
325 s
= iov_from_buf(in_iov
, in_num
, 0, &status
, sizeof(status
));
326 if (unlikely(s
!= sizeof(status
))) {
327 virtio_error(vdev
, "virtio-crypto status incorrect");
328 virtqueue_detach_element(vq
, elem
, 0);
331 virtqueue_push(vq
, elem
, sizeof(status
));
332 virtio_notify(vdev
, vq
);
339 static void virtio_crypto_handle_ctrl(VirtIODevice
*vdev
, VirtQueue
*vq
)
341 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
342 struct virtio_crypto_op_ctrl_req ctrl
;
343 VirtQueueElement
*elem
;
344 VirtIOCryptoSessionReq
*sreq
;
349 struct virtio_crypto_session_input input
;
352 struct iovec
*out_iov
;
353 struct iovec
*in_iov
;
356 g_autofree
struct iovec
*out_iov_copy
= NULL
;
358 elem
= virtqueue_pop(vq
, sizeof(VirtQueueElement
));
362 if (elem
->out_num
< 1 || elem
->in_num
< 1) {
363 virtio_error(vdev
, "virtio-crypto ctrl missing headers");
364 virtqueue_detach_element(vq
, elem
, 0);
369 out_num
= elem
->out_num
;
370 out_iov_copy
= g_memdup2(elem
->out_sg
, sizeof(out_iov
[0]) * out_num
);
371 out_iov
= out_iov_copy
;
373 in_num
= elem
->in_num
;
374 in_iov
= elem
->in_sg
;
376 if (unlikely(iov_to_buf(out_iov
, out_num
, 0, &ctrl
, sizeof(ctrl
))
378 virtio_error(vdev
, "virtio-crypto request ctrl_hdr too short");
379 virtqueue_detach_element(vq
, elem
, 0);
383 iov_discard_front(&out_iov
, &out_num
, sizeof(ctrl
));
385 opcode
= ldl_le_p(&ctrl
.header
.opcode
);
386 queue_id
= ldl_le_p(&ctrl
.header
.queue_id
);
388 sreq
= g_new0(VirtIOCryptoSessionReq
, 1);
394 case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION
:
395 sreq
->cb
= virtio_crypto_create_session_completion
;
396 ret
= virtio_crypto_create_sym_session(vcrypto
,
397 &ctrl
.u
.sym_create_session
,
402 virtio_crypto_create_session_completion(sreq
, ret
);
406 case VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION
:
407 sreq
->cb
= virtio_crypto_create_session_completion
;
408 ret
= virtio_crypto_create_asym_session(vcrypto
,
409 &ctrl
.u
.akcipher_create_session
,
414 virtio_crypto_create_session_completion(sreq
, ret
);
418 case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION
:
419 case VIRTIO_CRYPTO_HASH_DESTROY_SESSION
:
420 case VIRTIO_CRYPTO_MAC_DESTROY_SESSION
:
421 case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION
:
422 case VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION
:
423 sreq
->cb
= virtio_crypto_destroy_session_completion
;
424 ret
= virtio_crypto_handle_close_session(vcrypto
,
425 &ctrl
.u
.destroy_session
, queue_id
,
428 virtio_crypto_destroy_session_completion(sreq
, ret
);
432 case VIRTIO_CRYPTO_HASH_CREATE_SESSION
:
433 case VIRTIO_CRYPTO_MAC_CREATE_SESSION
:
434 case VIRTIO_CRYPTO_AEAD_CREATE_SESSION
:
436 memset(&input
, 0, sizeof(input
));
437 error_report("virtio-crypto unsupported ctrl opcode: %d", opcode
);
438 stl_le_p(&input
.status
, VIRTIO_CRYPTO_NOTSUPP
);
439 s
= iov_from_buf(in_iov
, in_num
, 0, &input
, sizeof(input
));
440 if (unlikely(s
!= sizeof(input
))) {
441 virtio_error(vdev
, "virtio-crypto input incorrect");
442 virtqueue_detach_element(vq
, elem
, 0);
444 virtqueue_push(vq
, elem
, sizeof(input
));
445 virtio_notify(vdev
, vq
);
451 } /* end switch case */
456 static void virtio_crypto_init_request(VirtIOCrypto
*vcrypto
, VirtQueue
*vq
,
457 VirtIOCryptoReq
*req
)
459 req
->vcrypto
= vcrypto
;
465 req
->flags
= CRYPTODEV_BACKEND_ALG__MAX
;
466 memset(&req
->op_info
, 0x00, sizeof(req
->op_info
));
469 static void virtio_crypto_free_request(VirtIOCryptoReq
*req
)
475 if (req
->flags
== CRYPTODEV_BACKEND_ALG_SYM
) {
477 CryptoDevBackendSymOpInfo
*op_info
= req
->op_info
.u
.sym_op_info
;
479 max_len
= op_info
->iv_len
+
483 op_info
->digest_result_len
;
485 /* Zeroize and free request data structure */
486 memset(op_info
, 0, sizeof(*op_info
) + max_len
);
488 } else if (req
->flags
== CRYPTODEV_BACKEND_ALG_ASYM
) {
489 CryptoDevBackendAsymOpInfo
*op_info
= req
->op_info
.u
.asym_op_info
;
491 g_free(op_info
->src
);
492 g_free(op_info
->dst
);
493 memset(op_info
, 0, sizeof(*op_info
));
503 virtio_crypto_sym_input_data_helper(VirtIODevice
*vdev
,
504 VirtIOCryptoReq
*req
,
506 CryptoDevBackendSymOpInfo
*sym_op_info
)
509 struct iovec
*in_iov
= req
->in_iov
;
511 if (status
!= VIRTIO_CRYPTO_OK
) {
515 len
= sym_op_info
->src_len
;
516 /* Save the cipher result */
517 s
= iov_from_buf(in_iov
, req
->in_num
, 0, sym_op_info
->dst
, len
);
519 virtio_error(vdev
, "virtio-crypto dest data incorrect");
523 iov_discard_front(&in_iov
, &req
->in_num
, len
);
525 if (sym_op_info
->op_type
==
526 VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING
) {
527 /* Save the digest result */
528 s
= iov_from_buf(in_iov
, req
->in_num
, 0,
529 sym_op_info
->digest_result
,
530 sym_op_info
->digest_result_len
);
531 if (s
!= sym_op_info
->digest_result_len
) {
532 virtio_error(vdev
, "virtio-crypto digest result incorrect");
538 virtio_crypto_akcipher_input_data_helper(VirtIODevice
*vdev
,
539 VirtIOCryptoReq
*req
, int32_t status
,
540 CryptoDevBackendAsymOpInfo
*asym_op_info
)
543 struct iovec
*in_iov
= req
->in_iov
;
545 if (status
!= VIRTIO_CRYPTO_OK
) {
549 len
= asym_op_info
->dst_len
;
554 s
= iov_from_buf(in_iov
, req
->in_num
, 0, asym_op_info
->dst
, len
);
556 virtio_error(vdev
, "virtio-crypto asym dest data incorrect");
560 iov_discard_front(&in_iov
, &req
->in_num
, len
);
562 /* For akcipher, dst_len may be changed after operation */
563 req
->in_len
= sizeof(struct virtio_crypto_inhdr
) + asym_op_info
->dst_len
;
566 static void virtio_crypto_req_complete(void *opaque
, int ret
)
568 VirtIOCryptoReq
*req
= (VirtIOCryptoReq
*)opaque
;
569 VirtIOCrypto
*vcrypto
= req
->vcrypto
;
570 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
571 uint8_t status
= -ret
;
573 if (req
->flags
== CRYPTODEV_BACKEND_ALG_SYM
) {
574 virtio_crypto_sym_input_data_helper(vdev
, req
, status
,
575 req
->op_info
.u
.sym_op_info
);
576 } else if (req
->flags
== CRYPTODEV_BACKEND_ALG_ASYM
) {
577 virtio_crypto_akcipher_input_data_helper(vdev
, req
, status
,
578 req
->op_info
.u
.asym_op_info
);
580 stb_p(&req
->in
->status
, status
);
581 virtqueue_push(req
->vq
, &req
->elem
, req
->in_len
);
582 virtio_notify(vdev
, req
->vq
);
583 virtio_crypto_free_request(req
);
586 static VirtIOCryptoReq
*
587 virtio_crypto_get_request(VirtIOCrypto
*s
, VirtQueue
*vq
)
589 VirtIOCryptoReq
*req
= virtqueue_pop(vq
, sizeof(VirtIOCryptoReq
));
592 virtio_crypto_init_request(s
, vq
, req
);
597 static CryptoDevBackendSymOpInfo
*
598 virtio_crypto_sym_op_helper(VirtIODevice
*vdev
,
599 struct virtio_crypto_cipher_para
*cipher_para
,
600 struct virtio_crypto_alg_chain_data_para
*alg_chain_para
,
601 struct iovec
*iov
, unsigned int out_num
)
603 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
604 CryptoDevBackendSymOpInfo
*op_info
;
605 uint32_t src_len
= 0, dst_len
= 0;
607 uint32_t aad_len
= 0, hash_result_len
= 0;
608 uint32_t hash_start_src_offset
= 0, len_to_hash
= 0;
609 uint32_t cipher_start_src_offset
= 0, len_to_cipher
= 0;
611 uint64_t max_len
, curr_size
= 0;
616 iv_len
= ldl_le_p(&cipher_para
->iv_len
);
617 src_len
= ldl_le_p(&cipher_para
->src_data_len
);
618 dst_len
= ldl_le_p(&cipher_para
->dst_data_len
);
619 } else if (alg_chain_para
) { /* Algorithm chain */
620 iv_len
= ldl_le_p(&alg_chain_para
->iv_len
);
621 src_len
= ldl_le_p(&alg_chain_para
->src_data_len
);
622 dst_len
= ldl_le_p(&alg_chain_para
->dst_data_len
);
624 aad_len
= ldl_le_p(&alg_chain_para
->aad_len
);
625 hash_result_len
= ldl_le_p(&alg_chain_para
->hash_result_len
);
626 hash_start_src_offset
= ldl_le_p(
627 &alg_chain_para
->hash_start_src_offset
);
628 cipher_start_src_offset
= ldl_le_p(
629 &alg_chain_para
->cipher_start_src_offset
);
630 len_to_cipher
= ldl_le_p(&alg_chain_para
->len_to_cipher
);
631 len_to_hash
= ldl_le_p(&alg_chain_para
->len_to_hash
);
636 max_len
= (uint64_t)iv_len
+ aad_len
+ src_len
+ dst_len
+ hash_result_len
;
637 if (unlikely(max_len
> vcrypto
->conf
.max_size
)) {
638 virtio_error(vdev
, "virtio-crypto too big length");
642 op_info
= g_malloc0(sizeof(CryptoDevBackendSymOpInfo
) + max_len
);
643 op_info
->iv_len
= iv_len
;
644 op_info
->src_len
= src_len
;
645 op_info
->dst_len
= dst_len
;
646 op_info
->aad_len
= aad_len
;
647 op_info
->digest_result_len
= hash_result_len
;
648 op_info
->hash_start_src_offset
= hash_start_src_offset
;
649 op_info
->len_to_hash
= len_to_hash
;
650 op_info
->cipher_start_src_offset
= cipher_start_src_offset
;
651 op_info
->len_to_cipher
= len_to_cipher
;
652 /* Handle the initilization vector */
653 if (op_info
->iv_len
> 0) {
654 DPRINTF("iv_len=%" PRIu32
"\n", op_info
->iv_len
);
655 op_info
->iv
= op_info
->data
+ curr_size
;
657 s
= iov_to_buf(iov
, out_num
, 0, op_info
->iv
, op_info
->iv_len
);
658 if (unlikely(s
!= op_info
->iv_len
)) {
659 virtio_error(vdev
, "virtio-crypto iv incorrect");
662 iov_discard_front(&iov
, &out_num
, op_info
->iv_len
);
663 curr_size
+= op_info
->iv_len
;
666 /* Handle additional authentication data if exists */
667 if (op_info
->aad_len
> 0) {
668 DPRINTF("aad_len=%" PRIu32
"\n", op_info
->aad_len
);
669 op_info
->aad_data
= op_info
->data
+ curr_size
;
671 s
= iov_to_buf(iov
, out_num
, 0, op_info
->aad_data
, op_info
->aad_len
);
672 if (unlikely(s
!= op_info
->aad_len
)) {
673 virtio_error(vdev
, "virtio-crypto additional auth data incorrect");
676 iov_discard_front(&iov
, &out_num
, op_info
->aad_len
);
678 curr_size
+= op_info
->aad_len
;
681 /* Handle the source data */
682 if (op_info
->src_len
> 0) {
683 DPRINTF("src_len=%" PRIu32
"\n", op_info
->src_len
);
684 op_info
->src
= op_info
->data
+ curr_size
;
686 s
= iov_to_buf(iov
, out_num
, 0, op_info
->src
, op_info
->src_len
);
687 if (unlikely(s
!= op_info
->src_len
)) {
688 virtio_error(vdev
, "virtio-crypto source data incorrect");
691 iov_discard_front(&iov
, &out_num
, op_info
->src_len
);
693 curr_size
+= op_info
->src_len
;
696 /* Handle the destination data */
697 op_info
->dst
= op_info
->data
+ curr_size
;
698 curr_size
+= op_info
->dst_len
;
700 DPRINTF("dst_len=%" PRIu32
"\n", op_info
->dst_len
);
702 /* Handle the hash digest result */
703 if (hash_result_len
> 0) {
704 DPRINTF("hash_result_len=%" PRIu32
"\n", hash_result_len
);
705 op_info
->digest_result
= op_info
->data
+ curr_size
;
716 virtio_crypto_handle_sym_req(VirtIOCrypto
*vcrypto
,
717 struct virtio_crypto_sym_data_req
*req
,
718 CryptoDevBackendOpInfo
*op_info
,
719 struct iovec
*iov
, unsigned int out_num
)
721 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
722 CryptoDevBackendSymOpInfo
*sym_op_info
;
725 op_type
= ldl_le_p(&req
->op_type
);
726 if (op_type
== VIRTIO_CRYPTO_SYM_OP_CIPHER
) {
727 sym_op_info
= virtio_crypto_sym_op_helper(vdev
, &req
->u
.cipher
.para
,
732 } else if (op_type
== VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING
) {
733 sym_op_info
= virtio_crypto_sym_op_helper(vdev
, NULL
,
740 /* VIRTIO_CRYPTO_SYM_OP_NONE */
741 error_report("virtio-crypto unsupported cipher type");
742 return -VIRTIO_CRYPTO_NOTSUPP
;
745 sym_op_info
->op_type
= op_type
;
746 op_info
->u
.sym_op_info
= sym_op_info
;
752 virtio_crypto_handle_asym_req(VirtIOCrypto
*vcrypto
,
753 struct virtio_crypto_akcipher_data_req
*req
,
754 CryptoDevBackendOpInfo
*op_info
,
755 struct iovec
*iov
, unsigned int out_num
)
757 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
758 CryptoDevBackendAsymOpInfo
*asym_op_info
;
765 asym_op_info
= g_new0(CryptoDevBackendAsymOpInfo
, 1);
766 src_len
= ldl_le_p(&req
->para
.src_data_len
);
767 dst_len
= ldl_le_p(&req
->para
.dst_data_len
);
770 src
= g_malloc0(src_len
);
771 len
= iov_to_buf(iov
, out_num
, 0, src
, src_len
);
772 if (unlikely(len
!= src_len
)) {
773 virtio_error(vdev
, "virtio-crypto asym src data incorrect"
774 "expected %u, actual %u", src_len
, len
);
778 iov_discard_front(&iov
, &out_num
, src_len
);
782 dst
= g_malloc0(dst_len
);
784 if (op_info
->op_code
== VIRTIO_CRYPTO_AKCIPHER_VERIFY
) {
785 len
= iov_to_buf(iov
, out_num
, 0, dst
, dst_len
);
786 if (unlikely(len
!= dst_len
)) {
787 virtio_error(vdev
, "virtio-crypto asym dst data incorrect"
788 "expected %u, actual %u", dst_len
, len
);
792 iov_discard_front(&iov
, &out_num
, dst_len
);
796 asym_op_info
->src_len
= src_len
;
797 asym_op_info
->dst_len
= dst_len
;
798 asym_op_info
->src
= src
;
799 asym_op_info
->dst
= dst
;
800 op_info
->u
.asym_op_info
= asym_op_info
;
805 g_free(asym_op_info
);
813 virtio_crypto_handle_request(VirtIOCryptoReq
*request
)
815 VirtIOCrypto
*vcrypto
= request
->vcrypto
;
816 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
817 VirtQueueElement
*elem
= &request
->elem
;
818 int queue_index
= virtio_crypto_vq2q(virtio_get_queue_index(request
->vq
));
819 struct virtio_crypto_op_data_req req
;
821 g_autofree
struct iovec
*in_iov_copy
= NULL
;
822 g_autofree
struct iovec
*out_iov_copy
= NULL
;
823 struct iovec
*in_iov
;
824 struct iovec
*out_iov
;
828 CryptoDevBackendOpInfo
*op_info
= &request
->op_info
;
830 if (elem
->out_num
< 1 || elem
->in_num
< 1) {
831 virtio_error(vdev
, "virtio-crypto dataq missing headers");
835 out_num
= elem
->out_num
;
836 out_iov_copy
= g_memdup2(elem
->out_sg
, sizeof(out_iov
[0]) * out_num
);
837 out_iov
= out_iov_copy
;
839 in_num
= elem
->in_num
;
840 in_iov_copy
= g_memdup2(elem
->in_sg
, sizeof(in_iov
[0]) * in_num
);
841 in_iov
= in_iov_copy
;
843 if (unlikely(iov_to_buf(out_iov
, out_num
, 0, &req
, sizeof(req
))
845 virtio_error(vdev
, "virtio-crypto request outhdr too short");
848 iov_discard_front(&out_iov
, &out_num
, sizeof(req
));
850 if (in_iov
[in_num
- 1].iov_len
<
851 sizeof(struct virtio_crypto_inhdr
)) {
852 virtio_error(vdev
, "virtio-crypto request inhdr too short");
855 /* We always touch the last byte, so just see how big in_iov is. */
856 request
->in_len
= iov_size(in_iov
, in_num
);
857 request
->in
= (void *)in_iov
[in_num
- 1].iov_base
858 + in_iov
[in_num
- 1].iov_len
859 - sizeof(struct virtio_crypto_inhdr
);
860 iov_discard_back(in_iov
, &in_num
, sizeof(struct virtio_crypto_inhdr
));
863 * The length of operation result, including dest_data
864 * and digest_result if exists.
866 request
->in_num
= in_num
;
867 request
->in_iov
= in_iov
;
868 /* now, we free the in_iov_copy inside virtio_crypto_free_request */
871 opcode
= ldl_le_p(&req
.header
.opcode
);
872 op_info
->session_id
= ldq_le_p(&req
.header
.session_id
);
873 op_info
->op_code
= opcode
;
876 case VIRTIO_CRYPTO_CIPHER_ENCRYPT
:
877 case VIRTIO_CRYPTO_CIPHER_DECRYPT
:
878 op_info
->algtype
= request
->flags
= CRYPTODEV_BACKEND_ALG_SYM
;
879 ret
= virtio_crypto_handle_sym_req(vcrypto
,
880 &req
.u
.sym_req
, op_info
,
884 case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT
:
885 case VIRTIO_CRYPTO_AKCIPHER_DECRYPT
:
886 case VIRTIO_CRYPTO_AKCIPHER_SIGN
:
887 case VIRTIO_CRYPTO_AKCIPHER_VERIFY
:
888 op_info
->algtype
= request
->flags
= CRYPTODEV_BACKEND_ALG_ASYM
;
889 ret
= virtio_crypto_handle_asym_req(vcrypto
,
890 &req
.u
.akcipher_req
, op_info
,
894 /* Serious errors, need to reset virtio crypto device */
895 if (ret
== -EFAULT
) {
897 } else if (ret
== -VIRTIO_CRYPTO_NOTSUPP
) {
898 virtio_crypto_req_complete(request
, -VIRTIO_CRYPTO_NOTSUPP
);
900 ret
= cryptodev_backend_crypto_operation(vcrypto
->cryptodev
,
901 request
, queue_index
,
902 virtio_crypto_req_complete
,
905 virtio_crypto_req_complete(request
, ret
);
910 case VIRTIO_CRYPTO_HASH
:
911 case VIRTIO_CRYPTO_MAC
:
912 case VIRTIO_CRYPTO_AEAD_ENCRYPT
:
913 case VIRTIO_CRYPTO_AEAD_DECRYPT
:
915 error_report("virtio-crypto unsupported dataq opcode: %u",
917 virtio_crypto_req_complete(request
, -VIRTIO_CRYPTO_NOTSUPP
);
923 static void virtio_crypto_handle_dataq(VirtIODevice
*vdev
, VirtQueue
*vq
)
925 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
926 VirtIOCryptoReq
*req
;
928 while ((req
= virtio_crypto_get_request(vcrypto
, vq
))) {
929 if (virtio_crypto_handle_request(req
) < 0) {
930 virtqueue_detach_element(req
->vq
, &req
->elem
, 0);
931 virtio_crypto_free_request(req
);
937 static void virtio_crypto_dataq_bh(void *opaque
)
939 VirtIOCryptoQueue
*q
= opaque
;
940 VirtIOCrypto
*vcrypto
= q
->vcrypto
;
941 VirtIODevice
*vdev
= VIRTIO_DEVICE(vcrypto
);
943 /* This happens when device was stopped but BH wasn't. */
944 if (!vdev
->vm_running
) {
948 /* Just in case the driver is not ready on more */
949 if (unlikely(!(vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
))) {
954 virtio_crypto_handle_dataq(vdev
, q
->dataq
);
955 virtio_queue_set_notification(q
->dataq
, 1);
957 /* Are we done or did the guest add more buffers? */
958 if (virtio_queue_empty(q
->dataq
)) {
962 virtio_queue_set_notification(q
->dataq
, 0);
967 virtio_crypto_handle_dataq_bh(VirtIODevice
*vdev
, VirtQueue
*vq
)
969 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
970 VirtIOCryptoQueue
*q
=
971 &vcrypto
->vqs
[virtio_crypto_vq2q(virtio_get_queue_index(vq
))];
973 /* This happens when device was stopped but VCPU wasn't. */
974 if (!vdev
->vm_running
) {
977 virtio_queue_set_notification(vq
, 0);
978 qemu_bh_schedule(q
->dataq_bh
);
981 static uint64_t virtio_crypto_get_features(VirtIODevice
*vdev
,
988 static void virtio_crypto_reset(VirtIODevice
*vdev
)
990 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
991 /* multiqueue is disabled by default */
992 vcrypto
->curr_queues
= 1;
993 if (!cryptodev_backend_is_ready(vcrypto
->cryptodev
)) {
994 vcrypto
->status
&= ~VIRTIO_CRYPTO_S_HW_READY
;
996 vcrypto
->status
|= VIRTIO_CRYPTO_S_HW_READY
;
1000 static void virtio_crypto_init_config(VirtIODevice
*vdev
)
1002 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
1004 vcrypto
->conf
.crypto_services
=
1005 vcrypto
->conf
.cryptodev
->conf
.crypto_services
;
1006 vcrypto
->conf
.cipher_algo_l
=
1007 vcrypto
->conf
.cryptodev
->conf
.cipher_algo_l
;
1008 vcrypto
->conf
.cipher_algo_h
=
1009 vcrypto
->conf
.cryptodev
->conf
.cipher_algo_h
;
1010 vcrypto
->conf
.hash_algo
= vcrypto
->conf
.cryptodev
->conf
.hash_algo
;
1011 vcrypto
->conf
.mac_algo_l
= vcrypto
->conf
.cryptodev
->conf
.mac_algo_l
;
1012 vcrypto
->conf
.mac_algo_h
= vcrypto
->conf
.cryptodev
->conf
.mac_algo_h
;
1013 vcrypto
->conf
.aead_algo
= vcrypto
->conf
.cryptodev
->conf
.aead_algo
;
1014 vcrypto
->conf
.akcipher_algo
= vcrypto
->conf
.cryptodev
->conf
.akcipher_algo
;
1015 vcrypto
->conf
.max_cipher_key_len
=
1016 vcrypto
->conf
.cryptodev
->conf
.max_cipher_key_len
;
1017 vcrypto
->conf
.max_auth_key_len
=
1018 vcrypto
->conf
.cryptodev
->conf
.max_auth_key_len
;
1019 vcrypto
->conf
.max_size
= vcrypto
->conf
.cryptodev
->conf
.max_size
;
1022 static void virtio_crypto_device_realize(DeviceState
*dev
, Error
**errp
)
1024 VirtIODevice
*vdev
= VIRTIO_DEVICE(dev
);
1025 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(dev
);
1028 vcrypto
->cryptodev
= vcrypto
->conf
.cryptodev
;
1029 if (vcrypto
->cryptodev
== NULL
) {
1030 error_setg(errp
, "'cryptodev' parameter expects a valid object");
1032 } else if (cryptodev_backend_is_used(vcrypto
->cryptodev
)) {
1033 error_setg(errp
, "can't use already used cryptodev backend: %s",
1034 object_get_canonical_path_component(OBJECT(vcrypto
->conf
.cryptodev
)));
1038 vcrypto
->max_queues
= MAX(vcrypto
->cryptodev
->conf
.peers
.queues
, 1);
1039 if (vcrypto
->max_queues
+ 1 > VIRTIO_QUEUE_MAX
) {
1040 error_setg(errp
, "Invalid number of queues (= %" PRIu32
"), "
1041 "must be a positive integer less than %d.",
1042 vcrypto
->max_queues
, VIRTIO_QUEUE_MAX
);
1046 virtio_init(vdev
, VIRTIO_ID_CRYPTO
, vcrypto
->config_size
);
1047 vcrypto
->curr_queues
= 1;
1048 vcrypto
->vqs
= g_new0(VirtIOCryptoQueue
, vcrypto
->max_queues
);
1049 for (i
= 0; i
< vcrypto
->max_queues
; i
++) {
1050 vcrypto
->vqs
[i
].dataq
=
1051 virtio_add_queue(vdev
, 1024, virtio_crypto_handle_dataq_bh
);
1052 vcrypto
->vqs
[i
].dataq_bh
=
1053 qemu_bh_new(virtio_crypto_dataq_bh
, &vcrypto
->vqs
[i
]);
1054 vcrypto
->vqs
[i
].vcrypto
= vcrypto
;
1057 vcrypto
->ctrl_vq
= virtio_add_queue(vdev
, 1024, virtio_crypto_handle_ctrl
);
1058 if (!cryptodev_backend_is_ready(vcrypto
->cryptodev
)) {
1059 vcrypto
->status
&= ~VIRTIO_CRYPTO_S_HW_READY
;
1061 vcrypto
->status
|= VIRTIO_CRYPTO_S_HW_READY
;
1064 virtio_crypto_init_config(vdev
);
1065 cryptodev_backend_set_used(vcrypto
->cryptodev
, true);
1068 static void virtio_crypto_device_unrealize(DeviceState
*dev
)
1070 VirtIODevice
*vdev
= VIRTIO_DEVICE(dev
);
1071 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(dev
);
1072 VirtIOCryptoQueue
*q
;
1075 max_queues
= vcrypto
->multiqueue
? vcrypto
->max_queues
: 1;
1076 for (i
= 0; i
< max_queues
; i
++) {
1077 virtio_delete_queue(vcrypto
->vqs
[i
].dataq
);
1078 q
= &vcrypto
->vqs
[i
];
1079 qemu_bh_delete(q
->dataq_bh
);
1082 g_free(vcrypto
->vqs
);
1083 virtio_delete_queue(vcrypto
->ctrl_vq
);
1085 virtio_cleanup(vdev
);
1086 cryptodev_backend_set_used(vcrypto
->cryptodev
, false);
1089 static const VMStateDescription vmstate_virtio_crypto
= {
1090 .name
= "virtio-crypto",
1092 .minimum_version_id
= VIRTIO_CRYPTO_VM_VERSION
,
1093 .version_id
= VIRTIO_CRYPTO_VM_VERSION
,
1094 .fields
= (VMStateField
[]) {
1095 VMSTATE_VIRTIO_DEVICE
,
1096 VMSTATE_END_OF_LIST()
1100 static Property virtio_crypto_properties
[] = {
1101 DEFINE_PROP_LINK("cryptodev", VirtIOCrypto
, conf
.cryptodev
,
1102 TYPE_CRYPTODEV_BACKEND
, CryptoDevBackend
*),
1103 DEFINE_PROP_END_OF_LIST(),
1106 static void virtio_crypto_get_config(VirtIODevice
*vdev
, uint8_t *config
)
1108 VirtIOCrypto
*c
= VIRTIO_CRYPTO(vdev
);
1109 struct virtio_crypto_config crypto_cfg
= {};
1112 * Virtio-crypto device conforms to VIRTIO 1.0 which is always LE,
1113 * so we can use LE accessors directly.
1115 stl_le_p(&crypto_cfg
.status
, c
->status
);
1116 stl_le_p(&crypto_cfg
.max_dataqueues
, c
->max_queues
);
1117 stl_le_p(&crypto_cfg
.crypto_services
, c
->conf
.crypto_services
);
1118 stl_le_p(&crypto_cfg
.cipher_algo_l
, c
->conf
.cipher_algo_l
);
1119 stl_le_p(&crypto_cfg
.cipher_algo_h
, c
->conf
.cipher_algo_h
);
1120 stl_le_p(&crypto_cfg
.hash_algo
, c
->conf
.hash_algo
);
1121 stl_le_p(&crypto_cfg
.mac_algo_l
, c
->conf
.mac_algo_l
);
1122 stl_le_p(&crypto_cfg
.mac_algo_h
, c
->conf
.mac_algo_h
);
1123 stl_le_p(&crypto_cfg
.aead_algo
, c
->conf
.aead_algo
);
1124 stl_le_p(&crypto_cfg
.max_cipher_key_len
, c
->conf
.max_cipher_key_len
);
1125 stl_le_p(&crypto_cfg
.max_auth_key_len
, c
->conf
.max_auth_key_len
);
1126 stq_le_p(&crypto_cfg
.max_size
, c
->conf
.max_size
);
1127 stl_le_p(&crypto_cfg
.akcipher_algo
, c
->conf
.akcipher_algo
);
1129 memcpy(config
, &crypto_cfg
, c
->config_size
);
1132 static bool virtio_crypto_started(VirtIOCrypto
*c
, uint8_t status
)
1134 VirtIODevice
*vdev
= VIRTIO_DEVICE(c
);
1135 return (status
& VIRTIO_CONFIG_S_DRIVER_OK
) &&
1136 (c
->status
& VIRTIO_CRYPTO_S_HW_READY
) && vdev
->vm_running
;
1139 static void virtio_crypto_vhost_status(VirtIOCrypto
*c
, uint8_t status
)
1141 VirtIODevice
*vdev
= VIRTIO_DEVICE(c
);
1142 int queues
= c
->multiqueue
? c
->max_queues
: 1;
1143 CryptoDevBackend
*b
= c
->cryptodev
;
1144 CryptoDevBackendClient
*cc
= b
->conf
.peers
.ccs
[0];
1146 if (!cryptodev_get_vhost(cc
, b
, 0)) {
1150 if ((virtio_crypto_started(c
, status
)) == !!c
->vhost_started
) {
1154 if (!c
->vhost_started
) {
1157 c
->vhost_started
= 1;
1158 r
= cryptodev_vhost_start(vdev
, queues
);
1160 error_report("unable to start vhost crypto: %d: "
1161 "falling back on userspace virtio", -r
);
1162 c
->vhost_started
= 0;
1165 cryptodev_vhost_stop(vdev
, queues
);
1166 c
->vhost_started
= 0;
1170 static void virtio_crypto_set_status(VirtIODevice
*vdev
, uint8_t status
)
1172 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
1174 virtio_crypto_vhost_status(vcrypto
, status
);
1177 static void virtio_crypto_guest_notifier_mask(VirtIODevice
*vdev
, int idx
,
1180 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
1181 int queue
= virtio_crypto_vq2q(idx
);
1183 assert(vcrypto
->vhost_started
);
1185 cryptodev_vhost_virtqueue_mask(vdev
, queue
, idx
, mask
);
1188 static bool virtio_crypto_guest_notifier_pending(VirtIODevice
*vdev
, int idx
)
1190 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
1191 int queue
= virtio_crypto_vq2q(idx
);
1193 assert(vcrypto
->vhost_started
);
1195 return cryptodev_vhost_virtqueue_pending(vdev
, queue
, idx
);
1198 static struct vhost_dev
*virtio_crypto_get_vhost(VirtIODevice
*vdev
)
1200 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(vdev
);
1201 CryptoDevBackend
*b
= vcrypto
->cryptodev
;
1202 CryptoDevBackendClient
*cc
= b
->conf
.peers
.ccs
[0];
1203 CryptoDevBackendVhost
*vhost_crypto
= cryptodev_get_vhost(cc
, b
, 0);
1204 return &vhost_crypto
->dev
;
1207 static void virtio_crypto_class_init(ObjectClass
*klass
, void *data
)
1209 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1210 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_CLASS(klass
);
1212 device_class_set_props(dc
, virtio_crypto_properties
);
1213 dc
->vmsd
= &vmstate_virtio_crypto
;
1214 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1215 vdc
->realize
= virtio_crypto_device_realize
;
1216 vdc
->unrealize
= virtio_crypto_device_unrealize
;
1217 vdc
->get_config
= virtio_crypto_get_config
;
1218 vdc
->get_features
= virtio_crypto_get_features
;
1219 vdc
->reset
= virtio_crypto_reset
;
1220 vdc
->set_status
= virtio_crypto_set_status
;
1221 vdc
->guest_notifier_mask
= virtio_crypto_guest_notifier_mask
;
1222 vdc
->guest_notifier_pending
= virtio_crypto_guest_notifier_pending
;
1223 vdc
->get_vhost
= virtio_crypto_get_vhost
;
1226 static void virtio_crypto_instance_init(Object
*obj
)
1228 VirtIOCrypto
*vcrypto
= VIRTIO_CRYPTO(obj
);
1231 * The default config_size is sizeof(struct virtio_crypto_config).
1232 * Can be overriden with virtio_crypto_set_config_size.
1234 vcrypto
->config_size
= sizeof(struct virtio_crypto_config
);
1237 static const TypeInfo virtio_crypto_info
= {
1238 .name
= TYPE_VIRTIO_CRYPTO
,
1239 .parent
= TYPE_VIRTIO_DEVICE
,
1240 .instance_size
= sizeof(VirtIOCrypto
),
1241 .instance_init
= virtio_crypto_instance_init
,
1242 .class_init
= virtio_crypto_class_init
,
1245 static void virtio_register_types(void)
1247 type_register_static(&virtio_crypto_info
);
1250 type_init(virtio_register_types
)